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/parser/TO_TEXTTest.java
-rw-r--r--
2247
 1package io.protobase.f7.formulas.parser;
 2
 3import io.protobase.f7.errors.DivException;
 4import io.protobase.f7.errors.NAException;
 5import io.protobase.f7.errors.NumException;
 6import io.protobase.f7.models.Grid;
 7import io.protobase.f7.testutils.TestFormula;
 8import org.junit.Test;
 9
10import static com.google.common.truth.Truth.assertThat;
11import static org.mockito.Mockito.verify;
12import static org.mockito.Mockito.verifyNoMoreInteractions;
13import static org.mockito.Mockito.when;
14
15public class TO_TEXTTest extends TestFormula {
16  @Test
17  public void testApply() {
18    assertThat(TO_TEXT.SELF.apply(null, 0.99)).isEqualTo("0.99");
19    assertThat(TO_TEXT.SELF.apply(null, 0.489733)).isEqualTo("0.489733");
20    assertThat(TO_TEXT.SELF.apply(null, 0.0)).isEqualTo("0");
21    assertThat(TO_TEXT.SELF.apply(null, -0.66152156111)).isEqualTo("-0.66152156111");
22    assertThat(TO_TEXT.SELF.apply(null, -0.88)).isEqualTo("-0.88");
23    assertThat(TO_TEXT.SELF.apply(null, "Already Text")).isEqualTo("Already Text");
24    assertThat(TO_TEXT.SELF.apply(null, "")).isEqualTo("");
25    assertThat(TO_TEXT.SELF.apply(null, true)).isEqualTo("TRUE");
26    assertThat(TO_TEXT.SELF.apply(null, false)).isEqualTo("FALSE");
27  }
28
29  @Test
30  public void testApply_exceptions() {
31    assertThat(TO_TEXT.SELF.apply(null, new DivException())).isEqualTo(new DivException());
32    assertThat(TO_TEXT.SELF.apply(null, new NumException())).isEqualTo(new NumException());
33  }
34
35  @Test
36  public void testApply_grid() {
37    assertThat(TO_TEXT.SELF.apply(null,
38        Grid.builder().add(0, 0, 19873218.11).add(0, 1, "Don't mind me.").build()
39    )).isEqualTo("1.987321811E7");
40    assertThat(TO_TEXT.SELF.apply(null,
41        Grid.builder().add(0, 0, true).add(0, 1, "Don't mind me.").build()
42    )).isEqualTo("TRUE");
43  }
44
45  @Test
46  public void test_lookup() {
47    TO_TEXT F = new TO_TEXT(lookup, collateralLookup);
48    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(10.0);
49    assertThat(F.apply(A1, M22_RANGE)).isEqualTo("10");
50    verify(collateralLookup).apply(A1, M22_RANGE);
51    verifyNoMoreInteractions(collateralLookup);
52  }
53
54  @Test
55  public void testApply_argumentsMismatch() {
56    assertThat(TO_TEXT.SELF.apply(null, "A", "Too many")).isEqualTo(new NAException());
57  }
58}