blob: 2ccf943a8266eeb57258ae514d683a09a1fb0e7b [file] [log] [blame]
milind-u7d834eb2021-11-20 08:46:11 -08001#!/usr/bin/python3
2
3import unittest
4import cv2 as cv
5
6import codelab
7
8
9# TODO(milind): this should be integrated with bazel
10class TestCodelab(unittest.TestCase):
Ravago Jones5127ccc2022-07-31 16:32:45 -070011
milind-u7d834eb2021-11-20 08:46:11 -080012 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
41if __name__ == "__main__":
42 unittest.main()