def setUp(self): #Create empty self.node1 = Node(None) self.node2 = Node("") self.node3 = Node("spark") self.node4 = Node("storm")
class TestNode(unittest.TestCase): #Runs before each test case def setUp(self): #Create empty self.node1 = Node(None) self.node2 = Node("") self.node3 = Node("spark") self.node4 = Node("storm") def tearDown(self): del self.node1 del self.node2 del self.node3 del self.node4 def test_constructor_state(self): #Checks if node has its hashtag correct assigned self.assertEqual(self.node1.get_hashtag(),None) self.assertEqual(self.node2.get_hashtag(),"") self.assertEqual(self.node3.get_hashtag(),"spark") #Checks if node has degree equals to zero self.assertEqual(self.node1.get_degree(),0) self.assertEqual(self.node2.get_degree(),0) self.assertEqual(self.node3.get_degree(),0) #Check if length adjacent list equals to zero self.assertEqual(len(self.node1.get_adjacency_structure()),0) self.assertEqual(len(self.node2.get_adjacency_structure()),0) self.assertEqual(len(self.node3.get_adjacency_structure()),0) print "Check state of the attributes in the Node class constructor [OK]" def test_add_neighbor_execute_correctly(self): epoch = Graph.convert_timestamp_to_epoch("Thu Oct 29 17:51:01 +0000 2015") self.node3.add_neighbor(self.node4.get_hashtag(),epoch) #Check if a node 3 is neighbor of node 4 self.assertIn(self.node4.get_hashtag(),self.node3.get_adjacency_structure()) #Check if list adjacent of node 3 has correct timestamp self.assertIn(epoch,self.node3.get_adjacency_structure()[self.node4.get_hashtag()]) print "Check if add_neighbor function is executing correctly [OK]" def test_add_neighbor_add_wrong_timestamp(self): #Check timestamp wrong format with self.assertRaises(ValueError) as context: self.node4.add_neighbor(self.node3.get_hashtag(),"this is a test") msg = "Timestamp must be a float number (epoch time)" self.assertTrue(msg in context.exception) print "Check if add_neighbor function does not execute with wrong timestamp type [OK]"