milind-u | 7d834eb | 2021-11-20 08:46:11 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | import unittest |
| 4 | import cv2 as cv |
| 5 | |
| 6 | import codelab |
| 7 | |
| 8 | |
| 9 | # TODO(milind): this should be integrated with bazel |
| 10 | class TestCodelab(unittest.TestCase): |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 11 | |
milind-u | 7d834eb | 2021-11-20 08:46:11 -0800 | [diff] [blame] | 12 | def codelab_test(self, alliance, letter=None, img_path=None): |
| 13 | if img_path is None: |
| 14 | img_path = "%s_%s.png" % (alliance.name.lower(), |
| 15 | letter.name.lower()) |
| 16 | mask, path = codelab.galactic_search_path(img_path) |
| 17 | |
| 18 | cv.imwrite("test_" + img_path, mask) |
| 19 | |
| 20 | self.assertEqual(path.alliance, alliance) |
| 21 | if letter is not None: |
| 22 | self.assertEqual(path.letter, letter) |
| 23 | |
| 24 | def test_red_a(self): |
| 25 | self.codelab_test(codelab.Alliance.RED, codelab.Letter.A) |
| 26 | |
| 27 | def test_red_b(self): |
| 28 | self.codelab_test(codelab.Alliance.RED, codelab.Letter.B) |
| 29 | |
| 30 | def test_blue_a(self): |
| 31 | self.codelab_test(codelab.Alliance.BLUE, codelab.Letter.A) |
| 32 | |
| 33 | def test_blue_b(self): |
| 34 | self.codelab_test(codelab.Alliance.BLUE, codelab.Letter.B) |
| 35 | |
| 36 | def test_unknown_path(self): |
| 37 | """ Makes sure that Alliance.UNKNOWN is returned when there aren't balls in an image """ |
| 38 | self.codelab_test(codelab.Alliance.UNKNOWN, img_path="unknown.png") |
| 39 | |
| 40 | |
| 41 | if __name__ == "__main__": |
| 42 | unittest.main() |