class TestLevelConnectivity(): """ Class for testing level connectivity matcher """ def __init__(self): """ Default constructor """ self.level = None self.matcher = None self.wall_empty = None self.floor_rock = None self.wall_ground = None def setup(self): """ Setup the tests """ self.wall_empty = None self.floor_rock = 2 self.wall_ground = 3 self.level = (LevelBuilder().with_size((20, 10)).with_floor_tile( self.floor_rock).with_wall_tile(self.wall_ground).build()) self.matcher = MapConnectivity() def test_unconnected_level(self): """ Test that unconnected level is reported correctly """ for loc_x in range(2, 5): wall_tile(self.level, (loc_x, 2), self.wall_empty) wall_tile(self.level, (loc_x, 5), self.wall_empty) assert_that(self.matcher._matches(self.level), is_(equal_to(False))) def test_connected_level(self): """ Test that connected level is reported correctly """ for loc_x in range(2, 8): wall_tile(self.level, (loc_x, 3), self.wall_empty) wall_tile(self.level, (loc_x, 6), self.wall_empty) wall_tile(self.level, (5, loc_x), self.wall_empty) assert_that(self.matcher._matches(self.level), is_(equal_to(True))) def test_that_all_points_are_found(self): """ Test that connectivity can find all open points """ wall_tile(self.level, (0, 0), self.wall_empty) wall_tile(self.level, (5, 5), self.wall_empty) wall_tile(self.level, (20, 10), self.wall_empty) points = self.matcher.get_all_points(self.level, self.wall_empty) assert_that(points, has_length(3)) def test_that_open_corners_work(self): """ Test that finding connectivity with open corners work """ wall_tile(self.level, (0, 0), self.wall_empty) wall_tile(self.level, (20, 0), self.wall_empty) wall_tile(self.level, (0, 10), self.wall_empty) wall_tile(self.level, (20, 10), self.wall_empty) assert_that(self.matcher._matches(self.level), is_(equal_to(False))) def test_that_convoluted_case_works(self): """ Test a convoluted case with 3 open areas and 2 of them being connected to border """ self.level = (LevelBuilder().with_size((10, 10)).with_floor_tile( self.floor_rock).with_wall_tile(self.wall_ground).build()) wall_tile(self.level, (2, 5), self.wall_empty) wall_tile(self.level, (2, 6), self.wall_empty) wall_tile(self.level, (2, 7), self.wall_empty) wall_tile(self.level, (2, 8), self.wall_empty) wall_tile(self.level, (2, 9), self.wall_empty) wall_tile(self.level, (2, 10), self.wall_empty) wall_tile(self.level, (5, 8), self.wall_empty) wall_tile(self.level, (5, 2), self.wall_empty) wall_tile(self.level, (6, 2), self.wall_empty) wall_tile(self.level, (7, 2), self.wall_empty) wall_tile(self.level, (8, 2), self.wall_empty) wall_tile(self.level, (9, 2), self.wall_empty) wall_tile(self.level, (10, 2), self.wall_empty) all_points = self.matcher.get_all_points(self.level, self.wall_empty) connected_points = self.matcher.get_connected_points( self.level, all_points[0], self.wall_empty, []) assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
class TestLevelConnectivity: """ Class for testing level connectivity matcher """ def __init__(self): """ Default constructor """ self.level = None self.matcher = None self.wall_empty = None self.floor_rock = None self.wall_ground = None def setup(self): """ Setup the tests """ self.wall_empty = 1 self.floor_rock = 2 self.wall_ground = 3 self.level = Level(size=(20, 10), floor_type=self.floor_rock, wall_type=self.wall_ground) self.matcher = MapConnectivity(self.wall_empty) def test_unconnected_level(self): """ Test that unconnected level is reported correctly """ for loc_x in range(2, 5): self.level.walls[loc_x][2] = self.wall_empty self.level.walls[loc_x][5] = self.wall_empty assert_that(self.matcher._matches(self.level), is_(equal_to(False))) def test_connected_level(self): """ Test that connected level is reported correctly """ for loc_x in range(2, 8): self.level.walls[loc_x][3] = self.wall_empty self.level.walls[loc_x][5] = self.wall_empty self.level.walls[5][loc_x] = self.wall_empty assert_that(self.matcher._matches(self.level), is_(equal_to(True))) def test_that_all_points_are_found(self): """ Test that connectivity can find all open points """ self.level.walls[0][0] = self.wall_empty self.level.walls[5][5] = self.wall_empty self.level.walls[20][10] = self.wall_empty points = self.matcher.get_all_points(self.level, self.wall_empty) assert_that(points, has_length(3)) def test_that_open_corners_work(self): """ Test that finding connectivity with open corners work """ self.level.walls[0][0] = self.wall_empty self.level.walls[20][0] = self.wall_empty self.level.walls[0][10] = self.wall_empty self.level.walls[20][10] = self.wall_empty assert_that(self.matcher._matches(self.level), is_(equal_to(False))) def test_that_convoluted_case_works(self): """ Test a convoluted case with 3 open areas and 2 of them being connected to border """ self.level = Level(size=(10, 10), floor_type=self.floor_rock, wall_type=self.wall_ground) self.level.walls[2][5] = self.wall_empty self.level.walls[2][6] = self.wall_empty self.level.walls[2][7] = self.wall_empty self.level.walls[2][8] = self.wall_empty self.level.walls[2][9] = self.wall_empty self.level.walls[2][10] = self.wall_empty self.level.walls[5][8] = self.wall_empty self.level.walls[5][2] = self.wall_empty self.level.walls[6][2] = self.wall_empty self.level.walls[7][2] = self.wall_empty self.level.walls[8][2] = self.wall_empty self.level.walls[9][2] = self.wall_empty self.level.walls[10][2] = self.wall_empty all_points = self.matcher.get_all_points(self.level, self.wall_empty) connected_points = self.matcher.get_connected_points(self.level, all_points[0], self.wall_empty, []) print "all points: {0}".format(all_points) print "connected points: {0}".format(connected_points) assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
class TestLevelConnectivity: """ Class for testing level connectivity matcher """ def __init__(self): """ Default constructor """ self.level = None self.matcher = None self.wall_empty = None self.floor_rock = None self.wall_ground = None def setup(self): """ Setup the tests """ self.wall_empty = None self.floor_rock = 2 self.wall_ground = 3 self.level = ( LevelBuilder().with_size((20, 10)).with_floor_tile(self.floor_rock).with_wall_tile(self.wall_ground).build() ) self.matcher = MapConnectivity() def test_unconnected_level(self): """ Test that unconnected level is reported correctly """ for loc_x in range(2, 5): wall_tile(self.level, (loc_x, 2), self.wall_empty) wall_tile(self.level, (loc_x, 5), self.wall_empty) assert_that(self.matcher._matches(self.level), is_(equal_to(False))) def test_connected_level(self): """ Test that connected level is reported correctly """ for loc_x in range(2, 8): wall_tile(self.level, (loc_x, 3), self.wall_empty) wall_tile(self.level, (loc_x, 6), self.wall_empty) wall_tile(self.level, (5, loc_x), self.wall_empty) assert_that(self.matcher._matches(self.level), is_(equal_to(True))) def test_that_all_points_are_found(self): """ Test that connectivity can find all open points """ wall_tile(self.level, (0, 0), self.wall_empty) wall_tile(self.level, (5, 5), self.wall_empty) wall_tile(self.level, (20, 10), self.wall_empty) points = self.matcher.get_all_points(self.level, self.wall_empty) assert_that(points, has_length(3)) def test_that_open_corners_work(self): """ Test that finding connectivity with open corners work """ wall_tile(self.level, (0, 0), self.wall_empty) wall_tile(self.level, (20, 0), self.wall_empty) wall_tile(self.level, (0, 10), self.wall_empty) wall_tile(self.level, (20, 10), self.wall_empty) assert_that(self.matcher._matches(self.level), is_(equal_to(False))) def test_that_convoluted_case_works(self): """ Test a convoluted case with 3 open areas and 2 of them being connected to border """ self.level = ( LevelBuilder().with_size((10, 10)).with_floor_tile(self.floor_rock).with_wall_tile(self.wall_ground).build() ) wall_tile(self.level, (2, 5), self.wall_empty) wall_tile(self.level, (2, 6), self.wall_empty) wall_tile(self.level, (2, 7), self.wall_empty) wall_tile(self.level, (2, 8), self.wall_empty) wall_tile(self.level, (2, 9), self.wall_empty) wall_tile(self.level, (2, 10), self.wall_empty) wall_tile(self.level, (5, 8), self.wall_empty) wall_tile(self.level, (5, 2), self.wall_empty) wall_tile(self.level, (6, 2), self.wall_empty) wall_tile(self.level, (7, 2), self.wall_empty) wall_tile(self.level, (8, 2), self.wall_empty) wall_tile(self.level, (9, 2), self.wall_empty) wall_tile(self.level, (10, 2), self.wall_empty) all_points = self.matcher.get_all_points(self.level, self.wall_empty) connected_points = self.matcher.get_connected_points(self.level, all_points[0], self.wall_empty, []) assert_that(self.matcher._matches(self.level), is_(equal_to(False)))