Пример #1
0
import argparse

from round_robin import RoundRobin


def describe(db: RoundRobin):
    print(db.c)


parser = argparse.ArgumentParser(
    "Utility used to print the content of a Round-Robin Database.")

parser.add_argument("-f",
                    "--file",
                    help="The path of the Round-Robin database.",
                    type=str,
                    nargs=1)

args = parser.parse_args()

if args.file:
    output_file = args.file[0]
else:
    output_file = 'du.db'  # In the current directory

if __name__ == "__main__":
    rrdb = RoundRobin.read_from_disk(output_file)
    describe(rrdb)
 def setUp(self):
     self.schedule = RoundRobin(2)
Пример #3
0
px_stars2_texture = sf.Texture.from_file('asset/stars_bg/spr_stars021.png')
ship_on_texture = sf.Texture.from_file('asset/ship_on.png')
ship_off_texture = sf.Texture.from_file('asset/ship_off.png')
ufo_texture = sf.Texture.from_file('asset/ufo.png')
shell_texture = sf.Texture.from_file('asset/shell.png')
## -----

background = ParallaxeBackground([
  nebula_texture,
  px_stars1_texture,
  px_stars2_texture
], RES_WIDTH)

window = sf.RenderWindow(sf.VideoMode(RES_WIDTH, RES_HEIGHT), WINDOW_NAME)

frames_time = RoundRobin(FRAME_POOL_SIZE, init=0)

objects = []

bars = []
bar_width = RES_WIDTH / FRAME_POOL_SIZE
y_base_pos = RES_HEIGHT
for i in range(FRAME_POOL_SIZE):
  bar = sf.RectangleShape((bar_width, 2))
  bar.fill_color = sf.Color(255, 0, 0, 127)
  bar.position = (i * bar_width, 0)
  bars.append(bar)

clock = sf.Clock()

player = Player(ship_off_texture)
class RoundRobinTestCase(unittest.TestCase):
    def setUp(self):
        self.schedule = RoundRobin(2)

    def test_round_robin_objects_should_be_created(self):
        self.assertTrue(self.schedule)

    def test_should_have_quantum(self):
        self.assertEqual(self.schedule.quantum, 2)

    def test_add_process_on_round_robin_list(self):
        process = Process(20)
        self.schedule.add_process(process)
        self.assertTrue(process in self.schedule.list_process)

    def test_run_process_should_reduce_one_task_of_process(self):
        process = Process(20)
        self.schedule.add_process(process)
        self.schedule.run_process()
        self.assertEqual(18, process.task)

    def test_on_run_all_tasks_of_process_should_remove_process_from_list(self):
        process = Process(1)
        self.schedule.add_process(process)
        self.schedule.run_process()
        self.assertTrue(process not in self.schedule.list_process)

    def test_run_all_tests_should_clean(self):
        for i in range(8):
            self.schedule.add_process(Process(random.randint(1, 20)))

        self.schedule.run()
        self.assertEqual([], self.schedule.list_process)