-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_consecutiveMax.py
58 lines (54 loc) · 1.93 KB
/
test_consecutiveMax.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
import pytest
def findConsecutiveMax(array):
maxCharacter=""
numMax=0
lastChar=""
numCurrent=1
try:
list(array)
except:
raise TypeError('Input must be an array or list.')
for i,x in enumerate(array):
if x == "":
continue
if x==lastChar:
numCurrent=numCurrent+1
else:
numCurrent=1
if numCurrent>numMax:
numMax=numCurrent
maxCharacter=x
lastChar=x
return maxCharacter
def test_consecMax():
res = findConsecutiveMax(["z","a","a","z","y","y","","y","z","z","z"])
assert res=="y"
res = findConsecutiveMax(["","a","a","z","y","y","","y","z","z","z"])
assert res=="y"
res = findConsecutiveMax(["z","a","a","z","y","y","","y","z","z",""])
assert res=="y"
res = findConsecutiveMax(["z","a","a","z","y","y","","","y","z","z","z"])
assert res=="y"
res = findConsecutiveMax(["z","a","a","z","y","","y","","y","z","z","z"])
assert res=="y"
res = findConsecutiveMax(["y","y","y","z","a","y","","y","z","z","z"])
assert res=="y"
res = findConsecutiveMax(["y","y","y","z","a","y","","y","z","z","z","z"])
assert res=="z"
res = findConsecutiveMax(["y",1,"y","z","a","y","","y","z","z","z","z"])
assert res=="z"
res = findConsecutiveMax(["y",1,1,1,"a","y","","y","z","z","z"])
assert res==1
res = findConsecutiveMax([1,1,1,"a","a","y","","y","z","z","z"])
assert res==1
res = findConsecutiveMax([1,1,1,"a","a","y","","y",2,2,2,2])
assert res==2
res = findConsecutiveMax([1,1,1,"a","a","y","","y",2,2,"",2,2])
assert res==2
def test_inputString():
res = findConsecutiveMax("abc")
assert res == "a"
with pytest.raises(TypeError,match='Input must be an array or list.'):
res = findConsecutiveMax(1)
with pytest.raises(TypeError,match='Input must be an array or list.'):
res = findConsecutiveMax(1.5)