Пример #1
0
 def test_is_tile_cleaned_clean(self):
     """ Test is_tile_cleaned"""
     width, height, dirt_amount = (3, 4, 0)
     room = pj1.RectangularRoom(width, height, dirt_amount)
     # Check all squares are unclean at start, given initial dirt > 1
     for x, y in xyrange(width, height):
         self.assertTrue(
             room.is_tile_cleaned(x, y),
             "Unclean tile {} was returned as clean".format((x, y)))
Пример #2
0
 def test_room_dirt_clean(self):
     """ 
     Can fail either because get_dirt_amount is working incorrectly 
     OR the student is initializing the dirt amount incorrectly
     """
     width, height, dirt_amount = (3, 4, 0)
     room = pj1.RectangularRoom(width, height, dirt_amount)
     for x, y in xyrange(width, height):
         self.assertEquals(
             room.get_dirt_amount(x, y), dirt_amount,
             "Tile {} was not initialized with correct dirt amount".format(
                 (x, y)))
Пример #3
0
 def test_clean_tile_at_position_PosToPos(self):
     """ Test if clean_tile_at_position removes all dirt"""
     width, height, dirt_amount = (3, 4, 2)
     room = pj1.RectangularRoom(width, height, dirt_amount)
     # Clean the tiles and confirm they are marked as clean
     for x, y in xyrange(width, height):
         room.clean_tile_at_position(
             test.Position(x + random.random(), y + random.random()),
             dirt_amount - 1)
         # using random.random in case there is any issue with specific parts of a tile
     for x, y in xyrange(width, height):
         self.assertFalse(room.is_tile_cleaned(x, y),
                          "Unclean tile {} was marked clean".format((x, y)))
Пример #4
0
 def test_get_num_cleaned_tiles_Partial(self):
     "Test get_num_cleaned_tiles for cleaning subset of room incompletely"
     width, height, dirt_amount = (3, 4, 2)
     room = pj1.RectangularRoom(width, height, dirt_amount)
     cleaned_tiles = 0
     # Clean some tiles
     for x, y in xyrange(width - 1, height - 1):
         room.clean_tile_at_position(
             test.Position(x + random.random(), y + random.random()), 1)
         num_cleaned = room.get_num_cleaned_tiles()
         self.assertEqual(
             num_cleaned, cleaned_tiles,
             "Number of clean tiles is incorrect: expected {}, got {}".
             format(cleaned_tiles, num_cleaned))
Пример #5
0
    def test_is_position_in_room(self):
        "Test is_position_in_room"
        width, height, dirt_amount = (3, 4, 2)
        room = pj1.RectangularRoom(width, height, dirt_amount)
        solution_room = test.RectangularRoom(width, height, dirt_amount)

        for x in [0.0, -0.1, width - 0.1, width, width + 0.1]:
            for y in [0.0, -0.1, height - 0.1, height, height + 0.1]:
                pos = test.Position(x, y)
                self.assertEquals(
                    solution_room.is_position_in_room(pos),
                    room.is_position_in_room(pos),
                    "position {},{} is incorrect: expected {}, got {}".format(
                        x, y, solution_room.is_position_in_room(pos),
                        room.is_position_in_room(pos)))
Пример #6
0
 def test_get_num_cleaned_tiles_OverClean(self):
     "Test cleaning already clean tiles does not increment counter"
     width, height, dirt_amount = (3, 4, 2)
     room = pj1.RectangularRoom(width, height, dirt_amount)
     # clean all of the tiles in the room
     for x, y in xyrange(width, height):
         room.clean_tile_at_position(
             test.Position(x + random.random(), y + random.random()),
             dirt_amount)
     for x, y in xyrange(width, height):
         room.clean_tile_at_position(
             test.Position(x + random.random(), y + random.random()), 1)
         num_cleaned = room.get_num_cleaned_tiles()
         self.assertEqual(
             num_cleaned, width * height,
             "Number of clean tiles is incorrect: re-cleaning cleaned tiles must not increase number of cleaned tiles"
         )