Leon преди 5 години
ревизия
527128b33a
променени са 80 файла, в които са добавени 3764 реда и са изтрити 0 реда
  1. 115
    0
      .gitignore
  2. 32
    0
      pom.xml
  3. 17
    0
      src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java
  4. 31
    0
      src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java
  5. 24
    0
      src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java
  6. 18
    0
      src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java
  7. 18
    0
      src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java
  8. 18
    0
      src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java
  9. 37
    0
      src/main/java/rocks/zipcode/io/quiz4/generics/Group.java
  10. 13
    0
      src/main/java/rocks/zipcode/io/quiz4/generics/GroupInterface.java
  11. 25
    0
      src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java
  12. 18
    0
      src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java
  13. 21
    0
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java
  14. 17
    0
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java
  15. 20
    0
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java
  16. 22
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/ComparableTreeSetPolymorphismTest.java
  17. 38
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/ToStringTest.java
  18. 38
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/multipleelement/CompareMultipleElementNegative.java
  19. 38
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/multipleelement/CompareMultipleElementNeutral.java
  20. 52
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/multipleelement/CompareMultipleElementPositive.java
  21. 49
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/singleelement/CompareSingleElementNeutral.java
  22. 49
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/singleelement/CompareSingleElementSetNegative.java
  23. 46
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/singleelement/CompareSingleElementSetPositive.java
  24. 47
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementNegative.java
  25. 47
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementNeutral.java
  26. 47
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementPositive.java
  27. 43
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/ClearTest.java
  28. 42
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/CountTest.java
  29. 51
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/DeleteTest.java
  30. 37
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/DistinctTest.java
  31. 59
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/GetTest.java
  32. 37
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/InsertTest.java
  33. 55
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/IterableTest.java
  34. 23
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/SimpleStringGroupPolymorphismTest.java
  35. 7
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/ToStringTest.java
  36. 7
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/WhereTest.java
  37. 44
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/EnrollTest.java
  38. 133
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/GetStudyMapTest.java
  39. 49
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/LectureTest.java
  40. 103
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetAllPrefixes.java
  41. 84
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetCommonSuffixesTest.java
  42. 70
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetLargestCommonSuffixTest.java
  43. 49
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/genericarrayutils/powerset/PowerSetOfThreeElements.java
  44. 49
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/genericarrayutils/powerset/PowerSetOfTwoElements.java
  45. 20
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/genericarrayutils/powerset/PowerSetTest.java
  46. 28
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/GroupPolymorphismTest.java
  47. 59
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/GroupToStringTest.java
  48. 43
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupClearTest.java
  49. 42
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupCountTest.java
  50. 37
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupDistinctTest.java
  51. 56
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupIterableTest.java
  52. 7
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupWhereTest.java
  53. 43
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupClearTest.java
  54. 42
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupCountTest.java
  55. 51
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupDeleteTest.java
  56. 37
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupDistinctTest.java
  57. 59
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupFetchTest.java
  58. 37
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupInsertTest.java
  59. 56
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupIterableTest.java
  60. 7
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupWhereTest.java
  61. 16
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/SortedGroupPolymorphismTest.java
  62. 91
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupDeleteTest.java
  63. 94
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupInsertTest.java
  64. 91
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/stringsortedgroup/StringSortedGroupDeleteTest.java
  65. 229
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/stringsortedgroup/StringSortedGroupInsertTest.java
  66. 22
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/stack/StackPolymorphismTest.java
  67. 35
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/stack/integerstack/IntegerStackIsEmptyTest.java
  68. 54
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/stack/integerstack/IntegerStackPopTest.java
  69. 67
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/stack/integerstack/IntegerStackPushTest.java
  70. 35
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/stack/stringstack/StringStackIsEmptyTest.java
  71. 55
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/stack/stringstack/StringStackPopTest.java
  72. 67
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/stack/stringstack/StringStackPushTest.java
  73. 52
    0
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectGetAllPalindromesTest.java
  74. 30
    0
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectIsPalindromeTestNegative.java
  75. 34
    0
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectIsPalindromeTestPositive.java
  76. 36
    0
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectReverseTest.java
  77. 88
    0
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/stringassembler/AppendTest.java
  78. 88
    0
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/student/LearnTest.java
  79. 54
    0
      src/test/java/rocks/zipcode/io/quiz4/utils/MyTestClass.java
  80. 63
    0
      src/test/java/rocks/zipcode/io/quiz4/utils/TestUtils.java

+ 115
- 0
.gitignore Целия файл

@@ -0,0 +1,115 @@
1
+# Created by .ignore support plugin (hsz.mobi)
2
+### Java template
3
+# Compiled class file
4
+*.class
5
+
6
+# Log file
7
+*.log
8
+
9
+# BlueJ files
10
+*.ctxt
11
+
12
+# Mobile Tools for Java (J2ME)
13
+.mtj.tmp/
14
+
15
+# Package Files #
16
+*.jar
17
+*.war
18
+*.ear
19
+*.zip
20
+*.tar.gz
21
+*.rar
22
+
23
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24
+hs_err_pid*
25
+### Eclipse template
26
+
27
+.metadata
28
+bin/
29
+tmp/
30
+*.tmp
31
+*.bak
32
+*.swp
33
+*~.nib
34
+local.properties
35
+.settings/
36
+.loadpath
37
+.recommenders
38
+
39
+# Eclipse Core
40
+.project
41
+
42
+# External tool builders
43
+.externalToolBuilders/
44
+
45
+# Locally stored "Eclipse launch configurations"
46
+*.launch
47
+
48
+# PyDev specific (Python IDE for Eclipse)
49
+*.pydevproject
50
+
51
+# CDT-specific (C/C++ Development Tooling)
52
+.cproject
53
+
54
+# JDT-specific (Eclipse Java Development Tools)
55
+.classpath
56
+
57
+# Java annotation processor (APT)
58
+.factorypath
59
+
60
+# PDT-specific (PHP Development Tools)
61
+.buildpath
62
+
63
+# sbteclipse plugin
64
+.target
65
+
66
+# Tern plugin
67
+.tern-project
68
+
69
+# TeXlipse plugin
70
+.texlipse
71
+
72
+# STS (Spring Tool Suite)
73
+.springBeans
74
+
75
+# Code Recommenders
76
+.recommenders/
77
+
78
+# Scala IDE specific (Scala & Java development for Eclipse)
79
+.cache-main
80
+.scala_dependencies
81
+.worksheet
82
+### macOS template
83
+*.DS_Store
84
+.AppleDouble
85
+.LSOverride
86
+
87
+# Icon must end with two \r
88
+Icon
89
+
90
+
91
+# Thumbnails
92
+._*
93
+
94
+# Files that might appear in the root of a volume
95
+.DocumentRevisions-V100
96
+.fseventsd
97
+.Spotlight-V100
98
+.TemporaryItems
99
+.Trashes
100
+.VolumeIcon.icns
101
+.com.apple.timemachine.donotpresent
102
+
103
+# Directories potentially created on remote AFP share
104
+.AppleDB
105
+.AppleDesktop
106
+Network Trash Folder
107
+Temporary Items
108
+.apdisk
109
+
110
+#Intellij files
111
+.idea
112
+*.iml
113
+
114
+#maven build target
115
+target/

+ 32
- 0
pom.xml Целия файл

@@ -0,0 +1,32 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>rocks.zipcode.io</groupId>
8
+    <artifactId>quiz4</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>8</source>
17
+                    <target>8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>junit</groupId>
25
+            <artifactId>junit</artifactId>
26
+            <version>4.12</version>
27
+            <scope>test</scope>
28
+        </dependency>
29
+    </dependencies>
30
+
31
+
32
+</project>

+ 17
- 0
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java Целия файл

@@ -0,0 +1,17 @@
1
+package rocks.zipcode.io.quiz4.collections;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class ComparableTreeSet<_> {
7
+    public ComparableTreeSet(_... arr) {
8
+    }
9
+
10
+
11
+    public ComparableTreeSet() {
12
+    }
13
+
14
+    public Integer compareTo(ComparableTreeSet<_> o) {
15
+        return null;
16
+    }
17
+}

+ 31
- 0
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java Целия файл

@@ -0,0 +1,31 @@
1
+package rocks.zipcode.io.quiz4.collections;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class SimpleStringGroup {
7
+    public SimpleStringGroup() {
8
+        throw new UnsupportedOperationException("Method not yet implemented");
9
+    }
10
+
11
+    public Integer count() {
12
+        return null;
13
+    }
14
+
15
+    public void insert(String string) {
16
+    }
17
+
18
+    public Boolean has(String valueToInsert) {
19
+        return null;
20
+    }
21
+
22
+    public String fetch(int indexOfValue) {
23
+        return null;
24
+    }
25
+
26
+    public void delete(String valueToInsert) {
27
+    }
28
+
29
+    public void clear() {
30
+    }
31
+}

+ 24
- 0
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java Целия файл

@@ -0,0 +1,24 @@
1
+package rocks.zipcode.io.quiz4.collections;
2
+
3
+import rocks.zipcode.io.quiz4.objectorientation.Student;
4
+
5
+import java.util.Map;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class ZipCodeWilmington {
11
+    public void enroll(Student student) {
12
+    }
13
+
14
+    public Boolean isEnrolled(Student student) {
15
+        return null;
16
+    }
17
+
18
+    public void lecture(double numberOfHours) {
19
+    }
20
+
21
+    public Map<Student, Double> getStudyMap() {
22
+        return null;
23
+    }
24
+}

+ 18
- 0
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java Целия файл

@@ -0,0 +1,18 @@
1
+package rocks.zipcode.io.quiz4.fundamentals;
2
+
3
+/**
4
+ * @author leon on 18/12/2018.
5
+ */
6
+public class PalindromeEvaluator {
7
+    public static String[] getAllPalindromes(String string) {
8
+        return null;
9
+    }
10
+
11
+    public static Boolean isPalindrome(String string) {
12
+        return null;
13
+    }
14
+
15
+    public static String reverseString(String string) {
16
+        return null;
17
+    }
18
+}

+ 18
- 0
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java Целия файл

@@ -0,0 +1,18 @@
1
+package rocks.zipcode.io.quiz4.fundamentals;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class StringEvaluator {
7
+    public static String[] getAllPrefixes(String string) {
8
+        return null;
9
+    }
10
+
11
+    public static String[] getCommonPrefixes(String string1, String string2) {
12
+        return null;
13
+    }
14
+
15
+    public static String getLargestCommonPrefix(String string1, String string2) {
16
+        return null;
17
+    }
18
+}

+ 18
- 0
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java Целия файл

@@ -0,0 +1,18 @@
1
+package rocks.zipcode.io.quiz4.generics;
2
+
3
+import java.util.Arrays;
4
+import java.util.Set;
5
+import java.util.TreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class GenericUtils {
11
+    public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(Set<_> originalSet) {
12
+        return null;
13
+    }
14
+
15
+    public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(_... originalSet) {
16
+        return powerSet(new TreeSet<>(Arrays.asList(originalSet)));
17
+    }
18
+}

+ 37
- 0
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java Целия файл

@@ -0,0 +1,37 @@
1
+package rocks.zipcode.io.quiz4.generics;
2
+
3
+import java.util.Iterator;
4
+
5
+/**
6
+ * @author leon on 18/12/2018.
7
+ */
8
+public class Group<_> {
9
+    public Group() {
10
+        throw new UnsupportedOperationException("Method not yet implemented");
11
+    }
12
+
13
+    public Integer count() {
14
+        return null;
15
+    }
16
+
17
+    public void insert(_ value) {
18
+    }
19
+
20
+    public Boolean has(_ value) {
21
+        return null;
22
+    }
23
+
24
+    public _ fetch(int indexOfValue) {
25
+        return null;
26
+    }
27
+
28
+    public void delete(_ value) {
29
+    }
30
+
31
+    public void clear() {
32
+    }
33
+
34
+    public Iterator<_> iterator() {
35
+        return null;
36
+    }
37
+}

+ 13
- 0
src/main/java/rocks/zipcode/io/quiz4/generics/GroupInterface.java Целия файл

@@ -0,0 +1,13 @@
1
+package rocks.zipcode.io.quiz4.generics;
2
+
3
+/**
4
+ * @author leon on 18/12/2018.
5
+ */
6
+public interface GroupInterface<_> extends Iterable<_> {
7
+    Integer count();
8
+    Boolean has(_ valueToInsert);
9
+    _ fetch(int indexOfValue);
10
+    void insert(_ string);
11
+    void delete(_ valueToInsert);
12
+    void clear();
13
+}

+ 25
- 0
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java Целия файл

@@ -0,0 +1,25 @@
1
+package rocks.zipcode.io.quiz4.generics;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class MyStack<SomeType> {
7
+    public MyStack() {
8
+        throw new UnsupportedOperationException("Method not yet implemented");
9
+    }
10
+
11
+    public Boolean isEmpty() {
12
+        return null;
13
+    }
14
+
15
+    public void push(SomeType i) {
16
+    }
17
+
18
+    public SomeType peek() {
19
+        throw new UnsupportedOperationException("Method not yet implemented");
20
+    }
21
+
22
+    public SomeType pop() {
23
+        return null;
24
+    }
25
+}

+ 18
- 0
src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java Целия файл

@@ -0,0 +1,18 @@
1
+package rocks.zipcode.io.quiz4.generics;
2
+
3
+/**
4
+ * @author leon on 18/12/2018.
5
+ */
6
+public class SortedGroup<_> extends Group<_> {
7
+    @Override
8
+    public void insert(_ value) {
9
+    }
10
+
11
+    @Override
12
+    public void delete(_ value) {
13
+    }
14
+
15
+    public Integer indexOf(_ firstValue) {
16
+        return null;
17
+    }
18
+}

+ 21
- 0
src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java Целия файл

@@ -0,0 +1,21 @@
1
+package rocks.zipcode.io.quiz4.objectorientation;
2
+
3
+/**
4
+ * @author leon on 18/12/2018.
5
+ */
6
+public class PalindromeObject {
7
+    public PalindromeObject(String input) {
8
+    }
9
+
10
+    public String[] getAllPalindromes(){
11
+        return null;
12
+    }
13
+
14
+    public Boolean isPalindrome(){
15
+        return null;
16
+    }
17
+
18
+    public String reverseString(){
19
+        return null;
20
+    }
21
+}

+ 17
- 0
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java Целия файл

@@ -0,0 +1,17 @@
1
+package rocks.zipcode.io.quiz4.objectorientation;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class StringAssembler {
7
+    public StringAssembler(Character delimeter) {
8
+    }
9
+
10
+    public StringAssembler append(String str) {
11
+        return null;
12
+    }
13
+
14
+    public String assemble() {
15
+        return null;
16
+    }
17
+}

+ 20
- 0
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java Целия файл

@@ -0,0 +1,20 @@
1
+package rocks.zipcode.io.quiz4.objectorientation;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class Student {
7
+    public Student() {
8
+        this(null);
9
+    }
10
+
11
+    public Student(Integer id) {
12
+    }
13
+
14
+    public void learn(Double amountOfHours) {
15
+    }
16
+
17
+    public Double getTotalStudyTime() {
18
+        return null;
19
+    }
20
+}

+ 22
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/ComparableTreeSetPolymorphismTest.java Целия файл

@@ -0,0 +1,22 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+import java.util.TreeSet;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class ComparableTreeSetPolymorphismTest {
13
+    @Test
14
+    public void test1() {
15
+        Assert.assertTrue((Object)new ComparableTreeSet() instanceof TreeSet);
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        Assert.assertTrue(new ComparableTreeSet() instanceof Comparable);
21
+    }
22
+}

+ 38
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/ToStringTest.java Целия файл

@@ -0,0 +1,38 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class ToStringTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        String[] input = "qwertyuiop".split("");
15
+        ComparableTreeSet<String> set = new ComparableTreeSet<>(input);
16
+        String expected = "[e, i, o, p, q, r, t, u, w, y]";
17
+
18
+        // when
19
+        String actual = set.toString();
20
+
21
+        // then
22
+        Assert.assertEquals(expected, actual);
23
+    }
24
+
25
+    @Test
26
+    public void test2() {
27
+        // given
28
+        String[] input = "asdfghjk".split("");
29
+        ComparableTreeSet<String> set = new ComparableTreeSet<>(input);
30
+        String expected = "[a, d, f, g, h, j, k, s]";
31
+
32
+        // when
33
+        String actual = set.toString();
34
+
35
+        // then
36
+        Assert.assertEquals(expected, actual);
37
+    }
38
+}

+ 38
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/multipleelement/CompareMultipleElementNegative.java Целия файл

@@ -0,0 +1,38 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.flatset.multipleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class CompareMultipleElementNegative {
11
+
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Arty", "Fee", "Shawl");
16
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Burt", "Bot", "Boi");
17
+
18
+        // when
19
+        Integer actual = set1.compareTo(set2);
20
+
21
+        // then
22
+        Assert.assertTrue(actual < 0);
23
+    }
24
+
25
+
26
+    @Test
27
+    public void test2() {
28
+        // given
29
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Candy", "Cane");
30
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Corny", "Carl");
31
+
32
+        // when
33
+        Integer actual = set1.compareTo(set2);
34
+
35
+        // then
36
+        Assert.assertTrue(actual < 0);
37
+    }
38
+}

+ 38
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/multipleelement/CompareMultipleElementNeutral.java Целия файл

@@ -0,0 +1,38 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.flatset.multipleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class CompareMultipleElementNeutral {
11
+
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Arty", "Fee", "Shawl");
16
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Fee", "Shawl", "Arty");
17
+
18
+        // when
19
+        Integer actual = set1.compareTo(set2);
20
+
21
+        // then
22
+        Assert.assertTrue(actual == 0);
23
+    }
24
+
25
+
26
+    @Test
27
+    public void test2() {
28
+        // given
29
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("The", "Quick", "Brown", "Fox", "Jumps");
30
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Jumps", "Brown", "Fox", "Quick", "The");
31
+
32
+        // when
33
+        Integer actual = set1.compareTo(set2);
34
+
35
+        // then
36
+        Assert.assertTrue(actual == 0);
37
+    }
38
+}

+ 52
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/multipleelement/CompareMultipleElementPositive.java Целия файл

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.flatset.multipleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class CompareMultipleElementPositive {
11
+
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Burt", "Belly", "Bot");
16
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Arty", "Fee", "Shawl");
17
+
18
+        // when
19
+        Integer actual = set1.compareTo(set2);
20
+
21
+        // then
22
+        Assert.assertTrue(actual > 0);
23
+    }
24
+
25
+
26
+    @Test
27
+    public void test2() {
28
+        // given
29
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Corny", "Carl", "Cart");
30
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Candy", "Cane", "Corks");
31
+
32
+        // when
33
+        Integer actual = set1.compareTo(set2);
34
+
35
+        // then
36
+        Assert.assertTrue(actual > 0);
37
+    }
38
+
39
+
40
+    @Test
41
+    public void test3() {
42
+        // given
43
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Corny", "Carl", "Cart");
44
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("", "a", "z");
45
+
46
+        // when
47
+        Integer actual = set1.compareTo(set2);
48
+
49
+        // then
50
+        Assert.assertTrue(actual > 0);
51
+    }
52
+}

+ 49
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/singleelement/CompareSingleElementNeutral.java Целия файл

@@ -0,0 +1,49 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.flatset.singleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class CompareSingleElementNeutral {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("a");
15
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("a");
16
+        Integer expected = 0;
17
+        // when
18
+        Integer actual = set1.compareTo(set2);
19
+
20
+        // then
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        // given
27
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("b");
28
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("b");
29
+        Integer expected = 0;
30
+        // when
31
+        Integer actual = set1.compareTo(set2);
32
+
33
+        // then
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+
37
+    @Test
38
+    public void test3() {
39
+        // given
40
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("c");
41
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("c");
42
+        Integer expected = 0;
43
+        // when
44
+        Integer actual = set1.compareTo(set2);
45
+
46
+        // then
47
+        Assert.assertEquals(expected, actual);
48
+    }
49
+}

+ 49
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/singleelement/CompareSingleElementSetNegative.java Целия файл

@@ -0,0 +1,49 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.flatset.singleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class CompareSingleElementSetNegative {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        ComparableTreeSet<String> a = new ComparableTreeSet<>("a");
15
+        ComparableTreeSet<String> b = new ComparableTreeSet<>("b");
16
+
17
+        // when
18
+        Integer actual = a.compareTo(b);
19
+
20
+        // then
21
+        Assert.assertTrue(actual < 0);
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        // given
27
+        ComparableTreeSet<String> a = new ComparableTreeSet<>("a");
28
+        ComparableTreeSet<String> c = new ComparableTreeSet<>("c");
29
+
30
+        // when
31
+        Integer actual = a.compareTo(c);
32
+
33
+        // then
34
+        Assert.assertTrue(actual < 0);
35
+    }
36
+
37
+    @Test
38
+    public void test3() {
39
+        // given
40
+        ComparableTreeSet<String> a = new ComparableTreeSet<>("a");
41
+        ComparableTreeSet<String> d = new ComparableTreeSet<>("d");
42
+
43
+        // when
44
+        Integer actual = a.compareTo(d);
45
+
46
+        // then
47
+        Assert.assertTrue(actual < 0);
48
+    }
49
+}

+ 46
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/flatset/singleelement/CompareSingleElementSetPositive.java Целия файл

@@ -0,0 +1,46 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.flatset.singleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class CompareSingleElementSetPositive {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("b");
15
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("a");
16
+        // when
17
+        Integer actual = set1.compareTo(set2);
18
+
19
+        // then
20
+        Assert.assertTrue(actual > 0);
21
+    }
22
+
23
+    @Test
24
+    public void test2() {
25
+        // given
26
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("c");
27
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("a");
28
+        // when
29
+        Integer actual = set1.compareTo(set2);
30
+
31
+        // then
32
+        Assert.assertTrue(actual > 0);
33
+    }
34
+
35
+    @Test
36
+    public void test3() {
37
+        // given
38
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("d");
39
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("a");
40
+        // when
41
+        Integer actual = set1.compareTo(set2);
42
+
43
+        // then
44
+        Assert.assertTrue(actual > 0);
45
+    }
46
+}

+ 47
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementNegative.java Целия файл

@@ -0,0 +1,47 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.nestedset.multipleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class NestedSetCompareMultipleElementNegative {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Arty", "Fee", "Shawl");
15
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Burt", "Bot");
16
+        ComparableTreeSet<ComparableTreeSet<String>> powerset1 = new ComparableTreeSet<>(set1, set2);
17
+
18
+        ComparableTreeSet<String> set3 = new ComparableTreeSet<>("Candy", "Cane");
19
+        ComparableTreeSet<String> set4 = new ComparableTreeSet<>("Corny", "Carl");
20
+        ComparableTreeSet<ComparableTreeSet<String>> powerset2 = new ComparableTreeSet<>(set3, set4);
21
+
22
+        // when
23
+        Integer actual = powerset1.compareTo(powerset2);
24
+
25
+        // then
26
+        Assert.assertTrue(actual < 0);
27
+    }
28
+
29
+
30
+    @Test
31
+    public void test2() {
32
+        // given
33
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Froilan", "Miranda");
34
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Wilhem", "Alcivar");
35
+        ComparableTreeSet<ComparableTreeSet<String>> powerset1 = new ComparableTreeSet<>(set1, set2);
36
+
37
+        ComparableTreeSet<String> set3 = new ComparableTreeSet<>("Leon", "Hunter");
38
+        ComparableTreeSet<String> set4 = new ComparableTreeSet<>("Nhu", "Nguyen");
39
+        ComparableTreeSet<ComparableTreeSet<String>> powerset2 = new ComparableTreeSet<>(set3, set4);
40
+
41
+        // when
42
+        Integer actual = powerset1.compareTo(powerset2);
43
+
44
+        // then
45
+        Assert.assertTrue(actual < 0);
46
+    }
47
+}

+ 47
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementNeutral.java Целия файл

@@ -0,0 +1,47 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.nestedset.multipleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class NestedSetCompareMultipleElementNeutral {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Wilhem", "Alcivar");
15
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Leon", "Hunter");
16
+        ComparableTreeSet<ComparableTreeSet<String>> powerset1 = new ComparableTreeSet<>(set1, set2);
17
+
18
+        ComparableTreeSet<String> set3 = new ComparableTreeSet<>("Leon", "Hunter");
19
+        ComparableTreeSet<String> set4 = new ComparableTreeSet<>("Wilhem", "Alcivar");
20
+        ComparableTreeSet<ComparableTreeSet<String>> powerset2 = new ComparableTreeSet<>(set3, set4);
21
+
22
+        // when
23
+        Integer actual = powerset1.compareTo(powerset2);
24
+
25
+        // then
26
+        Assert.assertTrue(actual == 0);
27
+    }
28
+
29
+
30
+    @Test
31
+    public void test2() {
32
+        // given
33
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("The", "Quick", "Brown", "Fox", "Jumps");
34
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Over", "The", "Lazy", "Dog");
35
+        ComparableTreeSet<ComparableTreeSet<String>> powerset1 = new ComparableTreeSet<>(set1, set2);
36
+
37
+        ComparableTreeSet<String> set3 = new ComparableTreeSet<>("Brown", "Jumps", "Fox", "Quick", "The");
38
+        ComparableTreeSet<String> set4 = new ComparableTreeSet<>("The", "Lazy", "Dog", "Over");
39
+        ComparableTreeSet<ComparableTreeSet<String>> powerset2 = new ComparableTreeSet<>(set3, set4);
40
+
41
+        // when
42
+        Integer actual = powerset1.compareTo(powerset2);
43
+
44
+        // then
45
+        Assert.assertTrue(actual == 0);
46
+    }
47
+}

+ 47
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementPositive.java Целия файл

@@ -0,0 +1,47 @@
1
+package rocks.zipcode.io.quiz4.collections.comparabletreeset.compareto.nestedset.multipleelement;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class NestedSetCompareMultipleElementPositive {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        ComparableTreeSet<String> set3 = new ComparableTreeSet<>("Froilan", "Miranda");
15
+        ComparableTreeSet<String> set4 = new ComparableTreeSet<>("Nhu", "Nguyen");
16
+        ComparableTreeSet<ComparableTreeSet<String>> powerset1 = new ComparableTreeSet<>(set3, set4);
17
+
18
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Wilhem", "Alcivar");
19
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Leon", "Hunter");
20
+        ComparableTreeSet<ComparableTreeSet<String>> powerset2 = new ComparableTreeSet<>(set1, set2);
21
+
22
+        // when
23
+        Integer actual = powerset1.compareTo(powerset2);
24
+
25
+        // then
26
+        Assert.assertTrue(actual > 0);
27
+    }
28
+
29
+
30
+    @Test
31
+    public void test2() {
32
+        // given
33
+        ComparableTreeSet<String> set3 = new ComparableTreeSet<>("Kris", "Younger");
34
+        ComparableTreeSet<String> set4 = new ComparableTreeSet<>("Leon", "Hunter");
35
+        ComparableTreeSet<ComparableTreeSet<String>> powerset1 = new ComparableTreeSet<>(set3, set4);
36
+
37
+        ComparableTreeSet<String> set1 = new ComparableTreeSet<>("Nhu", "Nguyen");
38
+        ComparableTreeSet<String> set2 = new ComparableTreeSet<>("Wilhem", "Alcivar");
39
+        ComparableTreeSet<ComparableTreeSet<String>> powerset2 = new ComparableTreeSet<>(set1, set2);
40
+
41
+        // when
42
+        Integer actual = powerset1.compareTo(powerset2);
43
+
44
+        // then
45
+        Assert.assertTrue(actual > 0);
46
+    }
47
+}

+ 43
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/ClearTest.java Целия файл

@@ -0,0 +1,43 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class ClearTest {
11
+    @Test
12
+    public void test1() {
13
+        test("first", "clear", "test");
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test("an", "additional", "test", "here");
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test("a", "dash", "of", "anonymity");
24
+    }
25
+
26
+    private void test(String... valuesToInsert) {
27
+        // given
28
+        SimpleStringGroup group = new SimpleStringGroup();
29
+        for(String valueToInsert : valuesToInsert) {
30
+            group.insert(valueToInsert);
31
+            Assert.assertTrue(group.has(valueToInsert));
32
+        }
33
+
34
+        // when
35
+        group.clear();
36
+
37
+
38
+        // then
39
+        for(String valueToInsert : valuesToInsert) {
40
+            Assert.assertFalse(group.has(valueToInsert));
41
+        }
42
+    }
43
+}

+ 42
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/CountTest.java Целия файл

@@ -0,0 +1,42 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+import java.util.UUID;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class CountTest {
13
+    @Test
14
+    public void test1() {
15
+        test(1);
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        test(2);
21
+    }
22
+
23
+
24
+    @Test
25
+    public void test3() {
26
+        test(3);
27
+    }
28
+
29
+    public void test(Integer numberOfItemsToAdd) {
30
+        // given
31
+        SimpleStringGroup group = new SimpleStringGroup();
32
+
33
+        // when
34
+        for (int i = 0; i < numberOfItemsToAdd; i++) {
35
+            String itemToAdd = UUID.randomUUID().toString();
36
+            group.insert(itemToAdd);
37
+        }
38
+
39
+        // then
40
+        Assert.assertEquals(group.count(), numberOfItemsToAdd);
41
+    }
42
+}

+ 51
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/DeleteTest.java Целия файл

@@ -0,0 +1,51 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class DeleteTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        SimpleStringGroup group = new SimpleStringGroup();
15
+        String valueToInsert = "first test";
16
+
17
+        // when
18
+        group.insert(valueToInsert);
19
+        group.delete(valueToInsert);
20
+
21
+        Assert.assertFalse(group.has(valueToInsert));
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        // given
27
+        SimpleStringGroup group = new SimpleStringGroup();
28
+        String valueToInsert = "second test";
29
+
30
+        // when
31
+        group.insert(valueToInsert);
32
+        group.delete(valueToInsert);
33
+
34
+        // then
35
+        Assert.assertFalse(group.has(valueToInsert));
36
+    }
37
+
38
+    @Test
39
+    public void test3() {
40
+        // given
41
+        SimpleStringGroup group = new SimpleStringGroup();
42
+        String valueToInsert = "third test";
43
+
44
+        // when
45
+        group.insert(valueToInsert);
46
+        group.delete(valueToInsert);
47
+
48
+        // then
49
+        Assert.assertFalse(group.has(valueToInsert));
50
+    }
51
+}

+ 37
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/DistinctTest.java Целия файл

@@ -0,0 +1,37 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class DistinctTest {
11
+    @Test
12
+    public void test1() {
13
+        test("first test");
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test("second test");
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test("third test");
24
+    }
25
+
26
+    private void test(String valueToInsert) {
27
+        // given
28
+        SimpleStringGroup group = new SimpleStringGroup();
29
+
30
+        // when
31
+        Assert.assertFalse(group.has(valueToInsert));
32
+        group.insert(valueToInsert);
33
+
34
+        // then
35
+        Assert.assertTrue(group.has(valueToInsert));
36
+    }
37
+}

+ 59
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/GetTest.java Целия файл

@@ -0,0 +1,59 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+import java.util.Arrays;
8
+import java.util.List;
9
+
10
+/**
11
+ * @author leon on 11/12/2018.
12
+ */
13
+public class GetTest {
14
+    @Test
15
+    public void test1() {
16
+        test("first test");
17
+    }
18
+
19
+    @Test
20
+    public void test2() {
21
+        test("second test");
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        test("third test");
27
+    }
28
+
29
+    @Test(expected = IndexOutOfBoundsException.class)
30
+    public void test4() {
31
+        // given
32
+        SimpleStringGroup group = new SimpleStringGroup();
33
+
34
+        // when
35
+        group.fetch(10);
36
+    }
37
+
38
+    @Test(expected = IndexOutOfBoundsException.class)
39
+    public void test5() {
40
+        // given
41
+        SimpleStringGroup group = new SimpleStringGroup();
42
+
43
+        // when
44
+        group.fetch(15);
45
+    }
46
+
47
+
48
+    private void test(String... stringsToInsert) {
49
+        // given
50
+        SimpleStringGroup group = new SimpleStringGroup();
51
+        List<String> simpleStringGroupContents = Arrays.asList(stringsToInsert);
52
+        simpleStringGroupContents.forEach(string -> group.insert(string));
53
+
54
+        // when
55
+        for (int i = 0; i < stringsToInsert.length; i++) {
56
+            Assert.assertEquals(stringsToInsert[i], group.fetch(i));
57
+        }
58
+    }
59
+}

+ 37
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/InsertTest.java Целия файл

@@ -0,0 +1,37 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class InsertTest {
11
+    @Test
12
+    public void test1() {
13
+        test("first test");
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test("second test");
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test("third test");
24
+    }
25
+
26
+    private void test(String valueToInsert) {
27
+        // given
28
+        SimpleStringGroup group = new SimpleStringGroup();
29
+
30
+        // when
31
+        Assert.assertFalse(group.has(valueToInsert));
32
+        group.insert(valueToInsert);
33
+
34
+        // then
35
+        Assert.assertTrue(group.has(valueToInsert));
36
+    }
37
+}

+ 55
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/IterableTest.java Целия файл

@@ -0,0 +1,55 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+import java.util.ArrayList;
8
+import java.util.Arrays;
9
+import java.util.List;
10
+
11
+/**
12
+ * @author leon on 11/12/2018.
13
+ */
14
+public class IterableTest {
15
+    @Test
16
+    public void test1() {
17
+        test("the");
18
+    }
19
+
20
+    @Test
21
+    public void test2() {
22
+        test("the", "quick");
23
+    }
24
+
25
+    @Test
26
+    public void test3() {
27
+        test("the", "quick", "brown");
28
+    }
29
+
30
+
31
+    @Test
32
+    public void test4() {
33
+        test("the", "quick", "brown", "fox");
34
+    }
35
+
36
+    @Test
37
+    public void test5() {
38
+        test("the", "quick", "brown", "fox", "jumps");
39
+    }
40
+
41
+    private void test(String... stringsToInsert) {
42
+        // given
43
+        List<String> result = new ArrayList<>();
44
+        SimpleStringGroup group = new SimpleStringGroup();
45
+        List<String> simpleStringGroupContents = Arrays.asList(stringsToInsert);
46
+        simpleStringGroupContents.forEach(string -> group.insert(string));
47
+        Iterable<String> simpleStringGroup = (Iterable<String>)group;
48
+
49
+        // when
50
+        simpleStringGroup.forEach(string -> result.add(string));
51
+
52
+        // then
53
+        Assert.assertEquals(group.count().intValue(), result.size());
54
+    }
55
+}

+ 23
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/SimpleStringGroupPolymorphismTest.java Целия файл

@@ -0,0 +1,23 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+
7
+import java.util.Collection;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class SimpleStringGroupPolymorphismTest {
13
+    @Test
14
+    public void test1() {
15
+        Assert.assertTrue(new SimpleStringGroup() instanceof Iterable);
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        Assert.assertFalse(new SimpleStringGroup() instanceof Collection);
21
+    }
22
+
23
+}

+ 7
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/ToStringTest.java Целия файл

@@ -0,0 +1,7 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class ToStringTest {
7
+}

+ 7
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/WhereTest.java Целия файл

@@ -0,0 +1,7 @@
1
+package rocks.zipcode.io.quiz4.collections.simplestringgroup;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class WhereTest {
7
+}

+ 44
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/EnrollTest.java Целия файл

@@ -0,0 +1,44 @@
1
+package rocks.zipcode.io.quiz4.collections.zipcodewilmington;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ZipCodeWilmington;
6
+import rocks.zipcode.io.quiz4.objectorientation.Student;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class EnrollTest {
12
+    @Test
13
+    public void test1() {
14
+        test(new Student());
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        test(
20
+                new Student(),
21
+                new Student());
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        test(
27
+                new Student(),
28
+                new Student(),
29
+                new Student());
30
+    }
31
+
32
+    public void test(Student... students) {
33
+        // given
34
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
35
+
36
+        for (Student student : students) {
37
+            // when
38
+            zipCodeWilmington.enroll(student);
39
+
40
+            // then
41
+            Assert.assertTrue(zipCodeWilmington.isEnrolled(student));
42
+        }
43
+    }
44
+}

+ 133
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/GetStudyMapTest.java Целия файл

@@ -0,0 +1,133 @@
1
+package rocks.zipcode.io.quiz4.collections.zipcodewilmington;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ZipCodeWilmington;
6
+import rocks.zipcode.io.quiz4.objectorientation.Student;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import java.util.Map;
11
+
12
+/**
13
+ * @author leon on 11/12/2018.
14
+ */
15
+public class GetStudyMapTest {
16
+    @Test
17
+    public void test1() {
18
+        // given
19
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
20
+        Student expectedStudent1 = new Student();
21
+        Double expectedStudyTime1 = expectedStudent1.getTotalStudyTime();
22
+        zipCodeWilmington.enroll(expectedStudent1);
23
+
24
+
25
+
26
+        // when
27
+        Map<Student, Double> studyMap = zipCodeWilmington.getStudyMap();
28
+        List<Map.Entry<Student, Double>> entrySet = new ArrayList<>(studyMap.entrySet());
29
+        Map.Entry<Student, Double> firstEntry = entrySet.get(0);
30
+
31
+        Student actualStudent1 = firstEntry.getKey();
32
+        Double actualStudyTime1 = firstEntry.getValue();
33
+
34
+
35
+
36
+        // then
37
+        Assert.assertEquals(expectedStudent1, actualStudent1);
38
+        Assert.assertEquals(expectedStudyTime1, actualStudyTime1);
39
+    }
40
+
41
+    @Test
42
+    public void test2() {
43
+        // given
44
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
45
+        Student expectedStudent1 = new Student(1);
46
+        Student expectedStudent2 = new Student(2);
47
+
48
+        zipCodeWilmington.enroll(expectedStudent1);
49
+        zipCodeWilmington.enroll(expectedStudent2);
50
+
51
+        Double expectedStudyTime1 = 500.0;
52
+        Double expectedStudyTime2 = 250.0;
53
+
54
+        expectedStudent1.learn(expectedStudyTime1);
55
+        expectedStudent2.learn(expectedStudyTime2);
56
+
57
+
58
+
59
+        // when
60
+        Map<Student, Double> studyMap = zipCodeWilmington.getStudyMap();
61
+        List<Map.Entry<Student, Double>> entrySet = new ArrayList<>(studyMap.entrySet());
62
+        Map.Entry<Student, Double> firstEntry = entrySet.get(0);
63
+        Map.Entry<Student, Double> secondEntry = entrySet.get(1);
64
+
65
+        Student actualStudent1 = firstEntry.getKey();
66
+        Student actualStudent2 = secondEntry.getKey();
67
+
68
+        Double actualStudyTime1 = firstEntry.getValue();
69
+        Double actualStudyTime2 = secondEntry.getValue();
70
+
71
+
72
+
73
+        // then
74
+        Assert.assertEquals(expectedStudent1, actualStudent1);
75
+        Assert.assertEquals(expectedStudyTime1, actualStudyTime1);
76
+
77
+
78
+        Assert.assertEquals(expectedStudent2, actualStudent2);
79
+        Assert.assertEquals(expectedStudyTime2, actualStudyTime2);
80
+    }
81
+
82
+    @Test
83
+    public void test3() {
84
+        // given
85
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
86
+        Student expectedStudent1 = new Student(3);
87
+        Student expectedStudent2 = new Student(4);
88
+        Student expectedStudent3 = new Student(5);
89
+
90
+        zipCodeWilmington.enroll(expectedStudent1);
91
+        zipCodeWilmington.enroll(expectedStudent2);
92
+        zipCodeWilmington.enroll(expectedStudent3);
93
+
94
+        Double expectedStudyTime1 = 500.0;
95
+        Double expectedStudyTime2 = 250.0;
96
+        Double expectedStudyTime3 = 125.0;
97
+
98
+        expectedStudent1.learn(expectedStudyTime1);
99
+        expectedStudent2.learn(expectedStudyTime2);
100
+        expectedStudent3.learn(expectedStudyTime3);
101
+
102
+
103
+
104
+        // when
105
+        Map<Student, Double> studyMap = zipCodeWilmington.getStudyMap();
106
+        List<Map.Entry<Student, Double>> entrySet = new ArrayList<>(studyMap.entrySet());
107
+        Map.Entry<Student, Double> firstEntry = entrySet.get(0);
108
+        Map.Entry<Student, Double> secondEntry = entrySet.get(1);
109
+        Map.Entry<Student, Double> thirdEntry = entrySet.get(2);
110
+
111
+        Student actualStudent1 = firstEntry.getKey();
112
+        Student actualStudent2 = secondEntry.getKey();
113
+        Student actualStudent3 = thirdEntry.getKey();
114
+
115
+        Double actualStudyTime1 = firstEntry.getValue();
116
+        Double actualStudyTime2 = secondEntry.getValue();
117
+        Double actualStudyTime3 = thirdEntry.getValue();
118
+
119
+
120
+
121
+        // then
122
+        Assert.assertEquals(expectedStudent1, actualStudent1);
123
+        Assert.assertEquals(expectedStudyTime1, actualStudyTime1);
124
+
125
+
126
+        Assert.assertEquals(expectedStudent2, actualStudent2);
127
+        Assert.assertEquals(expectedStudyTime2, actualStudyTime2);
128
+
129
+
130
+        Assert.assertEquals(expectedStudent3, actualStudent3);
131
+        Assert.assertEquals(expectedStudyTime3, actualStudyTime3);
132
+    }
133
+}

+ 49
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/LectureTest.java Целия файл

@@ -0,0 +1,49 @@
1
+package rocks.zipcode.io.quiz4.collections.zipcodewilmington;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.ZipCodeWilmington;
6
+import rocks.zipcode.io.quiz4.objectorientation.Student;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class LectureTest {
12
+    @Test
13
+    public void test1() {
14
+        test(200.0,
15
+                new Student());
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        test(150.0,
21
+                new Student(),
22
+                new Student());
23
+    }
24
+
25
+    @Test
26
+    public void test3() {
27
+        test(100.0,
28
+                new Student(),
29
+                new Student(),
30
+                new Student());
31
+    }
32
+
33
+    public void test(Double lectureTime, Student... students) {
34
+        // given
35
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
36
+        for (Student student : students) {
37
+            zipCodeWilmington.enroll(student);
38
+            Assert.assertEquals(0.0, student.getTotalStudyTime().doubleValue(), 0);
39
+        }
40
+
41
+        // when
42
+        zipCodeWilmington.lecture(lectureTime);
43
+
44
+        // then
45
+        for (Student student : students) {
46
+            Assert.assertEquals(student.getTotalStudyTime(), lectureTime, 0);
47
+        }
48
+    }
49
+}

+ 103
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetAllPrefixes.java Целия файл

@@ -0,0 +1,103 @@
1
+package rocks.zipcode.io.quiz4.fundamentals.stringevaluator;
2
+
3
+import org.junit.Test;
4
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
5
+import rocks.zipcode.io.quiz4.utils.TestUtils;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class GetAllPrefixes {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        String input = "A";
15
+        String[] expected = {input};
16
+
17
+        // when
18
+        String[] actual = StringEvaluator.getAllPrefixes(input);
19
+
20
+        // then
21
+        TestUtils.assertArrayEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        // given
27
+        String input = "B";
28
+        String[] expected = {input};
29
+
30
+        // when
31
+        String[] actual = StringEvaluator.getAllPrefixes(input);
32
+
33
+        // then
34
+        TestUtils.assertArrayEquals(expected, actual);
35
+    }
36
+
37
+
38
+    @Test
39
+    public void test3() {
40
+        // given
41
+        String input = "AB";
42
+        String[] expected = {"A", "B", "AB"};
43
+
44
+        // when
45
+        String[] actual = StringEvaluator.getAllPrefixes(input);
46
+
47
+        // then
48
+        TestUtils.assertArrayEquals(expected, actual);
49
+    }
50
+
51
+
52
+    @Test
53
+    public void test4() {
54
+        // given
55
+        String input = "ABB";
56
+        String[] expected = {"A", "AB", "ABB", "B", "BB"};
57
+
58
+        // when
59
+        String[] actual = StringEvaluator.getAllPrefixes(input);
60
+
61
+        // then
62
+        TestUtils.assertArrayEquals(expected, actual);
63
+    }
64
+
65
+
66
+    @Test
67
+    public void test5() {
68
+        // given
69
+        String input = "AABB";
70
+        String[] expected = {"A", "AA", "AAB", "AABB", "AB", "ABB", "B", "BB"};
71
+
72
+        // when
73
+        String[] actual = StringEvaluator.getAllPrefixes(input);
74
+
75
+        // then
76
+        TestUtils.assertArrayEquals(expected, actual);
77
+    }
78
+
79
+
80
+    @Test
81
+    public void test6() {
82
+        // given
83
+        String input = "AnotherMethodToTest";
84
+        String[] expected = {
85
+                "A", "An", "Ano", "Anot", "Anoth", "Anothe", "Another", "AnotherM", "AnotherMe", "AnotherMet", "AnotherMeth", "AnotherMetho", "AnotherMethod", "AnotherMethodT", "AnotherMethodTo", "AnotherMethodToT", "AnotherMethodToTe", "AnotherMethodToTes", "AnotherMethodToTest",
86
+                "n", "no", "not", "noth", "nothe", "nother", "notherM", "notherMe", "notherMet", "notherMeth", "notherMetho", "notherMethod", "notherMethodT", "notherMethodTo", "notherMethodToT", "notherMethodToTe", "notherMethodToTes", "notherMethodToTest",
87
+                "o", "oT", "oTe", "oTes", "oTest", "od", "odT", "odTo", "odToT", "odToTe", "odToTes", "odToTest", "ot", "oth", "othe", "other", "otherM", "otherMe", "otherMet", "otherMeth", "otherMetho", "otherMethod", "otherMethodT", "otherMethodTo", "otherMethodToT", "otherMethodToTe", "otherMethodToTes", "otherMethodToTest",
88
+                "t", "th", "the", "ther", "therM", "therMe", "therMet", "therMeth", "therMetho", "therMethod", "therMethodT", "therMethodTo", "therMethodToT", "therMethodToTe", "therMethodToTes", "therMethodToTest", "tho", "thod", "thodT", "thodTo", "thodToT", "thodToTe", "thodToTes", "thodToTest",
89
+                "h", "he", "her", "herM", "herMe", "herMet", "herMeth", "herMetho", "herMethod", "herMethodT", "herMethodTo", "herMethodToT", "herMethodToTe", "herMethodToTes", "herMethodToTest", "ho", "hod", "hodT", "hodTo", "hodToT", "hodToTe", "hodToTes", "hodToTest",
90
+                "e", "er", "erM", "erMe", "erMet", "erMeth", "erMetho", "erMethod", "erMethodT", "erMethodTo", "erMethodToT", "erMethodToTe", "erMethodToTes", "erMethodToTest", "es", "est", "et", "eth", "etho", "ethod", "ethodT", "ethodTo", "ethodToT", "ethodToTe", "ethodToTes", "ethodToTest",
91
+                "r", "rM", "rMe", "rMet", "rMeth", "rMetho", "rMethod", "rMethodT", "rMethodTo", "rMethodToT", "rMethodToTe", "rMethodToTes", "rMethodToTest",
92
+                "M", "Me", "Met", "Meth", "Metho", "Method", "MethodT", "MethodTo", "MethodToT", "MethodToTe", "MethodToTes", "MethodToTest",
93
+                "T", "Te", "Tes", "Test", "To", "ToT", "ToTe", "ToTes", "ToTest",
94
+                "d", "dT", "dTo", "dToT", "dToTe", "dToTes", "dToTest",
95
+                "s", "st"};
96
+
97
+        // when
98
+        String[] actual = StringEvaluator.getAllPrefixes(input);
99
+
100
+        // then
101
+        TestUtils.assertArrayEquals(expected, actual);
102
+    }
103
+}

+ 84
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetCommonSuffixesTest.java Целия файл

@@ -0,0 +1,84 @@
1
+package rocks.zipcode.io.quiz4.fundamentals.stringevaluator;
2
+
3
+import org.junit.Test;
4
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
5
+import rocks.zipcode.io.quiz4.utils.TestUtils;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class GetCommonSuffixesTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        String firstInput = "AAB";
15
+        String secondInput = "AAAB";
16
+        String[] expected = {"A", "AA", "AAB", "AB", "B"};
17
+
18
+        // when
19
+        String[] actual = StringEvaluator.getCommonPrefixes(firstInput, secondInput);
20
+
21
+        // then
22
+        TestUtils.assertArrayEquals(expected, actual);
23
+    }
24
+
25
+    @Test
26
+    public void test2() {
27
+        // given
28
+        String firstInput = "AAZB";
29
+        String secondInput = "AAAB";
30
+        String[] expected = {"A", "AA", "B"};
31
+
32
+        // when
33
+        String[] actual = StringEvaluator.getCommonPrefixes(firstInput, secondInput);
34
+
35
+        // then
36
+        TestUtils.assertArrayEquals(expected, actual);
37
+    }
38
+
39
+
40
+    @Test
41
+    public void test3() {
42
+        // given
43
+        String firstInput = "Zapple";
44
+        String secondInput = "Candy apples!";
45
+        String[] expected = {"a", "ap", "app", "appl", "apple", "e", "l", "le", "p", "pl", "ple", "pp", "ppl", "pple"};
46
+
47
+        // when
48
+        String[] actual = StringEvaluator.getCommonPrefixes(firstInput, secondInput);
49
+
50
+        // then
51
+        TestUtils.assertArrayEquals(expected, actual);
52
+    }
53
+
54
+
55
+
56
+    @Test
57
+    public void tes4() {
58
+        // given
59
+        String firstInput = "Irreducible complexity";
60
+        String secondInput = "Deductive operations";
61
+        String[] expected = {" ", "c", "d", "du", "duc", "e", "e ", "ed", "edu", "educ", "i", "o", "p", "r", "t", "u", "uc"};
62
+
63
+        // when
64
+        String[] actual = StringEvaluator.getCommonPrefixes(firstInput, secondInput);
65
+
66
+        // then
67
+        TestUtils.assertArrayEquals(expected, actual);
68
+    }
69
+
70
+    @Test
71
+    public void test5() {
72
+        // given
73
+        String firstInput = "Peter piper picked a pepper";
74
+        String secondInput = "Jimmy neutron was a fancy scientist";
75
+        String[] expected = {" ", " a", " a ", "a", "a ", "c", "e", "i", "r", "t"};
76
+
77
+        // when
78
+        String[] actual = StringEvaluator.getCommonPrefixes(firstInput, secondInput);
79
+
80
+        // then
81
+        TestUtils.assertArrayEquals(expected, actual);
82
+    }
83
+
84
+}

+ 70
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetLargestCommonSuffixTest.java Целия файл

@@ -0,0 +1,70 @@
1
+package rocks.zipcode.io.quiz4.fundamentals.stringevaluator;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class GetLargestCommonSuffixTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        String firstInput = "AAB";
15
+        String secondInput = "AAAB";
16
+        String expected = "AAB";
17
+
18
+        // when
19
+        String actual = StringEvaluator.getLargestCommonPrefix(firstInput, secondInput);
20
+
21
+        // then
22
+        Assert.assertEquals(expected, actual);
23
+    }
24
+
25
+    @Test
26
+    public void test2() {
27
+        // given
28
+        String firstInput = "AAZB";
29
+        String secondInput = "AAAB";
30
+        String expected = "AA";
31
+
32
+        // when
33
+        String actual = StringEvaluator.getLargestCommonPrefix(firstInput, secondInput);
34
+
35
+        // then
36
+        Assert.assertEquals(expected, actual);
37
+    }
38
+
39
+
40
+
41
+    @Test
42
+    public void test3() {
43
+        // given
44
+        String firstInput = "Zapple";
45
+        String secondInput = "Candy apples!";
46
+        String expected = "apple";
47
+
48
+        // when
49
+        String actual = StringEvaluator.getLargestCommonPrefix(firstInput, secondInput);
50
+
51
+        // then
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+
55
+
56
+
57
+    @Test
58
+    public void test4() {
59
+        // given
60
+        String firstInput = "Irreducible complexity";
61
+        String secondInput = "Deductive operations";
62
+        String expected = "educ";
63
+
64
+        // when
65
+        String actual = StringEvaluator.getLargestCommonPrefix(firstInput, secondInput);
66
+
67
+        // then
68
+        Assert.assertEquals(expected, actual);
69
+    }
70
+}

+ 49
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/genericarrayutils/powerset/PowerSetOfThreeElements.java Целия файл

@@ -0,0 +1,49 @@
1
+package rocks.zipcode.io.quiz4.generics.genericarrayutils.powerset;
2
+
3
+import org.junit.Test;
4
+
5
+/**
6
+ * @author leon on 15/12/2018.
7
+ */
8
+public class PowerSetOfThreeElements {
9
+    @Test
10
+    public void test1() {
11
+        // given
12
+        String[] input = {"a", "b", "c"};
13
+        String expectedString = "[[a, b, c], [a, b], [a, c], [a], [b, a], [b, c], [b], [c, a], [c, b], [c], []]";
14
+        PowerSetTest.test(input, expectedString);
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        // given
20
+        String[] input = {"1", "2", "3"};
21
+        String expectedString = "[[1, 2, 3], [1, 2], [1, 3], [1], [2, 1], [2, 3], [2], [3, 1], [3, 2], [3], []]";
22
+        PowerSetTest.test(input, expectedString);
23
+    }
24
+
25
+    @Test
26
+    public void test3() {
27
+        // given
28
+        String[] input = {"x", "y", "z"};
29
+        String expectedString = "[[x, y, z], [x, y], [x, z], [x], [y, x], [y, z], [y], [z, x], [z, y], [z], []]";
30
+        PowerSetTest.test(input, expectedString);
31
+    }
32
+
33
+    @Test
34
+    public void test4() {
35
+        // given
36
+        String[] input = {"aFIRST", "bSECOND", "cTHIRD"};
37
+        String eaFIRSTpectedString = "[[aFIRST, bSECOND, cTHIRD], [aFIRST, bSECOND], [aFIRST, cTHIRD], [aFIRST], [bSECOND, aFIRST], [bSECOND, cTHIRD], [bSECOND], [cTHIRD, aFIRST], [cTHIRD, bSECOND], [cTHIRD], []]";
38
+        PowerSetTest.test(input, eaFIRSTpectedString);
39
+    }
40
+
41
+
42
+    @Test
43
+    public void test5() {
44
+        // given
45
+        String[] input = {"1WATER", "2FIRE", "3LIGHTNING"};
46
+        String e1WATERpectedString = "[[1WATER, 2FIRE, 3LIGHTNING], [1WATER, 2FIRE], [1WATER, 3LIGHTNING], [1WATER], [2FIRE, 1WATER], [2FIRE, 3LIGHTNING], [2FIRE], [3LIGHTNING, 1WATER], [3LIGHTNING, 2FIRE], [3LIGHTNING], []]";
47
+        PowerSetTest.test(input, e1WATERpectedString);
48
+    }
49
+}

+ 49
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/genericarrayutils/powerset/PowerSetOfTwoElements.java Целия файл

@@ -0,0 +1,49 @@
1
+package rocks.zipcode.io.quiz4.generics.genericarrayutils.powerset;
2
+
3
+import org.junit.Test;
4
+
5
+/**
6
+ * @author leon on 15/12/2018.
7
+ */
8
+public class PowerSetOfTwoElements {
9
+    @Test
10
+    public void test1() {
11
+        // given
12
+        String[] input = {"1", "2"};
13
+        String expectedString = "[[1, 2], [1], [2], []]";
14
+        PowerSetTest.test(input, expectedString);
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        // given
20
+        String[] input = {"1", "0"};
21
+        String expectedString = "[[0, 1], [0], [1], []]";
22
+        PowerSetTest.test(input, expectedString);
23
+    }
24
+
25
+    @Test
26
+    public void test3() {
27
+        // given
28
+        String[] input = {"a", "b"};
29
+        String expectedString = "[[a, b], [a], [b], []]";
30
+        PowerSetTest.test(input, expectedString);
31
+    }
32
+
33
+    @Test
34
+    public void test4() {
35
+        // given
36
+        String[] input = {"x", "y"};
37
+        String expectedString = "[[x, y], [x], [y], []]";
38
+        PowerSetTest.test(input, expectedString);
39
+    }
40
+
41
+
42
+    @Test
43
+    public void test5() {
44
+        // given
45
+        String[] input = {"red", "blue"};
46
+        String expectedString = "[[blue, red], [blue], [red], []]";
47
+        PowerSetTest.test(input, expectedString);
48
+    }
49
+}

+ 20
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/genericarrayutils/powerset/PowerSetTest.java Целия файл

@@ -0,0 +1,20 @@
1
+package rocks.zipcode.io.quiz4.generics.genericarrayutils.powerset;
2
+
3
+import org.junit.Assert;
4
+import rocks.zipcode.io.quiz4.generics.GenericUtils;
5
+
6
+/**
7
+ * @author leon on 15/12/2018.
8
+ */
9
+public class PowerSetTest {
10
+    public static void test(String[] input, String expectedString) {
11
+        // given
12
+
13
+        // when
14
+        Iterable<? extends Iterable<? extends String>> actualSet = GenericUtils.powerSet(input);
15
+        String actualString = actualSet.toString();
16
+
17
+        // then
18
+        Assert.assertEquals(expectedString, actualString);
19
+    }
20
+}

+ 28
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/GroupPolymorphismTest.java Целия файл

@@ -0,0 +1,28 @@
1
+package rocks.zipcode.io.quiz4.generics.group;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+import rocks.zipcode.io.quiz4.generics.GroupInterface;
7
+
8
+import java.util.Collection;
9
+
10
+/**
11
+ * @author leon on 11/12/2018.
12
+ */
13
+public class GroupPolymorphismTest {
14
+    @Test
15
+    public void test1() {
16
+        Assert.assertTrue(new Group() instanceof Iterable);
17
+    }
18
+
19
+    @Test
20
+    public void test3() {
21
+        Assert.assertTrue(new Group() instanceof GroupInterface);
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        Assert.assertFalse(new Group() instanceof Collection);
27
+    }
28
+}

+ 59
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/GroupToStringTest.java Целия файл

@@ -0,0 +1,59 @@
1
+package rocks.zipcode.io.quiz4.generics.group;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class GroupToStringTest {
11
+    @Test
12
+    public void test1() {
13
+        String expected = "[the, quick, brown, fox]";
14
+        Group<String> group = new Group<>();
15
+        group.insert("the");
16
+        group.insert("quick");
17
+        group.insert("brown");
18
+        group.insert("fox");
19
+
20
+        // when
21
+        String actual = group.toString();
22
+
23
+        // then
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    public void test2() {
29
+        String expected = "[123, 456, 789, 101112]";
30
+        Group<Number> group = new Group<>();
31
+        group.insert(123);
32
+        group.insert(456);
33
+        group.insert(789);
34
+        group.insert(101112);
35
+
36
+        // when
37
+        String actual = group.toString();
38
+
39
+        // then
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+
44
+    @Test
45
+    public void test3() {
46
+        String expected = "[a, b, c, d]";
47
+        Group<Character> group = new Group<>();
48
+        group.insert('a');
49
+        group.insert('b');
50
+        group.insert('c');
51
+        group.insert('d');
52
+
53
+        // when
54
+        String actual = group.toString();
55
+
56
+        // then
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+}

+ 43
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupClearTest.java Целия файл

@@ -0,0 +1,43 @@
1
+package rocks.zipcode.io.quiz4.generics.group.integergroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class IntegerGroupClearTest {
11
+    @Test
12
+    public void test1() {
13
+        test(1, 2, 3);
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test(7, 8, 9);
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test(4, 5, 6);
24
+    }
25
+
26
+    private void test(Integer... valuesToInsert) {
27
+        // given
28
+        Group<Integer> group = new Group<>();
29
+        for (Integer valueToInsert : valuesToInsert) {
30
+            group.insert(valueToInsert);
31
+            Assert.assertTrue(group.has(valueToInsert));
32
+        }
33
+
34
+        // when
35
+        group.clear();
36
+
37
+
38
+        // then
39
+        for (Integer valueToInsert : valuesToInsert) {
40
+            Assert.assertFalse(group.has(valueToInsert));
41
+        }
42
+    }
43
+}

+ 42
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupCountTest.java Целия файл

@@ -0,0 +1,42 @@
1
+package rocks.zipcode.io.quiz4.generics.group.integergroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+import java.util.UUID;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class IntegerGroupCountTest {
13
+    @Test
14
+    public void test1() {
15
+        test(1);
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        test(2);
21
+    }
22
+
23
+
24
+    @Test
25
+    public void test3() {
26
+        test(3);
27
+    }
28
+
29
+    public void test(Integer numberOfItemsToAdd) {
30
+        // given
31
+        Group<String> group = new Group<>();
32
+
33
+        // when
34
+        for (int i = 0; i < numberOfItemsToAdd; i++) {
35
+            String itemToAdd = UUID.randomUUID().toString();
36
+            group.insert(itemToAdd);
37
+        }
38
+
39
+        // then
40
+        Assert.assertEquals(group.count(), numberOfItemsToAdd);
41
+    }
42
+}

+ 37
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupDistinctTest.java Целия файл

@@ -0,0 +1,37 @@
1
+package rocks.zipcode.io.quiz4.generics.group.integergroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class IntegerGroupDistinctTest {
11
+    @Test
12
+    public void test1() {
13
+        test(1);
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test(2);
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test(3);
24
+    }
25
+
26
+    private void test(Integer valueToInsert) {
27
+        // given
28
+        Group<Integer> group = new Group<>();
29
+
30
+        // when
31
+        Assert.assertFalse(group.has(valueToInsert));
32
+        group.insert(valueToInsert);
33
+
34
+        // then
35
+        Assert.assertTrue(group.has(valueToInsert));
36
+    }
37
+}

+ 56
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupIterableTest.java Целия файл

@@ -0,0 +1,56 @@
1
+package rocks.zipcode.io.quiz4.generics.group.integergroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+import rocks.zipcode.io.quiz4.generics.Group;
7
+
8
+import java.util.ArrayList;
9
+import java.util.Arrays;
10
+import java.util.List;
11
+
12
+/**
13
+ * @author leon on 11/12/2018.
14
+ */
15
+public class IntegerGroupIterableTest {
16
+    @Test
17
+    public void test1() {
18
+        test(9);
19
+    }
20
+
21
+    @Test
22
+    public void test2() {
23
+        test(9, 99);
24
+    }
25
+
26
+    @Test
27
+    public void test3() {
28
+        test(9, 99, 999);
29
+    }
30
+
31
+
32
+    @Test
33
+    public void test4() {
34
+        test(9, 99, 999, 999);
35
+    }
36
+
37
+    @Test
38
+    public void test5() {
39
+        test(9, 99, 999, 999, 9999);
40
+    }
41
+
42
+    private void test(Integer... valuesToInsert) {
43
+        // given
44
+        Group<Integer> group = new Group<>();
45
+        List<Integer> result = new ArrayList<>();
46
+        List<Integer> contents = Arrays.asList(valuesToInsert);
47
+        contents.forEach(value -> group.insert(value));
48
+        Iterable<Integer> iterableGroup = (Iterable<Integer>)group;
49
+
50
+        // when
51
+        iterableGroup.forEach(string -> result.add(string));
52
+
53
+        // then
54
+        Assert.assertEquals(group.count().intValue(), contents.size());
55
+    }
56
+}

+ 7
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupWhereTest.java Целия файл

@@ -0,0 +1,7 @@
1
+package rocks.zipcode.io.quiz4.generics.group.integergroup;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class IntegerGroupWhereTest {
7
+}

+ 43
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupClearTest.java Целия файл

@@ -0,0 +1,43 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class StringGroupClearTest {
11
+    @Test
12
+    public void test1() {
13
+        test("first", "clear", "test");
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test("an", "additional", "test", "here");
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test("a", "dash", "of", "anonymity");
24
+    }
25
+
26
+    private void test(String... valuesToInsert) {
27
+        // given
28
+        Group<String> group = new Group<>();
29
+        for(String valueToInsert : valuesToInsert) {
30
+            group.insert(valueToInsert);
31
+            Assert.assertTrue(group.has(valueToInsert));
32
+        }
33
+
34
+        // when
35
+        group.clear();
36
+
37
+
38
+        // then
39
+        for(String valueToInsert : valuesToInsert) {
40
+            Assert.assertFalse(group.has(valueToInsert));
41
+        }
42
+    }
43
+}

+ 42
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupCountTest.java Целия файл

@@ -0,0 +1,42 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+import java.util.UUID;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class StringGroupCountTest {
13
+    @Test
14
+    public void test1() {
15
+        test(1);
16
+    }
17
+
18
+    @Test
19
+    public void test2() {
20
+        test(2);
21
+    }
22
+
23
+
24
+    @Test
25
+    public void test3() {
26
+        test(3);
27
+    }
28
+
29
+    public void test(Integer numberOfItemsToAdd) {
30
+        // given
31
+        Group<String> group = new Group<>();
32
+
33
+        // when
34
+        for (int i = 0; i < numberOfItemsToAdd; i++) {
35
+            String itemToAdd = UUID.randomUUID().toString();
36
+            group.insert(itemToAdd);
37
+        }
38
+
39
+        // then
40
+        Assert.assertEquals(group.count(), numberOfItemsToAdd);
41
+    }
42
+}

+ 51
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupDeleteTest.java Целия файл

@@ -0,0 +1,51 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class StringGroupDeleteTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        Group<String> group = new Group<>();
15
+        String valueToInsert = "first test";
16
+
17
+        // when
18
+        group.insert(valueToInsert);
19
+        group.delete(valueToInsert);
20
+
21
+        Assert.assertFalse(group.has(valueToInsert));
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        // given
27
+        Group<String> group = new Group<>();
28
+        String valueToInsert = "second test";
29
+
30
+        // when
31
+        group.insert(valueToInsert);
32
+        group.delete(valueToInsert);
33
+
34
+        // then
35
+        Assert.assertFalse(group.has(valueToInsert));
36
+    }
37
+
38
+    @Test
39
+    public void test3() {
40
+        // given
41
+        Group<String> group = new Group<>();
42
+        String valueToInsert = "third test";
43
+
44
+        // when
45
+        group.insert(valueToInsert);
46
+        group.delete(valueToInsert);
47
+
48
+        // then
49
+        Assert.assertFalse(group.has(valueToInsert));
50
+    }
51
+}

+ 37
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupDistinctTest.java Целия файл

@@ -0,0 +1,37 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class StringGroupDistinctTest {
11
+    @Test
12
+    public void test1() {
13
+        test("first test");
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test("second test");
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test("third test");
24
+    }
25
+
26
+    private void test(String valueToInsert) {
27
+        // given
28
+        Group<String> group = new Group<>();
29
+
30
+        // when
31
+        Assert.assertFalse(group.has(valueToInsert));
32
+        group.insert(valueToInsert);
33
+
34
+        // then
35
+        Assert.assertTrue(group.has(valueToInsert));
36
+    }
37
+}

+ 59
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupFetchTest.java Целия файл

@@ -0,0 +1,59 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+import java.util.Arrays;
8
+import java.util.List;
9
+
10
+/**
11
+ * @author leon on 11/12/2018.
12
+ */
13
+public class StringGroupFetchTest {
14
+    @Test
15
+    public void test1() {
16
+        test("first test");
17
+    }
18
+
19
+    @Test
20
+    public void test2() {
21
+        test("second test");
22
+    }
23
+
24
+    @Test
25
+    public void test3() {
26
+        test("third test");
27
+    }
28
+
29
+    @Test(expected = IndexOutOfBoundsException.class)
30
+    public void test4() {
31
+        // given
32
+        Group<String> group = new Group<>();
33
+
34
+        // when
35
+        group.fetch(10);
36
+    }
37
+
38
+    @Test(expected = IndexOutOfBoundsException.class)
39
+    public void test5() {
40
+        // given
41
+        Group<String> group = new Group<>();
42
+
43
+        // when
44
+        group.fetch(15);
45
+    }
46
+
47
+
48
+    private void test(String... stringsToInsert) {
49
+        // given
50
+        Group<String> group = new Group<>();
51
+        List<String> simpleStringGroupContents = Arrays.asList(stringsToInsert);
52
+        simpleStringGroupContents.forEach(string -> group.insert(string));
53
+
54
+        // when
55
+        for (int i = 0; i < stringsToInsert.length; i++) {
56
+            Assert.assertEquals(stringsToInsert[i], group.fetch(i));
57
+        }
58
+    }
59
+}

+ 37
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupInsertTest.java Целия файл

@@ -0,0 +1,37 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.Group;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class StringGroupInsertTest {
11
+    @Test
12
+    public void test1() {
13
+        test("first test");
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test("second test");
19
+    }
20
+
21
+    @Test
22
+    public void test3() {
23
+        test("third test");
24
+    }
25
+
26
+    private void test(String valueToInsert) {
27
+        // given
28
+        Group<String> group = new Group<>();
29
+
30
+        // when
31
+        Assert.assertFalse(group.has(valueToInsert));
32
+        group.insert(valueToInsert);
33
+
34
+        // then
35
+        Assert.assertTrue(group.has(valueToInsert));
36
+    }
37
+}

+ 56
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupIterableTest.java Целия файл

@@ -0,0 +1,56 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.collections.SimpleStringGroup;
6
+import rocks.zipcode.io.quiz4.generics.Group;
7
+
8
+import java.util.ArrayList;
9
+import java.util.Arrays;
10
+import java.util.List;
11
+
12
+/**
13
+ * @author leon on 11/12/2018.
14
+ */
15
+public class StringGroupIterableTest {
16
+    @Test
17
+    public void test1() {
18
+        test("the");
19
+    }
20
+
21
+    @Test
22
+    public void test2() {
23
+        test("the", "quick");
24
+    }
25
+
26
+    @Test
27
+    public void test3() {
28
+        test("the", "quick", "brown");
29
+    }
30
+
31
+
32
+    @Test
33
+    public void test4() {
34
+        test("the", "quick", "brown", "fox");
35
+    }
36
+
37
+    @Test
38
+    public void test5() {
39
+        test("the", "quick", "brown", "fox", "jumps");
40
+    }
41
+
42
+    private void test(String... valuesToInsert) {
43
+        // given
44
+        Group<String> group = new Group<>();
45
+        List<String> result = new ArrayList<>();
46
+        List<String> contents = Arrays.asList(valuesToInsert);
47
+        contents.forEach(value -> group.insert(value));
48
+        Iterable<String> iterableGroup = (Iterable<String>)group;
49
+
50
+        // when
51
+        iterableGroup.forEach(string -> result.add(string));
52
+
53
+        // then
54
+        Assert.assertEquals(group.count().intValue(), contents.size());
55
+    }
56
+}

+ 7
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/group/stringgroup/StringGroupWhereTest.java Целия файл

@@ -0,0 +1,7 @@
1
+package rocks.zipcode.io.quiz4.generics.group.stringgroup;
2
+
3
+/**
4
+ * @author leon on 11/12/2018.
5
+ */
6
+public class StringGroupWhereTest {
7
+}

+ 16
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/SortedGroupPolymorphismTest.java Целия файл

@@ -0,0 +1,16 @@
1
+package rocks.zipcode.io.quiz4.generics.sortedgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.GroupInterface;
6
+import rocks.zipcode.io.quiz4.generics.SortedGroup;
7
+
8
+/**
9
+ * @author leon on 18/12/2018.
10
+ */
11
+public class SortedGroupPolymorphismTest {
12
+    @Test
13
+    public void test1() {
14
+        Assert.assertTrue(new SortedGroup() instanceof GroupInterface);
15
+    }
16
+}

+ 91
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupDeleteTest.java Целия файл

@@ -0,0 +1,91 @@
1
+package rocks.zipcode.io.quiz4.generics.sortedgroup.integersortedgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.SortedGroup;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class IntegerSortedGroupDeleteTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        SortedGroup<Integer> group = new SortedGroup<>();
15
+        Integer firstValue = 1;
16
+        Integer secondValue = 2;
17
+        Integer thirdValue = 3;
18
+        Integer fourthValue = 4;
19
+
20
+        group.insert(fourthValue);
21
+        group.insert(firstValue);
22
+        group.insert(thirdValue);
23
+        group.insert(secondValue);
24
+
25
+        // when
26
+        group.delete(firstValue);
27
+
28
+        int secondValueIndex = group.indexOf(secondValue);
29
+        int thirdValueIndex = group.indexOf(thirdValue);
30
+        int fourthValueIndex = group.indexOf(fourthValue);
31
+
32
+        // then
33
+        Assert.assertEquals(secondValueIndex, 0);
34
+        Assert.assertEquals(thirdValueIndex, 1);
35
+        Assert.assertEquals(fourthValueIndex, 2);
36
+    }
37
+
38
+    @Test
39
+    public void test2() {
40
+        // given
41
+        SortedGroup<Integer> group = new SortedGroup<>();
42
+        Integer firstValue = 1;
43
+        Integer secondValue = 2;
44
+        Integer thirdValue = 3;
45
+        Integer fourthValue = 4;
46
+
47
+        group.insert(fourthValue);
48
+        group.insert(firstValue);
49
+        group.insert(thirdValue);
50
+        group.insert(secondValue);
51
+
52
+        // when
53
+        group.delete(secondValue);
54
+
55
+        int firstValueIndex = group.indexOf(firstValue);
56
+        int thirdValueIndex = group.indexOf(thirdValue);
57
+        int fourthValueIndex = group.indexOf(fourthValue);
58
+
59
+        // then
60
+        Assert.assertEquals(firstValueIndex, 0);
61
+        Assert.assertEquals(thirdValueIndex, 1);
62
+        Assert.assertEquals(fourthValueIndex, 2);
63
+    }
64
+
65
+    @Test
66
+    public void test3() {
67
+        // given
68
+        SortedGroup<Integer> group = new SortedGroup<>();
69
+        Integer firstValue = 1;
70
+        Integer secondValue = 2;
71
+        Integer thirdValue = 3;
72
+        Integer fourthValue = 4;
73
+
74
+        group.insert(fourthValue);
75
+        group.insert(firstValue);
76
+        group.insert(thirdValue);
77
+        group.insert(secondValue);
78
+
79
+        // when
80
+        group.delete(thirdValue);
81
+
82
+        int firstValueIndex = group.indexOf(firstValue);
83
+        int secondValueIndex = group.indexOf(secondValue);
84
+        int fourthValueIndex = group.indexOf(fourthValue);
85
+
86
+        // then
87
+        Assert.assertEquals(firstValueIndex, 0);
88
+        Assert.assertEquals(secondValueIndex, 1);
89
+        Assert.assertEquals(fourthValueIndex, 2);
90
+    }
91
+}

+ 94
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupInsertTest.java Целия файл

@@ -0,0 +1,94 @@
1
+package rocks.zipcode.io.quiz4.generics.sortedgroup.integersortedgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import org.omg.CORBA.INTERNAL;
6
+import rocks.zipcode.io.quiz4.generics.Group;
7
+import rocks.zipcode.io.quiz4.generics.SortedGroup;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class IntegerSortedGroupInsertTest {
13
+    @Test
14
+    public void test1() {
15
+        // given
16
+        SortedGroup<Integer> group = new SortedGroup<>();
17
+        Integer firstValue = 1;
18
+        Integer secondValue = 2;
19
+        Integer thirdValue = 3;
20
+        Integer fourthValue = 4;
21
+
22
+        // when
23
+        group.insert(fourthValue);
24
+        group.insert(firstValue);
25
+        group.insert(thirdValue);
26
+        group.insert(secondValue);
27
+
28
+        int firstValueIndex = group.indexOf(firstValue);
29
+        int secondValueIndex = group.indexOf(secondValue);
30
+        int thirdValueIndex = group.indexOf(thirdValue);
31
+        int fourthValueIndex = group.indexOf(fourthValue);
32
+
33
+        // then
34
+        Assert.assertEquals(firstValueIndex, 0);
35
+        Assert.assertEquals(secondValueIndex, 1);
36
+        Assert.assertEquals(thirdValueIndex, 2);
37
+        Assert.assertEquals(fourthValueIndex, 3);
38
+    }
39
+
40
+    @Test
41
+    public void test2() {
42
+        // given
43
+        SortedGroup<Integer> group = new SortedGroup<>();
44
+        Integer firstValue = 98;
45
+        Integer secondValue = 102;
46
+        Integer thirdValue = 362;
47
+        Integer fourthValue = 999;
48
+
49
+        // when
50
+        group.insert(fourthValue);
51
+        group.insert(firstValue);
52
+        group.insert(thirdValue);
53
+        group.insert(secondValue);
54
+
55
+        int firstValueIndex = group.indexOf(firstValue);
56
+        int secondValueIndex = group.indexOf(secondValue);
57
+        int thirdValueIndex = group.indexOf(thirdValue);
58
+        int fourthValueIndex = group.indexOf(fourthValue);
59
+
60
+        // then
61
+        Assert.assertEquals(firstValueIndex, 0);
62
+        Assert.assertEquals(secondValueIndex, 1);
63
+        Assert.assertEquals(thirdValueIndex, 2);
64
+        Assert.assertEquals(fourthValueIndex, 3);
65
+    }
66
+
67
+
68
+    @Test
69
+    public void test3() {
70
+        // given
71
+        SortedGroup<Integer> group = new SortedGroup<>();
72
+        Integer firstValue = Integer.MIN_VALUE;
73
+        Integer secondValue = firstValue + 1;
74
+        Integer thirdValue = secondValue + 1;
75
+        Integer fourthValue = Integer.MAX_VALUE;
76
+
77
+        // when
78
+        group.insert(fourthValue);
79
+        group.insert(firstValue);
80
+        group.insert(thirdValue);
81
+        group.insert(secondValue);
82
+
83
+        int firstValueIndex = group.indexOf(firstValue);
84
+        int secondValueIndex = group.indexOf(secondValue);
85
+        int thirdValueIndex = group.indexOf(thirdValue);
86
+        int fourthValueIndex = group.indexOf(fourthValue);
87
+
88
+        // then
89
+        Assert.assertEquals(firstValueIndex, 0);
90
+        Assert.assertEquals(secondValueIndex, 1);
91
+        Assert.assertEquals(thirdValueIndex, 2);
92
+        Assert.assertEquals(fourthValueIndex, 3);
93
+    }
94
+}

+ 91
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/stringsortedgroup/StringSortedGroupDeleteTest.java Целия файл

@@ -0,0 +1,91 @@
1
+package rocks.zipcode.io.quiz4.generics.sortedgroup.stringsortedgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.SortedGroup;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class StringSortedGroupDeleteTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        SortedGroup<String> group = new SortedGroup<>();
15
+        String firstValue = "1";
16
+        String secondValue = "2";
17
+        String thirdValue = "3";
18
+        String fourthValue = "4";
19
+
20
+        group.insert(fourthValue);
21
+        group.insert(firstValue);
22
+        group.insert(thirdValue);
23
+        group.insert(secondValue);
24
+
25
+        // when
26
+        group.delete(firstValue);
27
+
28
+        int secondValueIndex = group.indexOf(secondValue);
29
+        int thirdValueIndex = group.indexOf(thirdValue);
30
+        int fourthValueIndex = group.indexOf(fourthValue);
31
+
32
+        // then
33
+        Assert.assertEquals(secondValueIndex, 0);
34
+        Assert.assertEquals(thirdValueIndex, 1);
35
+        Assert.assertEquals(fourthValueIndex, 2);
36
+    }
37
+
38
+    @Test
39
+    public void test2() {
40
+        // given
41
+        SortedGroup<String> group = new SortedGroup<>();
42
+        String firstValue = "1";
43
+        String secondValue = "2";
44
+        String thirdValue = "3";
45
+        String fourthValue = "4";
46
+
47
+        group.insert(fourthValue);
48
+        group.insert(firstValue);
49
+        group.insert(thirdValue);
50
+        group.insert(secondValue);
51
+
52
+        // when
53
+        group.delete(secondValue);
54
+
55
+        int firstValueIndex = group.indexOf(firstValue);
56
+        int thirdValueIndex = group.indexOf(thirdValue);
57
+        int fourthValueIndex = group.indexOf(fourthValue);
58
+
59
+        // then
60
+        Assert.assertEquals(firstValueIndex, 0);
61
+        Assert.assertEquals(thirdValueIndex, 1);
62
+        Assert.assertEquals(fourthValueIndex, 2);
63
+    }
64
+
65
+    @Test
66
+    public void test3() {
67
+        // given
68
+        SortedGroup<String> group = new SortedGroup<>();
69
+        String firstValue = "1";
70
+        String secondValue = "2";
71
+        String thirdValue = "3";
72
+        String fourthValue = "4";
73
+
74
+        group.insert(fourthValue);
75
+        group.insert(firstValue);
76
+        group.insert(thirdValue);
77
+        group.insert(secondValue);
78
+
79
+        // when
80
+        group.delete(thirdValue);
81
+
82
+        int firstValueIndex = group.indexOf(firstValue);
83
+        int secondValueIndex = group.indexOf(secondValue);
84
+        int fourthValueIndex = group.indexOf(fourthValue);
85
+
86
+        // then
87
+        Assert.assertEquals(firstValueIndex, 0);
88
+        Assert.assertEquals(secondValueIndex, 1);
89
+        Assert.assertEquals(fourthValueIndex, 2);
90
+    }
91
+}

+ 229
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/stringsortedgroup/StringSortedGroupInsertTest.java Целия файл

@@ -0,0 +1,229 @@
1
+package rocks.zipcode.io.quiz4.generics.sortedgroup.stringsortedgroup;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.SortedGroup;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class StringSortedGroupInsertTest {
11
+
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        SortedGroup<String> group = new SortedGroup<>();
16
+        String firstValue = "A";
17
+        String secondValue = "B";
18
+        String thirdValue = "C";
19
+        String fourthValue = "D";
20
+
21
+        // when
22
+        group.insert(fourthValue);
23
+        group.insert(firstValue);
24
+        group.insert(thirdValue);
25
+        group.insert(secondValue);
26
+
27
+        int indexOfFirstValue = group.indexOf(firstValue);
28
+        int indexOfSecondValue = group.indexOf(secondValue);
29
+        int indexOfThirdValue = group.indexOf(thirdValue);
30
+        int indexOfFourthValue = group.indexOf(fourthValue);
31
+        System.out.println(group);
32
+        // then
33
+        Assert.assertEquals(indexOfFirstValue, 0);
34
+        Assert.assertEquals(indexOfSecondValue, 1);
35
+        Assert.assertEquals(indexOfThirdValue, 2);
36
+        Assert.assertEquals(indexOfFourthValue, 3);
37
+    }
38
+    @Test
39
+    public void test2() {
40
+        // given
41
+        SortedGroup<String> group = new SortedGroup<>();
42
+        String firstValue = "a";
43
+        String secondValue = "b";
44
+        String thirdValue = "c";
45
+        String fourthValue = "d";
46
+
47
+        // when
48
+        group.insert(fourthValue);
49
+        group.insert(firstValue);
50
+        group.insert(thirdValue);
51
+        group.insert(secondValue);
52
+
53
+        int indexOfFirstValue = group.indexOf(firstValue);
54
+        int indexOfSecondValue = group.indexOf(secondValue);
55
+        int indexOfThirdValue = group.indexOf(thirdValue);
56
+        int indexOfFourthValue = group.indexOf(fourthValue);
57
+        System.out.println(group);
58
+        // then
59
+        Assert.assertEquals(indexOfFirstValue, 0);
60
+        Assert.assertEquals(indexOfSecondValue, 1);
61
+        Assert.assertEquals(indexOfThirdValue, 2);
62
+        Assert.assertEquals(indexOfFourthValue, 3);
63
+    }
64
+
65
+    @Test
66
+    public void test3() {
67
+        // given
68
+        SortedGroup<String> group = new SortedGroup<>();
69
+        String firstValue = "A";
70
+        String secondValue = "B";
71
+        String thirdValue = "a";
72
+        String fourthValue = "b";
73
+
74
+        // when
75
+        group.insert(fourthValue);
76
+        group.insert(firstValue);
77
+        group.insert(thirdValue);
78
+        group.insert(secondValue);
79
+
80
+        int indexOfFirstValue = group.indexOf(firstValue);
81
+        int indexOfSecondValue = group.indexOf(secondValue);
82
+        int indexOfThirdValue = group.indexOf(thirdValue);
83
+        int indexOfFourthValue = group.indexOf(fourthValue);
84
+        System.out.println(group);
85
+        // then
86
+        Assert.assertEquals(indexOfFirstValue, 0);
87
+        Assert.assertEquals(indexOfSecondValue, 1);
88
+        Assert.assertEquals(indexOfThirdValue, 2);
89
+        Assert.assertEquals(indexOfFourthValue, 3);
90
+    }
91
+
92
+
93
+    @Test
94
+    public void test4() {
95
+        // given
96
+        SortedGroup<String> group = new SortedGroup<>();
97
+        String firstValue = "Astro";
98
+        String secondValue = "Bicycle";
99
+        String thirdValue = "Carnations";
100
+        String fourthValue = "Dinosaur";
101
+
102
+        // when
103
+        group.insert(fourthValue);
104
+        group.insert(firstValue);
105
+        group.insert(thirdValue);
106
+        group.insert(secondValue);
107
+
108
+        int indexOfFirstValue = group.indexOf(firstValue);
109
+        int indexOfSecondValue = group.indexOf(secondValue);
110
+        int indexOfThirdValue = group.indexOf(thirdValue);
111
+        int indexOfFourthValue = group.indexOf(fourthValue);
112
+        System.out.println(group);
113
+        // then
114
+        Assert.assertEquals(indexOfFirstValue, 0);
115
+        Assert.assertEquals(indexOfSecondValue, 1);
116
+        Assert.assertEquals(indexOfThirdValue, 2);
117
+        Assert.assertEquals(indexOfFourthValue, 3);
118
+    }
119
+
120
+    @Test
121
+    public void test6() {
122
+        // given
123
+        SortedGroup<String> group = new SortedGroup<>();
124
+        String firstValue = "Astro";
125
+        String secondValue = "Carnations";
126
+        String thirdValue = "bicycle";
127
+        String fourthValue = "dinosaur";
128
+
129
+        // when
130
+        group.insert(fourthValue);
131
+        group.insert(firstValue);
132
+        group.insert(thirdValue);
133
+        group.insert(secondValue);
134
+
135
+        int indexOfFirstValue = group.indexOf(firstValue);
136
+        int indexOfSecondValue = group.indexOf(secondValue);
137
+        int indexOfThirdValue = group.indexOf(thirdValue);
138
+        int indexOfFourthValue = group.indexOf(fourthValue);
139
+        System.out.println(group);
140
+        // then
141
+        Assert.assertEquals(indexOfFirstValue, 0);
142
+        Assert.assertEquals(indexOfSecondValue, 1);
143
+        Assert.assertEquals(indexOfThirdValue, 2);
144
+        Assert.assertEquals(indexOfFourthValue, 3);
145
+    }
146
+
147
+
148
+    @Test
149
+    public void test7() {
150
+        // given
151
+        SortedGroup<String> group = new SortedGroup<>();
152
+        String firstValue = "1";
153
+        String secondValue = "2";
154
+        String thirdValue = "3";
155
+        String fourthValue = "4";
156
+
157
+        // when
158
+        group.insert(fourthValue);
159
+        group.insert(firstValue);
160
+        group.insert(thirdValue);
161
+        group.insert(secondValue);
162
+
163
+        int firstValueIndex = group.indexOf(firstValue);
164
+        int secondValueIndex = group.indexOf(secondValue);
165
+        int thirdValueIndex = group.indexOf(thirdValue);
166
+        int fourthValueIndex = group.indexOf(fourthValue);
167
+
168
+        // then
169
+        Assert.assertEquals(firstValueIndex, 0);
170
+        Assert.assertEquals(secondValueIndex, 1);
171
+        Assert.assertEquals(thirdValueIndex, 2);
172
+        Assert.assertEquals(fourthValueIndex, 3);
173
+    }
174
+
175
+    @Test
176
+    public void test8() {
177
+        // given
178
+        SortedGroup<String> group = new SortedGroup<>();
179
+        String firstValue = "102";
180
+        String secondValue = "362";
181
+        String thirdValue = "98";
182
+        String fourthValue = "999";
183
+
184
+        // when
185
+        group.insert(fourthValue);
186
+        group.insert(firstValue);
187
+        group.insert(thirdValue);
188
+        group.insert(secondValue);
189
+
190
+        int indexOfFirstValue = group.indexOf(firstValue);
191
+        int indexOfSecondValue = group.indexOf(secondValue);
192
+        int indexOfThirdValue = group.indexOf(thirdValue);
193
+        int indexOfFourthValue = group.indexOf(fourthValue);
194
+        System.out.println(group);
195
+        // then
196
+        Assert.assertEquals(indexOfFirstValue, 0);
197
+        Assert.assertEquals(indexOfSecondValue, 1);
198
+        Assert.assertEquals(indexOfThirdValue, 2);
199
+        Assert.assertEquals(indexOfFourthValue, 3);
200
+    }
201
+
202
+
203
+    @Test
204
+    public void test9() {
205
+        // given
206
+        SortedGroup<String> group = new SortedGroup<>();
207
+        String firstValue = String.valueOf(Integer.MIN_VALUE + 2);
208
+        String secondValue = String.valueOf(Integer.MIN_VALUE + 1);
209
+        String thirdValue = String.valueOf(Integer.MIN_VALUE);
210
+        String fourthValue = String.valueOf(Integer.MAX_VALUE);
211
+
212
+        // when
213
+        group.insert(fourthValue);
214
+        group.insert(firstValue);
215
+        group.insert(thirdValue);
216
+        group.insert(secondValue);
217
+
218
+        int firstValueIndex = group.indexOf(firstValue);
219
+        int secondValueIndex = group.indexOf(secondValue);
220
+        int thirdValueIndex = group.indexOf(thirdValue);
221
+        int fourthValueIndex = group.indexOf(fourthValue);
222
+
223
+        // then
224
+        Assert.assertEquals(firstValueIndex, 0);
225
+        Assert.assertEquals(secondValueIndex, 1);
226
+        Assert.assertEquals(thirdValueIndex, 2);
227
+        Assert.assertEquals(fourthValueIndex, 3);
228
+    }
229
+}

+ 22
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/StackPolymorphismTest.java Целия файл

@@ -0,0 +1,22 @@
1
+package rocks.zipcode.io.quiz4.generics.stack;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.MyStack;
6
+
7
+import java.util.Collection;
8
+
9
+/**
10
+ * @author leon on 11/12/2018.
11
+ */
12
+public class StackPolymorphismTest {
13
+    @Test
14
+    public void ensureStackIsIterable() {
15
+        Assert.assertTrue(new MyStack<>() instanceof Iterable);
16
+    }
17
+
18
+    @Test
19
+    public void ensureStackIsNotCollection() {
20
+        Assert.assertFalse(new MyStack<>() instanceof Collection);
21
+    }
22
+}

+ 35
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/integerstack/IntegerStackIsEmptyTest.java Целия файл

@@ -0,0 +1,35 @@
1
+package rocks.zipcode.io.quiz4.generics.stack.integerstack;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import rocks.zipcode.io.quiz4.generics.MyStack;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class IntegerStackIsEmptyTest {
12
+    private MyStack<Integer> stack;
13
+
14
+    @Before
15
+    public void setup() {
16
+        this.stack = new MyStack<>();
17
+    }
18
+
19
+    @Test
20
+    public void test1() {
21
+        Assert.assertTrue(stack.isEmpty());
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        stack.push(0);
27
+        Assert.assertFalse(stack.isEmpty());
28
+    }
29
+
30
+    @Test
31
+    public void test3() {
32
+        stack.push(1);
33
+        Assert.assertFalse(stack.isEmpty());
34
+    }
35
+}

+ 54
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/integerstack/IntegerStackPopTest.java Целия файл

@@ -0,0 +1,54 @@
1
+package rocks.zipcode.io.quiz4.generics.stack.integerstack;
2
+
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.generics.MyStack;
6
+import rocks.zipcode.io.quiz4.utils.TestUtils;
7
+
8
+import java.util.ArrayList;
9
+import java.util.Arrays;
10
+import java.util.EmptyStackException;
11
+import java.util.List;
12
+
13
+/**
14
+ * @author leon on 11/12/2018.
15
+ */
16
+public class IntegerStackPopTest {
17
+    private MyStack<Integer> stack;
18
+
19
+    @Before
20
+    public void setup() {
21
+        this.stack = new MyStack<>();
22
+    }
23
+
24
+    @Test(expected = EmptyStackException.class)
25
+    public void test1() {
26
+        stack.pop();
27
+    }
28
+
29
+    @Test
30
+    public void test2() {
31
+        test(765, 321, 9, 342, 98, 132);
32
+    }
33
+    
34
+    @Test
35
+    public void test3() {
36
+        test(1123, 65, 4568, 21, 3154);
37
+    }
38
+
39
+    private void test(Integer... elementsToBePushed) {
40
+        List<Integer> listOfElementsTobePushed = Arrays.asList(elementsToBePushed);
41
+        List<Integer> result = new ArrayList<>();
42
+        for (Integer elementToBePushed : listOfElementsTobePushed) {
43
+            stack.push(elementToBePushed);
44
+        }
45
+
46
+        for (Integer elementToBePopped : listOfElementsTobePushed) {
47
+            result.add(stack.pop());
48
+        }
49
+
50
+        Integer[] actual = TestUtils.reveseList(result).toArray(Integer[]::new);
51
+        Integer[] expected = listOfElementsTobePushed.stream().toArray(Integer[]::new);
52
+        TestUtils.assertArrayEquals(expected, actual);
53
+    }
54
+}

+ 67
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/integerstack/IntegerStackPushTest.java Целия файл

@@ -0,0 +1,67 @@
1
+package rocks.zipcode.io.quiz4.generics.stack.integerstack;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import rocks.zipcode.io.quiz4.generics.MyStack;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class IntegerStackPushTest {
12
+    private MyStack<Integer> stack;
13
+
14
+    @Before
15
+    public void setup() {
16
+        this.stack = new MyStack<>();
17
+    }
18
+
19
+    @Test
20
+    public void test1() {
21
+        Assert.assertNull(stack.peek());
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        Integer expected = 0;
27
+        stack.push(expected);
28
+        Assert.assertEquals(stack.peek(), expected);
29
+    }
30
+
31
+    @Test
32
+    public void test3() {
33
+        Integer expected = 1;
34
+        stack.push(expected);
35
+        Assert.assertEquals(stack.peek(), expected);
36
+    }
37
+
38
+    @Test
39
+    public void test4() {
40
+        Integer val1 = 10;
41
+        Integer val2 = 15;
42
+        Integer val3 = 20;
43
+        Integer expected = 25;
44
+
45
+        stack.push(val1);
46
+        stack.push(val2);
47
+        stack.push(val3);
48
+        stack.push(expected);
49
+
50
+        Assert.assertEquals(stack.peek(), expected);
51
+    }
52
+
53
+    @Test
54
+    public void test5() {
55
+        Integer  val1 = 30;
56
+        Integer  val2 = 30;
57
+        Integer  val3 = 40;
58
+        Integer  expected = 45;
59
+
60
+        stack.push(val1);
61
+        stack.push(val2);
62
+        stack.push(val3);
63
+        stack.push(expected);
64
+
65
+        Assert.assertEquals(stack.peek(), expected);
66
+    }
67
+}

+ 35
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/stringstack/StringStackIsEmptyTest.java Целия файл

@@ -0,0 +1,35 @@
1
+package rocks.zipcode.io.quiz4.generics.stack.stringstack;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import rocks.zipcode.io.quiz4.generics.MyStack;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class StringStackIsEmptyTest {
12
+    private MyStack<String> stack;
13
+
14
+    @Before
15
+    public void setup() {
16
+        this.stack = new MyStack<>();
17
+    }
18
+
19
+    @Test
20
+    public void test1() {
21
+        Assert.assertTrue(stack.isEmpty());
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        stack.push("0");
27
+        Assert.assertFalse(stack.isEmpty());
28
+    }
29
+
30
+    @Test
31
+    public void test3() {
32
+        stack.push("1");
33
+        Assert.assertFalse(stack.isEmpty());
34
+    }
35
+}

+ 55
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/stringstack/StringStackPopTest.java Целия файл

@@ -0,0 +1,55 @@
1
+package rocks.zipcode.io.quiz4.generics.stack.stringstack;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import rocks.zipcode.io.quiz4.generics.MyStack;
7
+import rocks.zipcode.io.quiz4.utils.TestUtils;
8
+
9
+import java.util.ArrayList;
10
+import java.util.Arrays;
11
+import java.util.EmptyStackException;
12
+import java.util.List;
13
+
14
+/**
15
+ * @author leon on 11/12/2018.
16
+ */
17
+public class StringStackPopTest {
18
+    private MyStack<String> stack;
19
+
20
+    @Before
21
+    public void setup() {
22
+        this.stack = new MyStack<>();
23
+    }
24
+
25
+    @Test(expected = EmptyStackException.class)
26
+    public void test1() {
27
+        stack.pop();
28
+    }
29
+
30
+    @Test
31
+    public void test2() {
32
+        test("765", "321", "9", "342", "98", "132");
33
+    }
34
+    
35
+    @Test
36
+    public void test3() {
37
+        test("1123", "65", "4568", "21", "3154");
38
+    }
39
+
40
+    private void test(String... elementsToBePushed) {
41
+        List<String> listOfElementsTobePushed = Arrays.asList(elementsToBePushed);
42
+        List<String> result = new ArrayList<>();
43
+        for (String elementToBePushed : listOfElementsTobePushed) {
44
+            stack.push(elementToBePushed);
45
+        }
46
+
47
+        for (String elementToBePopped : listOfElementsTobePushed) {
48
+            result.add(stack.pop());
49
+        }
50
+
51
+        String[] actual = TestUtils.reveseList(result).toArray(String[]::new);
52
+        String[] expected = listOfElementsTobePushed.stream().toArray(String[]::new);
53
+        TestUtils.assertArrayEquals(expected, actual);
54
+    }
55
+}

+ 67
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/stack/stringstack/StringStackPushTest.java Целия файл

@@ -0,0 +1,67 @@
1
+package rocks.zipcode.io.quiz4.generics.stack.stringstack;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import rocks.zipcode.io.quiz4.generics.MyStack;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class StringStackPushTest {
12
+    private MyStack<String> stack;
13
+
14
+    @Before
15
+    public void setup() {
16
+        this.stack = new MyStack<>();
17
+    }
18
+
19
+    @Test
20
+    public void test1() {
21
+        Assert.assertNull(stack.peek());
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        String expected = "0";
27
+        stack.push(expected);
28
+        Assert.assertEquals(stack.peek(), expected);
29
+    }
30
+
31
+    @Test
32
+    public void test3() {
33
+        String expected = "1";
34
+        stack.push(expected);
35
+        Assert.assertEquals(stack.peek(), expected);
36
+    }
37
+
38
+    @Test
39
+    public void test4() {
40
+        String val1 = "10";
41
+        String val2 = "15";
42
+        String val3 = "20";
43
+        String expected = "25";
44
+
45
+        stack.push(val1);
46
+        stack.push(val2);
47
+        stack.push(val3);
48
+        stack.push(expected);
49
+
50
+        Assert.assertEquals(stack.peek(), expected);
51
+    }
52
+
53
+    @Test
54
+    public void test5() {
55
+        String  val1 = "30";
56
+        String  val2 = "35";
57
+        String  val3 = "40";
58
+        String  expected = "45";
59
+
60
+        stack.push(val1);
61
+        stack.push(val2);
62
+        stack.push(val3);
63
+        stack.push(expected);
64
+
65
+        Assert.assertEquals(stack.peek(), expected);
66
+    }
67
+}

+ 52
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectGetAllPalindromesTest.java Целия файл

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.palindromeobject;
2
+
3
+import org.junit.Test;
4
+import rocks.zipcode.io.quiz4.fundamentals.PalindromeEvaluator;
5
+import rocks.zipcode.io.quiz4.objectorientation.PalindromeObject;
6
+import rocks.zipcode.io.quiz4.utils.TestUtils;
7
+
8
+/**
9
+ * @author leon on 11/12/2018.
10
+ */
11
+public class PalindromeObjectGetAllPalindromesTest {
12
+    @Test
13
+    public void test1() {
14
+        // given
15
+        String input = "racecar";
16
+        String[] expected = new String[]{"a", "aceca", "c", "cec", "e", "r", "racecar"};
17
+        test(input, expected);
18
+    }
19
+
20
+    @Test
21
+    public void test2() {
22
+        // given
23
+        String input = "redder";
24
+        String[] expected = new String[]{"d", "dd", "e", "edde", "r", "redder"};
25
+        test(input, expected);
26
+    }
27
+
28
+
29
+    @Test
30
+    public void test3() {
31
+        // given
32
+        String input = "rotor";
33
+        String[] expected = new String[]{"o", "oto", "r", "rotor", "t"};
34
+        test(input, expected);
35
+    }
36
+
37
+    @Test
38
+    public void test4() {
39
+        // given
40
+        String input = "civic";
41
+        String[] expected = new String[]{"c", "civic", "i", "ivi", "v"};
42
+        test(input, expected);
43
+    }
44
+
45
+    public void test(String input, String... expected) {
46
+        // when
47
+        String[] actual = new PalindromeObject(input).getAllPalindromes();
48
+
49
+        // then
50
+        TestUtils.assertArrayEquals(expected, actual);
51
+    }
52
+}

+ 30
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectIsPalindromeTestNegative.java Целия файл

@@ -0,0 +1,30 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.palindromeobject;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.fundamentals.PalindromeEvaluator;
6
+import rocks.zipcode.io.quiz4.objectorientation.PalindromeObject;
7
+
8
+/**
9
+ * @author leon on 18/12/2018.
10
+ */
11
+public class PalindromeObjectIsPalindromeTestNegative {
12
+    @Test
13
+    public void test1() {
14
+        test("Racecar");
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        test("Redder");
20
+    }
21
+
22
+    @Test
23
+    public void test3() {
24
+        test("Redrum murder");
25
+    }
26
+
27
+    public void test(String input) {
28
+        Assert.assertTrue(new PalindromeObject(input).isPalindrome());
29
+    }
30
+}

+ 34
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectIsPalindromeTestPositive.java Целия файл

@@ -0,0 +1,34 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.palindromeobject;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.objectorientation.PalindromeObject;
6
+
7
+/**
8
+ * @author leon on 18/12/2018.
9
+ */
10
+public class PalindromeObjectIsPalindromeTestPositive {
11
+    @Test
12
+    public void test1() {
13
+        test("racecar");
14
+    }
15
+
16
+    @Test
17
+    public void test2() {
18
+        test("racEcar");
19
+    }
20
+    
21
+    @Test
22
+    public void test3() {
23
+        test("redder");
24
+    }
25
+    
26
+    @Test
27
+    public void test4() {
28
+        test("redrum murder");
29
+    }
30
+    
31
+    public void test(String input) {
32
+        Assert.assertTrue(new PalindromeObject(input).isPalindrome());
33
+    }
34
+}

+ 36
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectReverseTest.java Целия файл

@@ -0,0 +1,36 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.palindromeobject;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.fundamentals.PalindromeEvaluator;
6
+import rocks.zipcode.io.quiz4.objectorientation.PalindromeObject;
7
+
8
+/**
9
+ * @author leon on 18/12/2018.
10
+ */
11
+public class PalindromeObjectReverseTest {
12
+    @Test
13
+    public void test1() {
14
+        test("leon", "noel");
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        test("Jerry", "yrreJ");
20
+    }
21
+
22
+    @Test
23
+    public void test3() {
24
+        test("KJack", "kcaJK");
25
+    }
26
+
27
+    @Test
28
+    public void test4() {
29
+        test("redrum murder", "redrum murder");
30
+    }
31
+
32
+    public void test(String input, String expected) {
33
+        String actual =  new PalindromeObject(input).reverseString();
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+}

+ 88
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/stringassembler/AppendTest.java Целия файл

@@ -0,0 +1,88 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.stringassembler;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.objectorientation.StringAssembler;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class AppendTest {
11
+    @Test
12
+    public void test1() {
13
+        // given
14
+        Character delimeter = ' ';
15
+        String expected = "The quick brown fox jumps";
16
+
17
+        // when
18
+        String actual = new StringAssembler(delimeter)
19
+                .append("The")
20
+                .append("quick")
21
+                .append("brown")
22
+                .append("fox")
23
+                .append("jumps")
24
+                .assemble();
25
+
26
+        // then
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void test2() {
32
+        // given
33
+        Character delimeter = '\n';
34
+        String expected = "The\nquick\nbrown\nfox\njumps";
35
+
36
+        // when
37
+        String actual = new StringAssembler(delimeter)
38
+                .append("The")
39
+                .append("quick")
40
+                .append("brown")
41
+                .append("fox")
42
+                .append("jumps")
43
+                .assemble();
44
+
45
+        // then
46
+        Assert.assertEquals(expected, actual);
47
+    }
48
+
49
+    @Test
50
+    public void test3() {
51
+        // given
52
+        Character delimeter = '_';
53
+        String expected = "The_quick_brown_fox_jumps";
54
+
55
+        // when
56
+        String actual = new StringAssembler(delimeter)
57
+                .append("The")
58
+                .append("quick")
59
+                .append("brown")
60
+                .append("fox")
61
+                .append("jumps")
62
+                .assemble();
63
+
64
+        // then
65
+        Assert.assertEquals(expected, actual);
66
+    }
67
+
68
+
69
+    @Test
70
+    public void test4() {
71
+        // given
72
+        Character delimeter = ';';
73
+        String expected = "The;quick;brown;fox;jumps";
74
+
75
+        // when
76
+        String actual = new StringAssembler(delimeter)
77
+                .append("The")
78
+                .append("quick")
79
+                .append("brown")
80
+                .append("fox")
81
+                .append("jumps")
82
+                .assemble();
83
+
84
+        // then
85
+        Assert.assertEquals(expected, actual);
86
+    }
87
+
88
+}

+ 88
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/student/LearnTest.java Целия файл

@@ -0,0 +1,88 @@
1
+package rocks.zipcode.io.quiz4.objectorientation.student;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+import rocks.zipcode.io.quiz4.objectorientation.Student;
6
+
7
+/**
8
+ * @author leon on 11/12/2018.
9
+ */
10
+public class LearnTest {
11
+    @Test
12
+    public void test1() {
13
+        Student student = new Student();
14
+        Double expected = 15.0;
15
+
16
+        // when
17
+        student.learn(expected);
18
+        Double actual = student.getTotalStudyTime();
19
+
20
+        // then
21
+        Assert.assertEquals(expected, actual);
22
+    }
23
+
24
+    @Test
25
+    public void test2() {
26
+        Student student = new Student();
27
+        Double expected = 30.0;
28
+
29
+        // when
30
+        student.learn(expected);
31
+        Double actual = student.getTotalStudyTime();
32
+
33
+        // then
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+
37
+    @Test
38
+    public void test3() {
39
+        Student student = new Student();
40
+        Double firstLecture = 15.0;
41
+        Double secondLecture = 25.0;
42
+        Double expected = firstLecture + secondLecture;
43
+
44
+        // when
45
+        student.learn(firstLecture);
46
+        student.learn(secondLecture);
47
+        Double actual = student.getTotalStudyTime();
48
+
49
+        // then
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+
53
+
54
+    @Test
55
+    public void test4() {
56
+        Student student = new Student();
57
+        Double firstLecture = 35.0;
58
+        Double secondLecture = 25.0;
59
+        Double expected = firstLecture + secondLecture;
60
+
61
+        // when
62
+        student.learn(firstLecture);
63
+        student.learn(secondLecture);
64
+        Double actual = student.getTotalStudyTime();
65
+
66
+        // then
67
+        Assert.assertEquals(expected, actual);
68
+    }
69
+
70
+
71
+
72
+    @Test
73
+    public void test5() {
74
+        Student student = new Student();
75
+        Double firstLecture = 98.0;
76
+        Double secondLecture = 72.0;
77
+        Double expected = firstLecture + secondLecture;
78
+
79
+        // when
80
+        student.learn(firstLecture);
81
+        student.learn(secondLecture);
82
+        Double actual = student.getTotalStudyTime();
83
+
84
+        // then
85
+        Assert.assertEquals(expected, actual);
86
+    }
87
+
88
+}

+ 54
- 0
src/test/java/rocks/zipcode/io/quiz4/utils/MyTestClass.java Целия файл

@@ -0,0 +1,54 @@
1
+package rocks.zipcode.io.quiz4.utils;
2
+
3
+import rocks.zipcode.io.quiz4.collections.ComparableTreeSet;
4
+
5
+import java.util.*;
6
+
7
+/**
8
+ * @author leon on 18/12/2018.
9
+ */
10
+public class MyTestClass {
11
+
12
+    public static <E> Set<Set<E>> findPowerSet(Set<E> set) {
13
+        Set<Set<E>> ret = new TreeSet<>();
14
+        ret.add(set);
15
+        if (set.isEmpty()) {
16
+            return ret;
17
+        }
18
+        Iterator<E> it = set.iterator();
19
+        while (it.hasNext()) {
20
+            Set<E> tmp = (Set)new ComparableTreeSet(set);   //create a copy of current set
21
+            tmp.remove(it.next());              //remove current element from copy set
22
+            ret.add(tmp);                       //add the remaining set to result
23
+            ret.addAll(findPowerSet(tmp));      //recursively find subsets of copy set
24
+        }
25
+        return ret;
26
+    }
27
+
28
+    public static void main(String[] args) {
29
+        Set<Character> set = (Set)new ComparableTreeSet<Character>();
30
+        set.add('x');
31
+        set.add('y');
32
+        set.add('z');
33
+        set.add('t');
34
+        System.out.println("Input set");
35
+        printSet(set);
36
+        System.out.println("\nsub sets");
37
+        findPowerSet(set).stream().forEach(MyTestClass::printSet);
38
+    }
39
+
40
+
41
+    public static <E> void printSet(E... val) {
42
+        printSet(new TreeSet<>(Arrays.asList(val)));
43
+    }
44
+
45
+    public static <E> void printSet(Set<E> set) {
46
+        StringBuilder sb = new StringBuilder(set.size() == 0 ? "{}\n" : "{");
47
+        Iterator<E> it = set.iterator();
48
+        while (it.hasNext()) {
49
+            sb.append(it.next().toString())
50
+                    .append(it.hasNext() ? ", " : "}\n");
51
+        }
52
+        System.out.print(sb.toString());
53
+    }
54
+}

+ 63
- 0
src/test/java/rocks/zipcode/io/quiz4/utils/TestUtils.java Целия файл

@@ -0,0 +1,63 @@
1
+package rocks.zipcode.io.quiz4.utils;
2
+
3
+import org.junit.Assert;
4
+
5
+import java.util.Arrays;
6
+import java.util.List;
7
+import java.util.concurrent.TimeoutException;
8
+import java.util.function.BiFunction;
9
+import java.util.function.Function;
10
+import java.util.stream.IntStream;
11
+import java.util.stream.Stream;
12
+
13
+/**
14
+ * @author leon on 11/12/2018.
15
+ */
16
+public class TestUtils {
17
+    public static <ObjectType> void assertArrayEquals(ObjectType[] array1, ObjectType[] array2) {
18
+        Arrays.sort(array1);
19
+        Arrays.sort(array2);
20
+        Assert.assertEquals(Arrays.toString(array1), Arrays.toString(array2));
21
+    }
22
+
23
+
24
+    public static <ArgType1, ReturnType> void constrainMethodPerformance(
25
+            Function<ArgType1, ReturnType> function,
26
+            ArgType1 arg1,
27
+            Long maxTimeInMilliseconds) {
28
+        constrainMethodPerformance((val1, val2) -> function.apply(val1), arg1, null, maxTimeInMilliseconds);
29
+    }
30
+
31
+    public static <ArgType1, ArgType2, ReturnType> void constrainMethodPerformance(
32
+            BiFunction<ArgType1, ArgType2, ReturnType> function,
33
+            ArgType1 arg1, ArgType2 arg2, Long maxTimeInMilliseconds) {
34
+        if (timeMethod(function, arg1, arg2) > maxTimeInMilliseconds) {
35
+            Throwable timeoutException = new TimeoutException("Method must perform in under " + maxTimeInMilliseconds + "millseconds");
36
+            ;
37
+            throw new Error(timeoutException);
38
+        }
39
+    }
40
+
41
+
42
+    public static <ArgType1, ReturnType> Long timeMethod(Function<ArgType1, ReturnType> function, ArgType1 arg1) {
43
+        return timeMethod((val1, val2) -> function.apply(val1), arg1, null);
44
+    }
45
+
46
+    public static <ArgType1, ArgType2, ReturnType> Long timeMethod(
47
+            BiFunction<ArgType1, ArgType2, ReturnType> function,
48
+            ArgType1 arg1, ArgType2 arg2) {
49
+        Long startTime = System.currentTimeMillis();
50
+        function.apply(arg1, arg2);
51
+        Long endTime = System.currentTimeMillis();
52
+        Long delta = endTime - startTime;
53
+        return delta;
54
+    }
55
+
56
+    @SuppressWarnings("unchecked")
57
+    public static <T> Stream<T> reveseList(List<T> input) {
58
+        Object[] temp = input.toArray();
59
+        return (Stream<T>) IntStream.range(0, temp.length)
60
+                .mapToObj(i -> temp[temp.length - i - 1]);
61
+    }
62
+
63
+}