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