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/ANDTest.java
-rw-r--r--
3289
 1package io.protobase.f7.formulas.logic;
 2
 3import io.protobase.f7.errors.DivException;
 4import io.protobase.f7.errors.NAException;
 5import io.protobase.f7.errors.NullException;
 6import io.protobase.f7.errors.ValueException;
 7import io.protobase.f7.models.Grid;
 8import io.protobase.f7.testutils.TestFormula;
 9import org.junit.Test;
10
11import static com.google.common.truth.Truth.assertThat;
12import static org.mockito.Mockito.verify;
13import static org.mockito.Mockito.verifyNoMoreInteractions;
14import static org.mockito.Mockito.when;
15
16public class ANDTest extends TestFormula {
17  @Test
18  public void test_boolean() {
19    assertThat(AND.SELF.apply(null, true)).isEqualTo(true);
20    assertThat(AND.SELF.apply(null, true, true)).isEqualTo(true);
21    assertThat(AND.SELF.apply(null, true, true, true)).isEqualTo(true);
22    assertThat(AND.SELF.apply(null, true, true, false)).isEqualTo(false);
23    assertThat(AND.SELF.apply(null, false)).isEqualTo(false);
24    assertThat(AND.SELF.apply(null, false, false)).isEqualTo(false);
25    assertThat(AND.SELF.apply(null, false, false, true)).isEqualTo(false);
26  }
27
28  @Test
29  public void test_string() {
30    assertThat(AND.SELF.apply(null, "TRUE")).isEqualTo(true);
31    assertThat(AND.SELF.apply(null, "true")).isEqualTo(true);
32    assertThat(AND.SELF.apply(null, "true", "false")).isEqualTo(false);
33    assertThat(AND.SELF.apply(null, "true", "nope no sir this is not a boolean")).isEqualTo(new ValueException());
34  }
35
36  @Test
37  public void test_number() {
38    assertThat(AND.SELF.apply(null, 1.0)).isEqualTo(true);
39    assertThat(AND.SELF.apply(null, 1.0, 2.2)).isEqualTo(true);
40    assertThat(AND.SELF.apply(null, 1.0, 2.2, 11.11)).isEqualTo(true);
41    assertThat(AND.SELF.apply(null, 1.0, 2.2, 11.11, 0.0)).isEqualTo(false);
42    assertThat(AND.SELF.apply(null, 0.0, 0.0, 0.0)).isEqualTo(false);
43  }
44
45  @Test
46  public void test_error() {
47    assertThat(AND.SELF.apply(null, 0.0, 0.0, new DivException())).isEqualTo(new DivException());
48    assertThat(AND.SELF.apply(null, 0.0, 0.0, new NullException())).isEqualTo(new NullException());
49  }
50
51  @Test
52  public void test_lookup() {
53    AND F = new AND(lookup, collateralLookup);
54    Grid D1_D3_grid = Grid.builder()
55        .add(0, 0, true)
56        .add(0, 1, true)
57        .add(0, 2, false)
58        .build();
59    when(lookup.apply(D1_TO_D3_RANGE)).thenReturn(D1_D3_grid);
60    assertThat(F.apply(A1, D1_TO_D3_RANGE)).isEqualTo(false);
61    verify(lookup).apply(D1_TO_D3_RANGE);
62    verifyNoMoreInteractions(lookup);
63  }
64
65  @Test
66  public void test_grid() {
67    assertThat(AND.SELF.apply(null, Grid.builder().add(0, 0, true).build())).isEqualTo(true);
68    assertThat(AND.SELF.apply(null, Grid.builder()
69        .add(0, 0, true)
70        .add(0, 1, true)
71        .add(0, 2, true)
72        .build())
73    ).isEqualTo(true);
74    assertThat(AND.SELF.apply(null, Grid.builder()
75        .add(0, 0, true)
76        .add(0, 1, true)
77        .add(0, 2, false)
78        .build())
79    ).isEqualTo(false);
80    assertThat(AND.SELF.apply(null, Grid.builder()
81        .add(0, 0, true)
82        .add(0, 1, true)
83        .add(0, 2, null)
84        .add(0, 3, false)
85        .build())
86    ).isEqualTo(false);
87  }
88
89  @Test
90  public void test_errorFromArgumentsMismatch() {
91    assertThat(AND.SELF.apply(null)).isEqualTo(new NAException());
92  }
93}