예제 #1
0
 def testThreeInserts(self):
     """
     Three items across two shelves
     """
     ITEM = item.Item(4, 2)
     ITEM2 = item.Item(5, 2)
     ITEM3 = item.Item(2, 2)
     self.sheet.insert(ITEM, heuristic='worst_area_fit')
     self.sheet.insert(ITEM2, heuristic='worst_area_fit')
     self.sheet.insert(ITEM3, heuristic='worst_area_fit')
     with self.subTest():
         correct = shelf.Shelf(8, 2, 0)
         correct.items = [ITEM, ITEM3]
         correct.available_width = 2
         self.assertEqual(self.sheet.shelves[0].__dict__,
                          correct.__dict__)
     with self.subTest():
         correct = shelf.Shelf(8, 2, 2)
         correct.items = [ITEM2]
         correct.available_width = 3
         self.assertEqual(self.sheet.shelves[1].__dict__,
                          correct.__dict__)
     with self.subTest():
         correct = [ITEM, ITEM2, ITEM3]
         self.assertEqual(self.sheet.items, correct)
예제 #2
0
 def testTwoInsertsB(self):
     """
     Two items that fit in two shelves
     """
     ITEM = item.Item(3, 2)
     ITEM2 = item.Item(6, 2)
     self.sheet.insert(ITEM, heuristic='first_fit')
     self.sheet.insert(ITEM2, heuristic='first_fit')
     with self.subTest():
         correct = shelf.Shelf(8, 2, 0)
         correct.items = [ITEM]
         correct.available_width = 5
         self.assertEqual(self.sheet.shelves[0].__dict__,
                          correct.__dict__)
     with self.subTest():
         correct = shelf.Shelf(8, 2, 2)
         correct.items = [ITEM2]
         correct.available_width = 2
         self.assertEqual(self.sheet.shelves[1].__dict__,
                          correct.__dict__)
     with self.subTest():
         correct = [ITEM, ITEM2]
         self.assertEqual(self.sheet.items, correct)
예제 #3
0
    def testSingleInsert(self):
        """
        Single item insertion doesn't use a heuristic
        """
        ITEM = item.Item(6, 2)
        self.sheet.insert(ITEM, heuristic='first_fit')
        with self.subTest():
            correct = shelf.Shelf(8, 2, 0)
            correct.items = [ITEM]
            correct.available_width = 2
            self.assertEqual(self.sheet.shelves[0].__dict__,
                             correct.__dict__)

        with self.subTest():
            correct = [ITEM]
            self.assertEqual(self.sheet.items, correct)
예제 #4
0
 def testTwoInsertsC(self):
     """
     Second item doesn't fit remaining vertical space in sheet
     """
     ITEM = item.Item(3, 2)
     ITEM2 = item.Item(6, 3)
     self.sheet.insert(ITEM, heuristic='first_fit')
     res = self.sheet.insert(ITEM2, heuristic='first_fit')
     with self.subTest():
         correct = shelf.Shelf(8, 2, 0)
         correct.items = [ITEM]
         correct.available_width = 5
         self.assertEqual(self.sheet.shelves[0].__dict__,
                          correct.__dict__)
     with self.subTest():
         self.assertFalse(res)
     with self.subTest():
         correct = [ITEM]
         self.assertEqual(self.sheet.items, correct)
예제 #5
0
 def setUp(self):
     self.shelf = shelf.Shelf(8,4, 0)