name:
src/test/java/io/protobase/f7/formulas/logic/NOTTest.java
-rw-r--r--
2359
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 NOTTest extends TestFormula {
17 @Test
18 public void test_boolean() {
19 assertThat(NOT.SELF.apply(null, true)).isEqualTo(false);
20 assertThat(NOT.SELF.apply(null, false)).isEqualTo(true);
21 }
22
23 @Test
24 public void test_string() {
25 assertThat(NOT.SELF.apply(null, "TRUE")).isEqualTo(false);
26 assertThat(NOT.SELF.apply(null, "true")).isEqualTo(false);
27 assertThat(NOT.SELF.apply(null, false)).isEqualTo(true);
28 assertThat(NOT.SELF.apply(null, "nope no sir this is not a boolean")).isEqualTo(new ValueException());
29 }
30
31 @Test
32 public void test_number() {
33 assertThat(NOT.SELF.apply(null, 1.0)).isEqualTo(false);
34 assertThat(NOT.SELF.apply(null, 98722.0)).isEqualTo(false);
35 assertThat(NOT.SELF.apply(null, 0.0)).isEqualTo(true);
36 }
37
38 @Test
39 public void test_error() {
40 assertThat(NOT.SELF.apply(null, new DivException())).isEqualTo(new DivException());
41 assertThat(NOT.SELF.apply(null, new NullException())).isEqualTo(new NullException());
42 }
43
44 @Test
45 public void test_lookup() {
46 NOT F = new NOT(lookup, collateralLookup);
47 when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(true);
48 assertThat(F.apply(A1, M22_RANGE)).isEqualTo(false);
49 verify(collateralLookup).apply(A1, M22_RANGE);
50 verifyNoMoreInteractions(collateralLookup);
51 }
52
53 @Test
54 public void test_grid() {
55 assertThat(NOT.SELF.apply(null, Grid.builder().add(0, 0, true).build())).isEqualTo(false);
56 assertThat(NOT.SELF.apply(null, Grid.builder()
57 .add(0, 0, true)
58 .add(0, 1, 17821.11)
59 .add(0, 2, "does not matter")
60 .build())
61 ).isEqualTo(false);
62 }
63
64 @Test
65 public void test_errorFromArgumentsMismatch() {
66 assertThat(NOT.SELF.apply(null)).isEqualTo(new NAException());
67 assertThat(NOT.SELF.apply(null, true, true)).isEqualTo(new NAException());
68 }
69}