示例#1
0
 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())
示例#2
0
 def test_creatingNewNodeAndGetKey(self):
     """
     Test that we can create a new NodeData. and get it's key (in the beginning should be 0).
     """
     # creating a new node
     newNode = NodeData()
     print("key of node is", newNode.getKey())
     self.assertEqual(0, newNode.getKey())
示例#3
0
 def dfs(self, node: NodeData) -> list:
     list = [node.getKey()]
     node.setInfo(
         'w')  # 'x' is not yes start, 'w' is processing, and 'v' is done
     self.time += 1  ## reize time of finding
     for e in self.graphAlgo.all_out_edges_of_node(
             node.getKey()).items():  # e id edge(other node id, weight)
         n = self.graphAlgo.get_all_v()[e[0]]
         if n.getInfo() == 'x':
             list += self.dfs(n)
     self.time += 1  ## reize time of finding
     self.lastTime.insert(len(self.lastTime), (self.time, node.getKey()))
     node.setInfo('v')
     return list
示例#4
0
 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())
 def test_get_key(self):
     n1 = NodeData(0, (1, 2, 3))
     n2 = NodeData(1)
     assert 0 == n1.getKey(), "n1 key is 0"
     assert 1 == n2.getKey(), "n2 key is 1"
     assert n1.__str__() == "{key: 0, pos: (1, 2, 3)}"