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/math/SUMTest.java
-rw-r--r--
2384
 1package io.protobase.f7.formulas.math;
 2
 3import io.protobase.f7.errors.NAException;
 4import io.protobase.f7.errors.NullException;
 5import io.protobase.f7.errors.RefException;
 6import io.protobase.f7.models.Grid;
 7import io.protobase.f7.testutils.TestFormula;
 8import org.junit.Test;
 9
10import static com.google.common.truth.Truth.assertThat;
11import static org.mockito.Mockito.verify;
12import static org.mockito.Mockito.verifyNoMoreInteractions;
13import static org.mockito.Mockito.when;
14
15public class SUMTest extends TestFormula {
16  private static final Grid GRID = Grid.builder()
17      .add(0, 0, 22.1)
18      .add(0, 1, 324.3)
19      .add(0, 2, 22.2312223131232)
20      .add(0, 3, 442309.4)
21      .add(0, 4, 131289731.0)
22      .build();
23
24  @Test
25  public void testApply_normalAddition() {
26    assertThat(SUM.SELF.apply(null, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)).isEqualTo(36.0);
27    assertThat(SUM.SELF.apply(null, 0.0)).isEqualTo(0.0);
28    assertThat(SUM.SELF.apply(null, 2984723.99382)).isEqualTo(2984723.99382);
29    assertThat(SUM.SELF.apply(null, 2984723e3)).isEqualTo(2984723e3);
30  }
31
32  @Test
33  public void testApply_conversion() {
34    assertThat(SUM.SELF.apply(null, "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8")).isEqualTo(36.0);
35    assertThat(SUM.SELF.apply(null, true, false, true, false, true)).isEqualTo(3.0);
36    assertThat(SUM.SELF.apply(null,
37        GRID
38    )).isEqualTo(1.3173240903122231E8);
39  }
40
41  @Test
42  public void testApply_error() {
43    assertThat(SUM.SELF.apply(null, 1.0, new RefException())).isEqualTo(new RefException());
44    assertThat(SUM.SELF.apply(null, 1.0, new NullException(), new RefException())).isEqualTo(new NullException());
45    assertThat(SUM.SELF.apply(null,
46        Grid.builder()
47            .add(0, 0, 22.1)
48            .add(0, 1, 324.3)
49            .add(0, 2, new RefException())
50            .add(0, 3, 442309.4)
51            .add(0, 4, 131289731.0)
52            .build()
53    )).isEqualTo(new RefException());
54  }
55
56  @Test
57  public void test_lookup() {
58    SUM F = new SUM(lookup, collateralLookup);
59    when(lookup.apply(M22_RANGE)).thenReturn(GRID);
60    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(1.3173240903122231E8);
61    verify(lookup).apply(M22_RANGE);
62    verifyNoMoreInteractions(lookup);
63  }
64
65  @Test
66  public void testApply_errorFromArgumentsMismatch() {
67    assertThat(SUM.SELF.apply(null)).isEqualTo(new NAException());
68  }
69}