def test_river_object(): x = 100 y = 100 width = 200 speed = 10 r_obj1 = RiverObject(x, y,width,Direction.RIGHT,speed) assert(r_obj1.get_position() == (x, y)) assert(r_obj1.get_width() == width) r_obj1.move() assert(r_obj1.get_position() == (x+speed, y)) r_obj2 = RiverObject(x, y,width,Direction.LEFT,speed) r_obj2.move() assert(r_obj2.get_position() == (x-speed, y)) # check the object wraps from left to right properly x1 = -CANVAS_WIDTH//2 + 1.5 * speed r_obj4 = RiverObject(x1, y,width,Direction.LEFT,speed) assert(r_obj4.get_position() == (x1, y)) r_obj4.move() assert(r_obj4.get_position() == (x1-speed, y)) r_obj4.move() assert(r_obj4.get_position() == (CANVAS_WIDTH, y)) #check contains function r_obj3 = RiverObject(x, y,width,Direction.LEFT,speed) frog1 = Frog(99,100) frog2 = Frog(200,100) frog3 = Frog(301,100) frog4 = Frog(200,90) assert(not r_obj3.contains(frog1)) assert(r_obj3.contains(frog2)) assert(not r_obj3.contains(frog3)) assert(not r_obj3.contains(frog4))
def test_river_object(): global speed x = 100 y = 100 width = 200 obj_speed = 10 r_obj1 = RiverObject(x, y, width, Direction.RIGHT, obj_speed) assert (r_obj1.get_position() == (x, y)) assert (r_obj1.get_width() == width) # test object moves as expected to right assert (speed == 1.0) # test assumes this is 1.0 r_obj1.move() assert (r_obj1.get_position() == (x + obj_speed, y)) # test object moves as expected to left r_obj2 = RiverObject(x, y, width, Direction.LEFT, obj_speed) r_obj2.move() assert (r_obj2.get_position() == (x - obj_speed, y)) # check the object wraps from left to right properly x1 = -CANVAS_WIDTH // 2 + 1.5 * obj_speed r_obj4 = RiverObject(x1, y, width, Direction.LEFT, obj_speed) assert (r_obj4.get_position() == (x1, y)) r_obj4.move() assert (r_obj4.get_position() == (x1 - obj_speed, y)) r_obj4.move() assert (r_obj4.get_position() == (CANVAS_WIDTH, y)) #check contains function r_obj3 = RiverObject(x, y, width, Direction.LEFT, obj_speed) frog1 = Frog(99, 100) frog2 = Frog(200, 100) frog3 = Frog(301, 100) frog4 = Frog(200, 90) assert (not r_obj3.contains(frog1)) assert (r_obj3.contains(frog2)) assert (not r_obj3.contains(frog3)) assert (not r_obj3.contains(frog4))
def test_frog(): x = 100 y = 100 frog = Frog(100, 100) assert (frog.get_position() == (x, y)) assert (frog.get_direction() == Direction.UP) assert (frog.on_log() == None) frog.move(Direction.UP) frog.finish_move() assert (frog.get_position() == (x, y - GRID_SIZE // 2)) sleep(0.2) frog.finish_move() assert (frog.get_position() == (x, y - GRID_SIZE)) frog.move(Direction.LEFT) sleep(0.2) frog.finish_move() assert (frog.get_position() == (x - GRID_SIZE, y - GRID_SIZE)) frog.move(Direction.DOWN) sleep(0.2) frog.finish_move() frog.move(Direction.RIGHT) sleep(0.2) frog.finish_move() assert (frog.get_position() == (x, y)) frog.move(Direction.DOWN) sleep(0.2) frog.finish_move() assert (frog.get_position() == (x, y + GRID_SIZE)) frog.reset_position() assert (frog.get_position() == (x, y)) #test moving with log lx = 80 ly = 100 lwidth = 40 #short log! lspeed = 10 log = Log(lx, ly, lwidth, Direction.RIGHT, lspeed) assert (log.contains(frog)) frog.move_with(log) assert (frog.get_position() == (x, y)) assert (frog.on_log() == log) log.move() frog.move_with(log) assert (frog.get_position() == (x + lspeed, y)) log.move() frog.move_with(log) assert (frog.get_position() == (x + lspeed * 2, y))
def test_frog(): x = 100 y = 100 frog = Frog(100,100) assert(frog.get_position() == (x, y)) assert(frog.get_direction() == Direction.UP) assert(frog.on_log() == None) frog.move(Direction.UP) frog.finish_move() assert(frog.get_position() == (x, y - GRID_SIZE//2)) sleep(0.2) frog.finish_move() assert(frog.get_position() == (x, y - GRID_SIZE)) frog.move(Direction.LEFT) sleep(0.2) frog.finish_move() assert(frog.get_position() == (x - GRID_SIZE, y - GRID_SIZE)) frog.move(Direction.DOWN) sleep(0.2) frog.finish_move() frog.move(Direction.RIGHT) sleep(0.2) frog.finish_move() assert(frog.get_position() == (x, y)) frog.move(Direction.DOWN) sleep(0.2) frog.finish_move() assert(frog.get_position() == (x, y + GRID_SIZE)) frog.reset_position() assert(frog.get_position() == (x, y)) #test moving with log lx = 80 ly = 100 lwidth = 40 #short log! lspeed = 10 log = Log(lx, ly, lwidth, Direction.RIGHT, lspeed) assert(log.contains(frog)) frog.move_with(log) assert(frog.get_position() == (x, y)) assert(frog.on_log() == log) log.move() frog.move_with(log) assert(frog.get_position() == (x + lspeed, y)) log.move() frog.move_with(log) assert(frog.get_position() == (x + lspeed*2, y))