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/SQRTPITest.java
-rw-r--r--
2273
 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 SQRTPITest extends TestFormula {
16  @Test
17  public void testApply() {
18    assertThat(SQRTPI.SELF.apply(null, 10.0)).isEqualTo(5.604991216397929);
19    assertThat(SQRTPI.SELF.apply(null, 128731.2)).isEqualTo(635.9410288759473);
20    assertThat(SQRTPI.SELF.apply(null, 11.11)).isEqualTo(5.907884086657642);
21    assertThat(SQRTPI.SELF.apply(null, 0.0)).isEqualTo(0.0);
22    assertThat(SQRTPI.SELF.apply(null, 88281.0)).isEqualTo(526.6335927868261);
23    assertThat(SQRTPI.SELF.apply(null, 2.0)).isEqualTo(2.5066282746310002);
24    assertThat(SQRTPI.SELF.apply(null, 4.0)).isEqualTo(3.5449077018110318);
25  }
26
27  @Test
28  public void testApply_stringConversion() {
29    assertThat(SQRTPI.SELF.apply(null, "88281.0")).isEqualTo(526.6335927868261);
30  }
31
32  @Test
33  public void testApply_numExceptions() {
34    assertThat(SQRTPI.SELF.apply(null, -0.0001)).isEqualTo(new NumException());
35    assertThat(SQRTPI.SELF.apply(null, -10124.0)).isEqualTo(new NumException());
36  }
37
38  @Test
39  public void testApply_grid() {
40    assertThat(SQRTPI.SELF.apply(null,
41        Grid.builder().add(0, 0, 4.0).add(0, 1, "Don't mind me.").build()
42    )).isEqualTo(3.5449077018110318);
43  }
44
45  @Test
46  public void test_lookup() {
47    SQRTPI F = new SQRTPI(lookup, collateralLookup);
48    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(10.0);
49    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(5.604991216397929);
50    verify(collateralLookup).apply(A1, M22_RANGE);
51    verifyNoMoreInteractions(collateralLookup);
52  }
53
54  @Test
55  public void testApply_errorsPassThrough() {
56    assertThat(SQRTPI.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
57  }
58
59  @Test
60  public void testApply_argumentsMismatch() {
61    assertThat(SQRTPI.SELF.apply(null, "A", "Too many")).isEqualTo(new NAException());
62  }
63}