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/UNARY_PERCENTTest.java
-rw-r--r--
1784
 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 UNARY_PERCENTTest extends TestFormula {
15  @Test
16  public void testApply() {
17    assertThat(UNARY_PERCENT.SELF.apply(null, 10.0)).isEqualTo(0.1);
18    assertThat(UNARY_PERCENT.SELF.apply(null, -10.0)).isEqualTo(-0.1);
19    assertThat(UNARY_PERCENT.SELF.apply(null, 0.0)).isEqualTo(0.0);
20    assertThat(UNARY_PERCENT.SELF.apply(null, 8278.28687)).isEqualTo(82.7828687);
21  }
22
23  @Test
24  public void testApply_stringConversion() {
25    assertThat(UNARY_PERCENT.SELF.apply(null, "10.0")).isEqualTo(0.1);
26  }
27
28  @Test
29  public void testApply_grid() {
30    assertThat(UNARY_PERCENT.SELF.apply(null,
31        Grid.builder().add(0, 0, -4.0).add(0, 1, "Don't mind me.").build()
32    )).isEqualTo(-0.04);
33  }
34
35  @Test
36  public void test_lookup() {
37    UNARY_PERCENT F = new UNARY_PERCENT(lookup, collateralLookup);
38    when(collateralLookup.apply(A1, M22_RANGE)).thenReturn(10.0);
39    assertThat(F.apply(A1, M22_RANGE)).isEqualTo(0.1);
40    verify(collateralLookup).apply(A1, M22_RANGE);
41    verifyNoMoreInteractions(collateralLookup);
42  }
43
44  @Test
45  public void testApply_errorsPassThrough() {
46    assertThat(UNARY_PERCENT.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
47  }
48
49  @Test
50  public void testApply_argumentsMismatch() {
51    assertThat(UNARY_PERCENT.SELF.apply(null, "A", "Too many")).isEqualTo(new NAException());
52  }
53}