Created
August 29, 2015 10:58
-
-
Save yyYank/c62a7d0d1fe5c131ca55 to your computer and use it in GitHub Desktop.
ぶれいすさんのやつ、http://bleis-tift.hatenablog.com/entry/20120119/1326944722 Javaでやってみたのテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.assertThat; | |
import java.util.Arrays; | |
import java.util.List; | |
import org.junit.Test; | |
public class RecursiveTest { | |
@Test | |
public void testSum() { | |
int actual = Recursive.sum(Arrays.asList(new Integer[]{1, 2, 3, 4, 5})); | |
int expected = 15; | |
assertThat(actual, is(expected)); | |
} | |
@Test | |
public void testLength() { | |
int actual = Recursive.length(Arrays.asList(new Integer[]{5, 4, 3, 2, 1})); | |
int expected = 5; | |
assertThat(actual, is(expected)); | |
} | |
@Test | |
public void testMax() { | |
int actual = Recursive.max(Arrays.asList(new Integer[]{1, 200, 3, 4, 10})); | |
int expected = 200; | |
assertThat(actual, is(expected)); | |
} | |
@Test | |
public void testForAll_not_match() { | |
boolean actual = Recursive.forall(Arrays.asList(new Integer[]{1, 200, 3, 4, 10}), i -> i % 2 == 0); | |
boolean expected = false; | |
assertThat(actual, is(expected)); | |
} | |
@Test | |
public void testForAll_all_match() { | |
boolean actual = Recursive.forall(Arrays.asList(new Integer[]{2, 4, 6, 8, 10}), i -> i % 2 == 0); | |
boolean expected = true; | |
assertThat(actual, is(expected)); | |
} | |
@Test | |
public void testFind_not_match() { | |
int actual = Recursive.find(Arrays.asList(new Integer[]{2, 4, 6, 8, 10}), i -> i == 100); | |
int expected = 0; | |
assertThat(actual, is(expected)); | |
} | |
@Test | |
public void testFind_match() { | |
int actual = Recursive.find(Arrays.asList(new Integer[]{2, 4, 6, 8, 100}), i -> i == 100); | |
int expected = 100; | |
assertThat(actual, is(expected)); | |
} | |
@Test | |
public void testSkip() { | |
List<Integer> actual = Recursive.skip(Arrays.asList(new Integer[]{1, 200, 3, 4, 10}), 3); | |
int expected = 2; | |
assertThat(actual.size(), is(expected)); | |
} | |
@Test | |
public void testMap() { | |
List<Integer> actual = Recursive.map(Arrays.asList(new Integer[]{1, 2, 3, 4, 5}), e -> e * 2); | |
assertThat(actual.get(0), is(2)); | |
assertThat(actual.get(1), is(4)); | |
assertThat(actual.get(2), is(6)); | |
assertThat(actual.get(3), is(8)); | |
assertThat(actual.get(4), is(10)); | |
} | |
@Test | |
public void testFilter() { | |
List<Integer> actual = Recursive.filter(Arrays.asList(new Integer[]{1, 200, 3, 4, 10}), i -> i % 2 == 0); | |
assertThat(actual.size(), is(3)); | |
assertThat(actual.get(0), is(200)); | |
assertThat(actual.get(1), is(4)); | |
assertThat(actual.get(2), is(10)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment