-
Notifications
You must be signed in to change notification settings - Fork 0
/
torpedoes_tests.py
115 lines (91 loc) · 4.84 KB
/
torpedoes_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import cv2
import os
import json
from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
from tasks.torpedoes.holes_detector import HeartDetector as CVLocatorHeart
from tasks.torpedoes.holes_detector import EllipseDetector as CVLocatorEllipse
PATH_DIRECOTRY = "./tests/image_detectors/torpedoes/"
DELTA_CORDINATES = 0.05
class TestRunner:
def __init__(self):
self.runner = TextTestRunner(verbosity=2)
def run(self):
test_suite = TestSuite(tests=[
makeSuite(TestTorpedoLocatorCV)#,
#makeSuite(TestTorpedoLocatorML)
])
return self.runner.run(test_suite)
class TestTorpedoLocatorCV(TestCase):
'''
def test_get_general_coordinates(self):
# Test get_general_coordinates method of CV solution
with open(PATH_DIRECOTRY + "general_coordinates.json", "r") as read_file:
all_expected_coordinates = json.load(read_file)
for filename in os.listdir(PATH_DIRECOTRY):
if filename.endswith("_general.png"):
relative_filename = PATH_DIRECOTRY+filename
image = cv2.imread(relative_filename)
locator = CVLocator()
cordinates = locator.get_general_cordinates(image)
expected_coordinates = all_expected_coordinates[filename]
self.assertAlmostEqual(expected_coordinates['x'], cordinates['x'], delta=DELTA_CORDINATES)
self.assertAlmostEqual(expected_coordinates['y'], cordinates['y'], delta=DELTA_CORDINATES)
'''
def test_get_heart_coordinates(self):
# Test get_heart_coordinates method of CV solution
with open(PATH_DIRECOTRY + "heart_coordinates.json", "r") as read_file:
all_expected_coordinates = json.load(read_file)
for filename in os.listdir(PATH_DIRECOTRY):
if filename.endswith("_heart.png"):
relative_filename = PATH_DIRECOTRY+filename
image = cv2.imread(relative_filename)
locator = CVLocatorHeart()
coordinates = locator.get_heart_cordinates(image)
expected_coordinates = all_expected_coordinates[filename]
self.assertAlmostEqual(expected_coordinates['x'], coordinates['x'], delta=DELTA_CORDINATES)
self.assertAlmostEqual(expected_coordinates['y'], coordinates['y'], delta=DELTA_CORDINATES)
def test_get_ellipse_coordinates(self):
# Test get_heart_coordinates method of CV solution
with open(PATH_DIRECOTRY + "ellipse_coordinates.json", "r") as read_file:
all_expected_coordinates = json.load(read_file)
for filename in os.listdir(PATH_DIRECOTRY):
if filename.endswith("_ellipse.png"):
relative_filename = PATH_DIRECOTRY+filename
image = cv2.imread(relative_filename)
locator = CVLocatorEllipse()
coordinates = locator.get_ellipse_cordinates(image)
expected_coordinates = all_expected_coordinates[filename]
self.assertAlmostEqual(expected_coordinates['x_open'], coordinates['x_open'], delta=DELTA_CORDINATES)
self.assertAlmostEqual(expected_coordinates['y_open'], coordinates['y_open'], delta=DELTA_CORDINATES)
self.assertAlmostEqual(expected_coordinates['x_closed'], coordinates['x_closed'], delta=DELTA_CORDINATES)
self.assertAlmostEqual(expected_coordinates['y_closed'], coordinates['y_closed'], delta=DELTA_CORDINATES)
'''
def test_get_lever_coordinates(self):
# Test get_lever_coordinates method of CV solution
with open(PATH_DIRECOTRY + "lever_coordinates.json", "r") as read_file:
all_expected_coordinates = json.load(read_file)
for filename in os.listdir(PATH_DIRECOTRY):
if filename.endswith("_lever.png"):
relative_filename = PATH_DIRECOTRY+filename
image = cv2.imread(relative_filename)
locator = CVLocator()
cordinates = locator.get_lever_cordinates(image)
expected_coordinates = all_expected_coordinates[filename]
self.assertAlmostEqual(expected_coordinates['x'], cordinates['x'], delta=DELTA_CORDINATES)
self.assertAlmostEqual(expected_coordinates['y'], cordinates['y'], delta=DELTA_CORDINATES)
'''
class TestTorpedoLocatorML(TestCase):
def test_get_general_coordinates(self):
pass
def test_get_heart_coordinates(self):
pass
def test_get_ellipse_coordinates(self):
pass
def test_get_lever_coordinates(self):
pass
if __name__ == '__main__':
print("Torpedo tester")
test_runner = TestRunner()
results = test_runner.run()
if results.failures:
print("Tests fail")