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/text/LENTest.java
-rw-r--r--
1870
 1package io.protobase.f7.formulas.text;
 2
 3import io.protobase.f7.errors.NAException;
 4import io.protobase.f7.errors.ValueException;
 5import io.protobase.f7.models.Grid;
 6import io.protobase.f7.testutils.TestFormula;
 7import org.junit.Test;
 8
 9import static com.google.common.truth.Truth.assertThat;
10import static org.mockito.Mockito.verify;
11import static org.mockito.Mockito.verifyNoMoreInteractions;
12import static org.mockito.Mockito.when;
13
14public class LENTest extends TestFormula {
15  @Test
16  public void testApply() {
17    assertThat(LEN.SELF.apply(null, 10.0)).isEqualTo(2.0);
18    assertThat(LEN.SELF.apply(null, 0.0)).isEqualTo(1.0);
19    assertThat(LEN.SELF.apply(null, 0.1)).isEqualTo(3.0);
20    assertThat(LEN.SELF.apply(null, -13283210.0)).isEqualTo(9.0);
21    assertThat(LEN.SELF.apply(null, 172398713981.23971923712)).isEqualTo(21.0);
22    assertThat(LEN.SELF.apply(null, true)).isEqualTo(4.0);
23    assertThat(LEN.SELF.apply(null, false)).isEqualTo(5.0);
24    assertThat(LEN.SELF.apply(null, "CountMe")).isEqualTo(7.0);
25  }
26
27  @Test
28  public void testApply_grid() {
29    assertThat(LEN.SELF.apply(null,
30        Grid.builder().add(0, 0, "Hello").add(0, 1, "I am ignored.").build()
31    )).isEqualTo(5.0);
32  }
33
34  @Test
35  public void test_lookup() {
36    LEN F = new LEN(lookup, collateralLookup);
37    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn("One");
38    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(3.0);
39    verify(collateralLookup).apply(A1, M22_RANGE);
40    verifyNoMoreInteractions(collateralLookup);
41  }
42
43  @Test
44  public void testApply_errorsPassThrough() {
45    assertThat(LEN.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
46  }
47
48  @Test
49  public void testApply_argumentsMismatch() {
50    assertThat(LEN.SELF.apply(null)).isEqualTo(new NAException());
51    assertThat(LEN.SELF.apply(null, "A", "B")).isEqualTo(new NAException());
52  }
53}