def test_rgb_to_hsv(): """Test translation function rgb_to_hsv""" # pass # ADD TESTS TO ME rgb = colormodel.RGB(15, 5, 75) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals(248.6, hsv.hue) cornelltest.assert_equals(0.933, hsv.saturation) cornelltest.assert_equals(0.294, hsv.value) rgb = colormodel.RGB(0, 0, 0) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals(0.000, hsv.hue) cornelltest.assert_equals(0.000, hsv.saturation) cornelltest.assert_equals(0.000, hsv.value) rgb = colormodel.RGB(100, 100, 100) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals(0.000, hsv.hue) cornelltest.assert_equals(0.000, hsv.saturation) cornelltest.assert_equals(0.392, hsv.value) rgb = colormodel.RGB(235, 19, 25) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals(358.3, hsv.hue) cornelltest.assert_equals(0.919, hsv.saturation) cornelltest.assert_equals(0.922, hsv.value) rgb = colormodel.RGB(1, 2, 3) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals(210.0, hsv.hue) cornelltest.assert_equals(0.667, hsv.saturation) cornelltest.assert_equals(0.012, hsv.value)
def test_rgb_to_hsv(): """Test translation function rgb_to_hsv""" #MAX = MIN rgb = colormodel.RGB(255, 255, 255) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('0.000', a3.str5(hsv.saturation)) cornelltest.assert_equals('1.000', a3.str5(hsv.value)) rgb = colormodel.RGB(0, 0, 0) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('0.000', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.000', a3.str5(hsv.value)) rgb = colormodel.RGB(100, 100, 100) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('0.000', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.392', a3.str5(hsv.value)) #MAX = R and G >= B rgb = colormodel.RGB(200, 150, 100) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('30.00', a3.str5(hsv.hue)) cornelltest.assert_equals('0.500', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.784', a3.str5(hsv.value)) rgb = colormodel.RGB(242, 67, 67) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('0.723', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.949', a3.str5(hsv.value)) rgb = colormodel.RGB(255, 0, 0) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('1.000', a3.str5(hsv.saturation)) cornelltest.assert_equals('1.000', a3.str5(hsv.value)) #MAX = R and G < B rgb = colormodel.RGB(123, 87, 99) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('340.0', a3.str5(hsv.hue)) cornelltest.assert_equals('0.293', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.482', a3.str5(hsv.value)) #MAX = G rgb = colormodel.RGB(1, 6, 2) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('132.0', a3.str5(hsv.hue)) cornelltest.assert_equals('0.833', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.024', a3.str5(hsv.value)) #MAX = B rgb = colormodel.RGB(12, 64, 242) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('226.4', a3.str5(hsv.hue)) cornelltest.assert_equals('0.950', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.949', a3.str5(hsv.value))
def register(self): """Initialize color values and force refresh""" self.rgb = colormodel.RGB(0, 255, 0) self.cmyk = a3.rgb_to_cmyk(self.rgb) assert (self.cmyk == None or type(self.cmyk) == colormodel.CMYK), 'rgb_to_cmyk does not return a CMYK object' self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.update()
def on_rgb_press(self,r,g,b): """Call back to rgb button""" self.rgb = colormodel.RGB(r, g, b) self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.cmyk = a3.rgb_to_cmyk(self.rgb) assert (self.cmyk == None or type(self.cmyk) == colormodel.CMYK), 'rgb_to_cmyk does not return a CMYK object' self.update()
def on_rgb_press(self,r,g,b): """Call back to rgb button""" self.bot.clear() self.rgb = colormodel.RGB(r, g, b) self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.cmyk = a3.rgb_to_cmyk(self.rgb) assert (self.cmyk == None or type(self.cmyk) == colormodel.CMYK), 'rgb_to_cmyk does not return a CMYK object' self.update()
def on_cmyk_press(self,c,m,y,k): """Call back to cmyk button""" self.cmyk = colormodel.CMYK(c, m, y, k) temp = a3.cmyk_to_rgb(self.cmyk) assert (temp == None or type(temp) == colormodel.RGB), 'cmyk_to_rgb does not return a RGB object' self.rgb = self.rgb if temp is None else temp self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.update()
def register(self): """Initialize color values and force refresh""" active = True self.rgb = colormodel.RGB(0, 255, 0) self.cmyk = a3.rgb_to_cmyk(self.rgb) assert (self.cmyk == None or type(self.cmyk) == colormodel.CMYK), 'rgb_to_cmyk does not return a CMYK object' self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.update()
def on_cmyk_press(self,c,m,y,k): """Call back to cmyk button""" self.bot.clear() self.cmyk = colormodel.CMYK(c, m, y, k) temp = a3.cmyk_to_rgb(self.cmyk) assert (temp == None or type(temp) == colormodel.RGB), 'cmyk_to_rgb does not return a RGB object' self.rgb = self.rgb if temp is None else temp self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.update()
def test_rgb_to_hsv(): """Test translation function rgb_to_hsv""" rgb = colormodel.RGB(255, 255, 255) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("0.000", a3.round5(hsv.hue)) cunittest.assert_equals("0.000", a3.round5(hsv.saturation)) cunittest.assert_equals("1.000", a3.round5(hsv.value)) rgb = colormodel.RGB(0, 0, 0) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("0.000", a3.round5(hsv.hue)) cunittest.assert_equals("0.000", a3.round5(hsv.saturation)) cunittest.assert_equals("0.000", a3.round5(hsv.value)) rgb = colormodel.RGB(217, 43, 164) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("318.3", a3.round5(hsv.hue)) cunittest.assert_equals("0.802", a3.round5(hsv.saturation)) cunittest.assert_equals("0.851", a3.round5(hsv.value))
def test_rgb_to_hsv(): """ Test translation function rgb_to_hsv """ # Testing MAX == MIN rgb = cornell.RGB(0, 0, 0) hsv = a3.rgb_to_hsv(rgb) cornell.assert_equals('0.000', a3.str5(hsv.hue)) cornell.assert_equals('0.000', a3.str5(hsv.saturation)) cornell.assert_equals('0.000', a3.str5(hsv.value)) cornell.assert_equals('(0.000, 0.000, 0.000)', a3.str5_hsv(hsv)) # Testing MAX == R and G >= B rgb = cornell.RGB(255, 150, 50) hsv = a3.rgb_to_hsv(rgb) cornell.assert_equals('29.27', a3.str5(hsv.hue)) cornell.assert_equals('0.804', a3.str5(hsv.saturation)) cornell.assert_equals('1.000', a3.str5(hsv.value)) cornell.assert_equals('(29.27, 0.804, 1.000)', a3.str5_hsv(hsv)) # Test MAX == R and G < B rgb = cornell.RGB(255, 50, 150) hsv = a3.rgb_to_hsv(rgb) cornell.assert_equals('330.7', a3.str5(hsv.hue)) cornell.assert_equals('0.804', a3.str5(hsv.saturation)) cornell.assert_equals('1.000', a3.str5(hsv.value)) cornell.assert_equals('(330.7, 0.804, 1.000)', a3.str5_hsv(hsv)) # Test MAX == G rgb = cornell.RGB(100, 240, 20) hsv = a3.rgb_to_hsv(rgb) cornell.assert_equals('98.18', a3.str5(hsv.hue)) cornell.assert_equals('0.917', a3.str5(hsv.saturation)) cornell.assert_equals('0.941', a3.str5(hsv.value)) cornell.assert_equals('(98.18, 0.917, 0.941)', a3.str5_hsv(hsv)) # Test MAX == B rgb = cornell.RGB(100, 20, 240) hsv = a3.rgb_to_hsv(rgb) cornell.assert_equals('261.8', a3.str5(hsv.hue)) cornell.assert_equals('0.917', a3.str5(hsv.saturation)) cornell.assert_equals('0.941', a3.str5(hsv.value)) cornell.assert_equals('(261.8, 0.917, 0.941)', a3.str5_hsv(hsv))
def on_rgb_slide(self,r,g,b): """Call back to rgb sliders""" if not self.active: return red = int(round(r / 100.0)) green = int(round(g / 100.0)) blue = int(round(b / 100.0)) self.rgb = colormodel.RGB(red, green, blue) self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.cmyk = a3.rgb_to_cmyk(self.rgb) assert (self.cmyk == None or type(self.cmyk) == colormodel.CMYK), 'rgb_to_cmyk does not return a CMYK object' self.update()
def test_rgb_to_hsv(): """ Test translation function rgb_to_hsv """ print('Testing rgb_to_hsv') # ADD TESTS TO ME # if M=m rgb = introcs.RGB(0,0,0) hsv = a3.rgb_to_hsv(rgb) introcs.assert_equals(0.0,round(hsv.hue,3)) introcs.assert_equals(0.0,round(hsv.saturation,3)) introcs.assert_equals(0.0,round(hsv.value,3)) #if M == red and green >= blue rgb = introcs.RGB(255,240,150) hsv = a3.rgb_to_hsv(rgb) introcs.assert_equals(51.429,round(hsv.hue,3)) introcs.assert_equals(0.412,round(hsv.saturation,3)) introcs.assert_equals(1.0,round(hsv.value,3)) #M == red and green < blue rgb = introcs.RGB(255,150,240) hsv = a3.rgb_to_hsv(rgb) introcs.assert_equals(308.571,round(hsv.hue,3)) introcs.assert_equals(0.412,round(hsv.saturation,3)) introcs.assert_equals(1.0,round(hsv.value,3)) #M == green rgb = introcs.RGB(100,255,100) hsv = a3.rgb_to_hsv(rgb) introcs.assert_equals(120.0,round(hsv.hue,3)) introcs.assert_equals(0.608,round(hsv.saturation,3)) introcs.assert_equals(1.0,round(hsv.value,3)) #M == blue rgb = introcs.RGB(100,100,255) hsv = a3.rgb_to_hsv(rgb) introcs.assert_equals(240.0,round(hsv.hue,3)) introcs.assert_equals(0.608,round(hsv.saturation,3)) introcs.assert_equals(1.0,round(hsv.value,3)) print('Tests for rgb_to_hsv passed')
def on_cmyk_slide(self,c,m,y,k): """Call back to cmyk sliders""" if not self.active: return cyan = c / 100.0 magenta = m / 100.0 yellow = y / 100.0 black = k / 100.0 self.cmyk = colormodel.CMYK(cyan, magenta, yellow, black) temp = a3.cmyk_to_rgb(self.cmyk) assert (temp == None or type(temp) == colormodel.RGB), 'cmyk_to_rgb does not return a RGB object' self.rgb = self.rgb if temp is None else temp self.hsv = a3.rgb_to_hsv(self.rgb) assert (self.hsv == None or type(self.hsv) == colormodel.HSV), 'rgb_to_hsv does not return a HSV object' self.update()
def test_rgb_to_hsv(): """Test translation function rgb_to_hsv""" #Test rgb_to_hsv when MAX = MIN and MAX = 0: rgb = colormodel.RGB(0, 0, 0) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("0.000", a3.round5(hsv.hue)) cunittest.assert_equals("0.000", a3.round5(hsv.saturation)) cunittest.assert_equals("0.000", a3.round5(hsv.value)) #Test rgb_to_hsv when MAX = MIN and MAX <> 0: rgb = colormodel.RGB(100, 100, 100) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("0.000", a3.round5(hsv.hue)) cunittest.assert_equals("0.000", a3.round5(hsv.saturation)) cunittest.assert_equals("0.392", a3.round5(hsv.value)) #Test rgb_to_hsv when MAX = R and G >=B: rgb = colormodel.RGB(161, 42, 42) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("0.000", a3.round5(hsv.hue)) cunittest.assert_equals("0.739", a3.round5(hsv.saturation)) cunittest.assert_equals("0.631", a3.round5(hsv.value)) rgb = colormodel.RGB(161, 72, 42) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("15.13", a3.round5(hsv.hue)) cunittest.assert_equals("0.739", a3.round5(hsv.saturation)) cunittest.assert_equals("0.631", a3.round5(hsv.value)) #Test rgb_to_hsv when MAX = R and G < B: rgb = colormodel.RGB(161, 42, 72) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("344.9", a3.round5(hsv.hue)) cunittest.assert_equals("0.739", a3.round5(hsv.saturation)) cunittest.assert_equals("0.631", a3.round5(hsv.value)) #Test rgb_to_hsv when MAX = G: rgb = colormodel.RGB(17, 101, 19) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("121.4", a3.round5(hsv.hue)) cunittest.assert_equals("0.832", a3.round5(hsv.saturation)) cunittest.assert_equals("0.396", a3.round5(hsv.value)) #Test rgb_to_hsv when MAX = B: rgb = colormodel.RGB(21, 100, 255) hsv = a3.rgb_to_hsv(rgb) cunittest.assert_equals("219.7", a3.round5(hsv.hue)) cunittest.assert_equals("0.918", a3.round5(hsv.saturation)) cunittest.assert_equals("1.000", a3.round5(hsv.value))
def test_rgb_to_hsv(): """Test translation function rgb_to_hsv""" cunittest.assert_equals(colormodel.HSV(0.000, 0.000, 0.471), a3.rgb_to_hsv(\ colormodel.RGB(120,120,120))) #All equal cunittest.assert_equals(colormodel.HSV(10.94, 0.795, 0.784), a3.rgb_to_hsv(\ colormodel.RGB(200,70,41))) #R > G > B cunittest.assert_equals(colormodel.HSV(356.3, 0.696, 0.902), a3.rgb_to_hsv(\ colormodel.RGB(230,70,80))) #R > G < B cunittest.assert_equals(colormodel.HSV(110.7, 0.794, 0.953), a3.rgb_to_hsv(\ colormodel.RGB(80, 243, 50))) #G is highest cunittest.assert_equals(colormodel.HSV(229.0, 0.600, 0.784), a3.rgb_to_hsv(\ colormodel.RGB(80, 102, 200)))#B is highest cunittest.assert_equals(colormodel.HSV(0.000, 0.000, 0.000), a3.rgb_to_hsv(\ colormodel.RGB(0, 0, 0))) #All low cunittest.assert_equals(colormodel.HSV(0.000, 0.000, 1.000), a3.rgb_to_hsv(\ colormodel.RGB(255, 255, 255))) #All high
def test_rgb_to_hsv(): """ Test translation function rgb_to_hsv """ rgb = cornell.RGB(0, 0, 0); hsv = a3.rgb_to_hsv(rgb); cornell.assert_equals('0.000', a3.str5(hsv.hue)) cornell.assert_equals('0.000', a3.str5(hsv.saturation)) cornell.assert_equals('0.000', a3.str5(hsv.value)) rgb = cornell.RGB(150, 10, 5); hsv = a3.rgb_to_hsv(rgb); cornell.assert_equals('2.069', a3.str5(hsv.hue)) cornell.assert_equals('0.967', a3.str5(hsv.saturation)) cornell.assert_equals('0.588', a3.str5(hsv.value)) rgb = cornell.RGB(150, 10, 10); hsv = a3.rgb_to_hsv(rgb); cornell.assert_equals('0.000', a3.str5(hsv.hue)) cornell.assert_equals('0.933', a3.str5(hsv.saturation)) cornell.assert_equals('0.588', a3.str5(hsv.value)) rgb = cornell.RGB(150, 60, 10); hsv = a3.rgb_to_hsv(rgb); cornell.assert_equals('21.43', a3.str5(hsv.hue)) cornell.assert_equals('0.933', a3.str5(hsv.saturation)) cornell.assert_equals('0.588', a3.str5(hsv.value)) rgb = cornell.RGB(150, 255, 10); hsv = a3.rgb_to_hsv(rgb); cornell.assert_equals('85.71', a3.str5(hsv.hue)) cornell.assert_equals('0.961', a3.str5(hsv.saturation)) cornell.assert_equals('1.000', a3.str5(hsv.value)) rgb = cornell.RGB(150, 76, 255); hsv = a3.rgb_to_hsv(rgb); cornell.assert_equals('264.8', a3.str5(hsv.hue)) cornell.assert_equals('0.702', a3.str5(hsv.saturation)) cornell.assert_equals('1.000', a3.str5(hsv.value)) rgb = cornell.RGB(255, 255, 255); hsv = a3.rgb_to_hsv(rgb); cornell.assert_equals('0.000', a3.str5(hsv.hue)) cornell.assert_equals('0.000', a3.str5(hsv.saturation)) cornell.assert_equals('1.000', a3.str5(hsv.value))
def test_rgb_to_hsv(): """Test translation function rgb_to_hsv""" rgb= colormodel.RGB(20,20,20) hsv= a3.rgb_to_hsv(rgb) cornelltest.assert_equals( '0.000', a3.str5(hsv.hue)) rgb= colormodel.RGB(100,25,20) hsv= a3.rgb_to_hsv(rgb) cornelltest.assert_equals( '3.750', a3.str5(hsv.hue)) cornelltest.assert_equals( '0.800', a3.str5(hsv.saturation)) cornelltest.assert_equals( '0.392', a3.str5(hsv.value)) rgb= colormodel.RGB(200,50,100) hsv= a3.rgb_to_hsv(rgb) cornelltest.assert_equals( '340.0', a3.str5(hsv.hue)) cornelltest.assert_equals( '0.750', a3.str5(hsv.saturation)) cornelltest.assert_equals( '0.784', a3.str5(hsv.value)) rgb= colormodel.RGB(20,100,20) hsv= a3.rgb_to_hsv(rgb) cornelltest.assert_equals( '120.0', a3.str5(hsv.hue)) cornelltest.assert_equals( '0.800', a3.str5(hsv.saturation)) cornelltest.assert_equals( '0.392', a3.str5(hsv.value)) rgb= colormodel.RGB(20,20,100) hsv= a3.rgb_to_hsv(rgb) cornelltest.assert_equals( '240.0', a3.str5(hsv.hue)) cornelltest.assert_equals( '0.800', a3.str5(hsv.saturation)) cornelltest.assert_equals( '0.392', a3.str5(hsv.value)) rgb= colormodel.RGB(0,0,0) hsv= a3.rgb_to_hsv(rgb) cornelltest.assert_equals( '0.000', a3.str5(hsv.hue)) cornelltest.assert_equals( '0.000', a3.str5(hsv.saturation)) cornelltest.assert_equals( '0.000', a3.str5(hsv.value)) rgb= colormodel.RGB(20,25,25) hsv= a3.rgb_to_hsv(rgb) cornelltest.assert_equals( '180.0', a3.str5(hsv.hue)) cornelltest.assert_equals( '0.200', a3.str5(hsv.saturation)) cornelltest.assert_equals( '0.098', a3.str5(hsv.value))
def test_rgb_to_hsv(): """Test translation function rgb_to_hsv""" rgb = colormodel.RGB(255, 255, 255) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('0.000', a3.str5(hsv.saturation)) cornelltest.assert_equals('1.000', a3.str5(hsv.value)) rgb = colormodel.RGB(245, 87, 7) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('20.17', a3.str5(hsv.hue)) cornelltest.assert_equals('0.971', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.961', a3.str5(hsv.value)) rgb = colormodel.RGB(99, 33, 33) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('0.667', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.388', a3.str5(hsv.value)) rgb = colormodel.RGB(54, 2, 3) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('358.8', a3.str5(hsv.hue)) cornelltest.assert_equals('0.963', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.212', a3.str5(hsv.value)) rgb = colormodel.RGB(99, 100, 98) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('90.00', a3.str5(hsv.hue)) cornelltest.assert_equals('0.020', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.392', a3.str5(hsv.value)) rgb = colormodel.RGB(100, 1, 150) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('279.9', a3.str5(hsv.hue)) cornelltest.assert_equals('0.993', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.588', a3.str5(hsv.value)) rgb = colormodel.RGB(0, 0, 0) hsv = a3.rgb_to_hsv(rgb) cornelltest.assert_equals('0.000', a3.str5(hsv.hue)) cornelltest.assert_equals('0.000', a3.str5(hsv.saturation)) cornelltest.assert_equals('0.000', a3.str5(hsv.value))