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/LNTest.java
-rw-r--r--
2083
 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 LNTest extends TestFormula {
16  @Test
17  public void testApply() {
18    assertThat(LN.SELF.apply(null, 128.0)).isEqualTo(Math.log(128));
19    assertThat(LN.SELF.apply(null, 1.0)).isEqualTo(Math.log(1));
20    assertThat(LN.SELF.apply(null, 2.0)).isEqualTo(Math.log(2));
21    assertThat(LN.SELF.apply(null, 3.0)).isEqualTo(Math.log(3));
22    assertThat(LN.SELF.apply(null, 0.1)).isEqualTo(Math.log(0.1));
23  }
24
25  @Test
26  public void testApply_parameterErrors() {
27    assertThat(LN.SELF.apply(null, 0.0)).isEqualTo(new NumException());
28    assertThat(LN.SELF.apply(null, -0.1)).isEqualTo(new NumException());
29  }
30
31  @Test
32  public void testApply_stringConversion() {
33    assertThat(LN.SELF.apply(null, "1")).isEqualTo(Math.log(1));
34  }
35
36  @Test
37  public void testApply_grid() {
38    assertThat(LN.SELF.apply(null,
39        Grid.builder().add(0, 0, 44.0).add(0, 1, "Don't mind me.").build()
40    )).isEqualTo(Math.log(44.0));
41  }
42
43  @Test
44  public void test_lookup() {
45    LN F = new LN(lookup, collateralLookup);
46    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(128.0);
47    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(Math.log(128));
48    verify(collateralLookup).apply(A1, M22_RANGE);
49    verifyNoMoreInteractions(collateralLookup);
50  }
51
52  @Test
53  public void testApply_errorsPassThrough() {
54    assertThat(LN.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
55  }
56
57  @Test
58  public void testApply_argumentsMismatch() {
59    assertThat(LN.SELF.apply(null)).isEqualTo(new NAException());
60    assertThat(LN.SELF.apply(null, "A", "B", "C")).isEqualTo(new NAException());
61  }
62}