name:
src/test/java/io/protobase/f7/formulas/math/POWTest.java
-rw-r--r--
2341
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 POWTest extends TestFormula {
16 @Test
17 public void testApply_clean() {
18 assertThat(POW.SELF.apply(null, 2.0, 6.0)).isEqualTo(64.0);
19 assertThat(POW.SELF.apply(null, -2.0, 6.0)).isEqualTo(64.0);
20 assertThat(POW.SELF.apply(null, -2.0, 5.0)).isEqualTo(-32.0);
21 assertThat(POW.SELF.apply(null, 2.0, -5.0)).isEqualTo(0.03125);
22 assertThat(POW.SELF.apply(null, 3.0, 1.668132)).isEqualTo(6.25030532353381);
23 }
24
25 @Test
26 public void testApply_NaN() {
27 assertThat(POW.SELF.apply(null, -2.0, -0.05)).isEqualTo(new NumException());
28 }
29
30 @Test
31 public void testApply_stringConversion() {
32 assertThat(POW.SELF.apply(null, "2.0", "10.0")).isEqualTo(1024.0);
33 }
34
35 @Test
36 public void testApply_grid() {
37 assertThat(POW.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(36.0);
41 }
42
43 @Test
44 public void test_lookup() {
45 POW F = new POW(lookup, collateralLookup);
46 when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(2.0);
47 when(collateralLookup.apply(A1, G19_RANGE)).thenReturn(4.0);
48 assertThat(F.apply(A1, M22_RANGE, G19_RANGE)).isEqualTo(16.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(POW.SELF.apply(null, 10.0, new ValueException())).isEqualTo(new ValueException());
57 assertThat(POW.SELF.apply(null, new ValueException(), 10.0)).isEqualTo(new ValueException());
58 }
59
60 @Test
61 public void testApply_argumentsMismatch() {
62 assertThat(POW.SELF.apply(null, "Too few")).isEqualTo(new NAException());
63 assertThat(POW.SELF.apply(null, "A", "B", "Too many")).isEqualTo(new NAException());
64 }
65}