def test_allcolors(self):
     myrange = (0,1,2,5,17,39,48,73,82,140,193,210,240,244,250,254,255)
     for r in myrange:
         for g in myrange:
             for b in myrange:
                 near = FindNearest(r,g,b)
                 assert near.all_slow() == near.all_fast(), 'Tested: {0}, {1}, {2}'.format(r,g,b)
 def test_exact(self):
     assert FindNearest(0,0,0).all_fast() == 0
     for n,color in enumerate(color_html):
         # Ignoring duplicates
         if n not in (16, 21, 46, 51, 196, 201, 226, 231, 244):
             rgb = (int(color[1:3],16), int(color[3:5],16), int(color[5:7],16))
             assert FindNearest(*rgb).all_fast() == n
Esempio n. 3
0
    def _init_number(self):
        """Should always be called after filling in r, g, b, and representation.
        Color will not be a reset color anymore."""

        if self.representation in (0, 1):
            number = FindNearest(*self.rgb).only_basic()
        elif self.representation == 2:
            number = FindNearest(*self.rgb).only_simple()
        elif self.representation in (3, 4):
            number = FindNearest(*self.rgb).all_fast()

        if self.number is None:
            self.number = number

        self.isreset = False
        self.exact = self.rgb == from_html(color_html[self.number])
        if not self.exact:
            self.number = number
 def test_simplecolor(self):
     assert FindNearest(1,2,4).only_basic() == 0
     assert FindNearest(0,255,0).only_basic() == 2
     assert FindNearest(100,100,0).only_basic() == 3
     assert FindNearest(140,140,140).only_basic() == 7
 def test_nearby(self):
     assert FindNearest(1,2,2).all_fast() == 0
     assert FindNearest(7,7,9).all_fast() == 232
Esempio n. 6
0
 def test_simplecolor(self):
     self.assertEqual(FindNearest(1,2,4).only_basic(), 0)
     self.assertEqual(FindNearest(0,255,0).only_basic(), 2)
     self.assertEqual(FindNearest(100,100,0).only_basic(), 3)
     self.assertEqual(FindNearest(140,140,140).only_basic(), 7)
Esempio n. 7
0
 def test_nearby(self):
     self.assertEqual(FindNearest(1,2,2).all_fast(),0)
     self.assertEqual(FindNearest(7,7,9).all_fast(),232)