def test_add_section(self): g = guillotine.Guillotine(100, 100) g._sections = [Rectangle(0, 50, 50, 50)] g._add_section(Rectangle(50, 0, 50, 50)) self.assertEqual(len(g._sections), 2) # Test sections are merged recursively g = guillotine.Guillotine(100, 100, merge=True) g._sections = [Rectangle(0, 50, 100, 50), Rectangle(50, 0, 50, 50)] g._add_section(Rectangle(0, 0, 50, 50)) self.assertEqual(len(g._sections), 1) self.assertEqual(g._sections[0], Rectangle(0, 0, 100, 100)) # Test merge disabled g = guillotine.Guillotine(100, 100, merge=False) g._sections = [Rectangle(0, 50, 100, 50), Rectangle(50, 0, 50, 50)] g._add_section(Rectangle(0, 0, 50, 50)) self.assertEqual(len(g._sections), 3) self.assertTrue(Rectangle(0, 50, 100, 50) in g._sections) self.assertTrue(Rectangle(50, 0, 50, 50) in g._sections) self.assertTrue(Rectangle(0, 0, 50, 50) in g._sections)
def test_fits_surface(self): g = guillotine.Guillotine(100, 200, rot=False) self.assertTrue(g._fits_surface(10, 10)) self.assertTrue(g._fits_surface(100, 200)) self.assertTrue(g._fits_surface(100, 100)) self.assertFalse(g._fits_surface(101, 200)) self.assertFalse(g._fits_surface(100, 201))
def test_init(self): # Test default section g = guillotine.Guillotine(100, 100) self.assertEqual(len(g._sections), 1) self.assertEqual(g._sections[0], Rectangle(0, 0, 100, 100)) # Test arguments g = guillotine.Guillotine(50, 100) self.assertEqual(g.width, 50) self.assertEqual(g.height, 100) # Test merge optional argument g = guillotine.Guillotine(50, 100) self.assertEqual(g._merge, True) g = guillotine.Guillotine(50, 100, merge=False) self.assertEqual(g._merge, False) g = guillotine.Guillotine(50, 100, merge=True) self.assertEqual(g._merge, True)
def test_split_vertical(self): # Normal split g = guillotine.Guillotine(100, 100) section = g._sections[0] g._sections = [] g._split_vertical(section, 50, 50) self.assertTrue(Rectangle(50, 0, 50, 100) in g._sections) self.assertTrue(Rectangle(0, 50, 50, 50) in g._sections) self.assertEqual(len(g._sections), 2) # Full width split g = guillotine.Guillotine(100, 100) section = g._sections[0] g._sections = [] g._split_vertical(section, 100, 50) self.assertTrue(Rectangle(0, 50, 100, 50) in g._sections) self.assertEqual(len(g._sections), 1) # Full Height split g = guillotine.Guillotine(100, 100) section = g._sections[0] g._sections = [] g._split_vertical(section, 50, 100) self.assertTrue(Rectangle(50, 0, 50, 100) in g._sections) self.assertEqual(len(g._sections), 1) # Full section split g = guillotine.Guillotine(100, 100) section = g._sections[0] g._sections = [] g._split_vertical(section, 100, 100) self.assertEqual(len(g._sections), 0)