f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/test/java/io/protobase/f7/formulas/statistical/MAXATest.java
-rw-r--r--
2795
 1package io.protobase.f7.formulas.statistical;
 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 MAXATest extends TestFormula {
15
16
17  @Test
18  public void testApply_normal() {
19    assertThat(MAXA.SELF.apply(null, 1.0, 2.0, 3.0)).isEqualTo(3.0);
20    assertThat(MAXA.SELF.apply(null, 3.0, 1.0, 2.0)).isEqualTo(3.0);
21    assertThat(MAXA.SELF.apply(null, 3.0, 2.0, 1.0)).isEqualTo(3.0);
22    assertThat(MAXA.SELF.apply(null, 0.0)).isEqualTo(0.0);
23    assertThat(MAXA.SELF.apply(null, 0.0, -1000.0, -0.0111)).isEqualTo(0.0);
24    assertThat(MAXA.SELF.apply(null, 261822.0, 991741987.1, 1991.0e2)).isEqualTo(991741987.1);
25  }
26
27  @Test
28  public void testApply_keyDifferenceWithMAXA() {
29    Grid<Object> grid = Grid.builder()
30        .add(0, 0, -11.0)
31        .add(0, 1, "100") // In both MAX and MAXA this is converted to 0.
32        .add(0, 2, -2.0)
33        .add(0, 3, true) // In MAXA this is converted to 1, but in MAX it is ignored.
34        .build();
35    assertThat(MAXA.SELF.apply(null, -1.0, grid, -11.0, "-100")).isEqualTo(1.0);
36    assertThat(MAX.SELF.apply(null, -1.0, grid, -11.0, "-100")).isEqualTo(-1.0);
37    assertThat(MAX.SELF.apply(null, -1.0, grid, -11.0, "200")).isEqualTo(200.0);
38  }
39
40  @Test
41  public void testApply_numeric() {
42    assertThat(MAXA.SELF.apply(null, 1.0, 2.0, "3.0")).isEqualTo(3.0);
43    assertThat(MAXA.SELF.apply(null, -1.0, -2.0, true)).isEqualTo(1.0);
44    assertThat(MAXA.SELF.apply(null, -1.0, -2.0, false)).isEqualTo(0.0);
45  }
46
47  @Test
48  public void testApply_grid() {
49    assertThat(MAXA.SELF.apply(null, Grid.builder().add(0, 0, 1.0).add(0, 1, "Bad").build(), 44.0)).isEqualTo(44.0);
50  }
51
52  @Test
53  public void test_lookup() {
54    Grid grid = Grid.builder()
55        .add(0, 0, 1.0)
56        .add(0, 1, 2.0)
57        .add(0, 2, 3.0)
58        .add(0, 3, 4.0)
59        .add(0, 4, 5.0)
60        .build();
61    MAXA F = new MAXA(lookup, collateralLookup);
62    when(lookup.apply(D1_TO_D5_RANGE)).thenReturn(grid);
63    assertThat(F.apply(A1, D1_TO_D5_RANGE)).isEqualTo(5.0);
64    verify(lookup).apply(D1_TO_D5_RANGE);
65    verifyNoMoreInteractions(lookup);
66  }
67
68  @Test
69  public void testApply_nonCoercableValuesInGridShouldBeIgnoreButNotInArgs() {
70    assertThat(MAXA.SELF.apply(null, Grid.builder().add(0, 0, 1.0).add(0, 1, "Bad").build(), "Bad")).isEqualTo(new ValueException());
71  }
72
73  @Test
74  public void testApply_errorFromArgumentsMismatch() {
75    assertThat(MAXA.SELF.apply(null)).isEqualTo(new NAException());
76  }
77}