name:
src/test/java/io/protobase/f7/formulas/math/ACOTTest.java
-rw-r--r--
2175
1package io.protobase.f7.formulas.math;
2
3import io.protobase.f7.errors.NAException;
4import io.protobase.f7.errors.ValueException;
5import io.protobase.f7.models.Grid;
6import io.protobase.f7.testutils.TestFormula;
7import org.junit.Test;
8
9import static com.google.common.truth.Truth.assertThat;
10import static org.mockito.Mockito.verify;
11import static org.mockito.Mockito.verifyNoMoreInteractions;
12import static org.mockito.Mockito.when;
13
14public class ACOTTest extends TestFormula {
15 @Test
16 public void testApply() {
17 assertThat(ACOT.SELF.apply(null, 10.0)).isEqualTo(0.09966865249116204);
18 assertThat(ACOT.SELF.apply(null, 128731.2)).isEqualTo(7.768124588133144E-6);
19 assertThat(ACOT.SELF.apply(null, 11.11)).isEqualTo(0.08976710276137885);
20 assertThat(ACOT.SELF.apply(null, 0.0)).isEqualTo(1.570796327);
21 assertThat(ACOT.SELF.apply(null, 88281.0)).isEqualTo(1.1327465705613094E-5);
22 assertThat(ACOT.SELF.apply(null, 2.0)).isEqualTo(0.4636476090008061);
23 assertThat(ACOT.SELF.apply(null, 4.0)).isEqualTo(0.24497866312686414);
24 assertThat(ACOT.SELF.apply(null, -4.0)).isEqualTo(-0.24497866312686414);
25 assertThat(ACOT.SELF.apply(null, -10124.0)).isEqualTo(-9.877518735162196E-5);
26 }
27
28 @Test
29 public void testApply_stringConversion() {
30 assertThat(ACOT.SELF.apply(null, "88281")).isEqualTo(1.1327465705613094E-5);
31 }
32
33 @Test
34 public void testApply_grid() {
35 assertThat(ACOT.SELF.apply(null,
36 Grid.builder().add(0, 0, 88281.0).add(0, 1, "Don't mind me.").build()
37 )).isEqualTo(1.1327465705613094E-5);
38 }
39
40 @Test
41 public void test_lookup() {
42 ACOT F = new ACOT(lookup, collateralLookup);
43 when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(10.0);
44 assertThat(F.apply(A1, M22_RANGE)).isEqualTo(0.09966865249116204);
45 verify(collateralLookup).apply(A1, M22_RANGE);
46 verifyNoMoreInteractions(collateralLookup);
47 }
48
49 @Test
50 public void testApply_errorsPassThrough() {
51 assertThat(ACOT.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
52 }
53
54 @Test
55 public void testApply_argumentsMismatch() {
56 assertThat(ACOT.SELF.apply(null, "A", "Too many")).isEqualTo(new NAException());
57 }
58}