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/test | |
| parent | d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd (diff) | |
Cleanup pass II
Part II of the cleanup pass
Diffstat (limited to 'base/src/test')
9 files changed, 90 insertions, 77 deletions
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")); |
