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