def test_isnt_free_position( self ): """Given a level with some flat tiles When a goldcar occupies a tile And we have a position on another tile far from goldcar Then is_free_position returns true """ # Given playfield = Playfield() playfield.level = Level() playfield.level.set_tile( Tile( Vec3D(0,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(1,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(2,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(3,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(4,0,0), Tile.Type.FLAT ) ) # When playfield.goldcars = [ GoldCar( TrailPosition(playfield.level.get_tile(2,0), 900), 1 )] pos = TrailPosition(playfield.level.get_tile(2,0), 100) # Then assert playfield.is_free_position( pos )
def test_get_free_position( self ): """Given a playfield with some tiles and goldcar When get_free_position is called Then that position doesn't collide with goldcar """ # Given playfield = Playfield() playfield.level = Level() playfield.level.set_tile( Tile( Vec3D(0,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(1,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(2,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(3,0,0), Tile.Type.FLAT ) ) playfield.level.set_tile( Tile( Vec3D(4,0,0), Tile.Type.FLAT ) ) playfield.goldcars = [ GoldCar( TrailPosition(playfield.level.get_tile(1,0), 500), 1 )] for i in range(0, 256): # When pos = playfield.get_free_position() # Then if pos is not None: assert playfield.is_free_position( pos )
def test_goldcar_ranking( self ): """Given a playfield with 5 goldcars When all goldcars have different scores Then get_goldcar_ranking returns them ordered""" # Given playfield = Playfield() playfield.goldcars = [GoldCar(None, i) for i in range(0,5)] # When playfield.goldcars[0].score = 55 playfield.goldcars[1].score = 12 playfield.goldcars[2].score = 100 playfield.goldcars[3].score = 0 playfield.goldcars[4].score = 25 # Then ranking = playfield.get_goldcar_ranking() assert len(ranking) == 5 for goldcars in ranking: assert len(goldcars) == 1 assert ranking[0][0] is playfield.goldcars[2] assert ranking[1][0] is playfield.goldcars[0] assert ranking[2][0] is playfield.goldcars[4] assert ranking[3][0] is playfield.goldcars[1] assert ranking[4][0] is playfield.goldcars[3]
def test_goldcar_ranking( self ): """Given a playfield with 6 goldcars When some goldcars have same scores Then get_goldcar_ranking returns in same list""" # Given playfield = Playfield() playfield.goldcars = [GoldCar(None, i) for i in range(0,6)] # When playfield.goldcars[0].score = 0 playfield.goldcars[1].score = 12 playfield.goldcars[2].score = 100 playfield.goldcars[3].score = 0 playfield.goldcars[4].score = 100 playfield.goldcars[5].score = 0 # Then ranking = playfield.get_goldcar_ranking() assert len(ranking) == 3 assert len(ranking[0]) == 2 assert len(ranking[1]) == 1 assert len(ranking[2]) == 3 assert playfield.goldcars[0] in ranking[2] assert playfield.goldcars[1] in ranking[1] assert playfield.goldcars[2] in ranking[0] assert playfield.goldcars[3] in ranking[2] assert playfield.goldcars[4] in ranking[0] assert playfield.goldcars[5] in ranking[2]
def test_isnt_free_position(self): """Given a level with some flat tiles When a goldcar occupies a tile And we have a position on another tile far from goldcar Then is_free_position returns true """ # Given playfield = Playfield() playfield.level = Level() playfield.level.set_tile(Tile(Vec3D(0, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(1, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(2, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(3, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(4, 0, 0), Tile.Type.FLAT)) # When playfield.goldcars = [ GoldCar(TrailPosition(playfield.level.get_tile(2, 0), 900), 1) ] pos = TrailPosition(playfield.level.get_tile(2, 0), 100) # Then assert playfield.is_free_position(pos)
def test_goldcar_ranking(self): """Given a playfield with 6 goldcars When some goldcars have same scores Then get_goldcar_ranking returns in same list""" # Given playfield = Playfield() playfield.goldcars = [GoldCar(None, i) for i in range(0, 6)] # When playfield.goldcars[0].score = 0 playfield.goldcars[1].score = 12 playfield.goldcars[2].score = 100 playfield.goldcars[3].score = 0 playfield.goldcars[4].score = 100 playfield.goldcars[5].score = 0 # Then ranking = playfield.get_goldcar_ranking() assert len(ranking) == 3 assert len(ranking[0]) == 2 assert len(ranking[1]) == 1 assert len(ranking[2]) == 3 assert playfield.goldcars[0] in ranking[2] assert playfield.goldcars[1] in ranking[1] assert playfield.goldcars[2] in ranking[0] assert playfield.goldcars[3] in ranking[2] assert playfield.goldcars[4] in ranking[0] assert playfield.goldcars[5] in ranking[2]
def test_goldcar_ranking(self): """Given a playfield with 5 goldcars When all goldcars have different scores Then get_goldcar_ranking returns them ordered""" # Given playfield = Playfield() playfield.goldcars = [GoldCar(None, i) for i in range(0, 5)] # When playfield.goldcars[0].score = 55 playfield.goldcars[1].score = 12 playfield.goldcars[2].score = 100 playfield.goldcars[3].score = 0 playfield.goldcars[4].score = 25 # Then ranking = playfield.get_goldcar_ranking() assert len(ranking) == 5 for goldcars in ranking: assert len(goldcars) == 1 assert ranking[0][0] is playfield.goldcars[2] assert ranking[1][0] is playfield.goldcars[0] assert ranking[2][0] is playfield.goldcars[4] assert ranking[3][0] is playfield.goldcars[1] assert ranking[4][0] is playfield.goldcars[3]
def test_game_tick(self): scenario = ScenarioPacman(60, 60) playfield = Playfield() playfield.load("tests/levelTest.lvl") scenario.playfield = playfield scenario.game_tick()
def test_game_tick( self ): scenario = ScenarioPacman(60, 60) playfield = Playfield() playfield.load("tests/levelTest.lvl") scenario.playfield = playfield scenario.game_tick()
def test_normal_portal_handling( self ): """Given a goldcar on a small track with 2 portals When goldcar rides through one portal Then it comes out of the other""" # Given level = Level() portalA = Enterance( Vec3D(2,0,0) ) tileAA = Tile( Vec3D(1,0,0), Tile.Type.FLAT ) tileA = Tile( Vec3D(0,0,0), Tile.Type.FLAT ) tileB = Tile( Vec3D(0,1,0), Tile.Type.FLAT ) tileC = Tile( Vec3D(0,2,0), Tile.Type.FLAT ) tileCC = Tile( Vec3D(1,2,0), Tile.Type.FLAT ) portalC = Enterance( Vec3D(2,2,0) ) level.set_tile( portalA ) level.set_tile( tileAA ) level.set_tile( tileA ) level.set_tile( tileB ) level.set_tile( tileC ) level.set_tile( tileCC ) level.set_tile( portalC) goldcar = GoldCar( TrailPosition( tileB, 0), 0 ) #goldcar.pos.reverse_progress() playfield = Playfield() playfield.level = level playfield.goldcars = [goldcar] order = [tileB, tileC, tileCC, portalC, portalA, tileAA, tileA, tileB] order_at = 0 count = 0 while order_at < len(order)-1 and count < 1000: playfield.game_tick() print goldcar.pos.tile, goldcar.pos.progress if goldcar.pos.tile == order[ order_at ]: pass elif goldcar.pos.tile == order[ order_at+1 ]: order_at += 1 else: assert False, "unknown tile after " + str(order_at) count += 1 assert count < 1000
def test_get_free_position(self): """Given a playfield with some tiles and goldcar When get_free_position is called Then that position doesn't collide with goldcar """ # Given playfield = Playfield() playfield.level = Level() playfield.level.set_tile(Tile(Vec3D(0, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(1, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(2, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(3, 0, 0), Tile.Type.FLAT)) playfield.level.set_tile(Tile(Vec3D(4, 0, 0), Tile.Type.FLAT)) playfield.goldcars = [ GoldCar(TrailPosition(playfield.level.get_tile(1, 0), 500), 1) ] for i in range(0, 256): # When pos = playfield.get_free_position() # Then if pos is not None: assert playfield.is_free_position(pos)
def test_normal_portal_handling(self): """Given a goldcar on a small track with 2 portals When goldcar rides through one portal Then it comes out of the other""" # Given level = Level() portalA = Enterance(Vec3D(2, 0, 0)) tileAA = Tile(Vec3D(1, 0, 0), Tile.Type.FLAT) tileA = Tile(Vec3D(0, 0, 0), Tile.Type.FLAT) tileB = Tile(Vec3D(0, 1, 0), Tile.Type.FLAT) tileC = Tile(Vec3D(0, 2, 0), Tile.Type.FLAT) tileCC = Tile(Vec3D(1, 2, 0), Tile.Type.FLAT) portalC = Enterance(Vec3D(2, 2, 0)) level.set_tile(portalA) level.set_tile(tileAA) level.set_tile(tileA) level.set_tile(tileB) level.set_tile(tileC) level.set_tile(tileCC) level.set_tile(portalC) goldcar = GoldCar(TrailPosition(tileB, 0), 0) #goldcar.pos.reverse_progress() playfield = Playfield() playfield.level = level playfield.goldcars = [goldcar] order = [tileB, tileC, tileCC, portalC, portalA, tileAA, tileA, tileB] order_at = 0 count = 0 while order_at < len(order) - 1 and count < 1000: playfield.game_tick() print goldcar.pos.tile, goldcar.pos.progress if goldcar.pos.tile == order[order_at]: pass elif goldcar.pos.tile == order[order_at + 1]: order_at += 1 else: assert False, "unknown tile after " + str(order_at) count += 1 assert count < 1000