-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_steropesWP4.py
97 lines (83 loc) · 3.52 KB
/
test_steropesWP4.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
import cv2
import matplotlib.pyplot as plt
def test_imread_func():
# Test case 1: Rotate_to_Original = True
pathfile = "test_image.jpg"
Rotate_to_Original = True
expected_output = cv2.imread(pathfile)[::-1, ::-1]
assert (imread_func(pathfile, Rotate_to_Original) == expected_output).all()
# Test case 2: Rotate_to_Original = False
pathfile = "test_image.jpg"
Rotate_to_Original = False
expected_output = cv2.imread(pathfile)
assert (imread_func(pathfile, Rotate_to_Original) == expected_output).all()
# Test case 3: Rotate_to_Original = True, with different image
pathfile = "another_image.jpg"
Rotate_to_Original = True
expected_output = cv2.imread(pathfile)[::-1, ::-1]
assert (imread_func(pathfile, Rotate_to_Original) == expected_output).all()
# Test case 4: Rotate_to_Original = False, with different image
pathfile = "another_image.jpg"
Rotate_to_Original = False
expected_output = cv2.imread(pathfile)
assert (imread_func(pathfile, Rotate_to_Original) == expected_output).all()
print("All test cases passed!")
# Run the test function
test_imread_func()def test_change_colorspace():
# Test case 1: Convert to HSV color space
img = cv2.imread("test_image.jpg")
to_save_or_not = False
output_folder = ""
output_save_name = ""
colorspace = "hsv"
expected_output = np.zeros_like(img)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
r, g, b = img[i, j]
expected_output[i, j] = colorsys.rgb_to_hsv(r, g, b)
assert (change_colorspace(img, to_save_or_not, output_folder, output_save_name, colorspace) == expected_output).all()
# Test case 2: Convert to HLS color space
img = cv2.imread("test_image.jpg")
to_save_or_not = False
output_folder = ""
output_save_name = ""
colorspace = "hls"
expected_output = np.zeros_like(img)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
r, g, b = img[i, j]
expected_output[i, j] = colorsys.rgb_to_hls(r, g, b)
assert (change_colorspace(img, to_save_or_not, output_folder, output_save_name, colorspace) == expected_output).all()
# Test case 3: Convert to YIQ color space
img = cv2.imread("test_image.jpg")
to_save_or_not = False
output_folder = ""
output_save_name = ""
colorspace = "yiq"
expected_output = np.zeros_like(img)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
r, g, b = img[i, j]
expected_output[i, j] = colorsys.rgb_to_yiq(r, g, b)
assert (change_colorspace(img, to_save_or_not, output_folder, output_save_name, colorspace) == expected_output).all()
print("All test cases passed!")
# Run the test function
test_change_colorspace()def test_find_optimal_clusters_silhouette():
# Test case 1: Test with 2 clusters
data = np.array([[1, 2], [3, 4], [5, 6]])
max_clusters = 2
expected_output = 2
assert find_optimal_clusters_silhouette(data, max_clusters) == expected_output
# Test case 2: Test with 3 clusters
data = np.array([[1, 2], [3, 4], [5, 6]])
max_clusters = 3
expected_output = 3
assert find_optimal_clusters_silhouette(data, max_clusters) == expected_output
# Test case 3: Test with 4 clusters
data = np.array([[1, 2], [3, 4], [5, 6]])
max_clusters = 4
expected_output = 3
assert find_optimal_clusters_silhouette(data, max_clusters) == expected_output
print("All test cases passed!")
# Run the test function
test_find_optimal_clusters_silhouette()