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/info/ERRORTYPETest.java
-rw-r--r--
2481
 1package io.protobase.f7.formulas.info;
 2
 3import com.google.common.truth.Truth;
 4import io.protobase.f7.errors.DivException;
 5import io.protobase.f7.errors.NAException;
 6import io.protobase.f7.errors.NameException;
 7import io.protobase.f7.errors.NullException;
 8import io.protobase.f7.errors.NumException;
 9import io.protobase.f7.errors.ParseException;
10import io.protobase.f7.errors.RefException;
11import io.protobase.f7.errors.ValueException;
12import io.protobase.f7.formulas.logic.EQ;
13import io.protobase.f7.models.Grid;
14import io.protobase.f7.testutils.TestFormula;
15import org.junit.Test;
16
17import static com.google.common.truth.Truth.assertThat;
18import static org.mockito.Mockito.verify;
19import static org.mockito.Mockito.when;
20
21public class ERRORTYPETest extends TestFormula {
22  @Test
23  public void test() {
24    assertThat(ERRORTYPE.SELF.apply(null, new NullException())).isEqualTo(1.0);
25    assertThat(ERRORTYPE.SELF.apply(null, new DivException())).isEqualTo(2.0);
26    assertThat(ERRORTYPE.SELF.apply(null, new ValueException())).isEqualTo(3.0);
27    assertThat(ERRORTYPE.SELF.apply(null, new RefException())).isEqualTo(4.0);
28    assertThat(ERRORTYPE.SELF.apply(null, new NameException())).isEqualTo(5.0);
29    assertThat(ERRORTYPE.SELF.apply(null, new NumException())).isEqualTo(6.0);
30    assertThat(ERRORTYPE.SELF.apply(null, new NAException())).isEqualTo(7.0);
31    assertThat(ERRORTYPE.SELF.apply(null, new ParseException())).isEqualTo(8.0);
32  }
33
34  @Test
35  public void test_grid() {
36    assertThat(ERRORTYPE.SELF.apply(null,
37        Grid.builder()
38            .add(0, 0, new NullException())
39            .add(0, 1, 10)
40            .build())
41    ).isEqualTo(1.0);
42  }
43
44  @Test
45  public void test_lookup() {
46    ERRORTYPE F = new ERRORTYPE(lookup, collateralLookup);
47    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(new DivException());
48    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(2.0);
49    verify(collateralLookup).apply(A1, M22_RANGE);
50  }
51
52  @Test
53  public void test_nonError() {
54    assertThat(ERRORTYPE.SELF.apply(null, 10.0)).isEqualTo(new NAException());
55    assertThat(ERRORTYPE.SELF.apply(null, true)).isEqualTo(new NAException());
56    assertThat(ERRORTYPE.SELF.apply(null, "Not an error.")).isEqualTo(new NAException());
57  }
58
59  @Test
60  public void test_errorFromArgumentsMismatch() {
61    Truth.assertThat(EQ.SELF.apply(null, "Too few")).isEqualTo(new NAException());
62    assertThat(EQ.SELF.apply(null, "A", "B", "Too many")).isEqualTo(new NAException());
63  }
64}