示例#1
0
 def test_run_empty_no_end_time(self):
     simulator.ready()
     self.assertEqual(simulator.now(), 0)
     self.assertFalse(simulator.is_finished())
     simulator.run()
     self.assertEqual(simulator.now(), 0)
     self.assertTrue(simulator.is_finished())
     simulator.reset()
示例#2
0
        def z():
            self.test_end_in_same_event_counter += 5

            self.assertFalse(simulator.is_init())
            self.assertFalse(simulator.is_ready())
            self.assertTrue(simulator.is_running())
            self.assertFalse(simulator.is_finished())

            simulator.end()  # End after this event has been executed

            self.assertFalse(simulator.is_init())
            self.assertFalse(simulator.is_ready())
            self.assertTrue(simulator.is_running())
            self.assertFalse(simulator.is_finished())
示例#3
0
    def test_end_in_event(self):

        self.test_end_in_event_counter = 22

        def x(val):
            self.test_end_in_event_counter += val

        def y():
            simulator.end(5)

        simulator.ready()
        simulator.schedule(60, x, 22)
        simulator.schedule(70, y)
        simulator.schedule(70, x, 3)
        simulator.schedule(71, y)
        simulator.schedule(74, x, 5)
        simulator.schedule(75, x, 22)
        simulator.schedule(76, x, 22)
        simulator.schedule(888, x, 22)
        simulator.schedule(999, x, 22)
        simulator.schedule(8953, x, 22)
        simulator.end(1000)
        simulator.run()
        self.assertEqual(self.test_end_in_event_counter, 22 + 22 + 3 + 5)
        self.assertEqual(simulator.now(), 75)
        self.assertTrue(simulator.is_finished())
        self.assertEqual(simulator.event_heap_size(), 5)
        simulator.reset()
示例#4
0
    def test_end_in_same_event(self):

        self.test_end_in_same_event_counter = 0

        def x():
            self.test_end_in_same_event_counter += 100

        def y():
            self.test_end_in_same_event_counter += 3

        def z():
            self.test_end_in_same_event_counter += 5

            self.assertFalse(simulator.is_init())
            self.assertFalse(simulator.is_ready())
            self.assertTrue(simulator.is_running())
            self.assertFalse(simulator.is_finished())

            simulator.end()  # End after this event has been executed

            self.assertFalse(simulator.is_init())
            self.assertFalse(simulator.is_ready())
            self.assertTrue(simulator.is_running())
            self.assertFalse(simulator.is_finished())

        simulator.ready()
        simulator.schedule_with_priority(70, 5, x)
        simulator.schedule_with_priority(70, 5, x)
        simulator.schedule_with_priority(70, 20, y)
        simulator.schedule_with_priority(70, 10, z)
        simulator.run()
        self.assertEqual(self.test_end_in_same_event_counter, 100 + 100 + 5)
        self.assertEqual(simulator.now(), 70)
        self.assertTrue(simulator.is_finished())
        self.assertEqual(simulator.event_heap_size(), 1)
        simulator.reset()
        self.assertTrue(simulator.is_init())
        self.assertFalse(simulator.is_ready())
        self.assertFalse(simulator.is_running())
        self.assertFalse(simulator.is_finished())
        self.assertEqual(simulator.now(), 0)
        self.assertEqual(simulator.event_heap_size(), 0)
示例#5
0
    def test_stage_transitions(self):

        self.assertTrue(simulator.is_init())
        self.assertFalse(simulator.is_ready())
        self.assertFalse(simulator.is_running())
        self.assertFalse(simulator.is_finished())

        simulator.ready()

        self.assertFalse(simulator.is_init())
        self.assertTrue(simulator.is_ready())
        self.assertFalse(simulator.is_running())
        self.assertFalse(simulator.is_finished())

        def check_running():
            self.assertFalse(simulator.is_init())
            self.assertFalse(simulator.is_ready())
            self.assertTrue(simulator.is_running())
            self.assertFalse(simulator.is_finished())
            self.assertEqual(simulator.now(), 0)

        simulator.schedule(0, check_running)
        simulator.end(100000)
        simulator.run()
        self.assertEqual(simulator.now(), 100000)

        self.assertFalse(simulator.is_init())
        self.assertFalse(simulator.is_ready())
        self.assertFalse(simulator.is_running())
        self.assertTrue(simulator.is_finished())

        simulator.reset()

        self.assertTrue(simulator.is_init())
        self.assertFalse(simulator.is_ready())
        self.assertFalse(simulator.is_running())
        self.assertFalse(simulator.is_finished())
示例#6
0
    def test_end_one(self):

        self.test_end_one_counter = 0

        def x(val):
            self.test_end_one_counter += val

        simulator.ready()
        simulator.schedule(10, x, 57)
        simulator.end(100)
        simulator.run()
        self.assertEqual(self.test_end_one_counter, 57)
        self.assertEqual(simulator.now(), 100)
        self.assertTrue(simulator.is_finished())
        simulator.reset()
示例#7
0
    def test_end_override(self):

        self.test_end_two_override_counter = 22

        def x(val):
            self.test_end_two_override_counter += val

        simulator.ready()
        simulator.schedule(57, x, 67)
        simulator.end(100)
        simulator.end(57)
        simulator.end(100)
        simulator.run()
        self.assertEqual(self.test_end_two_override_counter, 22)
        self.assertEqual(simulator.now(), 57)
        self.assertTrue(simulator.is_finished())
        simulator.reset()
示例#8
0
    def test_normal_not(self):

        self.test_normal_counter = 0

        def x(val):
            self.test_normal_counter -= val

        simulator.ready()
        simulator.schedule(100, x, 57)
        simulator.schedule(153, x, 245)
        simulator.schedule(199, x, 88)
        simulator.end(156)
        simulator.run()
        self.assertEqual(self.test_normal_counter, - 57 - 245)
        self.assertEqual(simulator.now(), 156)
        self.assertTrue(simulator.is_finished())
        self.assertEqual(simulator.event_heap_size(), 1)
        simulator.reset()
        self.assertEqual(simulator.event_heap_size(), 0)
示例#9
0
    def test_normal_just(self):

        self.test_normal_counter = 0

        def x(val):
            self.test_normal_counter += val

        simulator.ready()
        simulator.schedule(100, x, 57)
        simulator.schedule(100, x, 473)
        simulator.schedule(199, x, 88)
        simulator.end(200)
        simulator.run()
        self.assertEqual(self.test_normal_counter, 57 + 473 + 88)
        self.assertEqual(simulator.now(), 200)
        self.assertTrue(simulator.is_finished())
        self.assertEqual(simulator.event_heap_size(), 0)
        simulator.reset()
        self.assertEqual(simulator.event_heap_size(), 0)
示例#10
0
 def check_running():
     self.assertFalse(simulator.is_init())
     self.assertFalse(simulator.is_ready())
     self.assertTrue(simulator.is_running())
     self.assertFalse(simulator.is_finished())
     self.assertEqual(simulator.now(), 0)