Example #1
0
    def test_getting_object_size(self):
        obj_a = Object(1, (0, 0), [
            (0, 0),
            (1, 0),
            (2, 0),
            (3, 0),
            (3, 1),
            (3, 2),
            (2, 2),
            (1, 2),
            (0, 2),
            (0, 1),
        ])
        self.assertEqual(10, ObjectRuntime.get_size(obj_a))

        obj_b = Object(8, (7, 3), [
            (10, 12),
        ])
        self.assertEqual(1, ObjectRuntime.get_size(obj_b))

        obj_c = Object(1, (2, 9), [
            (0, 0),
            (1, 0),
            (1, 1),
            (2, 2),
            (3, 3),
            (4, 4),
        ])
        self.assertEqual(6, ObjectRuntime.get_size(obj_c))
Example #2
0
    def test_getting_the_biggest_object(self):
        obj_a = Object(1, (0, 0), [
            (0, 0),
            (1, 1),
            (2, 2),
        ])
        obj_b = Object(2, (0, 1), [
            (0, 0),
            (1, 1),
            (2, 2),
            (3, 3),
        ])
        obj_c = Object(3, (0, 2), [
            (0, 0),
            (1, 1),
        ])

        frame_model = ObjectRuntime.make_frame_model_from_objects(
            [obj_a, obj_b, obj_c], 0)

        # get list of objects
        # find id of biggest object
        #
        biggest_object = ListRuntime.map_list(
            lambda obj: (obj.id, ObjectRuntime.get_size(obj)),
            frame_model.objects_as_list())
        print("\n")
        print(biggest_object)

        new_frame_model = FrameModelRuntime.change_objects(
            frame_model,
            ListRuntime.filter_list(lambda obj: obj == biggest_object,
                                    frame_model.objects_as_list()))
        new_frame_model.to_grid().plot()
        self.assertEqual(1, len(list(new_frame_model.objects.values())))
        self.assertEqual(obj_b, list(new_frame_model.objects.values())[0])