diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:42:14 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:42:14 -0400 |
| commit | a2b0364035a52625fc043dc62618112599013744 (patch) | |
| tree | 90352922bc17cd50a4052da86369ad5f52fcf5b9 /base/src | |
| parent | d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd (diff) | |
Cleanup pass II
Part II of the cleanup pass
Diffstat (limited to 'base/src')
14 files changed, 132 insertions, 104 deletions
diff --git a/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java b/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java index c2348d5..e6eacfa 100644 --- a/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java +++ b/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java @@ -18,7 +18,7 @@ public class AbbrevMapTest { * Main method. * * @param args - * Unused CLI args. + * Unused CLI args. */ public static void main(final String[] args) { final Scanner scn = new Scanner(System.in); @@ -39,10 +39,11 @@ public class AbbrevMapTest { map.removeWords(commParts.get(1)); break; case "check": { - String[] strings = map.deabbrevAll(commParts.get(1)).toArray(new String[0]); - + String[] strings + = map.deabbrevAll(commParts.get(1)).toArray(new String[0]); + final String list = StringUtils.toEnglishList(strings, false); - + System.out.println(list); break; } @@ -50,7 +51,7 @@ public class AbbrevMapTest { System.out.println(map.toString()); break; case "help": - if(commParts.size() > 1) { + if (commParts.size() > 1) { help(commParts.get(1)); } else { help(); @@ -69,17 +70,18 @@ public class AbbrevMapTest { private static void help() { PrintStream strm = System.out; - + strm.println("Abbreviation Map Testing Commands:"); strm.println("\tadd <word>\tAdd a word to the abbreviation map"); strm.println("\tremove <word>\tRemove a word from the abbreviation map"); - strm.println("\tcheck <word>\tCheck all of the possible things a word could be an abbreviation for"); + strm.println( + "\tcheck <word>\tCheck all of the possible things a word could be an abbreviation for"); strm.println("\tdebug \tPrint out the abbreviation map"); strm.println("\thelp \tList commands, or get help on a command\n"); } private static void help(String com) { - switch(com) { + switch (com) { default: System.out.printf("\tNo help available for command: %s\n", com); } diff --git a/base/src/examples/java/bjc/utils/examples/BinarySearchTest.java b/base/src/examples/java/bjc/utils/examples/BinarySearchTest.java index 4c66494..5e8e372 100644 --- a/base/src/examples/java/bjc/utils/examples/BinarySearchTest.java +++ b/base/src/examples/java/bjc/utils/examples/BinarySearchTest.java @@ -12,8 +12,10 @@ import bjc.funcdata.bst.TreeLinearizationMethod; * */ public class BinarySearchTest { - private static void display(final BinarySearchTree<Character> tree, final Scanner input) { - System.out.print("What order would you like the tree to be printed in (m for options): "); + private static void display(final BinarySearchTree<Character> tree, + final Scanner input) { + System.out.print( + "What order would you like the tree to be printed in (m for options): "); char command; while (true) { @@ -23,9 +25,12 @@ public class BinarySearchTest { switch (command) { case 'm': System.out.println("Possible tree printing methods: "); - System.out.println("\tp: Preorder printing (print parent first, then left & right)."); - System.out.println("\ti: Inorder printing (print left first, then parent & right)."); - System.out.println("\to: Postorder printing (print left first, then right & parent)."); + System.out.println( + "\tp: Preorder printing (print parent first, then left & right)."); + System.out.println( + "\ti: Inorder printing (print left first, then parent & right)."); + System.out.println( + "\to: Postorder printing (print left first, then right & parent)."); break; case 'p': method = TreeLinearizationMethod.PREORDER; @@ -41,7 +46,7 @@ public class BinarySearchTest { } if (method != null) { - tree.traverse(method, (element) -> { + tree.traverse(method, element -> { System.out.println("Node: " + element); return true; }); @@ -49,7 +54,8 @@ public class BinarySearchTest { return; } - System.out.print("What order would you like the tree to be printed in (m for options): "); + System.out.print( + "What order would you like the tree to be printed in (m for options): "); } } @@ -57,12 +63,13 @@ public class BinarySearchTest { * Main method of class * * @param args - * Unused CLI args + * Unused CLI args */ public static void main(final String[] args) { final Scanner input = new Scanner(System.in); System.out.println("Binary Tree Constructor/Searcher"); - final BinarySearchTree<Character> tree = new BinarySearchTree<>((o1, o2) -> o1 - o2); + final BinarySearchTree<Character> tree + = new BinarySearchTree<>((o1, o2) -> o1 - o2); char command = ' '; while (command != 'e') { diff --git a/base/src/examples/java/bjc/utils/examples/ShuntTest.java b/base/src/examples/java/bjc/utils/examples/ShuntTest.java index aefa5ff..b62a5a6 100644 --- a/base/src/examples/java/bjc/utils/examples/ShuntTest.java +++ b/base/src/examples/java/bjc/utils/examples/ShuntTest.java @@ -17,7 +17,7 @@ public class ShuntTest { * Main method * * @param args - * Unused CLI args + * Unused CLI args */ public static void main(final String[] args) { final Scanner inputSource = new Scanner(System.in); @@ -27,7 +27,8 @@ public class ShuntTest { final ShuntingYard<String> yard = new ShuntingYard<>(true); - final IList<String> preTokens = new FunctionalStringTokenizer(line).toList(strang -> strang); + final IList<String> preTokens + = new FunctionalStringTokenizer(line).toList(strang -> strang); final IList<String> shuntedTokens = yard.postfix(preTokens, strang -> strang); System.out.println(shuntedTokens.toString()); diff --git a/base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java b/base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java index 429e84c..935a189 100644 --- a/base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java +++ b/base/src/examples/java/bjc/utils/examples/rangen/DiabloItemGen.java @@ -13,8 +13,10 @@ import bjc.utils.gen.WeightedGrammar; public class DiabloItemGen { private static WeightedGrammar<String> rules = new WeightedGrammar<>(); - private static void addCase(final String ruleName, final int probability, final String ruleParts) { - final IList<String> parts = FunctionalStringTokenizer.fromString(ruleParts).toList(strang -> strang); + private static void addCase(final String ruleName, final int probability, + final String ruleParts) { + final IList<String> parts = FunctionalStringTokenizer.fromString(ruleParts) + .toList(strang -> strang); rules.addCase(ruleName, probability, parts); } @@ -67,7 +69,7 @@ public class DiabloItemGen { * Main Method * * @param args - * Unused CLI args + * Unused CLI args */ public static void main(final String[] args) { rules.addRule("<item>"); diff --git a/base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java b/base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java index b305ebe..bdc4f53 100644 --- a/base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java +++ b/base/src/examples/java/bjc/utils/examples/rangen/RandomStringExamples.java @@ -18,7 +18,8 @@ public class RandomStringExamples { final IList<IList<String>> cses = new FunctionalList<>(); for (final String strang : cases) { - final IList<String> lst = FunctionalStringTokenizer.fromString(strang).toList(s -> s); + final IList<String> lst + = FunctionalStringTokenizer.fromString(strang).toList(s -> s); cses.add(lst); } @@ -30,13 +31,14 @@ public class RandomStringExamples { * Main method * * @param args - * Unused CLI args + * Unused CLI args */ public static void main(final String[] args) { rg = new RandomGrammar<>(); - addRule("<sentance>", "<person> <opines> <something>", "<person> thinks that I am <property>", - "I <opine> <something>", "You think that I am <property>"); + addRule("<sentance>", "<person> <opines> <something>", + "<person> thinks that I am <property>", "I <opine> <something>", + "You think that I am <property>"); addRule("<activity>", "dancing", "eating", "sleeping"); @@ -46,7 +48,8 @@ public class RandomStringExamples { addRule("<opines>", "hates", "loves"); - addRule("<person>", "my sister", "my father", "my girlfriend", "the man next door"); + addRule("<person>", "my sister", "my father", "my girlfriend", + "the man next door"); addRule("<property>", "creative", "intelligent"); diff --git a/base/src/test/java/bjc/utils/test/cli/objects/CommandTest.java b/base/src/test/java/bjc/utils/test/cli/objects/CommandTest.java index 1e253be..4728a5e 100644 --- a/base/src/test/java/bjc/utils/test/cli/objects/CommandTest.java +++ b/base/src/test/java/bjc/utils/test/cli/objects/CommandTest.java @@ -8,7 +8,7 @@ import bjc.utils.cli.objects.Command; /** * Test that CLI command objects work correctly. - * + * * @author bjculkin * */ @@ -20,34 +20,34 @@ public class CommandTest { @Test public void testBasic() { Command com = Command.fromString("a b c", 1, "console"); - + assertEquals("a b c", com.full); assertEquals("a", com.name); assertEquals("b c", com.remn); - + assertEquals("b", com.trimTo(' ')); assertEquals("c", com.remn); - + com = Command.fromString("a b c", 1, "console"); - + assertEquals("a b c", com.full); assertEquals("a", com.name); assertEquals("b c", com.remn); - + assertEquals("b", com.trimTo(" ")); assertEquals("c", com.remn); } - + /** * Test regex trimming works right. */ @Test public void testRX() { Command com = Command.fromString("a try1ZZZtry2ZZtry3", 1, "console"); - + assertEquals("try1", com.trimToRX("Z+")); assertEquals("try2ZZtry3", com.remn); - + assertEquals("try2", com.trimToRX("Z+")); assertEquals("try3", com.remn); } diff --git a/base/src/test/java/bjc/utils/test/funcutils/IteratorUtilsTest.java b/base/src/test/java/bjc/utils/test/funcutils/IteratorUtilsTest.java index 965582b..a3cb151 100644 --- a/base/src/test/java/bjc/utils/test/funcutils/IteratorUtilsTest.java +++ b/base/src/test/java/bjc/utils/test/funcutils/IteratorUtilsTest.java @@ -18,6 +18,8 @@ public class IteratorUtilsTest { */ @Test public void testChain() { - assertIteratorEquals(chain(I(asList("a b", "b c")), (arg) -> I(asList(arg.split(" ")))), "a", "b", "b", "c"); + assertIteratorEquals( + chain(I(asList("a b", "b c")), arg -> I(asList(arg.split(" ")))), "a", + "b", "b", "c"); } } diff --git a/base/src/test/java/bjc/utils/test/funcutils/StringUtilsTest.java b/base/src/test/java/bjc/utils/test/funcutils/StringUtilsTest.java index b53d3e9..21eda57 100644 --- a/base/src/test/java/bjc/utils/test/funcutils/StringUtilsTest.java +++ b/base/src/test/java/bjc/utils/test/funcutils/StringUtilsTest.java @@ -24,10 +24,12 @@ public class StringUtilsTest { assertReadLines("hallo there\na second line", "hallo there", "a second line"); - assertReadLines("hallo there \\\na continued line", "hallo there a continued line"); + assertReadLines("hallo there \\\na continued line", + "hallo there a continued line"); + + assertReadLines("hallo there\\\\\na second line", "hallo there\\", + "a second line"); - assertReadLines("hallo there\\\\\na second line", "hallo there\\", "a second line"); - assertReadLines("a\n\nb", "a", "", "b"); } diff --git a/base/src/test/java/bjc/utils/test/ioutils/LevelSplitterTest.java b/base/src/test/java/bjc/utils/test/ioutils/LevelSplitterTest.java index aadea72..5fb3756 100644 --- a/base/src/test/java/bjc/utils/test/ioutils/LevelSplitterTest.java +++ b/base/src/test/java/bjc/utils/test/ioutils/LevelSplitterTest.java @@ -9,7 +9,7 @@ import bjc.utils.ioutils.LevelSplitter; /** * Test of LevelSplitter. - * + * * @author bjculkin * */ @@ -33,11 +33,11 @@ public class LevelSplitterTest { */ @Test public void testRXSplit() { - //LevelSplitter splitter = LevelSplitter.def; + // LevelSplitter splitter = LevelSplitter.def; // Check generic splitting works - assertRXSplit("\\s+", pair("", ""), pair("a", "a"), pair("a b", "a", "b"), pair("a b", "a", "b"), - pair("a\t \tb", "a", "b")); + assertRXSplit("\\s+", pair("", ""), pair("a", "a"), pair("a b", "a", "b"), + pair("a b", "a", "b"), pair("a\t \tb", "a", "b")); } private static void assertRXSplit(String pat, RXPair... pairs) { diff --git a/base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java b/base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java index 4918b95..8a5807e 100644 --- a/base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java +++ b/base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java @@ -11,7 +11,7 @@ import bjc.utils.ioutils.ReportWriter; /** * Tests for ReportWriter. - * + * * @author EVE * */ diff --git a/base/src/test/java/bjc/utils/test/ioutils/SimplePropertiesTest.java b/base/src/test/java/bjc/utils/test/ioutils/SimplePropertiesTest.java index 81f7ac8..9de2ad3 100644 --- a/base/src/test/java/bjc/utils/test/ioutils/SimplePropertiesTest.java +++ b/base/src/test/java/bjc/utils/test/ioutils/SimplePropertiesTest.java @@ -12,7 +12,7 @@ import bjc.utils.ioutils.SimpleProperties.InvalidLineFormat; /** * Tests for SimpleProperties. - * + * * @author Ben Culkin * */ @@ -21,7 +21,7 @@ public class SimplePropertiesTest { @Test public void testSimpleProperties() { SimpleProperties props = new SimpleProperties(); - + assertEquals(0, props.size()); assertTrue(props.isEmpty()); } @@ -29,11 +29,11 @@ public class SimplePropertiesTest { @Test public void testLoadFrom() { SimpleProperties props = new SimpleProperties(); - + StringReader rdr = new StringReader("a a\nb b\nc c1\nc c2\n#c c3"); - + props.loadFrom(rdr, true); - + assertEquals(3, props.size()); assertEquals("a", props.get("a")); assertEquals("b", props.get("b")); @@ -43,18 +43,18 @@ public class SimplePropertiesTest { @Test(expected = DuplicateKeys.class) public void testDuplicateKeys() { SimpleProperties props = new SimpleProperties(); - + StringReader rdr = new StringReader("a a\nb b\nb b"); - + props.loadFrom(rdr, false); } - + @Test(expected = InvalidLineFormat.class) public void testInvalidFormat() { SimpleProperties props = new SimpleProperties(); - + StringReader rdr = new StringReader("a"); - + props.loadFrom(rdr, false); } }
\ No newline at end of file diff --git a/base/src/test/java/bjc/utils/test/math/DualExprParserTest.java b/base/src/test/java/bjc/utils/test/math/DualExprParserTest.java index 1f822b6..04915a1 100644 --- a/base/src/test/java/bjc/utils/test/math/DualExprParserTest.java +++ b/base/src/test/java/bjc/utils/test/math/DualExprParserTest.java @@ -21,7 +21,7 @@ public class DualExprParserTest { public void testBasics() { assertDEEvalsTo(new Dual(1.0, 0.0), "1"); } - + @Test public void testMath() { assertDEEvalsTo(new Dual(2.0, 0.0), "1 1 +"); @@ -29,105 +29,108 @@ public class DualExprParserTest { assertDEEvalsTo(new Dual(4.0, 0.0), "2 2 *"); assertDEEvalsTo(new Dual(2.0, 0.0), "4 2 /"); } - + @Test public void testFuncs() { assertDEEvalsTo(new Dual(2.0, -0.0), "-2 abs"); - - + assertDEEvalsTo(new Dual(Math.sin(2), -0.0), "2 sin"); assertDEEvalsTo(new Dual(Math.cos(2), -0.0), "2 cos"); - + assertDEEvalsTo(new Dual(Math.log(2.0), 0.0), "2 log"); assertDEEvalsTo(new Dual(Math.exp(2), 0.0), "2 exp"); assertDEEvalsTo(new Dual(Math.sqrt(2), 0.0), "2 0.5 pow"); assertDEEvalsTo(new Dual(4.0, 0.0), "2 2 pow"); - + assertDEEvalsTo(new Dual(4.0, 0.0), "1 2 + eval 1 +"); } - + @Test public void testVars() { assertDEEvalsTo(new Dual(2.0, 0.0), "x x +", "x", 1); - + assertDEEvalsTo(new Dual(4.0, 4.0), "x 2 pow", "x", new Dual(2.0, 1.0)); assertDEEvalsTo(new Dual(8.0, 12.0), "x 3 pow", "x", new Dual(2.0, 1.0)); } - + @Test(expected = IllegalArgumentException.class) public void testDivZero() { assertDEEvalsTo(new Dual(0.0, 0.0), "1 0 /"); } - + @Test(expected = OperandsRemaining.class) public void testOpsRemaining() { DualExprParser.parseExpression("1 2"); - + assertFalse("Shouldn't reach here", true); } - + @Test(expected = NonConstantPower.class) public void testNonConstantPower() { DualExprParser.parseExpression("1 1 1 dual pow"); } - + private static void assertDEEvalsTo(Dual res, String inp) { assertDEEvalsTo(false, res, inp); } - + private static void assertDEEvalsTo(Dual res, String inp, Object... vars) { assertDEEvalsTo(false, res, inp, vars); } - - private static void assertDEEvalsTo(boolean printExpr, Dual res, String inp, Object... vars) { + + private static void assertDEEvalsTo(boolean printExpr, Dual res, String inp, + Object... vars) { Map<String, DualExpr> varMap = new HashMap<>(); - + for (int idx = 0; idx < vars.length; idx += 2) { if (!(vars[idx] instanceof String)) { throw new IllegalArgumentException("Expected string for variable name"); } - + String name = (String) vars[idx]; - + DualExpr val; Object tentVal = vars[idx + 1]; - + if (tentVal instanceof Integer) { int vl = (int) tentVal; - + val = new DualExpr(new Dual(vl)); } else if (tentVal instanceof Double) { double vl = (double) tentVal; - + val = new DualExpr(new Dual(vl)); } else if (tentVal instanceof Dual) { val = new DualExpr((Dual) tentVal); } else if (tentVal instanceof DualExpr) { val = (DualExpr) tentVal; } else { - throw new IllegalArgumentException("Invalid argument type " + tentVal.getClass().getName()); + throw new IllegalArgumentException( + "Invalid argument type " + tentVal.getClass().getName()); } - + varMap.put(name, val); } - + Result res1 = DualExprParser.parseExpression(inp, varMap); - + DualExpr de1 = res1.expr; - - if (printExpr) System.out.printf("Expression: '%s'\n", de1); - + + if (printExpr) + System.out.printf("Expression: '%s'\n", de1); + assertEquals(res, de1.evaluate()); } - + private static void assertDEEvalsTo(boolean printExpr, Dual res, String inp) { Result res1 = DualExprParser.parseExpression(inp); - + DualExpr de1 = res1.expr; - - if (printExpr) System.out.printf("Expression: '%s'\n", de1); - + + if (printExpr) + System.out.printf("Expression: '%s'\n", de1); + assertEquals(res, de1.evaluate()); } }
\ No newline at end of file diff --git a/base/src/test/java/bjc/utils/test/math/NumberUtilsTest.java b/base/src/test/java/bjc/utils/test/math/NumberUtilsTest.java index 6176a41..47c264f 100644 --- a/base/src/test/java/bjc/utils/test/math/NumberUtilsTest.java +++ b/base/src/test/java/bjc/utils/test/math/NumberUtilsTest.java @@ -11,30 +11,30 @@ public class NumberUtilsTest { @Test public void testRomanNumerals() { assertRomanEquals("N", 0); - + assertRomanEquals("I", 1); assertRomanEquals("IV", 4); - + assertRomanEquals("VI", 6); - + assertRomanEquals("CCCXLIX", 349); assertRomanEquals("CCCLX", 360); - + assertRomanEquals("CDXC", 490); - + assertRomanEquals("DIX", 509); - + assertRomanEquals("CMX", 910); assertRomanEquals("MIV", 1004); - + assertRomanEquals("-IIII", -4, true); assertRomanEquals("IIII", 4, true); } - + private static void assertRomanEquals(String exp, long res) { assertRomanEquals(exp, res, false); } - + private static void assertRomanEquals(String exp, long res, boolean classic) { assertEquals(exp, NumberUtils.toRoman(res, classic)); } diff --git a/base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java b/base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java index 99593ed..133e0c0 100644 --- a/base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java +++ b/base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java @@ -29,7 +29,8 @@ public class TokenUtilsTest { * Check handling of mismatched strings with no matching strings. */ @Test - public void testRemoveDQuoted_MismatchedStringNoMatch() throws IllegalArgumentException { + public void testRemoveDQuoted_MismatchedStringNoMatch() + throws IllegalArgumentException { exp.expect(IllegalArgumentException.class); exp.expectMessage(containsString("Opening quote was at position 0")); @@ -40,7 +41,8 @@ public class TokenUtilsTest { * Check handling of mismatched strings with a matching string. */ @Test - public void testRemoveDQuoted_MismatchedStringMatch() throws IllegalArgumentException { + public void testRemoveDQuoted_MismatchedStringMatch() + throws IllegalArgumentException { exp.expect(IllegalArgumentException.class); exp.expectMessage(containsString("Opening quote was at position 7")); @@ -62,7 +64,8 @@ public class TokenUtilsTest { */ @Test public void testRemoveDQuoted_MultipleSerialString() { - final List<String> onMultipleSerialMatchString = removeDQuotedStrings("\"hello\"\"there\""); + final List<String> onMultipleSerialMatchString + = removeDQuotedStrings("\"hello\"\"there\""); assertThat(onMultipleSerialMatchString, hasItems("\"hello\"", "\"there\"")); } @@ -72,9 +75,11 @@ public class TokenUtilsTest { */ @Test public void testRemoveDQuoted_MultipleInterleavedString() { - final List<String> onMultipleInterleaveMatchString = removeDQuotedStrings("one\"two\"three\"four\""); + final List<String> onMultipleInterleaveMatchString + = removeDQuotedStrings("one\"two\"three\"four\""); - assertThat(onMultipleInterleaveMatchString, hasItems("one", "\"two\"", "three", "\"four\"")); + assertThat(onMultipleInterleaveMatchString, + hasItems("one", "\"two\"", "three", "\"four\"")); } /* @@ -144,7 +149,8 @@ public class TokenUtilsTest { * Check handling of strings with invalid single escapes. */ @Test - public void testDescapeString_InvalidSingleEscapeString() throws IllegalArgumentException { + public void testDescapeString_InvalidSingleEscapeString() + throws IllegalArgumentException { exp.expect(IllegalArgumentException.class); exp.expectMessage(containsString("at position 0")); |
