-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_case.py
More file actions
142 lines (107 loc) · 3.72 KB
/
test_case.py
File metadata and controls
142 lines (107 loc) · 3.72 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import os
import sys
import unittest
sys.path.append(os.path.abspath(".."))
from geek_for_geeks.challenge.move_zero import pushZerosToEnd
from geek_for_geeks.challenge.reverse_an_array import reverseArray
from geek_for_geeks.challenge.rotate_an_array import rotateArr
from geek_for_geeks.challenge.secondlargest import getSecondLargest
from geek_for_geeks.challenge.stock_buy_and_sell import maximumProfit
class Test_getSecondLargest:
def test_basic(self):
assert getSecondLargest([2, 3, 6, 6, 5]) == 5
def test_all_same(self):
assert getSecondLargest([4, 4, 4]) == -1
def test_one_element(self):
assert getSecondLargest([10]) == -1
def test_negative_numbers(self):
assert getSecondLargest([-5, -2, -9, -1]) == -2
def test_empty_array(self):
assert getSecondLargest([]) == -1
class TestPushZerosToEnd:
def test_general_case(self):
arr = [1, 0, 2, 0, 4, 0, 5]
expected = [1, 2, 4, 5, 0, 0, 0]
pushZerosToEnd(arr)
assert arr == expected
def test_all_zeros(self):
arr = [0, 0, 0, 0]
expected = [0, 0, 0, 0]
pushZerosToEnd(arr)
assert arr == expected
def test_no_zeros(self):
arr = [1, 2, 3, 4]
expected = [1, 2, 3, 4]
pushZerosToEnd(arr)
assert arr == expected
def test_empty_list(self):
arr = []
expected = []
pushZerosToEnd(arr)
assert arr == expected
def test_single_element_zero(self):
arr = [0]
expected = [0]
pushZerosToEnd(arr)
assert arr == expected
def test_single_element_nonzero(self):
arr = [5]
expected = [5]
pushZerosToEnd(arr)
assert arr == expected
def test_mixed_types(self):
arr = [0, 1, 0, 0, 2, 0, 3]
expected = [1, 2, 3, 0, 0, 0, 0]
pushZerosToEnd(arr)
assert arr == expected
class TestReverseArray:
def test_even_length(self):
arr = [1, 2, 3, 4]
expected = [4, 3, 2, 1]
assert reverseArray(arr) == expected
def test_odd_length(self):
arr = [1, 2, 3, 4, 5]
expected = [5, 4, 3, 2, 1]
assert reverseArray(arr) == expected
def test_single_element(self):
arr = [7]
expected = [7]
assert reverseArray(arr) == expected
def test_empty_list(self):
arr = []
expected = []
assert reverseArray(arr) == expected
def test_palindrome_list(self):
arr = [1, 2, 3, 2, 1]
expected = [1, 2, 3, 2, 1]
assert reverseArray(arr) == expected
class TestRotateArr:
def test_rotate_by_two(self):
arr = [1, 2, 3, 4, 5]
rotated = rotateArr(arr, 2)
assert rotated == [3, 4, 5, 1, 2]
def test_rotate_by_zero(self):
arr = [1, 2, 3]
rotated = rotateArr(arr, 0)
assert rotated == [1, 2, 3]
def test_rotate_by_length(self):
arr = [1, 2, 3]
rotated = rotateArr(arr, 3)
assert rotated == [1, 2, 3]
def test_rotate_by_more_than_length(self):
arr = [1, 2, 3, 4]
rotated = rotateArr(arr, 6) # 6 % 4 = 2
assert rotated == [3, 4, 1, 2]
class TestMaximumProfit(unittest.TestCase):
def test_empty_list(self):
self.assertEqual(maximumProfit([]), 0)
def test_single_day(self):
self.assertEqual(maximumProfit([10]), 0)
def test_increasing_prices(self):
self.assertEqual(maximumProfit([1, 2, 3, 4, 5]), 4)
def test_decreasing_prices(self):
self.assertEqual(maximumProfit([5, 4, 3, 2, 1]), 0)
def test_fluctuating_prices(self):
self.assertEqual(maximumProfit([7, 1, 5, 3, 6, 4]), 7)
def test_all_same_prices(self):
self.assertEqual(maximumProfit([2, 2, 2, 2, 2]), 0)