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/statistical/STDEVTest.java
-rw-r--r--
2634
 1package io.protobase.f7.formulas.statistical;
 2
 3import io.protobase.f7.errors.DivException;
 4import io.protobase.f7.errors.NAException;
 5import io.protobase.f7.errors.RefException;
 6import io.protobase.f7.errors.ValueException;
 7import io.protobase.f7.models.Grid;
 8import io.protobase.f7.testutils.TestFormula;
 9import org.junit.Test;
10
11import static com.google.common.truth.Truth.assertThat;
12import static org.mockito.Mockito.verify;
13import static org.mockito.Mockito.verifyNoMoreInteractions;
14import static org.mockito.Mockito.when;
15
16public class STDEVTest extends TestFormula {
17  private final static Grid GRID = Grid.builder()
18      .add(0, 0, 22.1)
19      .add(0, 1, 324.3)
20      .add(0, 2, 22.22)
21      .add(0, 3, 44.0)
22      .add(0, 4, 1311.0)
23      .build();
24  ;
25
26  @Test
27  public void testApply_normal() {
28    assertThat(STDEV.SELF.apply(null, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)).isEqualTo(2.449489742783178);
29    assertThat(STDEV.SELF.apply(null, 132.0, 110.0, 103.0, 132.0, 130.1, 131.972, 111.0, 143.43)).isEqualTo(14.202644037039626);
30    assertThat(STDEV.SELF.apply(null, 2.0, 4.0, -3.0, -2.0, -0.1, 1.972, 1.0, 3.43)).isEqualTo(2.4784437369330896);
31    assertThat(STDEV.SELF.apply(null, 2.0, 2.0)).isEqualTo(0.0);
32    assertThat(STDEV.SELF.apply(null, 2.0)).isEqualTo(new DivException());
33  }
34
35  @Test
36  public void testApply_failOnNonCoercableValues() {
37    assertThat(STDEV.SELF.apply(null, 1.0, 2.0, 3.0, "Bad.")).isEqualTo(new ValueException());
38  }
39
40  @Test
41  public void testApply_skipNonCoercableNestedValues() {
42    assertThat(STDEV.SELF.apply(null, 1.0, 2.0, 3.0, Grid.builder().add(0, 0, "Bad").build())).isEqualTo(1.0);
43  }
44
45  @Test
46  public void testApply_grid() {
47    assertThat(STDEV.SELF.apply(null, GRID)).isEqualTo(555.1208083651702);
48  }
49
50  @Test
51  public void testApply_conversion() {
52    assertThat(STDEV.SELF.apply(null, "0.1", "0.1", "0.1", "0.34")).isEqualTo(0.12000000000000001);
53  }
54
55  @Test
56  public void test_lookup() {
57    STDEV F = new STDEV(lookup, collateralLookup);
58    when(lookup.apply(D1_TO_D5_RANGE)).thenReturn(GRID);
59    assertThat(F.apply(A1, D1_TO_D5_RANGE)).isEqualTo(555.1208083651702);
60    verify(lookup).apply(D1_TO_D5_RANGE);
61    verifyNoMoreInteractions(lookup);
62  }
63
64  @Test
65  public void testApply_errors() {
66    assertThat(STDEV.SELF.apply(null, 91872.1, new RefException())).isEqualTo(new RefException());
67    assertThat(STDEV.SELF.apply(null, 91872.1, new ValueException(), new RefException())).isEqualTo(new ValueException());
68  }
69
70  @Test
71  public void testApply_errorFromArgumentsMismatch() {
72    assertThat(STDEV.SELF.apply(null)).isEqualTo(new NAException());
73  }
74}