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/math/SIGNTest.java
-rw-r--r--
1862
 1package io.protobase.f7.formulas.math;
 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 SIGNTest extends TestFormula {
15  @Test
16  public void testApply() {
17    assertThat(SIGN.SELF.apply(null, 10.0)).isEqualTo(1.0);
18    assertThat(SIGN.SELF.apply(null, -10.0)).isEqualTo(-1.0);
19    assertThat(SIGN.SELF.apply(null, 0.0)).isEqualTo(0.0);
20    assertThat(SIGN.SELF.apply(null, -0.0)).isEqualTo(0.0);
21    assertThat(SIGN.SELF.apply(null, -218637221.22)).isEqualTo(-1.0);
22    assertThat(SIGN.SELF.apply(null, true)).isEqualTo(1.0);
23    assertThat(SIGN.SELF.apply(null, false)).isEqualTo(0.0);
24  }
25
26  @Test
27  public void testApply_stringConversion() {
28    assertThat(SIGN.SELF.apply(null, "10.0")).isEqualTo(1.0);
29  }
30
31  @Test
32  public void testApply_grid() {
33    assertThat(SIGN.SELF.apply(null,
34        Grid.builder().add(0, 0, -4.0).add(0, 1, "Don't mind me.").build()
35    )).isEqualTo(-1.0);
36  }
37
38  @Test
39  public void test_lookup() {
40    SIGN F = new SIGN(lookup, collateralLookup);
41    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(10.0);
42    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(1.0);
43    verify(collateralLookup).apply(A1, M22_RANGE);
44    verifyNoMoreInteractions(collateralLookup);
45  }
46
47  @Test
48  public void testApply_errorsPassThrough() {
49    assertThat(SIGN.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
50  }
51
52  @Test
53  public void testApply_argumentsMismatch() {
54    assertThat(SIGN.SELF.apply(null, "A", "Too many")).isEqualTo(new NAException());
55  }
56}