def test_group_insertion_deeper(self): """Make sure deeper features of the logic get copied.""" arena = PSArena(magnitudes=(7, 8)) gp = PSObjectFromStructure((7, 8)) logic = gp.DescribeAs(BasicSuccessorCategory()) CategoryEvenInteger().TurnOnAttribute('half') gp.items[1].DescribeAs(CategoryEvenInteger()).Attributes()[ 'half'].DescribeAs(CategoryEvenInteger()) inner_logic = logic.Attributes()['end'].DescribeAs( CategoryEvenInteger()) self.assertEqual(4, inner_logic.Attributes()['half'].magnitude) inner_logic.Attributes()['half'].DescribeAs(CategoryEvenInteger()) CategoryEvenInteger().TurnOffAttribute('half') gp.SetSpanStart(0) merged = arena.MergeObject(gp) self.assertEqual((7, 8), merged.Structure()) self.assertEqual(arena.element[1], merged.items[1]) self.assertTrue(arena.element[1].IsKnownAsInstanceOf( CategoryEvenInteger())) logic = arena.element[1].categories[CategoryEvenInteger()] self.assertTrue(logic.Attributes()[ 'half'].IsKnownAsInstanceOf(CategoryEvenInteger())) self.assertTrue(merged.DescribeAs(BasicSuccessorCategory()).Attributes()[ 'end'].IsKnownAsInstanceOf(CategoryEvenInteger()))
def test_group_insertion(self): arena = PSArena(magnitudes=range(10)) # Create a group with structure ((5, 6), (7, 8)), and add it to arena. gp_56_78 = PSObjectFromStructure(((5, 6), (7, 8))) gp_56_78.items[0].items[0].DescribeAs(CategoryPrime()) self.assertFalse(arena.element[5].IsKnownAsInstanceOf(CategoryPrime())) # Cannot insert this without spans added... we won't know where it # should go. self.assertRaises(CannotInsertGroupWithoutSpans, arena.MergeObject, gp_56_78) self.assertFalse(arena.GetObjectsWithSpan((5, 8))) gp_56_78.SetSpanStart(5) inserted_gp = arena.MergeObject(gp_56_78) self.assertEqual((5, 8), inserted_gp.Span()) self.assertEqual(arena.element[5], inserted_gp.items[0].items[0]) self.assertEqual(arena.element[8], inserted_gp.items[1].items[1]) self.assertEqual(inserted_gp, arena.GetObjectsWithSpan( (5, 8))[((5, 6), (7, 8))]) self.assertEqual(inserted_gp.items[ 0], arena.GetObjectsWithSpan((5, 6))[(5, 6)]) self.assertEqual(inserted_gp.items[ 1], arena.GetObjectsWithSpan((7, 8))[(7, 8)]) self.assertTrue(arena.element[5].IsKnownAsInstanceOf(CategoryPrime())) gp_10_11 = PSObjectFromStructure((10, 11)) gp_10_11.SetSpanStart(2) self.assertRaises(UnmergableObjectException, arena.MergeObject, gp_10_11) gp_11_12 = PSObjectFromStructure((11, 12)) gp_11_12.SetSpanStart(11) self.assertRaises(ElementWayBeyondKnownSoughtException, arena.MergeObject, gp_11_12) gp_9_10_11 = PSObjectFromStructure((9, (10, 11))) gp_9_10_11.SetSpanStart(9) arena.MergeObject(gp_9_10_11) self.assertEqual(12, arena.Size())
def test_arena_merge(self): class SameStructureReln(PSCategory): _Checks = ( '_INSTANCE.first.Structure() == _INSTANCE.second.Structure()', ) gp = PSObjectFromStructure((5, 5)) r = gp.items[0].GetRelationTo(gp.items[1]) self.assertTrue(r.DescribeAs(SameStructureReln())) gp.SetSpanStart(0) a = PSArena(magnitudes=(5, 5, 5)) r2 = gp.items[1].GetRelationTo(a.element[2]) self.assertTrue(r2.DescribeAs(SameStructureReln())) self.assertFalse(a.element[0].GetRelationTo( a.element[1]).IsKnownAsInstanceOf(SameStructureReln())) self.assertFalse(a.element[1].GetRelationTo( a.element[2]).IsKnownAsInstanceOf(SameStructureReln())) a.MergeObject(gp) self.assertTrue(a.element[0].GetRelationTo( a.element[1]).IsKnownAsInstanceOf(SameStructureReln())) self.assertTrue(a.element[1].GetRelationTo( a.element[2]).IsKnownAsInstanceOf(SameStructureReln()))