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