class ColorTests(TestCase): """Tests of the Color class""" def setUp(self): """Color init should take name, coords, colorspace""" self.black = Color('black', (0,0,0)) self.red = Color('red', (255,0,0)) self.pink = Color('pink', (100,0,0)) self.green = Color('green', (0,255,0)) def test_str(self): """Color init and string representation should give correct result""" self.assertEqual(str(self.black), 'black:#000000') self.assertEqual(str(self.red), 'red:#ff0000') self.assertEqual(str(self.pink), 'pink:#640000') def test_toRGB(self): """Color toRGB should give correct r, g, b tuple (range 0-255)""" self.assertEqual(self.black.toRGB(), (0,0,0)) self.assertEqual(self.red.toRGB(), (255,0,0)) self.assertEqual(self.pink.toRGB(), (100,0,0)) def test_toMage(self): """Color toMage should give correct string using h, s, v tuple""" self.assertEqual(self.black.toMage(), '@hsvcolor {black} 0.0 0.0 0.0') self.assertEqual(self.red.toMage(), '@hsvcolor {red} 0.0 100.0 100.0') self.assertEqual(self.pink.toMage(), '@hsvcolor {pink} 0.0 100.0 39.2') self.assertEqual(self.green.toMage(), \ '@hsvcolor {green} 120.0 100.0 100.0') def test_toHex(self): """Color toHex should give correct hex string""" self.assertEqual(self.black.toHex(), '#000000') self.assertEqual(self.red.toHex(), '#ff0000') self.assertEqual(self.pink.toHex(), '#640000')
class ColorTests(TestCase): """Tests of the Color class""" def setUp(self): """Color init should take name, coords, colorspace""" self.black = Color('black', (0, 0, 0)) self.red = Color('red', (255, 0, 0)) self.pink = Color('pink', (100, 0, 0)) self.green = Color('green', (0, 255, 0)) def test_str(self): """Color init and string representation should give correct result""" self.assertEqual(str(self.black), 'black:#000000') self.assertEqual(str(self.red), 'red:#ff0000') self.assertEqual(str(self.pink), 'pink:#640000') def test_toRGB(self): """Color toRGB should give correct r, g, b tuple (range 0-255)""" self.assertEqual(self.black.toRGB(), (0, 0, 0)) self.assertEqual(self.red.toRGB(), (255, 0, 0)) self.assertEqual(self.pink.toRGB(), (100, 0, 0)) def test_toMage(self): """Color toMage should give correct string using h, s, v tuple""" self.assertEqual(self.black.toMage(), '@hsvcolor {black} 0.0 0.0 0.0') self.assertEqual(self.red.toMage(), '@hsvcolor {red} 0.0 100.0 100.0') self.assertEqual(self.pink.toMage(), '@hsvcolor {pink} 0.0 100.0 39.2') self.assertEqual(self.green.toMage(), \ '@hsvcolor {green} 120.0 100.0 100.0') def test_toHex(self): """Color toHex should give correct hex string""" self.assertEqual(self.black.toHex(), '#000000') self.assertEqual(self.red.toHex(), '#ff0000') self.assertEqual(self.pink.toHex(), '#640000')
def setUp(self): """Color init should take name, coords, colorspace""" self.black = Color('black', (0, 0, 0)) self.red = Color('red', (255, 0, 0)) self.pink = Color('pink', (100, 0, 0)) self.green = Color('green', (0, 255, 0))
def setUp(self): """Color init should take name, coords, colorspace""" self.black = Color("black", (0, 0, 0)) self.red = Color("red", (255, 0, 0)) self.pink = Color("pink", (100, 0, 0)) self.green = Color("green", (0, 255, 0))
class ColorTests(TestCase): """Tests of the Color class""" def setUp(self): """Color init should take name, coords, colorspace""" self.black = Color("black", (0, 0, 0)) self.red = Color("red", (255, 0, 0)) self.pink = Color("pink", (100, 0, 0)) self.green = Color("green", (0, 255, 0)) def test_str(self): """Color init and string representation should give correct result""" self.assertEqual(str(self.black), "black:#000000") self.assertEqual(str(self.red), "red:#ff0000") self.assertEqual(str(self.pink), "pink:#640000") def test_toRGB(self): """Color toRGB should give correct r, g, b tuple (range 0-255)""" self.assertEqual(self.black.toRGB(), (0, 0, 0)) self.assertEqual(self.red.toRGB(), (255, 0, 0)) self.assertEqual(self.pink.toRGB(), (100, 0, 0)) def test_toMage(self): """Color toMage should give correct string using h, s, v tuple""" self.assertEqual(self.black.toMage(), "@hsvcolor {black} 0.0 0.0 0.0") self.assertEqual(self.red.toMage(), "@hsvcolor {red} 0.0 100.0 100.0") self.assertEqual(self.pink.toMage(), "@hsvcolor {pink} 0.0 100.0 39.2") self.assertEqual(self.green.toMage(), "@hsvcolor {green} 120.0 100.0 100.0") def test_toHex(self): """Color toHex should give correct hex string""" self.assertEqual(self.black.toHex(), "#000000") self.assertEqual(self.red.toHex(), "#ff0000") self.assertEqual(self.pink.toHex(), "#640000") def test_toInt(self): """Color toHex should give correct hex string""" self.assertEqual(self.black.toInt(), 0) self.assertEqual(self.red.toInt(), 16711680) self.assertEqual(self.pink.toInt(), 6553600)