Ejemplo n.º 1
0
    def test_create_random_triangles(self):
        e = self.get_evolver()
        items = utils.create_random_triangles(e.size, 2, utils.RGB)
        self.assertEqual(len(items), 2)
        self.assertTrue(isinstance(items[0], Triangle))
        self.assertEqual(items[0].coordinates, [1, 2, 3, 4, 5, 6])
        self.assertEqual(items[0].color, (7, 8, 9))
        self.assertEqual(items[0].opacity, 10)

        items = utils.create_random_triangles(e.size, 4, utils.RGB)
        self.assertEqual(len(items), 4)
        self.assertTrue(isinstance(items[0], Triangle))
Ejemplo n.º 2
0
    def test_randomlyMoveTriangle(self):
        e = self.get_evolver()
        tri = utils.create_random_triangles(e.size, 1, utils.RGB)[0]
        self.assertEqual(tri.coordinates, [1, 2, 3, 4, 5, 6])
        e.randomly_move_triangle(tri, variance=20)

        # the triangle should now have had the center of the triangle
        # moved by some amount, limited to be between -variance, +variance
        self.assertEqual(tri.coordinates, [12, 14, 14, 16, 16, 18])
Ejemplo n.º 3
0
    def test_filter_triangles(self):
        s = self.get_seeder()
        triangles = utils.create_random_triangles(s.size, 20, utils.RGB)
        new_triangles = s.filter_and_sort_triangles(triangles)

        self.assertTrue(len(new_triangles) <= s.num_triangles)

        previous_area = new_triangles[0].get_area()
        for tri in new_triangles[1:]:
            area = tri.get_area()
            if area > previous_area:
                self.fail()
            previous_area = area