Browse Source

updated tests

Leon 7 years ago
parent
commit
e5d10b688d
35 changed files with 622 additions and 444 deletions
  1. 348
    336
      .idea/workspace.xml
  2. 4
    3
      src/main/java/com/zipcodewilmington/lambdas/anthropoid/PersonFactory.java
  3. 0
    32
      src/main/java/com/zipcodewilmington/lambdas/exercises/ArrayConversion.java
  4. 38
    0
      src/main/java/com/zipcodewilmington/lambdas/exercises/ArrayConverter.java
  5. 12
    1
      src/main/java/com/zipcodewilmington/lambdas/exercises/ConversionAgent.java
  6. 0
    32
      src/main/java/com/zipcodewilmington/lambdas/exercises/ListConversion.java
  7. 39
    0
      src/main/java/com/zipcodewilmington/lambdas/exercises/ListConverter.java
  8. 0
    32
      src/main/java/com/zipcodewilmington/lambdas/exercises/StreamConversion.java
  9. 42
    0
      src/main/java/com/zipcodewilmington/lambdas/exercises/StreamConverter.java
  10. 1
    1
      src/main/java/com/zipcodewilmington/lambdas/tools/StringUtils.java
  11. 7
    7
      src/test/java/com/zipcodewilmington/lambdas/TestStreamFilter.java
  12. 8
    0
      src/test/java/com/zipcodewilmington/lambdas/exercises/TestConstants.java
  13. 75
    0
      src/test/java/com/zipcodewilmington/lambdas/exercises/TestConversionAgent.java
  14. 10
    0
      src/test/java/com/zipcodewilmington/lambdas/exercises/TestConverterArray.java
  15. 10
    0
      src/test/java/com/zipcodewilmington/lambdas/exercises/TestConverterList.java
  16. 10
    0
      src/test/java/com/zipcodewilmington/lambdas/exercises/TestConverterStream.java
  17. 18
    0
      src/test/java/com/zipcodewilmington/lambdas/exercises/TestSuiteConversionRegression.java
  18. BIN
      target/classes/com/zipcodewilmington/lambdas/MapSyntax.class
  19. BIN
      target/classes/com/zipcodewilmington/lambdas/StreamFilter.class
  20. BIN
      target/classes/com/zipcodewilmington/lambdas/StreamMap.class
  21. BIN
      target/classes/com/zipcodewilmington/lambdas/anthropoid/PersonFactory.class
  22. BIN
      target/classes/com/zipcodewilmington/lambdas/exercises/ArrayConverter.class
  23. BIN
      target/classes/com/zipcodewilmington/lambdas/exercises/ConversionAgent.class
  24. BIN
      target/classes/com/zipcodewilmington/lambdas/exercises/ListConverter.class
  25. BIN
      target/classes/com/zipcodewilmington/lambdas/exercises/StreamConverter.class
  26. BIN
      target/classes/com/zipcodewilmington/lambdas/tools/StringUtils.class
  27. BIN
      target/test-classes/com/zipcodewilmington/lambdas/TestStreamFilter.class
  28. BIN
      target/test-classes/com/zipcodewilmington/lambdas/TestStreamMap.class
  29. BIN
      target/test-classes/com/zipcodewilmington/lambdas/TestSuiteFullRegression.class
  30. BIN
      target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConstants.class
  31. BIN
      target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConversionAgent.class
  32. BIN
      target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConverterArray.class
  33. BIN
      target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConverterList.class
  34. BIN
      target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConverterStream.class
  35. BIN
      target/test-classes/com/zipcodewilmington/lambdas/exercises/TestSuiteConversionRegression.class

+ 348
- 336
.idea/workspace.xml
File diff suppressed because it is too large
View File


+ 4
- 3
src/main/java/com/zipcodewilmington/lambdas/anthropoid/PersonFactory.java View File

@@ -10,6 +10,7 @@ import java.util.stream.Stream;
10 10
 
11 11
 /**
12 12
  * Created by leon on 5/1/17.
13
+ * @ATTENTION_TO_STUDENTS You are FORBIDDEN from using loops of any sort within the definition of this class.
13 14
  */
14 15
 public final class PersonFactory {
15 16
     private PersonFactory() {
@@ -35,7 +36,7 @@ public final class PersonFactory {
35 36
     /**
36 37
      * @param personCount - number of Person objects to create
37 38
      * @return - ArrayList of Person objects
38
-     */
39
+     */ // TODO
39 40
     public static List<Person> createPersonList(int personCount) {
40 41
         return createPersonStream(personCount).collect(Collectors.toList());
41 42
     }
@@ -44,7 +45,7 @@ public final class PersonFactory {
44 45
     /**
45 46
      * @param personCount - number of Person objects to create
46 47
      * @return - Array of Person objects
47
-     */
48
+     */ // TODO
48 49
     public static Person[] createPersonArray(int personCount) {
49 50
         return createPersonStream(personCount).toArray(Person[]::new);
50 51
     }
@@ -53,7 +54,7 @@ public final class PersonFactory {
53 54
     /**
54 55
      * @param personCount - number of Person objects to create
55 56
      * @return - Stream representation of collection of Person objects
56
-     */
57
+     */ // TODO
57 58
     public static Stream<Person> createPersonStream(int personCount) {
58 59
         return Stream.generate(PersonFactory::createRandomPerson).limit(personCount);
59 60
     }

+ 0
- 32
src/main/java/com/zipcodewilmington/lambdas/exercises/ArrayConversion.java View File

@@ -1,32 +0,0 @@
1
-package com.zipcodewilmington.lambdas.exercises;
2
-
3
-import com.zipcodewilmington.lambdas.anthropoid.Person;
4
-
5
-import java.util.List;
6
-import java.util.stream.Stream;
7
-
8
-/**
9
- * Created by leon on 5/25/17.
10
- */
11
-public final class ArrayConversion extends ConversionAgent {
12
-    private final Person[] people;
13
-
14
-    public ArrayConversion(Person... people) {
15
-        this.people = people;
16
-    }
17
-
18
-    //TODO
19
-    public Stream<Person> toStream() {
20
-        return null;
21
-    }
22
-
23
-    @Override
24
-    public Person[] toArray() {
25
-        return this.people;
26
-    }
27
-
28
-    //TODO
29
-    public List<Person> toList() {
30
-        return null;
31
-    }
32
-}

+ 38
- 0
src/main/java/com/zipcodewilmington/lambdas/exercises/ArrayConverter.java View File

@@ -0,0 +1,38 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+import com.zipcodewilmington.lambdas.anthropoid.Person;
4
+import com.zipcodewilmington.lambdas.anthropoid.PersonFactory;
5
+
6
+import java.util.Arrays;
7
+import java.util.List;
8
+import java.util.stream.Stream;
9
+
10
+/**
11
+ * Created by leon on 5/25/17.
12
+ */
13
+public final class ArrayConverter extends ConversionAgent<Person[]> {
14
+    public ArrayConverter(Person... people) {
15
+        super(people);
16
+    }
17
+
18
+    public ArrayConverter(int collectionSize) {
19
+        this(PersonFactory.createPersonArray(collectionSize));
20
+        /** Implementation of adapter pattern for testing purposes
21
+         *  @param collectionSize  - length of Array to be generated */
22
+    }
23
+
24
+    //TODO
25
+    public List<Person> toList() {
26
+        return Arrays.asList(toArray());
27
+    }
28
+
29
+    //TODO
30
+    public Stream<Person> toStream() {
31
+        return toList().stream();
32
+    }
33
+
34
+    @Override
35
+    public Person[] toArray() {
36
+        return this.people;
37
+    }
38
+}

+ 12
- 1
src/main/java/com/zipcodewilmington/lambdas/exercises/ConversionAgent.java View File

@@ -3,13 +3,20 @@ package com.zipcodewilmington.lambdas.exercises;
3 3
 import com.zipcodewilmington.lambdas.anthropoid.Person;
4 4
 
5 5
 import java.util.List;
6
+import java.util.function.Function;
6 7
 import java.util.function.Predicate;
7 8
 import java.util.stream.Stream;
8 9
 
9 10
 /**
10 11
  * Created by leon on 5/25/17.
12
+ * A ConversionAgent is some object whose purpose is to convert between different collection types
11 13
  */
12
-public abstract class ConversionAgent {
14
+public abstract class ConversionAgent<T> {
15
+    protected T people;
16
+
17
+    public ConversionAgent(T val) {
18
+        this.people = val;
19
+    }
13 20
 
14 21
     abstract public List<Person> toList();
15 22
 
@@ -20,4 +27,8 @@ public abstract class ConversionAgent {
20 27
     public Stream<Person> filter(Predicate<? super Person> predicate) {
21 28
         return toStream().filter(predicate);
22 29
     }
30
+
31
+    public Stream<Person> flatMap(Function<? super Person, ? extends Stream<Person>> predicate) {
32
+        return toStream().flatMap(predicate);
33
+    }
23 34
 }

+ 0
- 32
src/main/java/com/zipcodewilmington/lambdas/exercises/ListConversion.java View File

@@ -1,32 +0,0 @@
1
-package com.zipcodewilmington.lambdas.exercises;
2
-
3
-import com.zipcodewilmington.lambdas.anthropoid.Person;
4
-
5
-import java.util.List;
6
-import java.util.stream.Stream;
7
-
8
-/**
9
- * Created by leon on 5/25/17.
10
- */
11
-public final class ListConversion extends ConversionAgent {
12
-    private final List<Person> people;
13
-
14
-    public ListConversion(List<Person> people) {
15
-        this.people = people;
16
-    }
17
-
18
-    @Override
19
-    public List<Person> toList() {
20
-        return this.people;
21
-    }
22
-
23
-    //TODO
24
-    public Stream<Person> toStream() {
25
-        return null;
26
-    }
27
-
28
-    //TODO
29
-    public Person[] toArray() {
30
-        return null;
31
-    }
32
-}

+ 39
- 0
src/main/java/com/zipcodewilmington/lambdas/exercises/ListConverter.java View File

@@ -0,0 +1,39 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+import com.zipcodewilmington.lambdas.anthropoid.Person;
4
+import com.zipcodewilmington.lambdas.anthropoid.PersonFactory;
5
+
6
+import java.util.List;
7
+import java.util.stream.Stream;
8
+
9
+/**
10
+ * Created by leon on 5/25/17.
11
+ */
12
+public final class ListConverter extends ConversionAgent<List<Person>> {
13
+    public ListConverter(List<Person> people) {
14
+        super(people);
15
+    }
16
+
17
+    public ListConverter(int collectionSize) {
18
+        this(PersonFactory.createPersonList(collectionSize));
19
+        /** Implementation of adapter pattern for testing purposes
20
+         *  @param collectionSize  - size of List to be generated */
21
+    }
22
+
23
+    @Override
24
+    public List<Person> toList() {
25
+        return this.people;
26
+    }
27
+
28
+    //TODO
29
+    public Stream<Person> toStream() {
30
+        return toList().stream();
31
+    }
32
+
33
+    //TODO
34
+    public Person[] toArray() {
35
+        Long collectionSize = toStream().count();
36
+        Person[] personArray = new Person[collectionSize.intValue()];
37
+        return toList().toArray(personArray);
38
+    }
39
+}

+ 0
- 32
src/main/java/com/zipcodewilmington/lambdas/exercises/StreamConversion.java View File

@@ -1,32 +0,0 @@
1
-package com.zipcodewilmington.lambdas.exercises;
2
-
3
-import com.zipcodewilmington.lambdas.anthropoid.Person;
4
-
5
-import java.util.List;
6
-import java.util.stream.Stream;
7
-
8
-/**
9
- * Created by leon on 5/25/17.
10
- */
11
-public final class StreamConversion extends ConversionAgent {
12
-    private final Stream<Person> people;
13
-
14
-    public StreamConversion(Stream<Person> people) {
15
-        this.people = people;
16
-    }
17
-
18
-    // TODO
19
-    public List<Person> toList() {
20
-        return null;
21
-    }
22
-
23
-    // TODO
24
-    public Stream<Person> toStream() {
25
-        return this.people;
26
-    }
27
-
28
-    // TODO
29
-    public Person[] toArray() {
30
-        return null;
31
-    }
32
-}

+ 42
- 0
src/main/java/com/zipcodewilmington/lambdas/exercises/StreamConverter.java View File

@@ -0,0 +1,42 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+import com.zipcodewilmington.lambdas.anthropoid.Person;
4
+import com.zipcodewilmington.lambdas.anthropoid.PersonFactory;
5
+
6
+import java.util.List;
7
+import java.util.stream.Collectors;
8
+import java.util.stream.Stream;
9
+
10
+import static java.lang.System.out;
11
+
12
+/**
13
+ * Created by leon on 5/25/17.
14
+ */
15
+public final class StreamConverter extends ConversionAgent<Stream<Person>> {
16
+    List<Person> personList;
17
+    public StreamConverter(Stream<Person> people) {
18
+        super(people);
19
+        this.personList = super.people.collect(Collectors.toList());
20
+    }
21
+
22
+    public StreamConverter(int collectionSize) {
23
+        this(PersonFactory.createPersonStream(collectionSize));
24
+        /** Implementation of adapter pattern for testing purposes
25
+         *  @param collectionSize  - count of Stream to be generated */
26
+    }
27
+
28
+    // TODO
29
+    public List<Person> toList() {
30
+        return this.personList;
31
+    }
32
+
33
+    // TODO
34
+    public Stream<Person> toStream() {
35
+        return this.personList.stream();
36
+    }
37
+
38
+    // TODO
39
+    public Person[] toArray() {
40
+        return toStream().toArray(Person[]::new);
41
+    }
42
+}

+ 1
- 1
src/main/java/com/zipcodewilmington/lambdas/tools/StringUtils.java View File

@@ -21,7 +21,7 @@ public class StringUtils {
21 21
     /**
22 22
      * @param numberOfRepeats - number of times to repeat this string
23 23
      * @param val - value of string to repeat
24
-     * @return - `val` concatenated with itself `numberOfRepeats` times
24
+     * @return - `people` concatenated with itself `numberOfRepeats` times
25 25
      */
26 26
     public static String repeatString(int numberOfRepeats, String val) {
27 27
         StringBuffer sb = new StringBuffer();

+ 7
- 7
src/test/java/com/zipcodewilmington/lambdas/TestStreamFilter.java View File

@@ -11,31 +11,31 @@ import java.util.List;
11 11
  * Created by leon on 5/2/17.
12 12
  */
13 13
 public class TestStreamFilter {
14
-    private StreamFilter streamFilter;
14
+    private StreamFilter lambdaFilter;
15 15
 
16 16
     @Before
17 17
     public void setup() {
18
-        streamFilter = new StreamFilter();
18
+        lambdaFilter = new StreamFilter();
19 19
     }
20 20
 
21 21
     @Test
22 22
     public void testToListMultiLine() {
23
-        testFilter(streamFilter.toListMultiLine());
23
+        testFilter(lambdaFilter.toListMultiLine());
24 24
     }
25 25
 
26 26
     @Test
27 27
     public void testToListOneLine() {
28
-        testFilter(streamFilter.toListOneLine());
28
+        testFilter(lambdaFilter.toListOneLine());
29 29
     }
30 30
 
31 31
     @Test
32 32
     public void testToArrayMultiLine() {
33
-        testFilter(streamFilter.toArrayMultiLine());
33
+        testFilter(lambdaFilter.toArrayMultiLine());
34 34
     }
35 35
 
36 36
     @Test
37 37
     public void testToArrayOneLine() {
38
-        testFilter(streamFilter.toArrayOneLine());
38
+        testFilter(lambdaFilter.toArrayOneLine());
39 39
     }
40 40
 
41 41
 
@@ -47,7 +47,7 @@ public class TestStreamFilter {
47 47
 
48 48
     private void testFilter(List<Person> persons) {
49 49
         for (Person p : persons) {
50
-            assert (p.name.getValue().startsWith(streamFilter.startingCharacter));
50
+            assert (p.name.getValue().startsWith(lambdaFilter.startingCharacter));
51 51
         }
52 52
     }
53 53
 }

+ 8
- 0
src/test/java/com/zipcodewilmington/lambdas/exercises/TestConstants.java View File

@@ -0,0 +1,8 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+/**
4
+ * Created by leon on 5/25/17.
5
+ */
6
+public interface TestConstants {
7
+    int collectionSize = 999;
8
+}

+ 75
- 0
src/test/java/com/zipcodewilmington/lambdas/exercises/TestConversionAgent.java View File

@@ -0,0 +1,75 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+import com.zipcodewilmington.lambdas.anthropoid.Person;
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import java.util.List;
9
+import java.util.stream.Collectors;
10
+import java.util.stream.Stream;
11
+
12
+/**
13
+ * Created by leon on 5/25/17.
14
+ */
15
+public class TestConversionAgent<T extends ConversionAgent> {
16
+    private final T conversionAgent;
17
+
18
+    private List<Person> personList;
19
+    private Person[] personArray;
20
+    private Stream<Person> personStream;
21
+
22
+    public TestConversionAgent(T conversionAgent) {
23
+        this.conversionAgent = conversionAgent;
24
+    }
25
+
26
+    @Before
27
+    public void setup() {
28
+        this.personStream = conversionAgent.toStream();
29
+        this.personList = conversionAgent.toList();
30
+        this.personArray = conversionAgent.toArray();
31
+    }
32
+
33
+    @Test
34
+    public void testCount() {
35
+        int listSize = personList.size();
36
+        int arrayLength = personArray.length;
37
+        int streamCount = (int) personStream.count();
38
+
39
+        Assert.assertEquals(listSize, arrayLength);
40
+        Assert.assertEquals(listSize, streamCount);
41
+    }
42
+
43
+    @Test
44
+    public void testToList() {
45
+        for (int i = 0; i < personList.size(); i++) {
46
+            long listId = personList.get(i).personalId.getValue();
47
+            long arrayId = personArray[i].personalId.getValue();
48
+
49
+            Assert.assertEquals(listId, arrayId);
50
+        }
51
+    }
52
+
53
+
54
+    @Test
55
+    public void testToStream() {
56
+        List<Person> people = personStream.collect(Collectors.toList());
57
+
58
+        for (int i = 0; i < people.size(); i++) {
59
+            long arrayId = personArray[i].personalId.getValue();
60
+            long streamId = people.get(i).personalId.getValue();
61
+
62
+            Assert.assertEquals(streamId, arrayId);
63
+        }
64
+    }
65
+
66
+    @Test
67
+    public void testToArray() {
68
+        for (int i = 0; i < personArray.length; i++) {
69
+            long arrayId = personArray[i].personalId.getValue();
70
+            long listId = personList.get(i).personalId.getValue();
71
+
72
+            Assert.assertEquals(listId, arrayId);
73
+        }
74
+    }
75
+}

+ 10
- 0
src/test/java/com/zipcodewilmington/lambdas/exercises/TestConverterArray.java View File

@@ -0,0 +1,10 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+/**
4
+ * Created by leon on 5/25/17.
5
+ */
6
+public class TestConverterArray extends TestConversionAgent implements TestConstants {
7
+    public TestConverterArray() {
8
+        super(new ArrayConverter(collectionSize));
9
+    }
10
+}

+ 10
- 0
src/test/java/com/zipcodewilmington/lambdas/exercises/TestConverterList.java View File

@@ -0,0 +1,10 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+/**
4
+ * Created by leon on 5/25/17.
5
+ */
6
+public class TestConverterList extends TestConversionAgent implements TestConstants {
7
+    public TestConverterList() {
8
+        super(new ListConverter(collectionSize));
9
+    }
10
+}

+ 10
- 0
src/test/java/com/zipcodewilmington/lambdas/exercises/TestConverterStream.java View File

@@ -0,0 +1,10 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+/**
4
+ * Created by leon on 5/25/17.
5
+ */
6
+public class TestConverterStream extends TestConversionAgent implements TestConstants {
7
+    public TestConverterStream() {
8
+        super(new StreamConverter(collectionSize));
9
+    }
10
+}

+ 18
- 0
src/test/java/com/zipcodewilmington/lambdas/exercises/TestSuiteConversionRegression.java View File

@@ -0,0 +1,18 @@
1
+package com.zipcodewilmington.lambdas.exercises;
2
+
3
+import com.zipcodewilmington.lambdas.TestPersonFactory;
4
+import com.zipcodewilmington.lambdas.TestStreamFilter;
5
+import com.zipcodewilmington.lambdas.TestStreamMap;
6
+import org.junit.runner.RunWith;
7
+import org.junit.runners.Suite;
8
+
9
+@RunWith(Suite.class)
10
+
11
+@Suite.SuiteClasses({
12
+        TestConverterList.class,
13
+        TestConverterArray.class,
14
+        TestConverterStream.class
15
+})
16
+
17
+public class TestSuiteConversionRegression {
18
+}

BIN
target/classes/com/zipcodewilmington/lambdas/MapSyntax.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/LambdaFilter.class → target/classes/com/zipcodewilmington/lambdas/StreamFilter.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/StreamMap.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/anthropoid/PersonFactory.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/exercises/ArrayConverter.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/exercises/ConversionAgent.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/exercises/ListConverter.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/exercises/StreamConverter.class View File


BIN
target/classes/com/zipcodewilmington/lambdas/tools/StringUtils.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/TestLambdaFilter.class → target/test-classes/com/zipcodewilmington/lambdas/TestStreamFilter.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/TestMapSyntax.class → target/test-classes/com/zipcodewilmington/lambdas/TestStreamMap.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/TestSuiteFullRegression.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConstants.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConversionAgent.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConverterArray.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConverterList.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/exercises/TestConverterStream.class View File


BIN
target/test-classes/com/zipcodewilmington/lambdas/exercises/TestSuiteConversionRegression.class View File