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/SQRTTest.java
-rw-r--r--
2173
 1package io.protobase.f7.formulas.math;
 2
 3import io.protobase.f7.errors.NAException;
 4import io.protobase.f7.errors.NumException;
 5import io.protobase.f7.errors.ValueException;
 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 SQRTTest extends TestFormula {
16  @Test
17  public void testApply() {
18    assertThat(SQRT.SELF.apply(null, 10.0)).isEqualTo(Math.sqrt(10.0));
19    assertThat(SQRT.SELF.apply(null, 128731.2)).isEqualTo(Math.sqrt(128731.2));
20    assertThat(SQRT.SELF.apply(null, 11.11)).isEqualTo(Math.sqrt(11.11));
21    assertThat(SQRT.SELF.apply(null, 0.0)).isEqualTo(Math.sqrt(0.0));
22    assertThat(SQRT.SELF.apply(null, 88281.0)).isEqualTo(Math.sqrt(88281));
23    assertThat(SQRT.SELF.apply(null, 2.0)).isEqualTo(Math.sqrt(2.0));
24    assertThat(SQRT.SELF.apply(null, 4.0)).isEqualTo(Math.sqrt(4.0));
25    assertThat(SQRT.SELF.apply(null, -4.0)).isEqualTo(new NumException());
26    assertThat(SQRT.SELF.apply(null, -10124.0)).isEqualTo(new NumException());
27  }
28
29  @Test
30  public void testApply_stringConversion() {
31    assertThat(SQRT.SELF.apply(null, "10.0")).isEqualTo(Math.sqrt(10.0));
32  }
33
34  @Test
35  public void testApply_grid() {
36    assertThat(SQRT.SELF.apply(null,
37        Grid.builder().add(0, 0, 4.0).add(0, 1, "Don't mind me.").build()
38    )).isEqualTo(Math.sqrt(4.0));
39  }
40
41  @Test
42  public void test_lookup() {
43    SQRT F = new SQRT(lookup, collateralLookup);
44    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(10.0);
45    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(Math.sqrt(10.0));
46    verify(collateralLookup).apply(A1, M22_RANGE);
47    verifyNoMoreInteractions(collateralLookup);
48  }
49
50  @Test
51  public void testApply_errorsPassThrough() {
52    assertThat(SQRT.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
53  }
54
55  @Test
56  public void testApply_argumentsMismatch() {
57    assertThat(SQRT.SELF.apply(null, "A", "Too many")).isEqualTo(new NAException());
58  }
59}