diff --git a/simplTests/test/simpl/interpretation/UnderstandingCompositesTest.java b/simplTests/test/simpl/interpretation/UnderstandingCompositesTest.java index 28f44d65..a176b3d6 100644 --- a/simplTests/test/simpl/interpretation/UnderstandingCompositesTest.java +++ b/simplTests/test/simpl/interpretation/UnderstandingCompositesTest.java @@ -231,11 +231,11 @@ public void testUnderstandingWorksWithNestedComposites() throws SIMPLTranslation plainComposite pc = new plainComposite(); pc.myComposite = orig; - pc.myString = "string"; + pc.myString = "plain_string"; OuterComposite oc = new OuterComposite(); oc.ReferencedComp = pc; - oc.myString = "string"; + oc.myString = "outer_string"; //Building Interpretations: @@ -243,7 +243,7 @@ public void testUnderstandingWorksWithNestedComposites() throws SIMPLTranslation CompositeInterpretation rootObject = new CompositeInterpretation("outer_composite"); List outerInterps = new LinkedList(); - outerInterps.add(new ScalarInterpretation("myString", "string", "StringType")); + outerInterps.add(new ScalarInterpretation("myString", "outer_string", "StringType")); CompositeInterpretation ci_pc = new CompositeInterpretation("plain_composite"); ci_pc.setFieldName("ReferencedComp"); @@ -261,7 +261,7 @@ public void testUnderstandingWorksWithNestedComposites() throws SIMPLTranslation { ci_ms.addInterpretation(si); } - ci_pc.addInterpretation(new ScalarInterpretation("myString", "string", "StringType")); + ci_pc.addInterpretation(new ScalarInterpretation("myString", "plain_string", "StringType")); ci_pc.addInterpretation(ci_ms); outerInterps.add(ci_pc); @@ -275,13 +275,16 @@ public void testUnderstandingWorksWithNestedComposites() throws SIMPLTranslation OuterComposite r = ((OuterComposite)result); - assertEquals("OuterComposite.myString is incorrect", r.myString, oc.myString); - assertNotNull("ReferencedComp should not be null", r.ReferencedComp); - assertEquals("plainComposite.myString is incorrect", r.ReferencedComp.myString, pc.myString); - assertNotNull("MyScalar should not be null", r.ReferencedComp.myComposite); - assertEquals("MyScalar contains incorrect string", r.ReferencedComp.myComposite.aField, orig.aField); - assertEquals("MyScalar contains incorrect int", r.ReferencedComp.myComposite.aDouble, orig.aDouble); - assertEquals("MyScalar contains incorrect double", r.ReferencedComp.myComposite.aInteger, orig.aInteger); + + assertEquals("Outer result string does not match the original object string~", r.myString, oc.myString); + assertNotNull("The outer composite does not correctly reference its child~", r.ReferencedComp); + + assertEquals("The generated child's string does not match the original child's string~", r.ReferencedComp.myString, pc.myString); + assertNotNull("The child object does not correclty reference the grandchild~", r.ReferencedComp.myComposite); + + assertEquals("String in generated MyScalar (grandchild) does not match the original's~", r.ReferencedComp.myComposite.aField, orig.aField); + assertEquals("Double in generated MyScalar (grandchild) does not match the original's~", r.ReferencedComp.myComposite.aDouble, orig.aDouble); + assertEquals("Integer in generated MyScalar (grandchild) does not match the original's~", r.ReferencedComp.myComposite.aInteger, orig.aInteger); } @Test @@ -292,6 +295,7 @@ public void testUnderstandingOfSelfReference() throws SIMPLTranslationException A.myString = "Astring"; A.right = A; + CompositeInterpretation rootObject = new CompositeInterpretation("hard_composite_node"); rootObject.setIDString("1"); rootObject.addInterpretation(new ScalarInterpretation("myString", "Astring", "StringType")); @@ -311,11 +315,16 @@ public void testUnderstandingOfSelfReference() throws SIMPLTranslationException Object result = su.understandInterpretation(rootObject); hardCompositeNode r = ((hardCompositeNode)result); - assertEquals("myString is incorrect", r.myString, A.myString); - + ObjectIdentity IDofR = new ObjectIdentity(r); + ObjectIdentity IDofChild = new ObjectIdentity(r.right); + + assertNotNull("Generated Object should not be NULL", r); + assertEquals("String of generated object does not match the original~", r.myString, A.myString); assertNotNull("right should not be null!", r.right); - assertTrue("r.right should be the same object as r", r.right==r); - assertNull("left is not null, and should be", r.left); + assertTrue("r's child should be the same object as r~", r.right==r); + assertEquals("The child's string should be equal to that of the parent~", r.right.myString, r.myString); + assertNull("The optional second child is not NULL, and should be~", r.left); + assertTrue(IDofR.equals(IDofChild)); } @Test @@ -331,6 +340,8 @@ public void testUnderstandingOfMutualReference() throws SIMPLTranslationExceptio A.right = B; B.right = A; + + //Build interpretation CompositeInterpretation rootObject = new CompositeInterpretation("hard_composite_node"); // we'll treat A as the root node. rootObject.addInterpretation(new ScalarInterpretation("myString", "Astring", "StringType")); rootObject.setIDString("1"); @@ -353,12 +364,27 @@ public void testUnderstandingOfMutualReference() throws SIMPLTranslationExceptio Object result = su.understandInterpretation(rootObject); hardCompositeNode r = ((hardCompositeNode)result); //r should equal - assertEquals("myString of A does not match that of r", A.myString, r.myString); - assertEquals("myString of B does not match that of r's child", B.myString, r.right.myString); - assertEquals("myString of A does not match that of r's grandchild", A.myString, r.right.right.myString); - assertNull("A's left is not null, and should be", A.left); - assertNull("B's left is not null, and should be", B.left); + assertNotNull("Resulting object is null~",r); + assertNotNull("Resulting object's child is null~",r.right); + assertNotNull("Resulting object's child's reference to the original object is null~",r.right.right); + assertNotNull("Resulting object's grandchild is not itself",r.right.right.right); + + ObjectIdentity IDofR = new ObjectIdentity(r); + ObjectIdentity IDofChild = new ObjectIdentity(r.right); + ObjectIdentity IDofGrandchild = new ObjectIdentity(r.right.right); + ObjectIdentity IDofGreatgrandchild = new ObjectIdentity(r.right.right.right); + assertNull("A's left is not null, and should be~", A.left); + assertNull("B's left is not null, and should be~", B.left); + assertNull("Generated Object's left is not null, and should be~", r.left); + assertNull("Generated Child's left is not null, and should be~", r.right.left); + + assertEquals("myString of A does not match that of r~", A.myString, r.myString); + assertEquals("myString of B does not match that of r's child~", B.myString, r.right.myString); + assertEquals("myString of A does not match that of r's grandchild~", A.myString, r.right.right.myString); + + assertTrue("ID of generated object does not match that of it's grandchild~", IDofR.equals(IDofGrandchild)); + assertTrue("ID of generated object's child does not match that of it's greatgrandchild~", IDofChild.equals(IDofGreatgrandchild)); //Two composites reference each other. Cycle of 2 } @@ -406,6 +432,14 @@ public void testUnderstandingOfDirectedLoop() throws SIMPLTranslationException Object result = su.understandInterpretation(rootObject); hardCompositeNode r = ((hardCompositeNode)result); //r should equal + assertNotNull("Resulting object is null~", r); + assertNotNull("Resulting object's reference to child is null~",r.right); + assertNotNull("Resulting object's child's reference to grandchild is null~", r.right.right); + assertNotNull("Resulting object's grandchild's reference to the original object is null", r.right.right.right); + + ObjectIdentity IDofR = new ObjectIdentity(r); + ObjectIdentity IDofRggc = new ObjectIdentity(r.right.right.right); + assertEquals("myString of A does not match that of r", A.myString, r.myString); assertEquals("myString of B does not match that of r's child", B.myString, r.right.myString); assertEquals("myString of C does not match that of r's grandchild", C.myString, r.right.right.myString); @@ -413,6 +447,7 @@ public void testUnderstandingOfDirectedLoop() throws SIMPLTranslationException assertNull("left of A should be null", A.left); assertNull("left of B should be null", B.left); assertNull("left of C should be null", C.left); + assertTrue("resulting object does not match its great grandchild~",IDofR.equals(IDofRggc)); //Two composites reference each other. Cycle of 2 } @@ -468,13 +503,28 @@ public void testUnderstandingOfSpecialCase() throws SIMPLTranslationException // Object result = su.understandInterpretation(rootObject); hardCompositeNode r = ((hardCompositeNode)result); //r should equal - + + assertNotNull("Resulting object is null!",r); + assertNotNull("Resulting object's child is null~", r.right); + assertNotNull("Resulting object's child's right child is null~", r.right.right); + assertNotNull("Resulting object's child's left child is null~", r.right.left); + assertNotNull("Resulting object's unique grandchild's reference to the original node is null~", r.right.right.right); + + assertNull("Resulting object's left child is not null, and should be", r.left); + assertNull("Resulting object's grandchild's unused reference is not null", r.right.right.left); + + ObjectIdentity IDofR = new ObjectIdentity(r); + ObjectIdentity IDofRc = new ObjectIdentity(r.right); + ObjectIdentity IDofR2 = new ObjectIdentity(r.right.left); + assertEquals("myString of A does not match that of r", A.myString, r.myString); assertEquals("myString of B does not match that of r's child", B.myString, r.right.myString); assertEquals("myString of C does not match that of r's grandchild", C.myString, r.right.right.myString); assertEquals("myString of A does not match that of r's greatgrandchild", A.myString, r.right.right.right.myString); assertNull("Left of A should be Null", A.left); assertNull("Left of C should be Null", C.left); + + assertTrue("Resulting object does not match it's child's reference to it~",IDofR.equals(IDofR2)); //Three composites, A refers to b, b refers to c, c refers to b. B is both the child and great grandchild of A. B is its own grandchild } }