def test_cmyk_to_rgb(): """ Test translation function cmyk_to_rgb """ cmyk = introcs.CMYK(0.000, 100.0, 100.0, 0.000) rgb = a2.cmyk_to_rgb(cmyk) introcs.assert_equals('0.000', a2.str5(rgb.blue)) introcs.assert_equals('255.0', a2.str5(rgb.red)) introcs.assert_equals('0.000', a2.str5(rgb.green)) cmyk = introcs.CMYK(88.44, 76.99, 5.528, 21.96) rgb = a2.cmyk_to_rgb(cmyk) introcs.assert_equals('188.0', a2.str5(rgb.blue)) introcs.assert_equals('46.00', a2.str5(rgb.green)) introcs.assert_equals('23.00', a2.str5(rgb.red)) cmyk = introcs.CMYK(46.98, 55.10, 100.0, 2.122) rgb = a2.cmyk_to_rgb(cmyk) introcs.assert_equals('0.000', a2.str5(rgb.blue)) introcs.assert_equals('112.0', a2.str5(rgb.green)) introcs.assert_equals('132.0', a2.str5(rgb.red))
def test_rgb_to_cmyk(): """ Test translation function rgb_to_cmyk """ rgb = introcs.RGB(255, 255, 255) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('0.000', a2.str5(cmyk.cyan)) introcs.assert_equals('0.000', a2.str5(cmyk.magenta)) introcs.assert_equals('0.000', a2.str5(cmyk.yellow)) introcs.assert_equals('0.000', a2.str5(cmyk.black)) rgb = introcs.RGB(0, 0, 0) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('0.000', a2.str5(cmyk.cyan)) introcs.assert_equals('0.000', a2.str5(cmyk.magenta)) introcs.assert_equals('0.000', a2.str5(cmyk.yellow)) introcs.assert_equals('100.0', a2.str5(cmyk.black)) rgb = introcs.RGB(217, 43, 164) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('0.000', a2.str5(cmyk.cyan)) introcs.assert_equals('80.18', a2.str5(cmyk.magenta)) introcs.assert_equals('24.42', a2.str5(cmyk.yellow)) introcs.assert_equals('14.90', a2.str5(cmyk.black))
def test_str5(): """ Test function str5 """ introcs.assert_equals('130.6', a2.str5(130.59)) introcs.assert_equals('130.5', a2.str5(130.54)) introcs.assert_equals('100.0', a2.str5(100)) introcs.assert_equals('100.6', a2.str5(100.55)) introcs.assert_equals('99.57', a2.str5(99.566)) introcs.assert_equals('99.99', a2.str5(99.99)) introcs.assert_equals('100.0', a2.str5(99.995)) introcs.assert_equals('22.00', a2.str5(21.99575)) introcs.assert_equals('21.99', a2.str5(21.994)) introcs.assert_equals('10.01', a2.str5(10.013567)) introcs.assert_equals('10.00', a2.str5(10.000000005)) introcs.assert_equals('10.00', a2.str5(9.9999)) introcs.assert_equals('9.999', a2.str5(9.9993)) introcs.assert_equals('1.355', a2.str5(1.3546)) introcs.assert_equals('1.354', a2.str5(1.3544)) introcs.assert_equals('0.046', a2.str5(.0456)) introcs.assert_equals('0.045', a2.str5(.0453)) introcs.assert_equals('0.006', a2.str5(.0056)) introcs.assert_equals('0.001', a2.str5(.0013)) introcs.assert_equals('0.000', a2.str5(.0004)) introcs.assert_equals('0.001', a2.str5(.0009999))
def test_rgb_to_cmyk(): """ Test translation function rgb_to_cmyk """ rgb = introcs.RGB(255, 255, 255) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('0.000', a2.str5(cmyk.cyan)) introcs.assert_equals('0.000', a2.str5(cmyk.magenta)) introcs.assert_equals('0.000', a2.str5(cmyk.yellow)) introcs.assert_equals('0.000', a2.str5(cmyk.black)) rgb = introcs.RGB(0, 0, 0) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('0.000', a2.str5(cmyk.cyan)) introcs.assert_equals('0.000', a2.str5(cmyk.magenta)) introcs.assert_equals('0.000', a2.str5(cmyk.yellow)) introcs.assert_equals('100.0', a2.str5(cmyk.black)) rgb = introcs.RGB(217, 43, 164) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('0.000', a2.str5(cmyk.cyan)) introcs.assert_equals('80.18', a2.str5(cmyk.magenta)) introcs.assert_equals('24.42', a2.str5(cmyk.yellow)) introcs.assert_equals('14.90', a2.str5(cmyk.black)) rgb = introcs.RGB(0, 165, 39) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('100.0', a2.str5(cmyk.cyan)) introcs.assert_equals('0.000', a2.str5(cmyk.magenta)) introcs.assert_equals('76.36', a2.str5(cmyk.yellow)) introcs.assert_equals('35.29', a2.str5(cmyk.black)) rgb = introcs.RGB(23, 66, 188) cmyk = a2.rgb_to_cmyk(rgb) introcs.assert_equals('87.77', a2.str5(cmyk.cyan)) introcs.assert_equals('64.89', a2.str5(cmyk.magenta)) introcs.assert_equals('0.000', a2.str5(cmyk.yellow)) introcs.assert_equals('26.27', a2.str5(cmyk.black))
def test_hsv_to_rgb(): """ Test translation function hsv_to_rgb """ hsv = introcs.HSV(178, 0.999, 0.001) rgb = a2.hsv_to_rgb(hsv) introcs.assert_equals('0.000', a2.str5(rgb.red)) introcs.assert_equals('0.000', a2.str5(rgb.green)) introcs.assert_equals('0.000', a2.str5(rgb.blue)) hsv = introcs.HSV(77.23, 0.652, 0.148) rgb = a2.hsv_to_rgb(hsv) introcs.assert_equals('38.00', a2.str5(rgb.green)) introcs.assert_equals('31.00', a2.str5(rgb.red)) introcs.assert_equals('13.00', a2.str5(rgb.blue)) hsv = introcs.HSV(0.000, 1.000, 0.765) rgb = a2.hsv_to_rgb(hsv) introcs.assert_equals('0.000', a2.str5(rgb.green)) introcs.assert_equals('0.000', a2.str5(rgb.blue)) introcs.assert_equals('195.0', a2.str5(rgb.red)) hsv = introcs.HSV(240.1, 0.366, 0.771) rgb = a2.hsv_to_rgb(hsv) introcs.assert_equals('125.0', a2.str5(rgb.red)) introcs.assert_equals('125.0', a2.str5(rgb.green)) introcs.assert_equals('197.0', a2.str5(rgb.blue)) hsv = introcs.HSV(222.8, 1.000, 0.521) rgb = a2.hsv_to_rgb(hsv) introcs.assert_equals('0.000', a2.str5(rgb.red)) introcs.assert_equals('38.00', a2.str5(rgb.green)) introcs.assert_equals('133.0', a2.str5(rgb.blue))
def test_rgb_to_hsv(): """ Test translation function rgb_to_hsv """ rgb = introcs.RGB(255, 255, 255) hsv = a2.rgb_to_hsv(rgb) introcs.assert_equals('0.000', a2.str5(hsv.hue)) introcs.assert_equals('0.000', a2.str5(hsv.saturation)) introcs.assert_equals('1.000', a2.str5(hsv.value)) rgb = introcs.RGB(62, 7, 7) hsv = a2.rgb_to_hsv(rgb) introcs.assert_equals('0.000', a2.str5(hsv.hue)) introcs.assert_equals('0.887', a2.str5(hsv.saturation)) introcs.assert_equals('0.243', a2.str5(hsv.value)) rgb = introcs.RGB(188, 56, 9) hsv = a2.rgb_to_hsv(rgb) introcs.assert_equals('15.75', a2.str5(hsv.hue)) introcs.assert_equals('0.952', a2.str5(hsv.saturation)) introcs.assert_equals('0.737', a2.str5(hsv.value)) rgb = introcs.RGB(6, 2, 8) hsv = a2.rgb_to_hsv(rgb) introcs.assert_equals('280.0', a2.str5(hsv.hue)) introcs.assert_equals('0.750', a2.str5(hsv.saturation)) introcs.assert_equals('0.031', a2.str5(hsv.value)) rgb = introcs.RGB(24, 178, 88) hsv = a2.rgb_to_hsv(rgb) introcs.assert_equals('144.9', a2.str5(hsv.hue)) introcs.assert_equals('0.865', a2.str5(hsv.saturation)) introcs.assert_equals('0.698', a2.str5(hsv.value))