name:
src/test/java/io/protobase/f7/formulas/math/MINUSTest.java
-rw-r--r--
2217
1package io.protobase.f7.formulas.math;
2
3import io.protobase.f7.errors.NAException;
4import io.protobase.f7.errors.ValueException;
5import io.protobase.f7.models.Grid;
6import io.protobase.f7.testutils.TestFormula;
7import org.junit.Test;
8
9import static com.google.common.truth.Truth.assertThat;
10import static org.mockito.Mockito.verify;
11import static org.mockito.Mockito.verifyNoMoreInteractions;
12import static org.mockito.Mockito.when;
13
14public class MINUSTest extends TestFormula {
15 @Test
16 public void testApply_clean() {
17 assertThat(MINUS.SELF.apply(null, 10.0, 10.0)).isEqualTo(0.0);
18 assertThat(MINUS.SELF.apply(null, 10.0, 2.0)).isEqualTo(8.0);
19 assertThat(MINUS.SELF.apply(null, 10.0, 3.0)).isEqualTo(7.0);
20 assertThat(MINUS.SELF.apply(null, 0.0, 1628736813.2)).isEqualTo(-1628736813.2);
21 assertThat(MINUS.SELF.apply(null, 218637221.22, 2876.111)).isEqualTo(218634345.109);
22 }
23
24 @Test
25 public void testApply_stringConversion() {
26 assertThat(MINUS.SELF.apply(null, "10.0", "10.0")).isEqualTo(0.0);
27 }
28
29 @Test
30 public void testApply_grid() {
31 assertThat(MINUS.SELF.apply(null,
32 Grid.builder().add(0, 0, 6.0).add(0, 1, "Don't mind me.").build(),
33 Grid.builder().add(0, 0, 2.0).add(0, 1, "Don't mind me.").build()
34 )).isEqualTo(4.0);
35 }
36
37 @Test
38 public void test_lookup() {
39 MINUS F = new MINUS(lookup, collateralLookup);
40 when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(128.0);
41 when(collateralLookup.apply(A1, G19_RANGE)).thenReturn(2.0);
42 assertThat(F.apply(A1, M22_RANGE, G19_RANGE)).isEqualTo(126.0);
43 verify(collateralLookup).apply(A1, M22_RANGE);
44 verify(collateralLookup).apply(A1, G19_RANGE);
45 verifyNoMoreInteractions(collateralLookup);
46 }
47
48 @Test
49 public void testApply_errorsPassThrough() {
50 assertThat(MINUS.SELF.apply(null, 10.0, new ValueException())).isEqualTo(new ValueException());
51 assertThat(MINUS.SELF.apply(null, new ValueException(), 10.0)).isEqualTo(new ValueException());
52 }
53
54 @Test
55 public void testApply_argumentsMismatch() {
56 assertThat(MINUS.SELF.apply(null, "Too few")).isEqualTo(new NAException());
57 assertThat(MINUS.SELF.apply(null, "A", "B", "Too many")).isEqualTo(new NAException());
58 }
59}