-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasserty.py
76 lines (54 loc) · 1.49 KB
/
asserty.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
def lowercase(napis):
napis2 = ''
for i in range(len(napis)):
if napis[i] >= 'A' and napis[i] <= 'Z':
#ord - zamiana znaku na int
napis2 += chr((ord(napis[i]) + 32))
else:
napis2 += napis[i]
return napis2
def test_lower():
napis = "WiTaMy barDZO serDeczNIe"
assert lowercase(napis) == napis.lower()
def split(napis, separator):
lista = []
word = ''
for znak in napis:
if znak not in separator:
word += znak
elif word:
lista.append(word)
word = ''
if word:
lista.append(word)
return lista
def test_split():
napis = "54545454545; dsadadsadad; hahahaha; 5.32"
assert split(napis, ";") == napis.split(";")
def czy_jest(szukany, lista):
for e in lista:
if e == szukany:
return True
return False
def test_in():
lista = [5, 3, 3, 6, 7, 2, 1]
assert czy_jest(3, lista) == (3 in lista)
def bubble_sort(lista):
for i in range(len(lista)):
for j in range(len(lista) - 1):
if lista[j] > lista[j + 1]:
x = lista[j]
lista[j] = lista[j + 1]
lista[j + 1] = x
return lista
def test_sort():
lista = [5, 3, 3, 6, 7, 2, 1]
assert bubble_sort(lista) == sorted(lista)
def dlugosc(lista):
dl = 0
for i in lista:
dl += 1
return dl
def test_len():
lista = [5, 3, 6, 2, 8, 1, 0, 4, 1]
assert dlugosc(lista) == len(lista)