diff --git a/.travis.yml b/.travis.yml index 9df8ca0..379757b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,12 @@ language: java cache: directories: - "$HOME/.gradle" - - "$HOME/.m2" + - "$HOME/.m2/repository" jdk: - oraclejdk8 -script: mvn clean test package -script: gradle clean test jar +script: + - mvn clean test package + - gradle clean test jar after_success: - gradle jacocoTestReport coveralls diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer10Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer10Test.java new file mode 100644 index 0000000..41f87e9 --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer10Test.java @@ -0,0 +1,50 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer10Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer10 first = + (i1, i2, i3, i4, i5, i6, i7, i8, i9, i10) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10); + final Consumer10 second = + (i1, i2, i3, i4, i5, i6, i7, i8, i9, i10) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final int input4 = 4; + final int input5 = 5; + final int input6 = 6; + final int input7 = 7; + final int input8 = 8; + final int input9 = 9; + final int input10 = 10; + final List inputList = Arrays.asList(input1, input2, input3, input4, input5, input6, input7, input8, input9, input10); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer10.andThen(Consumer10)", "c10.andThen(c10_2) should do c10.accept(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) then c10_2.accept(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10). \n" + + "In other words, c10.andThen(c10_2) == c10(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); c10_2(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)") + .when(() -> + first.andThen(second).accept(input1, input2, input3, input4, input5, input6, input7, input8, input9, input10) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer3Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer3Test.java new file mode 100644 index 0000000..d321adb --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer3Test.java @@ -0,0 +1,43 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer3Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer3 first = + (i1, i2, i3) -> resultPair.value1(i1 + i2 + i3); + final Consumer3 second = + (i1, i2, i3) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final List inputList = Arrays.asList(input1, input2, input3); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer3.andThen(Consumer3)", "c3.andThen(c3_2) should do c3.accept(p1, p2, p3) then c3_2.accept(p1, p2, p3). \n" + + "In other words, c3.andThen(c3_2) == c3(p1, p2, p3); c3_2(p1, p2, p3)") + .when(() -> + first.andThen(second).accept(input1, input2, input3) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer4Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer4Test.java new file mode 100644 index 0000000..502048d --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer4Test.java @@ -0,0 +1,44 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer4Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer4 first = + (i1, i2, i3, i4) -> resultPair.value1(i1 + i2 + i3 + i4); + final Consumer4 second = + (i1, i2, i3, i4) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final int input4 = 4; + final List inputList = Arrays.asList(input1, input2, input3, input4); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer4.andThen(Consumer4)", "c4.andThen(c4_2) should do c4.accept(p1, p2, p3, p4) then c4_2.accept(p1, p2, p3, p4). \n" + + "In other words, c4.andThen(c4_2) == c4(p1, p2, p3, p4); c4_2(p1, p2, p3, p4)") + .when(() -> + first.andThen(second).accept(input1, input2, input3, input4) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer5Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer5Test.java new file mode 100644 index 0000000..7f3c5a5 --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer5Test.java @@ -0,0 +1,45 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer5Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer5 first = + (i1, i2, i3, i4, i5) -> resultPair.value1(i1 + i2 + i3 + i4 + i5); + final Consumer5 second = + (i1, i2, i3, i4, i5) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final int input4 = 4; + final int input5 = 5; + final List inputList = Arrays.asList(input1, input2, input3, input4, input5); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer5.andThen(Consumer5)", "c5.andThen(c5_2) should do c5.accept(p1, p2, p3, p4, p5) then c5_2.accept(p1, p2, p3, p4, p5). \n" + + "In other words, c5.andThen(c5_2) == c5(p1, p2, p3, p4, p5); c5_2(p1, p2, p3, p4, p5)") + .when(() -> + first.andThen(second).accept(input1, input2, input3, input4, input5) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer6Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer6Test.java new file mode 100644 index 0000000..936ce5b --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer6Test.java @@ -0,0 +1,46 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer6Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer6 first = + (i1, i2, i3, i4, i5, i6) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6); + final Consumer6 second = + (i1, i2, i3, i4, i5, i6) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final int input4 = 4; + final int input5 = 5; + final int input6 = 6; + final List inputList = Arrays.asList(input1, input2, input3, input4, input5, input6); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer6.andThen(Consumer6)", "c6.andThen(c6_2) should do c6.accept(p1, p2, p3, p4, p5, p6) then c6_2.accept(p1, p2, p3, p4, p5, p6). \n" + + "In other words, c6.andThen(c6_2) == c6(p1, p2, p3, p4, p5, p6); c6_2(p1, p2, p3, p4, p5, p6)") + .when(() -> + first.andThen(second).accept(input1, input2, input3, input4, input5, input6) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer7Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer7Test.java new file mode 100644 index 0000000..17cf732 --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer7Test.java @@ -0,0 +1,47 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer7Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer7 first = + (i1, i2, i3, i4, i5, i6, i7) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6 + i7); + final Consumer7 second = + (i1, i2, i3, i4, i5, i6, i7) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6, i7).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final int input4 = 4; + final int input5 = 5; + final int input6 = 6; + final int input7 = 7; + final List inputList = Arrays.asList(input1, input2, input3, input4, input5, input6, input7); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer7.andThen(Consumer7)", "c7.andThen(c7_2) should do c7.accept(p1, p2, p3, p4, p5, p6, p7) then c7_2.accept(p1, p2, p3, p4, p5, p6, p7). \n" + + "In other words, c7.andThen(c7_2) == c7(p1, p2, p3, p4, p5, p6, p7); c7_2(p1, p2, p3, p4, p5, p6, p7)") + .when(() -> + first.andThen(second).accept(input1, input2, input3, input4, input5, input6, input7) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer8Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer8Test.java new file mode 100644 index 0000000..50f8bb2 --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer8Test.java @@ -0,0 +1,48 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer8Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer8 first = + (i1, i2, i3, i4, i5, i6, i7, i8) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8); + final Consumer8 second = + (i1, i2, i3, i4, i5, i6, i7, i8) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6, i7, i8).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final int input4 = 4; + final int input5 = 5; + final int input6 = 6; + final int input7 = 7; + final int input8 = 8; + final List inputList = Arrays.asList(input1, input2, input3, input4, input5, input6, input7, input8); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer8.andThen(Consumer8)", "c8.andThen(c8_2) should do c8.accept(p1, p2, p3, p4, p5, p6, p7, p8) then c8_2.accept(p1, p2, p3, p4, p5, p6, p7, p8). \n" + + "In other words, c8.andThen(c8_2) == c8(p1, p2, p3, p4, p5, p6, p7, p8); c8_2(p1, p2, p3, p4, p5, p6, p7, p8)") + .when(() -> + first.andThen(second).accept(input1, input2, input3, input4, input5, input6, input7, input8) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Consumer9Test.java b/src/test/java/cc/kevinlee/functional/types/Consumer9Test.java new file mode 100644 index 0000000..ae12497 --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/Consumer9Test.java @@ -0,0 +1,49 @@ +package cc.kevinlee.functional.types; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static cc.kevinlee.testosterone.Testosterone.test; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public class Consumer9Test implements TypesUtil { + + @Test + public void testAndThen() throws Exception { + final MutablePair resultPair = new MutablePair<>(); + + final Consumer9 first = + (i1, i2, i3, i4, i5, i6, i7, i8, i9) -> resultPair.value1(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9); + final Consumer9 second = + (i1, i2, i3, i4, i5, i6, i7, i8, i9) -> resultPair.value2("Values are " + Arrays.asList(i1, i2, i3, i4, i5, i6, i7, i8, i9).stream().map(String::valueOf).collect(joining(", "))); + + final int input1 = 1; + final int input2 = 2; + final int input3 = 3; + final int input4 = 4; + final int input5 = 5; + final int input6 = 6; + final int input7 = 7; + final int input8 = 8; + final int input9 = 9; + final List inputList = Arrays.asList(input1, input2, input3, input4, input5, input6, input7, input8, input9); + final Pair expected = + new ImmutablePair<>(inputList.stream().reduce(0, (prev, i) -> prev + i), + "Values are " + inputList.stream().map(String::valueOf).collect(joining(", "))); + test("Consumer9.andThen(Consumer9)", "c9.andThen(c9_2) should do c9.accept(p1, p2, p3, p4, p5, p6, p7, p8, p9) then c9_2.accept(p1, p2, p3, p4, p5, p6, p7, p8, p9). \n" + + "In other words, c9.andThen(c9_2) == c9(p1, p2, p3, p4, p5, p6, p7, p8, p9); c9_2(p1, p2, p3, p4, p5, p6, p7, p8, p9)") + .when(() -> + first.andThen(second).accept(input1, input2, input3, input4, input5, input6, input7, input8, input9) + ) + .then(() -> + assertThat(resultPair).isEqualTo(expected) + ); + } +} \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Function3Test.java b/src/test/java/cc/kevinlee/functional/types/Function3Test.java index af85398..052dc92 100644 --- a/src/test/java/cc/kevinlee/functional/types/Function3Test.java +++ b/src/test/java/cc/kevinlee/functional/types/Function3Test.java @@ -2,14 +2,10 @@ import org.junit.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.function.Function; import static cc.kevinlee.testosterone.Testosterone.test; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; /** * @author Lee, Seong Hyun (Kevin) @@ -32,7 +28,7 @@ public void testAndThen() throws Exception { first.andThen(second).apply(input1, input2, input3) ) .then(actual -> - assertThat(actual).isEqualTo(second.apply(first.apply(input1, input2, input3))) + assertThat(actual).isEqualTo(second.apply(first.apply(input1, input2, input3))) ); } } \ No newline at end of file diff --git a/src/test/java/cc/kevinlee/functional/types/Function4Test.java b/src/test/java/cc/kevinlee/functional/types/Function4Test.java index bd1781a..7d53632 100644 --- a/src/test/java/cc/kevinlee/functional/types/Function4Test.java +++ b/src/test/java/cc/kevinlee/functional/types/Function4Test.java @@ -6,7 +6,6 @@ import static cc.kevinlee.testosterone.Testosterone.test; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; /** * @author Lee, Seong Hyun (Kevin) diff --git a/src/test/java/cc/kevinlee/functional/types/TypesUtil.java b/src/test/java/cc/kevinlee/functional/types/TypesUtil.java new file mode 100644 index 0000000..312737e --- /dev/null +++ b/src/test/java/cc/kevinlee/functional/types/TypesUtil.java @@ -0,0 +1,81 @@ +package cc.kevinlee.functional.types; + +import java.util.Objects; + +/** + * @author Lee, Seong Hyun (Kevin) + * @since 2015-05-17 + */ +public interface TypesUtil { + + interface Pair { + K value1(); + V value2(); + } + + static class ImmutablePair implements Pair { + public final K value1; + public final V value2; + + public ImmutablePair(final K value1, final V value2) { + this.value1 = value1; + this.value2 = value2; + } + + @Override + public K value1() { + return value1; + } + + @Override + public V value2() { + return value2; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (!(o instanceof Pair)) return false; + final Pair that = (Pair) o; + return Objects.equals(value1, that.value1()) && + Objects.equals(value2, that.value2()); + } + + @Override + public int hashCode() { + return Objects.hash(value1, value2); + } + } + static class MutablePair implements Pair { + private K value1; + private V value2; + + public K value1() { + return value1; + } + public void value1(final K value1) { + this.value1 = value1; + } + + public V value2() { + return value2; + } + public void value2(final V value2) { + this.value2 = value2; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (!(o instanceof Pair)) return false; + final Pair that = (Pair) o; + return Objects.equals(value1, that.value1()) && + Objects.equals(value2, that.value2()); + } + + @Override + public int hashCode() { + return Objects.hash(value1, value2); + } + } +}