Пример #1
0
    def test_is_position_valid(self):
        """ Test is_position_valid
        """
        for trial in range(5):
            width, height, dirt_amount = (3, 4, 2)
            room = ps3.FurnishedRoom(width, height, dirt_amount)
            room.add_furniture_to_room()
            sol_room = test.FurnishedRoom(width, height, dirt_amount)
            sol_room.furniture_tiles = room.furniture_tiles

            for x in [
                0.0,
                -0.1,
                width - 0.1,
                width,
                width + 0.1,
                room.furniture_tiles[0][0] + 0.3,
            ]:
                for y in [
                    0.0,
                    -0.1,
                    height - 0.1,
                    height,
                    height + 0.1,
                    room.furniture_tiles[0][1] + 0.3,
                ]:
                    pos = test.Position(x, y)
                    self.assertEqual(
                        sol_room.is_position_valid(pos),
                        room.is_position_valid(pos),
                        "student code and solution code disagree on whether position is valid:" + str(pos),
                    )
Пример #2
0
 def test_is_tile_furnished(self):
     """ test is_tile_furnished """        
     for trial in range(5):
         width, height, dirt_amount = (random.randint(2, 8), random.randint(2, 8), 1)
         # create room using student's class, set furniture tiles for solution class
         room = ps3.FurnishedRoom(width, height, dirt_amount)
         room.add_furniture_to_room()
         sol_room = test.FurnishedRoom(width, height, dirt_amount)
         # this relies on knowing the underlying details of the class
         sol_room.furniture_tiles = room.furniture_tiles 
         for x,y in xyrange(width,height):
             self.assertEquals(room.is_tile_furnished(x,y),sol_room.is_tile_furnished(x,y),
                               "student code and solution code disagree on whether tile is furnished"
                               )