name:
src/test/java/io/protobase/f7/formulas/statistical/AVEDEVTest.java
-rw-r--r--
2304
1package io.protobase.f7.formulas.statistical;
2
3import io.protobase.f7.errors.NAException;
4import io.protobase.f7.errors.RefException;
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 AVEDEVTest extends TestFormula {
16 private static final Grid GRID = Grid.builder()
17 .add(0, 0, 22.1)
18 .add(0, 1, 324.3)
19 .add(0, 2, 22.22)
20 .add(0, 3, 44.0)
21 .add(0, 4, 1311.0)
22 .build();
23
24 @Test
25 public void testApply_normal() {
26 assertThat(AVEDEV.SELF.apply(null, 1.0)).isEqualTo(0.0);
27 assertThat(AVEDEV.SELF.apply(null, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)).isEqualTo(2.0);
28 assertThat(AVEDEV.SELF.apply(null, 132.0, 110.0, 103.0, 132.0, 130.1, 131.972, 111.0, 143.43)).isEqualTo(12.140812500000003);
29 assertThat(AVEDEV.SELF.apply(null, 2.0, 4.0, -3.0, -2.0, -0.1, 1.972, 1.0, 3.43)).isEqualTo(1.9595625);
30 assertThat(AVEDEV.SELF.apply(null, 0.1, 0.1, 0.1, 0.1)).isEqualTo(0.0);
31 assertThat(AVEDEV.SELF.apply(null, 0.1, 0.1, 0.1, 0.34)).isEqualTo(0.09000000000000002);
32 }
33
34 @Test
35 public void testApply_grid() {
36 assertThat(AVEDEV.SELF.apply(null, GRID)).isEqualTo(386.5104);
37 }
38
39 @Test
40 public void testApply_conversion() {
41 assertThat(AVEDEV.SELF.apply(null, "0.1", "0.1", "0.1", "0.34")).isEqualTo(0.09000000000000002);
42 }
43
44 @Test
45 public void test_lookup() {
46 AVEDEV F = new AVEDEV(lookup, collateralLookup);
47 when(lookup.apply(D1_TO_D5_RANGE)).thenReturn(GRID);
48 assertThat(F.apply(A1, D1_TO_D5_RANGE)).isEqualTo(386.5104);
49 verify(lookup).apply(D1_TO_D5_RANGE);
50 verifyNoMoreInteractions(lookup);
51 }
52
53 @Test
54 public void testApply_errors() {
55 assertThat(AVEDEV.SELF.apply(null, 91872.1, new RefException())).isEqualTo(new RefException());
56 assertThat(AVEDEV.SELF.apply(null, 91872.1, new ValueException(), new RefException())).isEqualTo(new ValueException());
57 }
58
59 @Test
60 public void testApply_errorFromArgumentsMismatch() {
61 assertThat(AVEDEV.SELF.apply(null)).isEqualTo(new NAException());
62 }
63}