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