Skip to content

Add Integers tests #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions core/src/test/java/fj/function/IntegersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package fj.function;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import static fj.data.List.list;
import static fj.data.Option.none;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

public class IntegersTest {

@Test
public void testSum() {
assertThat(Integers.sum(list(3, 4, 5)), is(12));
}

@Test
public void testProduct() {
assertThat(Integers.product(list(3, 4, 5)), is(60));
}

@Test
public void testAdd() {
assertThat(Integers.add.f(10).f(20), is(30));
}

@Test
public void testMultiply() {
assertThat(Integers.multiply.f(3).f(5), is(15));
}

@Test
public void testAbs() {
assertThat(Integers.abs.f(-5), is(5));
}

@Test
public void testFromString() {
assertThat(Integers.fromString().f("-123").some(), is(-123));
}

@Test
public void testFromStringFail() {
assertThat(Integers.fromString().f("w"), is(none()));
}

@Test
public void testCannotInstantiate() throws NoSuchMethodException, IllegalAccessException, InstantiationException {
Constructor<Integers> constructor = Integers.class.getDeclaredConstructor();
constructor.setAccessible(true);
try {
constructor.newInstance();
fail("expected InvocationTargetException");
} catch (InvocationTargetException ite) {
assertTrue(ite.getCause() instanceof UnsupportedOperationException);
}
}

}