|
| 1 | +package fj.function; |
| 2 | + |
| 3 | +import static org.junit.Assert.*; |
| 4 | + |
| 5 | +import fj.F; |
| 6 | +import org.junit.Test; |
| 7 | + |
| 8 | +import java.lang.reflect.Constructor; |
| 9 | +import java.lang.reflect.InvocationTargetException; |
| 10 | +import java.lang.reflect.Method; |
| 11 | + |
| 12 | +import static org.hamcrest.core.Is.is; |
| 13 | + |
| 14 | +import static fj.data.List.list; |
| 15 | + |
| 16 | +public class DoublesTest { |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testSum() { |
| 20 | + assertThat(Doubles.sum(list(3.0, 4.0, 5.0)), is(12.0)); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + public void testProduct() { |
| 25 | + assertThat(Doubles.product(list(3.0, 4.0, 5.0)), is(60.0)); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testAdd() { |
| 30 | + assertThat(Doubles.add.f(10.0).f(20.0), is(30.0)); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testMultiply() { |
| 35 | + assertThat(Doubles.multiply.f(3.0).f(5.0), is(15.0)); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void testAbs() { |
| 40 | + assertThat(Doubles.abs.f(-5.0), is(5.0)); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testFromString() { |
| 45 | + assertThat(Doubles.fromString().f("-123.45").some(), is(-123.45)); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testCannotInstantiate() throws NoSuchMethodException, InvocationTargetException, |
| 50 | + IllegalAccessException, InstantiationException { |
| 51 | + Constructor<Doubles> constructor = Doubles.class.getDeclaredConstructor(new Class[0]); |
| 52 | + constructor.setAccessible(true); |
| 53 | + try { |
| 54 | + constructor.newInstance(new Object[0]); |
| 55 | + fail("expected InvocationTargetException"); |
| 56 | + } catch (InvocationTargetException ite) { |
| 57 | + assertTrue(ite.getCause() instanceof UnsupportedOperationException); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments