def test_setAndGetKeysAndInfosAndCopyNodeData(self): """ Test that we can create Node Datas, set and get their infos, and get their keys(in the beginning should be 0). Then, to CHANGE their keys and infos, and get them changed: *create Node Datas *get their keys *set and get their infos *set (change) and get their keys *set (change) and get their infos """ # creating a new node node1 = NodeData() node2 = NodeData() node1.setInfo("first") node2.setInfo("second") print("key of node1 is", node1.getKey()) self.assertEqual(0, node1.getKey()) print("key of node2 is", node2.getKey()) self.assertEqual(1, node2.getKey()) print("info of node1 is", node1.getInfo()) self.assertEqual("first", node1.getInfo()) print("key of node2 is", node2.getInfo()) self.assertEqual("second", node2.getInfo()) print("set the info of node1 to be change1", node1.setInfo("change1")) self.assertEqual("change1", node1.getInfo()) print("change the key of node2 to be 3", node2.setkey(3)) self.assertEqual(3, node2.getKey()) print("copying node1 to copyNode") copyNode = NodeData() copyNode.copyNodeData(node1) print("key of node1 is", node1.getInfo()) print("info of node1 is", node1.getInfo()) print("key of copyNode is", copyNode.getInfo()) print("info of copyNode is", copyNode.getInfo())
def testCopyNodeData(self): """ Tests copy constructor. takes a NodeData named n and copies it into this self NodeData. @return """ node1 = NodeData() print("copying node1 to copyNode") copyNode = NodeData() node1.setInfo("first") copyNode.setInfo("second") print("key of node1 is", node1.getKey()) self.assertEqual(0, node1.getKey()) print("key of copyNode is", copyNode.getKey()) self.assertNotEqual(copyNode.getKey(), node1.getKey()) copyNode.copyNodeData(node1) self.assertEqual(copyNode.getKey(), node1.getKey()) self.assertEqual(copyNode.getInfo(), node1.getInfo()) print("key of node1 is", node1.getInfo()) print("info of node1 is", node1.getInfo()) print("key of copyNode is", copyNode.getInfo()) print("info of copyNode is", copyNode.getInfo())