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): |
| 11 | def codelab_test(self, alliance, letter=None, img_path=None): |
| 12 | if img_path is None: |
| 13 | img_path = "%s_%s.png" % (alliance.name.lower(), |
| 14 | letter.name.lower()) |
| 15 | mask, path = codelab.galactic_search_path(img_path) |
| 16 | |
| 17 | cv.imwrite("test_" + img_path, mask) |
| 18 | |
| 19 | self.assertEqual(path.alliance, alliance) |
| 20 | if letter is not None: |
| 21 | self.assertEqual(path.letter, letter) |
| 22 | |
| 23 | def test_red_a(self): |
| 24 | self.codelab_test(codelab.Alliance.RED, codelab.Letter.A) |
| 25 | |
| 26 | def test_red_b(self): |
| 27 | self.codelab_test(codelab.Alliance.RED, codelab.Letter.B) |
| 28 | |
| 29 | def test_blue_a(self): |
| 30 | self.codelab_test(codelab.Alliance.BLUE, codelab.Letter.A) |
| 31 | |
| 32 | def test_blue_b(self): |
| 33 | self.codelab_test(codelab.Alliance.BLUE, codelab.Letter.B) |
| 34 | |
| 35 | def test_unknown_path(self): |
| 36 | """ Makes sure that Alliance.UNKNOWN is returned when there aren't balls in an image """ |
| 37 | self.codelab_test(codelab.Alliance.UNKNOWN, img_path="unknown.png") |
| 38 | |
| 39 | |
| 40 | if __name__ == "__main__": |
| 41 | unittest.main() |