3 Incheckningar

Upphovsman SHA1 Meddelande Datum
  curtiscook 247f1978a6 Curtis Cook's Quiz 4 6 år sedan
  Leon c15ab321e7 created an additional oop class & tests 6 år sedan
  Leon 8dcb8d3769 created an additional oop class & tests 6 år sedan
15 ändrade filer med 286 tillägg och 39 borttagningar
  1. 38
    4
      src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java
  2. 25
    3
      src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java
  3. 32
    1
      src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java
  4. 1
    1
      src/main/java/rocks/zipcode/io/quiz4/generics/Group.java
  5. 15
    4
      src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java
  6. 20
    5
      src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java
  7. 0
    7
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/ToStringTest.java
  8. 0
    7
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/WhereTest.java
  9. 52
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorGetAllPalindromesTest.java
  10. 30
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorIsPalindromeTestNegative.java
  11. 35
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorIsPalindromeTestPositive.java
  12. 36
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorReverseTest.java
  13. 0
    7
      src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupWhereTest.java
  14. 1
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupDeleteTest.java
  15. 1
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/stringsortedgroup/StringSortedGroupDeleteTest.java

+ 38
- 4
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java Visa fil

@@ -1,17 +1,51 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+import java.util.Arrays;
4
+import java.util.TreeSet;
5
+
3 6
 /**
4 7
  * @author leon on 11/12/2018.
5 8
  */
6
-public class ComparableTreeSet<_> {
9
+public class ComparableTreeSet<_> extends TreeSet implements Comparable {
10
+    _[] array;
11
+
7 12
     public ComparableTreeSet(_... arr) {
13
+//        TreeSet<_> treeSet = new TreeSet<>();
14
+//        for (_ generic : arr) {
15
+//            treeSet.add(generic);
16
+//        }
17
+//
18
+//        for (_ branch : treeSet) {
19
+//            System.out.println(branch);
20
+//        }
21
+
22
+        TreeSet<_> treeSet = new TreeSet<_>(Arrays.asList(arr));
23
+        treeSet.toString();
24
+//        array = (_[]) treeSet.toArray();
8 25
     }
9 26
 
10 27
 
11 28
     public ComparableTreeSet() {
12 29
     }
13 30
 
14
-    public Integer compareTo(ComparableTreeSet<_> o) {
15
-        return null;
31
+//    public Integer compareTo(ComparableTreeSet<_> o) {
32
+//        return null;
33
+//    }
34
+
35
+    @Override
36
+    public int compareTo(Object o) {
37
+        for (int i = 0; i < array.length; i++) {
38
+            if (array[i].hashCode() > o.hashCode()) {
39
+                return 1;
40
+            } else {
41
+                return -1;
42
+            }
43
+        }
44
+        return 0;
45
+    }
46
+
47
+    @Override
48
+    public String toString() {
49
+        return super.toString();
16 50
     }
17
-}
51
+}

+ 25
- 3
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java Visa fil

@@ -1,18 +1,40 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
+import java.util.TreeSet;
4
+
3 5
 /**
4 6
  * @author leon on 18/12/2018.
5 7
  */
6 8
 public class PalindromeEvaluator {
7 9
     public static String[] getAllPalindromes(String string) {
8
-        return null;
10
+        TreeSet<String> treeSet = new TreeSet<>();
11
+        for (int i = 0; i < string.length(); i++) {
12
+            treeSet.add(String.valueOf(string.charAt(i)));
13
+        }
14
+
15
+        for (int i = 0; i < string.length() / 2; i++) {
16
+            if(string.charAt(i) == string.charAt(string.length() - 1 - i)) {
17
+                treeSet.add(string.substring(i, string.length() - i));
18
+            }
19
+        }
20
+        return treeSet.toArray(new String[0]);
9 21
     }
10 22
 
11 23
     public static Boolean isPalindrome(String string) {
12
-        return null;
24
+        for (int i = 0; i < string.length() - 1; i++) {
25
+            if (string.charAt(i) != string.charAt(string.length() - 1 - i)) {
26
+                return false;
27
+            }
28
+        }
29
+        return true;
13 30
     }
14 31
 
15 32
     public static String reverseString(String string) {
16
-        return null;
33
+        String[] reversedString = new String[string.length()];
34
+        StringBuilder sb = new StringBuilder(string.length());
35
+        for (int i = string.length() - 1, j = 0; i >= 0; i--, j++) {
36
+            sb.append(string.charAt(i));
37
+        }
38
+        return sb.toString();
17 39
     }
18 40
 }

+ 32
- 1
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java Visa fil

@@ -1,11 +1,42 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
+import java.util.TreeSet;
4
+
3 5
 /**
4 6
  * @author leon on 11/12/2018.
5 7
  */
6 8
 public class StringEvaluator {
7 9
     public static String[] getAllPrefixes(String string) {
8
-        return null;
10
+        TreeSet<String> treeSet = new TreeSet<>();
11
+        for (int i = 0, j = string.length(); i < string.length(); i++, j--) {
12
+//            treeSet.add(String.valueOf(string.charAt(i)));
13
+//            System.out.println(string.charAt(i));
14
+//            treeSet.add(string.substring(i));
15
+//            System.out.println(string.substring(i));
16
+//            if (i > 1) {
17
+//                treeSet.add(string.substring(0, i));
18
+//                System.out.println(string.substring(0, i));
19
+//            }
20
+//            if (j > i) {
21
+//                treeSet.add(string.substring(i, j));
22
+//                System.out.println(string.substring(i, j));
23
+//            }
24
+            treeSet.add(String.valueOf(string.charAt(i)));
25
+            treeSet.add(string.substring(i));
26
+            if (i > 0 && j > 1) {
27
+                treeSet.add(string.substring(1, j));
28
+            }
29
+            if (j > i) {
30
+                treeSet.add(string.substring(i, j));
31
+                System.out.println(string.substring(i, j));
32
+            }
33
+            if (j > 0) {
34
+                treeSet.add(string.substring(0, j));
35
+                System.out.println(string.substring(0, j));
36
+            }
37
+        }
38
+
39
+        return treeSet.toArray(new String[0]);
9 40
     }
10 41
 
11 42
     public static String[] getCommonPrefixes(String string1, String string2) {

+ 1
- 1
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java Visa fil

@@ -7,7 +7,7 @@ import java.util.Iterator;
7 7
  */
8 8
 public class Group<_> {
9 9
     public Group() {
10
-        throw new UnsupportedOperationException("Method not yet implemented");
10
+//        throw new UnsupportedOperationException("Method not yet implemented");
11 11
     }
12 12
 
13 13
     public Integer count() {

+ 15
- 4
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java Visa fil

@@ -1,25 +1,36 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
+import java.util.Iterator;
4
+import java.util.Stack;
5
+
3 6
 /**
4 7
  * @author leon on 11/12/2018.
5 8
  */
6
-public class MyStack<SomeType> {
9
+public class MyStack<SomeType> implements Iterable {
10
+    Stack<SomeType> someTypeStack = new Stack<>();
11
+
7 12
     public MyStack() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
13
+
9 14
     }
10 15
 
11 16
     public Boolean isEmpty() {
12
-        return null;
17
+        return someTypeStack.empty();
13 18
     }
14 19
 
15 20
     public void push(SomeType i) {
21
+        someTypeStack.push(i);
16 22
     }
17 23
 
18 24
     public SomeType peek() {
19
-        throw new UnsupportedOperationException("Method not yet implemented");
25
+        return someTypeStack.peek();
20 26
     }
21 27
 
22 28
     public SomeType pop() {
29
+        return someTypeStack.pop();
30
+    }
31
+
32
+    @Override
33
+    public Iterator iterator() {
23 34
         return null;
24 35
     }
25 36
 }

+ 20
- 5
src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java Visa fil

@@ -3,16 +3,31 @@ package rocks.zipcode.io.quiz4.generics;
3 3
 /**
4 4
  * @author leon on 18/12/2018.
5 5
  */
6
-public class SortedGroup<_> extends Group<_> {
6
+public class SortedGroup<_> extends Group<_> implements GroupInterface {
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
+
7 19
     @Override
8
-    public void insert(_ value) {
20
+    public Boolean has(Object valueToInsert) {
21
+        return null;
9 22
     }
10 23
 
11 24
     @Override
12
-    public void delete(_ value) {
25
+    public void insert(Object string) {
26
+
13 27
     }
14 28
 
15
-    public Integer indexOf(_ firstValue) {
16
-        return null;
29
+    @Override
30
+    public void delete(Object valueToInsert) {
31
+
17 32
     }
18 33
 }

+ 0
- 7
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/ToStringTest.java Visa fil

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

+ 0
- 7
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/WhereTest.java Visa fil

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

+ 52
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorGetAllPalindromesTest.java Visa fil

@@ -0,0 +1,52 @@
1
+package rocks.zipcode.io.quiz4.fundamentals.palindromeevaluator;
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 PalindromeEvaluatorGetAllPalindromesTest {
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 = PalindromeEvaluator.getAllPalindromes(input);
48
+
49
+        // then
50
+        TestUtils.assertArrayEquals(expected, actual);
51
+    }
52
+}

+ 30
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorIsPalindromeTestNegative.java Visa fil

@@ -0,0 +1,30 @@
1
+package rocks.zipcode.io.quiz4.fundamentals.palindromeevaluator;
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 PalindromeEvaluatorIsPalindromeTestNegative {
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.assertFalse(PalindromeEvaluator.isPalindrome(input));
29
+    }
30
+}

+ 35
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorIsPalindromeTestPositive.java Visa fil

@@ -0,0 +1,35 @@
1
+package rocks.zipcode.io.quiz4.fundamentals.palindromeevaluator;
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 PalindromeEvaluatorIsPalindromeTestPositive {
12
+    @Test
13
+    public void test1() {
14
+        test("racecar");
15
+    }
16
+
17
+    @Test
18
+    public void test2() {
19
+        test("racEcar");
20
+    }
21
+    
22
+    @Test
23
+    public void test3() {
24
+        test("redder");
25
+    }
26
+    
27
+    @Test
28
+    public void test4() {
29
+        test("redrum murder");
30
+    }
31
+    
32
+    public void test(String input) {
33
+        Assert.assertTrue(PalindromeEvaluator.isPalindrome(input));
34
+    }
35
+}

+ 36
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/palindromeevaluator/PalindromeEvaluatorReverseTest.java Visa fil

@@ -0,0 +1,36 @@
1
+package rocks.zipcode.io.quiz4.fundamentals.palindromeevaluator;
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 PalindromeEvaluatorReverseTest {
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 = PalindromeEvaluator.reverseString(input);
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+}

+ 0
- 7
src/test/java/rocks/zipcode/io/quiz4/generics/group/integergroup/IntegerGroupWhereTest.java Visa fil

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

+ 1
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupDeleteTest.java Visa fil

@@ -7,6 +7,7 @@ import rocks.zipcode.io.quiz4.generics.SortedGroup;
7 7
 /**
8 8
  * @author leon on 11/12/2018.
9 9
  */
10
+@SuppressWarnings("all")
10 11
 public class IntegerSortedGroupDeleteTest {
11 12
     @Test
12 13
     public void test1() {

+ 1
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/stringsortedgroup/StringSortedGroupDeleteTest.java Visa fil

@@ -7,6 +7,7 @@ import rocks.zipcode.io.quiz4.generics.SortedGroup;
7 7
 /**
8 8
  * @author leon on 11/12/2018.
9 9
  */
10
+@SuppressWarnings("all")
10 11
 public class StringSortedGroupDeleteTest {
11 12
     @Test
12 13
     public void test1() {