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/logic/EXACTTest.java
-rw-r--r--
2395
 1package io.protobase.f7.formulas.logic;
 2
 3import io.protobase.f7.errors.DivException;
 4import io.protobase.f7.errors.NAException;
 5import io.protobase.f7.errors.ValueException;
 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.when;
13
14public class EXACTTest extends TestFormula {
15
16  @Test
17  public void test_sameType() {
18    assertThat(EXACT.SELF.apply(null, 10.0, 10.0)).isEqualTo(true);
19    assertThat(EXACT.SELF.apply(null, 10.0, "10.0")).isEqualTo(false);
20    assertThat(EXACT.SELF.apply(null, 10.0, "10")).isEqualTo(true);
21    assertThat(EXACT.SELF.apply(null, 10.0, 0.0)).isEqualTo(false);
22    assertThat(EXACT.SELF.apply(null, "Same", "Same")).isEqualTo(true);
23    assertThat(EXACT.SELF.apply(null, "Same", "Different")).isEqualTo(false);
24    assertThat(EXACT.SELF.apply(null, true, true)).isEqualTo(true);
25    assertThat(EXACT.SELF.apply(null, true, false)).isEqualTo(false);
26    assertThat(EXACT.SELF.apply(null, false, false)).isEqualTo(true);
27  }
28
29  @Test
30  public void test_error() {
31    assertThat(EXACT.SELF.apply(null, new ValueException(), new ValueException())).isEqualTo(new ValueException());
32    assertThat(EXACT.SELF.apply(null, new DivException(), new ValueException())).isEqualTo(new DivException());
33    assertThat(EXACT.SELF.apply(null, 4.4444, new ValueException())).isEqualTo(new ValueException());
34  }
35
36  @Test
37  public void test_lookup() {
38    EXACT F = new EXACT(lookup, collateralLookup);
39    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn("A");
40    when(collateralLookup.apply(A1, G19_RANGE)).thenReturn("B");
41    assertThat(F.apply(A1, M22_RANGE, G19_RANGE)).isEqualTo(false);
42    verify(collateralLookup).apply(A1, M22_RANGE);
43  }
44
45  @Test
46  public void test_grids() {
47    Grid one = Grid.builder()
48        .add(0, 0, 44.0)
49        .add(0, 1, "A")
50        .build();
51    Grid two = Grid.builder()
52        .add(0, 0, 44.0)
53        .add(0, 1, "B")
54        .build();
55    assertThat(EXACT.SELF.apply(null, one, two)).isEqualTo(true);
56  }
57
58  @Test
59  public void test_errorFromArgumentsMismatch() {
60    assertThat(EXACT.SELF.apply(null, "Too few")).isEqualTo(new NAException());
61    assertThat(EXACT.SELF.apply(null, "A", "B", "Too many")).isEqualTo(new NAException());
62  }
63}