def test_duplicate_cube(self): cube_list = [] on_cube = parse_cube_defn("on x=10..12,y=10..12,z=10..12") second_cube = parse_cube_defn("on x=10..12,y=10..12,z=10..12") cube_list = consolidate_cubes(cube_list, on_cube) cube_list = consolidate_cubes(cube_list, second_cube) self.assertEqual(get_total_volume(cube_list), 27) self.assertEqual(len(cube_list), 1)
def test_switch_off(self): cube_list = [] first_cube = parse_cube_defn("on x=10..12,y=10..12,z=10..12") second_cube = parse_cube_defn("on x=11..13,y=11..13,z=11..13") off_cube = parse_cube_defn("off x=9..11,y=9..11,z=9..11") cube_list = consolidate_cubes(cube_list, first_cube) self.assertEqual(get_total_volume(cube_list), 27) cube_list = consolidate_cubes(cube_list, second_cube) self.assertEqual(get_total_volume(cube_list), 46) cube_list = consolidate_cubes(cube_list, off_cube) self.assertEqual(get_total_volume(cube_list), 38)
def test_distinct(self): cube_list = [] first_cube = parse_cube_defn("on x=0..2,y=0..2,z=0..2") second_cube = parse_cube_defn("on x=3..4,y=3..4,z=3..4") unit_cube = parse_cube_defn("on x=1..1,y=1..1,z=1..1") off_cube = parse_cube_defn("off x=0..1,y=0..1,z=0..1") cube_list = consolidate_cubes(cube_list, first_cube) self.assertEqual(get_total_volume(cube_list), 27) cube_list = consolidate_cubes(cube_list, second_cube) self.assertEqual(get_total_volume(cube_list), 27 + 8) cube_list = consolidate_cubes(cube_list, unit_cube) self.assertEqual(get_total_volume(cube_list), 27 + 8) cube_list = consolidate_cubes(cube_list, off_cube) self.assertEqual(get_total_volume(cube_list), 19 + 8) cube_list = consolidate_cubes(cube_list, unit_cube) self.assertEqual(get_total_volume(cube_list), 20 + 8) cube_list = consolidate_cubes(cube_list, unit_cube) self.assertEqual(get_total_volume(cube_list), 20 + 8) cube_list = consolidate_cubes(cube_list, first_cube) self.assertEqual(get_total_volume(cube_list), 27 + 8) cube_list = consolidate_cubes(cube_list, off_cube) self.assertEqual(get_total_volume(cube_list), 19 + 8)
def test_engulf_on(self): cube_list = [] first_cube = parse_cube_defn("on x=10..12,y=10..12,z=10..12") second_cube = parse_cube_defn("on x=11..13,y=11..13,z=11..13") off_cube = parse_cube_defn("off x=9..11,y=9..11,z=9..11") fourth_cube = parse_cube_defn("on x=10..10,y=10..10,z=10..10") outter = parse_cube_defn("on x=-1..15,y=-1..15,z=-1..15") cube_list = consolidate_cubes(cube_list, first_cube) self.assertEqual(get_total_volume(cube_list), 27) cube_list = consolidate_cubes(cube_list, second_cube) self.assertEqual(get_total_volume(cube_list), 46) cube_list = consolidate_cubes(cube_list, off_cube) self.assertEqual(get_total_volume(cube_list), 38) cube_list = consolidate_cubes(cube_list, fourth_cube) self.assertEqual(get_total_volume(cube_list), 39) cube_list = consolidate_cubes(cube_list, outter) self.assertEqual(1, len(cube_list)) self.assertEqual(get_total_volume(cube_list), 17 * 17 * 17)
def test_engulfed_on(self): cube_list = [] first_cube = parse_cube_defn("on x=0..2,y=0..2,z=0..2") unit_cube = parse_cube_defn("on x=1..1,y=1..1,z=1..1") off_cube = parse_cube_defn("off x=0..1,y=0..1,z=0..1") cube_list = consolidate_cubes(cube_list, first_cube) self.assertEqual(get_total_volume(cube_list), 27) cube_list = consolidate_cubes(cube_list, unit_cube) self.assertEqual(get_total_volume(cube_list), 27) cube_list = consolidate_cubes(cube_list, off_cube) self.assertEqual(get_total_volume(cube_list), 19) cube_list = consolidate_cubes(cube_list, unit_cube) self.assertEqual(get_total_volume(cube_list), 20) cube_list = consolidate_cubes(cube_list, unit_cube) self.assertEqual(get_total_volume(cube_list), 20) cube_list = consolidate_cubes(cube_list, first_cube) self.assertEqual(get_total_volume(cube_list), 27) cube_list = consolidate_cubes(cube_list, off_cube) self.assertEqual(get_total_volume(cube_list), 19)
def test_empty_list_on(self): cube_list = [] on_cube = parse_cube_defn("on x=10..12,y=10..12,z=10..12") cube_list = consolidate_cubes(cube_list, on_cube) self.assertEqual(get_total_volume(cube_list), 27)