From 3af0ea5c4fc4bb3bcb19bff7681cf63867b8b0dc Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Thu, 17 Dec 2015 20:49:28 +0100 Subject: [PATCH] Add tests for Pair refs #53 --- src/main/java/eva2/tools/Pair.java | 21 ++---- src/main/java/eva2/tools/math/BayNet.java | 4 +- src/test/java/eva2/tools/PairTest.java | 79 +++++++++++++++++++++++ 3 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 src/test/java/eva2/tools/PairTest.java diff --git a/src/main/java/eva2/tools/Pair.java b/src/main/java/eva2/tools/Pair.java index 15006514..ec807335 100644 --- a/src/main/java/eva2/tools/Pair.java +++ b/src/main/java/eva2/tools/Pair.java @@ -1,5 +1,7 @@ package eva2.tools; +import eva2.util.annotation.Parameter; + import java.io.Serializable; /** @@ -11,7 +13,6 @@ public class Pair implements Serializable { /** * */ - private static final long serialVersionUID = -3620465393975181451L; public S head; public T tail; @@ -24,9 +25,6 @@ public class Pair implements Serializable { this.tail = tail; } - public Pair() { - } - /** * @return */ @@ -75,10 +73,6 @@ public class Pair implements Serializable { return head; } - public String headTipText() { - return "First pair entry"; - } - /** * @return */ @@ -90,15 +84,6 @@ public class Pair implements Serializable { return tail; } - public String tailTipText() { - return "Last pair entry"; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "(" + head.toString() + "," + tail.toString() + ")"; @@ -111,6 +96,7 @@ public class Pair implements Serializable { /** * @param head */ + @Parameter(description="First pair entry") public void setHead(S head) { this.head = head; } @@ -118,6 +104,7 @@ public class Pair implements Serializable { /** * @param tail */ + @Parameter(description = "Last pair entry") public void setTail(T tail) { this.tail = tail; } diff --git a/src/main/java/eva2/tools/math/BayNet.java b/src/main/java/eva2/tools/math/BayNet.java index 34c75c38..06392b11 100644 --- a/src/main/java/eva2/tools/math/BayNet.java +++ b/src/main/java/eva2/tools/math/BayNet.java @@ -1052,9 +1052,7 @@ public final class BayNet { line = line + ": " + pTable[j]; result += line; } - Pair p = new Pair<>(); - p.setHead(length); - p.setTail(result); + Pair p = new Pair<>(length, result); return p; } diff --git a/src/test/java/eva2/tools/PairTest.java b/src/test/java/eva2/tools/PairTest.java new file mode 100644 index 00000000..80a92950 --- /dev/null +++ b/src/test/java/eva2/tools/PairTest.java @@ -0,0 +1,79 @@ +package eva2.tools; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PairTest { + private Pair p; + + @Before + public void setUp() { + p = new Pair<>("Head", 12.0); + } + + @Test + public void testCar() throws Exception { + assertEquals("Head", p.car()); + } + + @Test + public void testCdr() throws Exception { + assertEquals(12.0, p.cdr(), 0.0); + } + + @Test + public void testClone() throws Exception { + //assertEquals(p, p.clone()); + } + + @Test + public void testHashCode() throws Exception { + assertNotNull(p.hashCode()); + } + + @Test + public void testHead() throws Exception { + assertEquals("Head", p.head()); + } + + @Test + public void testGetHead() throws Exception { + assertEquals("Head", p.getHead()); + } + + @Test + public void testTail() throws Exception { + assertEquals(12.0, p.tail(), 0.0); + } + + @Test + public void testGetTail() throws Exception { + assertEquals(12.0, p.getTail(), 0.0); + } + + @Test + public void testToString() throws Exception { + assertEquals("(Head,12.0)", p.toString()); + } + + @Test + public void testGetName() throws Exception { + assertEquals("(Head,12.0)", p.toString()); + } + + @Test + public void testSetHead() throws Exception { + String newHead = "newHead"; + p.setHead(newHead); + assertEquals(newHead, p.getHead()); + } + + @Test + public void testSetTail() throws Exception { + Double newTail = 42.0; + p.setTail(newTail); + assertEquals(newTail, p.getTail()); + } +} \ No newline at end of file