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/QUOTIENTTest.java
-rw-r--r--
2878
 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 QUOTIENTTest extends TestFormula {
16  @Test
17  public void testApply_cleanDivision() {
18    assertThat(QUOTIENT.SELF.apply(null, 10.0, 10.0)).isEqualTo(1.0);
19    assertThat(QUOTIENT.SELF.apply(null, 10.0, 2.0)).isEqualTo(5.0);
20    assertThat(QUOTIENT.SELF.apply(null, 10.0, 3.0)).isEqualTo(3.0);
21    assertThat(QUOTIENT.SELF.apply(null, 0.0, 1628736813.2)).isEqualTo(0.0);
22    assertThat(QUOTIENT.SELF.apply(null, 218637221.22, 2876.111)).isEqualTo(76018.0);
23    assertThat(QUOTIENT.SELF.apply(null, 9.0, -4.0)).isEqualTo(-2.0);
24    assertThat(QUOTIENT.SELF.apply(null, -9.0, -4.0)).isEqualTo(2.0);
25    assertThat(QUOTIENT.SELF.apply(null, -9.0, 4.0)).isEqualTo(-2.0);
26  }
27
28  @Test
29  public void testApply_stringConversion() {
30    assertThat(QUOTIENT.SELF.apply(null, "10.0", "10.0")).isEqualTo(1.0);
31    assertThat(QUOTIENT.SELF.apply(null, "10.0", "2.0")).isEqualTo(5.0);
32    assertThat(QUOTIENT.SELF.apply(null, "10.0", "3.0")).isEqualTo(3.0);
33  }
34
35  @Test
36  public void testApply_grid() {
37    assertThat(QUOTIENT.SELF.apply(null,
38        Grid.builder().add(0, 0, 6.0).add(0, 1, "Don't mind me.").build(),
39        Grid.builder().add(0, 0, 2.0).add(0, 1, "Don't mind me.").build()
40    )).isEqualTo(3.0);
41  }
42
43  @Test
44  public void test_lookup() {
45    QUOTIENT F = new QUOTIENT(lookup, collateralLookup);
46    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(10.0);
47    when(collateralLookup.apply(A1, G19_RANGE)).thenReturn(2.0);
48    assertThat(F.apply(A1, M22_RANGE, G19_RANGE)).isEqualTo(5.0);
49    verify(collateralLookup).apply(A1, M22_RANGE);
50    verify(collateralLookup).apply(A1, G19_RANGE);
51    verifyNoMoreInteractions(collateralLookup);
52  }
53
54  @Test
55  public void testApply_errorsPassThrough() {
56    assertThat(QUOTIENT.SELF.apply(null, 10.0, new ValueException())).isEqualTo(new ValueException());
57    assertThat(QUOTIENT.SELF.apply(null, new ValueException(), 10.0)).isEqualTo(new ValueException());
58  }
59
60  @Test
61  public void testApply_argumentsMismatch() {
62    assertThat(QUOTIENT.SELF.apply(null, "Too few")).isEqualTo(new NAException());
63    assertThat(QUOTIENT.SELF.apply(null, "A", "B", "Too many")).isEqualTo(new NAException());
64  }
65
66  @Test
67  public void testApply_errorDivideByZero() {
68    assertThat(QUOTIENT.SELF.apply(null, 328467.0, 0.0)).isEqualTo(new DivException());
69    assertThat(QUOTIENT.SELF.apply(null, 0.0, 0.0)).isEqualTo(new DivException());
70  }
71}