Revision: 12145
http://sourceforge.net/p/foray/code/12145
Author: victormote
Date: 2021-11-28 01:37:07 +0000 (Sun, 28 Nov 2021)
Log Message:
-----------
Put branches at both ends of the test to make sure they are traversed correctly.
Modified Paths:
--------------
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 01:19:17 UTC (rev 12144)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-28 01:37:07 UTC (rev 12145)
@@ -52,74 +52,99 @@
final ParaConfig config = Mockito.mock(ParaConfig.class);
final ParaBranch4a out = new ParaBranch4a(config);
- final ParaBranch4a greatness = new ParaBranch4a(config);
- greatness.add(new ParaBoxChars("great"));
- greatness.add(DiscretionaryHyphen4a.GOOD);
- greatness.add(new ParaBoxChars("ness"));
+ final ParaBranch4a nodeGreatness = new ParaBranch4a(config);
+ nodeGreatness.add(new ParaBoxChars("great"));
+ nodeGreatness.add(DiscretionaryHyphen4a.GOOD);
+ nodeGreatness.add(new ParaBoxChars("ness"));
- out.add(new ParaBoxChars("Be")); // Node 0, Leaf 0
- out.add(ParaGlueChars.SPACE); // Node 1, Leaf 1
- out.add(new ParaBoxChars("not")); // Node 2, Leaf 2
- out.add(ParaGlueChars.SPACE); // Node 3, Leaf 3
- out.add(new ParaBoxChars("afraid")); // Node 4, Leaf 4
- out.add(ParaGlueChars.SPACE); // Node 5, Leaf 5
- out.add(new ParaBoxChars("of")); // Node 6, Leaf 6
- out.add(ParaGlueChars.SPACE); // Node 7, Leaf 7
- out.add(greatness); // Node 8, Leaf 8 - 10
- out.add(new ParaBoxChars(".")); // Node 9, Leaf 11
- out.add(ParaGlueChars.SPACE); // Node 10, Leaf 12
- out.add(new ParaBoxChars("Some")); // Node 11, Leaf 13
- out.add(ParaGlueChars.SPACE); // Node 12, Leaf 14
- out.add(new ParaBoxChars("are")); // Node 13, Leaf 15
- out.add(ParaGlueChars.SPACE); // Node 14, Leaf 16
- out.add(new ParaBoxChars("born")); // Node 15, Leaf 17
- out.add(ParaGlueChars.SPACE); // Node 16, Leaf 18
- out.add(new ParaBoxChars("great,")); // Node 17, Leaf 19
- out.add(ParaGlueChars.SPACE); // Node 18, Leaf 20
- out.add(new ParaBoxChars("some")); // Node 19, Leaf 21
- out.add(ParaGlueChars.SPACE); // Node 20, Leaf 22
- out.add(new ParaBoxChars("achieve")); // Node 21, Leaf 23
- out.add(ParaGlueChars.SPACE); // Node 22, Leaf 24
- out.add(greatness); // Node 23, Leaf 25 - 27
- out.add(new ParaBoxChars(",")); // Node 24, Leaf 28
- out.add(ParaGlueChars.SPACE); // Node 25, Leaf 29
- out.add(new ParaBoxChars("and")); // Node 26, Leaf 30
- out.add(ParaGlueChars.SPACE); // Node 27, Leaf 31
- out.add(new ParaBoxChars("some")); // Node 28, Leaf 32
- out.add(ParaGlueChars.SPACE); // Node 29, Leaf 33
- out.add(new ParaBoxChars("have")); // Node 30, Leaf 34
- out.add(ParaGlueChars.SPACE); // Node 31, Leaf 35
- out.add(greatness); // Node 32, Leaf 36 - 38
- out.add(ParaGlueChars.SPACE); // Node 33, Leaf 39
- out.add(new ParaBoxChars("thrust")); // Node 34, Leaf 40
- out.add(ParaGlueChars.SPACE); // Node 35, Leaf 41
- out.add(new ParaBoxChars("upon")); // Node 36, Leaf 42
- out.add(ParaGlueChars.SPACE); // Node 37, Leaf 43
- out.add(new ParaBoxChars("them.")); // Node 38, Leaf 44
+ /* Putting "Be" in a branch is unnecessary, but we with to test a branch as the first node. */
+ final ParaBranch4a nodeBe = new ParaBranch4a(config);
+ nodeBe.add(new ParaBoxChars("B"));
+ nodeBe.add(new ParaBoxChars("e"));
+ out.add(nodeBe); // Node 0, Leaf 0 - 1
+ out.add(ParaGlueChars.SPACE); // Node 1, Leaf 2
+ out.add(new ParaBoxChars("not")); // Node 2, Leaf 3
+ out.add(ParaGlueChars.SPACE); // Node 3, Leaf 4
+ out.add(new ParaBoxChars("afraid")); // Node 4, Leaf 5
+ out.add(ParaGlueChars.SPACE); // Node 5, Leaf 6
+ out.add(new ParaBoxChars("of")); // Node 6, Leaf 7
+ out.add(ParaGlueChars.SPACE); // Node 7, Leaf 8
+ out.add(nodeGreatness); // Node 8, Leaf 9 - 11
+ out.add(new ParaBoxChars(".")); // Node 9, Leaf 12
+ out.add(ParaGlueChars.SPACE); // Node 10, Leaf 13
+ out.add(new ParaBoxChars("Some")); // Node 11, Leaf 14
+ out.add(ParaGlueChars.SPACE); // Node 12, Leaf 15
+ out.add(new ParaBoxChars("are")); // Node 13, Leaf 16
+ out.add(ParaGlueChars.SPACE); // Node 14, Leaf 17
+ out.add(new ParaBoxChars("born")); // Node 15, Leaf 18
+ out.add(ParaGlueChars.SPACE); // Node 16, Leaf 19
+ out.add(new ParaBoxChars("great,")); // Node 17, Leaf 20
+ out.add(ParaGlueChars.SPACE); // Node 18, Leaf 21
+ out.add(new ParaBoxChars("some")); // Node 19, Leaf 22
+ out.add(ParaGlueChars.SPACE); // Node 20, Leaf 23
+ out.add(new ParaBoxChars("achieve")); // Node 21, Leaf 24
+ out.add(ParaGlueChars.SPACE); // Node 22, Leaf 25
+ out.add(nodeGreatness); // Node 23, Leaf 26 - 28
+ out.add(new ParaBoxChars(",")); // Node 24, Leaf 29
+ out.add(ParaGlueChars.SPACE); // Node 25, Leaf 30
+ out.add(new ParaBoxChars("and")); // Node 26, Leaf 31
+ out.add(ParaGlueChars.SPACE); // Node 27, Leaf 32
+ out.add(new ParaBoxChars("some")); // Node 28, Leaf 33
+ out.add(ParaGlueChars.SPACE); // Node 29, Leaf 34
+ out.add(new ParaBoxChars("have")); // Node 30, Leaf 35
+ out.add(ParaGlueChars.SPACE); // Node 31, Leaf 36
+ out.add(nodeGreatness); // Node 32, Leaf 37 - 39
+ out.add(ParaGlueChars.SPACE); // Node 33, Leaf 40
+ out.add(new ParaBoxChars("thrust")); // Node 34, Leaf 41
+ out.add(ParaGlueChars.SPACE); // Node 35, Leaf 42
+ out.add(new ParaBoxChars("upon")); // Node 36, Leaf 43
+ out.add(ParaGlueChars.SPACE); // Node 37, Leaf 44
- /* 39 lines, each adding one node. */
+ /* Putting "them." in a branch is unnecessary, but we with to test a branch as the last node. */
+ final ParaBranch4a nodeThem = new ParaBranch4a(config);
+ nodeThem.add(new ParaBoxChars("t"));
+ nodeThem.add(new ParaBoxChars("h"));
+ nodeThem.add(new ParaBoxChars("e"));
+ nodeThem.add(new ParaBoxChars("m"));
+ nodeThem.add(new ParaBoxChars("."));
+ out.add(nodeThem); // Node 38, Leaf 45 - 49
+
+ /* Test the /node/ count. */
Assert.assertEquals(39, out.paraNodeSize());
/* Test the /nodes/ at each end, and one in the middle. */
- Assert.assertEquals("Be", out.paraNodeAt(0).asParaLeaf().getText());
- Assert.assertEquals("them.", out.paraNodeAt(38).asParaLeaf().getText());
- Assert.assertEquals("born", out.paraNodeAt(15).asParaLeaf().getText());
+ Assert.assertEquals("Be", out.paraNodeAt(0).getText());
+ Assert.assertEquals("them.", out.paraNodeAt(38).getText());
+ Assert.assertEquals("born", out.paraNodeAt(15).getText());
/* Most nodes are exactly one leaf. 3 lines each add an additional 2 leaves each, adding 6 leaves. */
- Assert.assertEquals(45, out.paraLeafSize());
+ Assert.assertEquals(50, out.paraLeafSize());
/* Test the /leaves/ at each end. */
- Assert.assertEquals("Be", out.paraLeafAt(0).getText());
- Assert.assertEquals("them.", out.paraLeafAt(44).getText());
+ Assert.assertEquals("B", out.paraLeafAt(0).getText());
+ Assert.assertEquals("e", out.paraLeafAt(1).getText());
+ Assert.assertEquals(" ", out.paraLeafAt(2).getText());
+ Assert.assertEquals("not", out.paraLeafAt(3).getText());
+ Assert.assertEquals("upon", out.paraLeafAt(43).getText());
+ Assert.assertEquals(" ", out.paraLeafAt(44).getText());
+ Assert.assertEquals("t", out.paraLeafAt(45).getText());
+ Assert.assertEquals("h", out.paraLeafAt(46).getText());
+ Assert.assertEquals("e", out.paraLeafAt(47).getText());
+ Assert.assertEquals("m", out.paraLeafAt(48).getText());
+ Assert.assertEquals(".", out.paraLeafAt(49).getText());
- /* Make sure the nested branches can find their child nodes properly. */
- Assert.assertEquals("great", out.paraLeafAt(8).getText());
- Assert.assertEquals("-", out.paraLeafAt(9).getText());
- Assert.assertEquals("ness", out.paraLeafAt(10).getText());
+ /* Make sure other nested branches can find their child nodes properly. */
+ Assert.assertEquals("great", out.paraLeafAt(9).getText());
+ Assert.assertEquals("-", out.paraLeafAt(10).getText());
+ Assert.assertEquals("ness", out.paraLeafAt(11).getText());
- Assert.assertEquals("great", out.paraLeafAt(36).getText());
- Assert.assertEquals("-", out.paraLeafAt(37).getText());
- Assert.assertEquals("ness", out.paraLeafAt(38).getText());
+ Assert.assertEquals("great", out.paraLeafAt(37).getText());
+ Assert.assertEquals("-", out.paraLeafAt(38).getText());
+ Assert.assertEquals("ness", out.paraLeafAt(39).getText());
+
+ /* Test some internal leaves. */
+ Assert.assertEquals("afraid", out.paraLeafAt(5).getText());
+ Assert.assertEquals("achieve", out.paraLeafAt(24).getText());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|