def test_find_nearest_colour_by_euclidean_distance_when_no_distance_type_is_specified( self): colours_to_find = [Colour("#000000", "hex"), Colour("#010101", "hex")] origin_colour = Colour("#010101", "hex") self.assertEqual( Colour("#010101", "hex"), find_nearest_colour(colours_to_find, origin_colour, ""))
def test_colour_evaluates_rgb_from_rgba_decimal_when_instantiating(self): self.assertTupleEqual( (0, 0, 0), Colour("0 0 0 0", "rgba_decimal").rgb, ) self.assertTupleEqual((51, 51, 51), Colour("0.2 0.2 0.2 0.2", "rgba_decimal").rgb) self.assertTupleEqual((255, 255, 255), Colour("1 1 1 1", "rgba_decimal").rgb)
def test_find_nearest_colour_by_euclidean_distance(self): colours_to_find = [ Colour("#ff0000", "hex"), Colour("#00ff00", "hex"), Colour("#0000ff", "hex") ] origin_colour = Colour("#123456", "hex") self.assertEqual( Colour("#0000ff", "hex"), find_nearest_colour(colours_to_find, origin_colour, ""))
def test_colour_distance_calculates_uniform_distance_when_distance_type_is_specified( self): self.assertEqual( 1, ColourDistance(Colour("#010101", "hex"), Colour("#000000", "hex"))["uniform"])
def test_colour_distance_calculates_manhattan_distance_when_distance_type_is_specified( self): self.assertEqual( 3, ColourDistance(Colour("#010101", "hex"), Colour("#000000", "hex"))["manhattan"])
def test_colour_distance_calculates_euclidean_distance_when_distance_type_is_specified( self): self.assertEqual( math.sqrt(3), ColourDistance(Colour("#010101", "hex"), Colour("#000000", "hex"))["euclidean"])
def test_colour_distances_equal_when_they_have_same_differences(self): self.assertEqual( ColourDistance(Colour("#010101", "hex"), Colour("#000000", "hex")), ColourDistance(Colour("#020202", "hex"), Colour("#010101", "hex")))
def test_colour_distance_calculates_rgb_respective_differences(self): self.assertTupleEqual((1, 1, 1), ColourDistance(Colour("#010101", "hex"), Colour("#000000", "hex")).rgb_differences)
def test_colour_outputs_to_text_by_format(self): colour = Colour("#333333", "hex") self.assertEqual("#333333", format(colour, "hex")) self.assertEqual("0.2 0.2 0.2", format(colour, "rgba_decimal"))
def test_colours_subtraction_results_in_a_colour_distance(self): self.assertEqual( ColourDistance(Colour("#010101", "hex"), Colour("#000000", "hex")), Colour("#010101", "hex") - Colour("#000000", "hex"))
def test_colour_unequals_when_rgb_is_different(self): self.assertNotEqual(Colour("#000000", "hex"), Colour("#123456", "hex"))
def test_colour_equals_when_text_is_exactly_same(self): self.assertEqual(Colour("#000000", "hex"), Colour("#000000", "hex"))
def test_colour_represents_twice(self): colour = Colour("#000000", "hex") self.assertEqual("Colour(original_text=#000000, rgb=(0, 0, 0))", repr(colour)) self.assertEqual("Colour(original_text=#000000, rgb=(0, 0, 0))", repr(colour))
def test_colour_evaluates_rgb_from_hex_when_instantiating(self): self.assertTupleEqual((0, 0, 0), Colour("#000000", "hex").rgb)
def test_colour_keep_original_text_when_instantiating(self): self.assertEqual("#000000", Colour("#000000", "hex").original_text)