blob: e14d1cd51eb7def967fda92ea90442bd6e9cfc83 [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):
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
40if __name__ == "__main__":
41 unittest.main()