def test_now(self):
        ''' Testing Now Method'''
        a = CounterSim()

        t = a.now()

        self.assertEqual(0.0, t)
 def testEmpty_constructor(self):
     ''' Testing Constructor Method'''
     a = CounterSim()
     t = a.getset()
     time = a.now()
     self.assertEqual(0.0,time)
     self.assertEqual('[]',str(t))
    def test_now(self):
        ''' Testing Now Method'''
        a = CounterSim()

        t = a.now()

        self.assertEqual(0.0,t)
 def testEmpty_constructor(self):
     ''' Testing Constructor Method'''
     a = CounterSim()
     t = a.getset()
     time = a.now()
     self.assertEqual(0.0, time)
     self.assertEqual('[]', str(t))
 def test_Insert_Exception(self):
     ''' Testing insertion method for Exception'''
     try:
         a = CounterSim()
         a.insert(4)
         self.assertTrue(False,'no exception or/ no right type of excepttion raised')
     except TypeError:
         pass
 def test_DoallEvents_one_Bigger_than_10(self):
     a = CounterSim()
     a.setup(0)
     print('********************************************************')
     print('##TEST for one event (time is bigger than 10)')
     print('##Initial event: <Event: 20.0>')
     print('Pay attention here to check whether the simulation driver is doing the rihgt thing')
     a.doAllEvents()
 def test_DoallEvents_one_initial_envent(self):
     '''Testing DoallEventsMethod'''
     a = CounterSim()
     a.setup(0)
     print('********************************************************')
     print('##TEST for one event (time is less than 10)')
     print('##Initial Event: <Event: 0.0>')
     print('Pay attention here to check whether the simulation driver is doing the rihgt thing')
     a.doAllEvents()
 def test_Insert_Exception(self):
     ''' Testing insertion method for Exception'''
     try:
         a = CounterSim()
         a.insert(4)
         self.assertTrue(
             False, 'no exception or/ no right type of excepttion raised')
     except TypeError:
         pass
 def test_DoAllEvents_multiple_all_less_than_10(self):
     '''Testing DoallEventsMethod'''
     a = CounterSim()
     a.setup(0)
     a.setup(2.4)
     a.setup(5.4)
     a.setup(2)
     a.setup(3)
     print('********************************************************')
     print('##TEST for Multiple events_all (times of all less than time 10) ')
     print('##Initial events: <Event: 0.0> <Event: 2.0>  <Event: 2.4> <Event: 3.0> <Event: 5.4>')
     
     print('Pay attention here to check whether the simulation driver is doing the rihgt thing')
     a.doAllEvents()
    def test_DoAllEvents_multiple_all_less_than_10(self):
        '''Testing DoallEventsMethod'''
        a = CounterSim()
        a.setup(0)
        a.setup(2.4)
        a.setup(5.4)
        a.setup(2)
        a.setup(3)
        print('********************************************************')
        print(
            '##TEST for Multiple events_all (times of all less than time 10) ')
        print(
            '##Initial events: <Event: 0.0> <Event: 2.0>  <Event: 2.4> <Event: 3.0> <Event: 5.4>'
        )

        print(
            'Pay attention here to check whether the simulation driver is doing the rihgt thing'
        )
        a.doAllEvents()
    def test_SetUP(self):
        ''' Testing Setup method'''
        a = CounterSim()
        a.setup(3)
        a.setup(5)
        a.setup(1)

        self.assertEqual(str(a.getset()),
                         '[<Event: 1.0>*, <Event: 3.0>, <Event: 5.0>]')
    def test_SetUP(self):
        ''' Testing Setup method'''
        a = CounterSim()
        a.setup(3)
        a.setup(5)
        a.setup(1)

        self.assertEqual(str(a.getset()),'[<Event: 1.0>*, <Event: 3.0>, <Event: 5.0>]')
    def test_Insert(self):
        ''' Testing insertion method'''
        a = CounterEvent(4)
        a1 = CounterEvent(1)
        a2 = CounterEvent(0)

        b = CounterSim()
        b.insert(a)
        b.insert(a1)
        b.insert(a2)

        self.assertEqual(str(b.getset()),
                         '[<Event: 0.0>*, <Event: 1.0>, <Event: 4.0>]')
 def test_DoallEvents_one_Bigger_than_10(self):
     a = CounterSim()
     a.setup(0)
     print('********************************************************')
     print('##TEST for one event (time is bigger than 10)')
     print('##Initial event: <Event: 20.0>')
     print(
         'Pay attention here to check whether the simulation driver is doing the rihgt thing'
     )
     a.doAllEvents()
 def test_DoallEvents_one_initial_envent(self):
     '''Testing DoallEventsMethod'''
     a = CounterSim()
     a.setup(0)
     print('********************************************************')
     print('##TEST for one event (time is less than 10)')
     print('##Initial Event: <Event: 0.0>')
     print(
         'Pay attention here to check whether the simulation driver is doing the rihgt thing'
     )
     a.doAllEvents()
    def test_now_not_emp(self):
        ''' Testing Now Method when not start from initial value'''
        a = CounterSim()
        a.setup(4)
        print('********************************************************')
        print('********************************************************')
        print('********************************************************')

        print('********************************************************')
        print('********************************************************')
        print('Not A part of DoAllEvents TEST')
        a.doAllEvents()
        t = a.now()

        self.assertEqual(10.0, t)
    def test_Insert(self):
        ''' Testing insertion method'''
        a = CounterEvent(4)
        a1 = CounterEvent(1)
        a2 = CounterEvent(0)
        
        b = CounterSim()
        b.insert(a)
        b.insert(a1)
        b.insert(a2)

        self.assertEqual(str(b.getset()),'[<Event: 0.0>*, <Event: 1.0>, <Event: 4.0>]')
    def test_now_not_emp(self):
        ''' Testing Now Method when not start from initial value'''
        a = CounterSim()
        a.setup(4)
        print('********************************************************')
        print('********************************************************')
        print('********************************************************')
   
        print('********************************************************')
        print('********************************************************')
        print('Not A part of DoAllEvents TEST')
        a.doAllEvents()
        t = a.now()
        

        self.assertEqual(10.0,t)
Example #19
0
    def test_execute(self):

        #Case 1 event time at 0.0
        #------------------------------------------------------------------------------
        a = CounterSim()
        a.setup(1)
        b = CounterEvent(0)

        self.assertEqual(b.time(), 0.0)

        p = b.execute(a)

        #get the real list object
        l = a.getset().getset()

        #Check wether it has been rescheduled correclty
        self.assertEqual(b.time(), 2.0)
        #Check the thing it retunrs(It prints out)
        self.assertEqual('The event time is 0.0', p)
        #CHeck whether it has been reinserted  back to the events collection correctly after rescheduleing
        self.assertTrue(l[1] is b)

        #Case 2 event time at 2.0
        #------------------------------------------------------------------------------
        a = CounterSim()
        a.setup(1)
        a.setup(13)
        b = CounterEvent(2.0)

        self.assertEqual(b.time(), 2.0)

        p = b.execute(a)

        #get the real list object
        l = a.getset().getset()

        self.assertEqual(b.time(), 4.0)
        self.assertEqual('The event time is 2.0', p)
        self.assertTrue(l[1] is b)
        #Case 3 event time at 14.0 (So won't be reschedued and reinserted)
        #------------------------------------------------------------------------------
        a = CounterSim()
        a.setup(1)
        a.setup(13)
        b = CounterEvent(14.0)

        self.assertEqual(b.time(), 14.0)

        p = b.execute(a)

        #get the real list object
        l = a.getset().getset()

        self.assertEqual(b.time(), 14.0)
        self.assertEqual('The event time is 14.0', p)
        self.assertTrue(b not in l)
    def test_execute(self):

#Case 1 event time at 0.0
#------------------------------------------------------------------------------ 
        a = CounterSim()
        a.setup(1)
        b = CounterEvent(0)

        self.assertEqual(b.time(),0.0)


        p = b.execute(a)

        #get the real list object
        l = a.getset().getset()

        #Check wether it has been rescheduled correclty
        self.assertEqual(b.time(),2.0)
        #Check the thing it retunrs(It prints out)
        self.assertEqual('The event time is 0.0',p)
        #CHeck whether it has been reinserted  back to the events collection correctly after rescheduleing
        self.assertTrue(l[1] is b)

#Case 2 event time at 2.0
#------------------------------------------------------------------------------ 
        a = CounterSim()
        a.setup(1)
        a.setup(13)
        b = CounterEvent(2.0)

        self.assertEqual(b.time(),2.0)


        p = b.execute(a)

        #get the real list object
        l = a.getset().getset()

        self.assertEqual(b.time(),4.0) 
        self.assertEqual('The event time is 2.0',p)
        self.assertTrue(l[1] is b)        
#Case 3 event time at 14.0 (So won't be reschedued and reinserted)
#------------------------------------------------------------------------------
        a = CounterSim()
        a.setup(1)
        a.setup(13)
        b = CounterEvent(14.0)

        self.assertEqual(b.time(),14.0)


        p = b.execute(a)

        #get the real list object
        l = a.getset().getset()

        self.assertEqual(b.time(),14.0) 
        self.assertEqual('The event time is 14.0',p)
        self.assertTrue(b not in l)