Esempio n. 1
0
 def test_init_with_invalid_arg_types_raises_TypeError(self):
     with self.assertRaises(TypeError):
         # Test red
         soft.SoftColor('NONSENSE', 255, 255)
     with self.assertRaises(TypeError):
         # Test green
         soft.SoftColor(255, 'NONSENSE', 255)
     with self.assertRaises(TypeError):
         # Test blue
         soft.SoftColor(255, 255, 'NONSENSE')
Esempio n. 2
0
 def __init__(self, value, allow_change):
     """
     Args:
         value (bool): The starting value of this cell
         allow_change (SoftFloat): the probability to accept
             changes according to the Rules of Life
     """
     self.color_alive = soft.SoftColor(([(255, 5), (200, 0)],),
                                       ([(255, 5), (200, 0)],),
                                       ([(255, 5), (200, 0)],))
     self.color_dead = soft.SoftColor(0, 0, 0)
     self.value = value
     self.allow_change = allow_change
Esempio n. 3
0
 def test_init_from_existing_softints(self):
     red = soft.SoftInt.bounded_uniform(0, 255)
     green = soft.SoftInt.bounded_uniform(0, 255)
     blue = soft.SoftInt.bounded_uniform(0, 255)
     test_object = soft.SoftColor(red, green, blue)
     # Test that attributes were assigned correctly
     self.assertEqual(test_object.red.weights, red.weights)
     self.assertEqual(test_object.green.weights, green.weights)
     self.assertEqual(test_object.blue.weights, blue.weights)
Esempio n. 4
0
 def test_init_from_tuples_of_args_for_softints(self):
     red_args = ([(0, 1), (255, 10)],)
     green_args = ([(0, 1), (255, 10)],)
     blue_args = ([(0, 1), (255, 10)],)
     test_object = soft.SoftColor(red_args, green_args, blue_args)
     # Test that SoftInt's were initialized correctly from args
     self.assertIsInstance(test_object.red, soft.SoftInt)
     self.assertIsInstance(test_object.green, soft.SoftInt)
     self.assertIsInstance(test_object.blue, soft.SoftInt)
     # Test that attributes were assigned correctly
     self.assertEqual(test_object.red.weights, [(0, 1), (255, 10)])
     self.assertEqual(test_object.green.weights, [(0, 1), (255, 10)])
     self.assertEqual(test_object.blue.weights, [(0, 1), (255, 10)])
Esempio n. 5
0
 def test_init_from_int_values(self):
     red = 50
     green = 80
     blue = 90
     test_object = soft.SoftColor(red, green, blue)
     # Test that types were not converted
     self.assertIsInstance(test_object.red, int)
     self.assertIsInstance(test_object.green, int)
     self.assertIsInstance(test_object.blue, int)
     # Test that attributes were assigned correctly
     self.assertEqual(test_object.red, red)
     self.assertEqual(test_object.green, green)
     self.assertEqual(test_object.blue, blue)
Esempio n. 6
0
 def test_get_with_mixed_color_types(self):
     red_input = soft.SoftInt.bounded_uniform(0, 2)
     green_input = ([(200, 1), (255, 10)],)
     blue_input = 255
     test_object = soft.SoftColor(red_input, green_input, blue_input)
     red, green, blue = test_object.get()
     # Test that only int's were returned
     self.assertIsInstance(red, int)
     self.assertIsInstance(green, int)
     self.assertIsInstance(blue, int)
     # Test that return values are within expected ranges
     self.assertTrue(0 <= red <= 2)
     self.assertTrue(200 <= green <= 255)
     self.assertEqual(blue, 255)
Esempio n. 7
0
 def test_get_with_only_softint_color_types(self):
     red_input = soft.SoftInt.bounded_uniform(1, 2)
     green_input = soft.SoftInt.bounded_uniform(3, 4)
     blue_input = soft.SoftInt.bounded_uniform(5, 6)
     test_object = soft.SoftColor(red_input, green_input, blue_input)
     red, green, blue = test_object.get()
     # Test that only int's were returned
     self.assertIsInstance(red, int)
     self.assertIsInstance(green, int)
     self.assertIsInstance(blue, int)
     # Test that return values are within expected ranges
     self.assertTrue(1 <= red <= 2)
     self.assertTrue(3 <= green <= 4)
     self.assertTrue(5 <= blue <= 6)
Esempio n. 8
0
 def test_get_with_only_int_color_types(self):
     red_input = 128
     green_input = 200
     blue_input = 255
     test_object = soft.SoftColor(red_input, green_input, blue_input)
     red, green, blue = test_object.get()
     # Test that only int's were returned
     self.assertIsInstance(red, int)
     self.assertIsInstance(green, int)
     self.assertIsInstance(blue, int)
     # Test that return values are within expected ranges
     self.assertEqual(red, red_input)
     self.assertEqual(green, green_input)
     self.assertEqual(blue, blue_input)
Esempio n. 9
0
 def test_get_as_hex_returns_uppercase(self):
     test_object = soft.SoftColor(128, 200, 255)
     hex_color = test_object.get_as_hex()
     self.assertEqual(hex_color, '#80C8FF')
Esempio n. 10
0
 def test_get_as_hex(self):
     test_object = soft.SoftColor(128, 200, 255)
     hex_color = test_object.get_as_hex()
     # Convert to uppercase to separate upper/lower case
     #   into a different test
     self.assertEqual(hex_color.upper(), '#80C8FF')
Esempio n. 11
0
 def test_init_from_tuples_of_args_for_softints_with_bad_args_fails(self):
     with self.assertRaises(TypeError):
         red_args = ([(0, 1), (255, 10)],)
         green_args = ([(0, 1), (255, 10)],)
         blue_args = ()  # empty tuple - wrong number of args
         soft.SoftColor(red_args, green_args, blue_args)