def test_storage_visgroups(self): store = DNAStorage() vg = DNAVisGroup("my_vg") vg.addVisible("visible1") vg.addVisible("visible2") vg.addVisible("visible3") store.storeDNAVisGroup(vg) self.assertEqual(store.getNumDNAVisGroups(), 1) self.assertEqual(store.getNumDNAVisGroupsAI(), 1) self.assertEqual(store.getDNAVisGroupAI(0), vg) self.assertEqual(store.getDNAVisGroupName(0), vg.getName()) num_visibles = store.getNumVisiblesInDNAVisGroup(0) self.assertEqual(num_visibles, 3) for i in xrange(num_visibles): self.assertEqual(store.getVisibleName(0, i), "visible%d" % (i + 1)) vg.removeVisible("visible2") self.assertEqual(store.getNumVisiblesInDNAVisGroup(0), 2) self.assertEqual(store.getVisibleName(0, 0), "visible1") self.assertEqual(store.getVisibleName(0, 1), "visible3") store.resetDNAVisGroups() self.assertEqual(store.getNumDNAVisGroups(), 0) self.assertEqual(store.getNumDNAVisGroupsAI(), 0)
def test_group(self): group1 = DNAGroup('groupA') group2 = DNAGroup('group2') group3 = DNAGroup('group3') self.assertEqual(group1.getName(), 'groupA') group1.setName('group1') self.assertEqual(group1.getName(), 'group1') self.assertEqual(group1.getNumChildren(), 0) group1.add(group2) self.assertEqual(group1.getNumChildren(), 1) self.assertEqual(group1.at(0), group2) visgroup = DNAVisGroup('vg') self.assertEqual(group1.getVisGroup(), None) group1.setVisGroup(visgroup) self.assertEqual(group1.getVisGroup(), visgroup) self.assertEqual(group1.getParent(), None) group1.setParent(group3) self.assertEqual(group1.getParent(), group3) group1.clearParent() self.assertEqual(group1.getParent(), None) self.assertEqual(group1.getVisGroup(), None) # Now let's test if interrogates casts the object types correctly # For this we use a DNAFlatDoor, but anything inheriting from DNAGroup # must do flatdoor = DNAFlatDoor('flatdoor') # 1. Visgroup group1.setVisGroup(flatdoor) self.assertEqual(group1.getVisGroup(), flatdoor) # 2. At group1.add(flatdoor) self.assertEqual(group1.at(1), flatdoor) # N.B. at(0) is the DNAGroup we added above
def test_vis_group(self): visgroup = DNAVisGroup('vg') # Test visibles self.assertEqual(visgroup.getNumVisibles(), 0) visgroup.addVisible('test1') visgroup.addVisible('test2') visgroup.addVisible('test3') self.assertEqual(visgroup.getNumVisibles(), 3) for i in xrange(1, 4): self.assertEqual(visgroup.getVisible(i - 1), 'test%d' % i) self.assertTrue(visgroup.removeVisible('test1')) self.assertTrue(visgroup.removeVisible('test2')) # Removing a visible which doesn't exist must return False self.assertFalse(visgroup.removeVisible('bad')) self.assertEqual(visgroup.getNumVisibles(), 1) self.assertEqual(visgroup.getVisible(0), 'test3') # Test suit edges edge1 = DNASuitEdge(DNASuitPoint(1, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)), DNASuitPoint(2, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)), 1000) edge2 = DNASuitEdge(DNASuitPoint(1, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)), DNASuitPoint(2, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)), 1000) edge3 = DNASuitEdge(DNASuitPoint(1, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)), DNASuitPoint(2, DNASuitPoint.STREET_POINT, Point3(0, 0, 0)), 1000) self.assertEqual(visgroup.getNumSuitEdges(), 0) visgroup.addSuitEdge(edge1) visgroup.addSuitEdge(edge2) self.assertEqual(visgroup.getNumSuitEdges(), 2) self.assertEqual(visgroup.getSuitEdge(0), edge1) self.assertEqual(visgroup.getSuitEdge(1), edge2) self.assertTrue(visgroup.removeSuitEdge(edge1)) self.assertEqual(visgroup.getNumSuitEdges(), 1) self.assertEqual(visgroup.getSuitEdge(0), edge2) # Removing an edge which doesn't exist must return False self.assertFalse(visgroup.removeSuitEdge(edge3)) # Test battle cells cell1 = DNABattleCell(20, 20, Point3(0, 0, 0)) cell2 = DNABattleCell(20, 20, Point3(0, 0, 0)) cell3 = DNABattleCell(20, 20, Point3(0, 0, 0)) self.assertEqual(visgroup.getNumBattleCells(), 0) visgroup.addBattleCell(cell1) visgroup.addBattleCell(cell2) self.assertEqual(visgroup.getNumBattleCells(), 2) self.assertEqual(visgroup.getBattleCell(0), cell1) self.assertEqual(visgroup.getBattleCell(1), cell2) self.assertTrue(visgroup.removeBattleCell(cell1)) self.assertEqual(visgroup.getNumBattleCells(), 1) self.assertEqual(visgroup.getBattleCell(0), cell2) # Removing a battle cell which doesn't exist must return False self.assertFalse(visgroup.removeBattleCell(cell3))