| 151 | | pass |
|---|
| | 151 | """ |
|---|
| | 152 | Rules for class functionality: |
|---|
| | 153 | - color names are strings predefined in a dictionary |
|---|
| | 154 | - if a name is not in the dictionary, treat it as a hex string or color tuple string |
|---|
| | 155 | |
|---|
| | 156 | Class Requirements for proper behavior go here: |
|---|
| | 157 | - colorTupleFromName should return a valid color tuple for all valid color name inputs |
|---|
| | 158 | - colorTupleFromName should return a valid color tuple for all valid hex string inputs |
|---|
| | 159 | - colorTupleFromName should return a valid color tuple for all valid color tuple string inputs |
|---|
| | 160 | - colorTupleFromName should fail when recieving an input that is not a valid color name, |
|---|
| | 161 | hex string input, or color tuple string |
|---|
| | 162 | """ |
|---|
| | 163 | |
|---|
| | 164 | #happy path tests |
|---|
| | 165 | def testKnownColorValues(self): |
|---|
| | 166 | """colorTupleFromName should return a known value for a known color name input""" |
|---|
| | 167 | for name in dColors.colorDict.keys(): |
|---|
| | 168 | result = dColors.colorTupleFromName(name) |
|---|
| | 169 | self.assertEqual(result, dColors.colorDict[name]) |
|---|
| | 170 | |
|---|
| | 171 | #need to refactor these next 2. Test smells for repeated code tests |
|---|
| | 172 | def testKnownHexStringValues(self): |
|---|
| | 173 | """colorTupleFromName should return a known value for a known hex string input""" |
|---|
| | 174 | self.assertEqual(dColors.colorTupleFromName("#010101"), (1, 1, 1)) |
|---|
| | 175 | |
|---|
| | 176 | def testKnownColorTupleStringValues(self): |
|---|
| | 177 | """colorTupleFromName should return a known value for a known color tuple string input""" |
|---|
| | 178 | self.assertEqual(dColors.colorTupleFromName("(1, 1, 1)"), (1, 1, 1)) |
|---|
| | 179 | |
|---|
| | 180 | #error tests |
|---|
| | 181 | def testColorNameError(self): |
|---|
| | 182 | """colorTupleFromName should fail when given a string that is not a valid color name, hex string, |
|---|
| | 183 | or color tuple string""" |
|---|
| | 184 | self.assertRaises(KeyError, dColors.colorTupleFromName, "Some Invalid Color Name") |
|---|
| 154 | | pass |
|---|
| | 187 | """ |
|---|
| | 188 | Rules for class functionality: |
|---|
| | 189 | - tuple strings are in form of "(int, int, int)" |
|---|
| | 190 | - Color tuples must have three integers |
|---|
| | 191 | - Integers must be between 0-255 |
|---|
| | 192 | |
|---|
| | 193 | Class Requirements for proper behavior go here: |
|---|
| | 194 | - colorTupleFromString should return a valid tuple for all valid results |
|---|
| | 195 | - colorTupleFromString should fail when recieving an improperly formatted string |
|---|
| | 196 | - colorTupleFromString should fail when there are not three elements in tuple representation of string |
|---|
| | 197 | - colorTupleFromString should fail when elements in the string are not integers |
|---|
| | 198 | - colorTupleFromString should fail when integer elements are not in range 0-255 |
|---|
| | 199 | """ |
|---|
| | 200 | |
|---|
| | 201 | #happy path tests |
|---|
| | 202 | def testKnownValues(self): |
|---|
| | 203 | """colorTupleFromString should return known results for known values""" |
|---|
| | 204 | for a in range(256): |
|---|
| | 205 | test = "(%i, %i, %i)" % (a, 255-a, a) |
|---|
| | 206 | result = dColors.colorTupleFromString(test) |
|---|
| | 207 | self.assertEqual((a, 255-a, a), result) |
|---|
| | 208 | |
|---|
| | 209 | test = "(%i, %i, %i)" % (a, a, a) |
|---|
| | 210 | result = dColors.colorTupleFromString(test) |
|---|
| | 211 | self.assertEqual((a, a, a), result) |
|---|
| | 212 | |
|---|
| | 213 | #Error Path Tests |
|---|
| | 214 | def testMissingCommas(self): |
|---|
| | 215 | """colorTupleFromString should fail with a lack of commas between integer values""" |
|---|
| | 216 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1 1, 1)") |
|---|
| | 217 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1 1)") |
|---|
| | 218 | |
|---|
| | 219 | def testMissingParentheses(self): |
|---|
| | 220 | """colorTupleFromString should fail with a lack of parentheses surrounding the tuple""" |
|---|
| | 221 | self.assertRaises(KeyError, dColors.colorTupleFromString, "1, 1, 1)") |
|---|
| | 222 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1, 1") |
|---|
| | 223 | |
|---|
| | 224 | def testTupleTooSmall(self): |
|---|
| | 225 | """colorTupleFromString should fail when the number of integer elements in the string is below 3""" |
|---|
| | 226 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1)") |
|---|
| | 227 | |
|---|
| | 228 | def testTupleTooLarge(self): |
|---|
| | 229 | """colorTupleFromString should fail when the number of integer elements in the string is above 3""" |
|---|
| | 230 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1, 1, 1)") |
|---|
| | 231 | |
|---|
| | 232 | def testTupleNonInteger(self): |
|---|
| | 233 | """colorTupleFromString should fail when one or more of the numbers are non-integers""" |
|---|
| | 234 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1.5, 1, 1)") |
|---|
| | 235 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1.5, 1)") |
|---|
| | 236 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1, 1.5)") |
|---|
| | 237 | |
|---|
| | 238 | def testIntegerTooLarge(self): |
|---|
| | 239 | """colorTupleFromTest should fail when one or more of the integers is above 255""" |
|---|
| | 240 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(256, 1, 1)") |
|---|
| | 241 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 256, 1)") |
|---|
| | 242 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1, 256)") |
|---|
| | 243 | |
|---|
| | 244 | def testIntegerTooSmall(self): |
|---|
| | 245 | """colorTupleFromTest should fail when one or more of the integers is below 0""" |
|---|
| | 246 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(-1, 1, 1)") |
|---|
| | 247 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, -1, 1)") |
|---|
| | 248 | self.assertRaises(KeyError, dColors.colorTupleFromString, "(1, 1, -1)") |
|---|