summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2019-06-11 22:28:51 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2019-06-11 22:28:51 -0300
commiteba653d0d712e43676e28f93b7cba217cb56cecc (patch)
tree1d5849556c99a5bbcc955e217296e5fdf9f990e6 /src/test
parent71c35c0ffba04e7c7932ffa06b9528b2a5efb48d (diff)
Initial commit p2
The rest of the files, for initial upload to github
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/bjc/replpair/AppTest.java20
-rw-r--r--src/test/java/bjc/replpair/ReplPairTest.java104
2 files changed, 104 insertions, 20 deletions
diff --git a/src/test/java/bjc/replpair/AppTest.java b/src/test/java/bjc/replpair/AppTest.java
deleted file mode 100644
index a81acfd..0000000
--- a/src/test/java/bjc/replpair/AppTest.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package bjc.replpair;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
-{
- /**
- * Rigorous Test :-)
- */
- @Test
- public void shouldAnswerWithTrue()
- {
- assertTrue( true );
- }
-}
diff --git a/src/test/java/bjc/replpair/ReplPairTest.java b/src/test/java/bjc/replpair/ReplPairTest.java
new file mode 100644
index 0000000..4ce918f
--- /dev/null
+++ b/src/test/java/bjc/replpair/ReplPairTest.java
@@ -0,0 +1,104 @@
+package bjc.replpair;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import java.util.List;
+import java.util.Scanner;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ * Unit test for ReplPair.
+ *
+ * @author Ben Culkin
+ */
+public class ReplPairTest {
+ // Test that we load empty files fine
+ @Test
+ public void testLoadFile() {
+ List<ReplPair> lrp = null;
+ String fName = "data/test/test1.rp";
+
+ try (FileInputStream fis = new FileInputStream(fName); Scanner scn = new Scanner(fis)) {
+ lrp = ReplPair.readList(scn);
+
+ assertTrue(lrp.size() == 0);
+ } catch (IOException ioex) {
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void testSingleReplace() {
+ assertMultiReplace("data/test/test2.rp", "test2", "test1", "test2", "test2");
+ }
+
+ @Test
+ public void testMultiReplace() {
+ assertMultiReplace("data/test/test3.rp", "A B C", "a b c", "A A B", "a a b", "AAB", "aab");
+ }
+
+ @Test
+ public void testReplaceOrder() {
+ assertMultiReplace("data/test/test4.rp", "a", "a", "d", "ab");
+ }
+
+ @Test
+ public void testReplaceExpOrder() {
+ assertMultiReplace("data/test/test5.rp", "a", "a", "aa", "ab");
+ }
+
+ private void assertMultiReplace(String fle, String... inps) {
+ assertMultiReplace(false, fle, inps);
+ }
+
+ private void assertMultiReplace(boolean logRep, String fle, String... inps) {
+ if (inps.length < 2) throw new IllegalArgumentException("ERROR: Must provide at least two strings to assertMultiReplace");
+ if (inps.length % 2 != 0) throw new IllegalArgumentException("ERROR: Odd number of strings passed to assertMultiReplace");
+
+ List<ReplPair> lrp = null;
+
+ try (FileInputStream fis = new FileInputStream(fle); Scanner scn = new Scanner(fis)) {
+ lrp = ReplPair.readList(scn);
+ } catch (Exception ex) {
+ System.err.println("EXCEPTION");
+ ex.printStackTrace();
+
+ assertTrue(false);
+
+ return;
+ }
+
+ for (int i = 0; i < inps.length; i += 2) {
+ String right = inps[i];
+ String inp = inps[i + 1];
+
+ assertReplacesTo(logRep, right, lrp, inp);
+ }
+ }
+
+ private void assertReplacesFrom(String right, String inp, String fle) {
+ assertMultiReplace(fle, right, inp);
+ }
+
+ private void assertReplacesTo(String right, List<ReplPair> rps, String inp) {
+ assertReplacesTo(false, right, rps, inp);
+ }
+
+ private void assertReplacesTo(boolean logRep, String right, List<ReplPair> rps, String inp) {
+ String tmp = inp;
+
+ for (ReplPair rp : rps) {
+ String oldTmp = tmp;
+
+ tmp = rp.apply(tmp);
+
+ if (logRep) System.err.printf("\t[LOG] '%s' -> '%s'\t%s\n", oldTmp, tmp, rp);
+ }
+
+ assertEquals(right, tmp);
+ }
+}