def setUp(self): magnet1 = MagnetModel(1.0, 0.0, 1.5) magnet2 = MagnetModel(-1.0, 1.0, 1.5) magnet3 = MagnetModel(-1.0, -1.0, 1.5) magnet4 = MagnetModel(0.0, 0.0, 0.5) self.magnets = [magnet1, magnet2, magnet3, magnet4] self.plane_distance = 0.25 self.friction = 0.3 self.gravity_pullback = 0.5 self.pendulum = PendulumModel(self.friction, self.gravity_pullback, self.plane_distance) self.pendulum.magnets = self.magnets self.time_step = 0.01 self.integrator = EulerIntegrator(self.time_step) self.r = 255 self.g = 0 self.b = 0 self.image_generator = BasicImageGenerator(self.r, self.g, self.b) self.size = 5 self.resolution = 640 self.basins_generator = BasinsGenerator(self.size, self.resolution) self.basins_generator.pendulum_model = self.pendulum self.basins_generator.integrator = self.integrator self.basins_generator.image_generator = self.image_generator
class TestBasicImageGenerator(unittest.TestCase): def setUp(self): self.r = 255 self.g = 0 self.b = 0 self.image_generator = BasicImageGenerator(self.r, self.g, self.b) def test_generator_initalization(self): self.assertEqual(self.image_generator.base_hsv, colorsys.rgb_to_hsv(self.r / 255.0, self.g /255.0, self.b / 255.0)) def test_image_generation_1(self): number_of_colors = 3 test_data = numpy.array([[0, 2, 1], [1, 0, 1], [1, 2, 0]]) self.image_generator.generate_image("test_image_1", test_data, test_data, number_of_colors) self.assertEqual(len(self.image_generator.color_list), number_of_colors) def test_image_generation_2(self): number_of_colors = 10 test_data = numpy.array([[random.randint(0, number_of_colors - 1) for j in range(1, 100)] for i in range(1, 100)]) self.image_generator.generate_image("test_image_2", test_data, test_data, number_of_colors) self.assertEqual(len(self.image_generator.color_list), number_of_colors) def test_image_generation_3(self): number_of_colors = 5 test_data = numpy.array([[0, 2, 2, 4, 1], [1, 0, 2, 4, 1], [1, 1, 0, 4, 1], [4, 4, 4, 0, 1], [3, 3, 3, 3, 0]]) self.image_generator.generate_image("test_image_3", test_data, test_data, number_of_colors) self.assertEqual(len(self.image_generator.color_list), number_of_colors)
class TestBasicImageGenerator(unittest.TestCase): def setUp(self): self.r = 255 self.g = 0 self.b = 0 self.image_generator = BasicImageGenerator(self.r, self.g, self.b) def test_generator_initalization(self): self.assertEqual( self.image_generator.base_hsv, colorsys.rgb_to_hsv(self.r / 255.0, self.g / 255.0, self.b / 255.0)) def test_image_generation_1(self): number_of_colors = 3 test_data = numpy.array([[0, 2, 1], [1, 0, 1], [1, 2, 0]]) self.image_generator.generate_image("test_image_1", test_data, test_data, number_of_colors) self.assertEqual(len(self.image_generator.color_list), number_of_colors) def test_image_generation_2(self): number_of_colors = 10 test_data = numpy.array( [[random.randint(0, number_of_colors - 1) for j in range(1, 100)] for i in range(1, 100)]) self.image_generator.generate_image("test_image_2", test_data, test_data, number_of_colors) self.assertEqual(len(self.image_generator.color_list), number_of_colors) def test_image_generation_3(self): number_of_colors = 5 test_data = numpy.array([[0, 2, 2, 4, 1], [1, 0, 2, 4, 1], [1, 1, 0, 4, 1], [4, 4, 4, 0, 1], [3, 3, 3, 3, 0]]) self.image_generator.generate_image("test_image_3", test_data, test_data, number_of_colors) self.assertEqual(len(self.image_generator.color_list), number_of_colors)
def setUp(self): self.r = 255 self.g = 0 self.b = 0 self.image_generator = BasicImageGenerator(self.r, self.g, self.b)