class TestSendJob(unittest.TestCase): def setUp(self): """ initial setup for SendJob class. """ self.nodelist = [(Node(1, 0.2, 'decentralized', 'sources','n')),\ (Node(3, 0.2, 'decentralized', 'sources', 'n'))] self.msg = Message(1, 3, 'data') self.job = SendJob(self.nodelist) def testSend(self): """ it just runs the send method. """ self.job.send(self.msg, self.msg.recipient) def testIdentifyNode(self): """ tests identifyNode method for an existing name. """ self.name = self.job.identifyNode(self.msg.recipient) self.assertTrue(self.name) def testBadIdentifyNode(self): """ tests identifyNode method for a bad (non-existent) name.""" self.name = self.job.identifyNode('dummy_name') self.assertFalse(self.name) def testTravelingTime(self): """ tests the randomness of traveling time.""" self.coll = [] for i in range(100): self.coll.append(self.job.travelingTime()) # now put the list to a set and check if any values are double # a valuable source for using set as is exhibited, is here: # http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order self.assertEqual(len(set(self.coll)), len(self.coll))
def setUp(self): """ initial setup for SendJob class. """ self.nodelist = [(Node(1, 0.2, 'decentralized', 'sources','n')),\ (Node(3, 0.2, 'decentralized', 'sources', 'n'))] self.msg = Message(1, 3, 'data') self.job = SendJob(self.nodelist)