From fe22278fe627e45d6b867b7f493a51d5d3eed551 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Fri, 4 May 2018 12:38:20 +0200 Subject: [PATCH] 100% Code Coverage beim bisherigen Code --- .../java2/praktikum/praktikum1/GrosseZahl.java | 6 +++--- .../hs/java2/vorlesungen/binaryTree/Node.java | 8 -------- .../hs/java2/vorlesungen/binaryTree/Tree.java | 5 ----- .../hs/java2/tests/CharCollectionTest.java | 1 + .../joethei/hs/java2/tests/GrosseZahlTest.java | 18 ++++++++++++++++++ .../joethei/hs/java2/tests/VorlesungsTest.java | 5 +++++ 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java index 79dc73f..ba94468 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java @@ -17,7 +17,7 @@ public class GrosseZahl { zahl[w] = Integer.parseInt(String.valueOf(d.charAt(w))); } } else { - System.out.println("Incorrect Input!"); + throw new IllegalArgumentException("falscher Input"); } } @@ -118,11 +118,11 @@ public class GrosseZahl { } - private int length() { + public int length() { return zahl.length; } - private int numberAt(int i) { + public int numberAt(int i) { return zahl[i]; } diff --git a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java index b74dcd7..0832ef7 100644 --- a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java +++ b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Node.java @@ -10,9 +10,6 @@ public class Node { private Logger logger = Logger.getLogger(getClass().getName()); - public Node() { - } - public Node(T value) { this.value = value; } @@ -35,11 +32,6 @@ public class Node { return right; } - @Override - public String toString() { - return super.toString(); - } - @Override public boolean equals(Object obj) { if (obj instanceof Node) { diff --git a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java index 95d6b6d..a594a5e 100644 --- a/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java +++ b/src/main/java/de/joethei/hs/java2/vorlesungen/binaryTree/Tree.java @@ -12,9 +12,4 @@ public class Tree { return root; } - @Override - public boolean equals(Object obj) { - if(obj instanceof Tree) return root.equals(obj); - return false; - } } \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java b/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java index b8f47c8..39aa249 100644 --- a/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/CharCollectionTest.java @@ -49,6 +49,7 @@ public class CharCollectionTest { @Test public void equals() { assertEquals(new CharCollection("llo"), new CharCollection("lol")); + assertNotEquals(new CharCollection("Hallo"), "Hallo"); } @Test diff --git a/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java b/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java index 53b7a4f..6c36b19 100644 --- a/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java @@ -14,6 +14,18 @@ public class GrosseZahlTest { assertNotEquals(new GrosseZahl(14), 14); } + @Test + public void length() { + assertEquals(4, new GrosseZahl("1234").length()); + assertNotEquals(5, new GrosseZahl(1234).length()); + } + + @Test + public void numberAt() { + assertEquals(5, new GrosseZahl("125").numberAt(2)); + assertNotEquals(5, new GrosseZahl(125).numberAt(1)); + } + @Test public void add() { @@ -33,6 +45,7 @@ public class GrosseZahlTest { assertNotEquals(new GrosseZahl(43), new GrosseZahl(100).sub(new GrosseZahl(58))); assertEquals(new GrosseZahl(100), new GrosseZahl(150).sub(new GrosseZahl(50))); assertEquals(new GrosseZahl(0), new GrosseZahl(10).sub(new GrosseZahl("10"))); + assertEquals(new GrosseZahl(0), new GrosseZahl(10).sub(new GrosseZahl(15))); } @Test @@ -64,4 +77,9 @@ public class GrosseZahlTest { assertNotEquals(new GrosseZahl(2), new GrosseZahl("7").ggT(new GrosseZahl(13))); } + @Test(expected = IllegalArgumentException.class) + public void wrongInput() { + new GrosseZahl("42B"); + } + } \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java b/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java index e2a159b..16397d2 100644 --- a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java @@ -10,6 +10,8 @@ import java.util.Set; import java.util.TreeSet; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; public class VorlesungsTest { @@ -29,5 +31,8 @@ public class VorlesungsTest { assertEquals(Integer.valueOf(16), tree.getRoot().getRight().getValue()); assertEquals(tree.getRoot(), node); + + + assertNotEquals(node, "HalloWelt"); } } \ No newline at end of file