Add quiz 3 content, and quiz 3 practice
This commit is contained in:
32
tests/practice/Q3/practice_questions.py
Normal file
32
tests/practice/Q3/practice_questions.py
Normal file
@ -0,0 +1,32 @@
|
||||
def is_word(word):
|
||||
counter = 0
|
||||
for l in word:
|
||||
if (counter % 2) == 0: #zero is vowel, one is constanant
|
||||
if l == 'a' or l == 'e' or l == 'i' or l == 'o' or l == 'u':
|
||||
counter = counter + 1
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
if l == 'b' or l == 'k' or l == 'p' or l == 't' or l == 'z':
|
||||
counter = counter + 1
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
def cycle(lst):
|
||||
while True:
|
||||
yield lst
|
||||
x = lst[0]
|
||||
lst = lst[1:]
|
||||
lst.append(x)
|
||||
|
||||
class Skippy:
|
||||
def __init__(self, lst, offset)
|
||||
self.lst = lst
|
||||
self.offset = offset
|
||||
self.counter = 0
|
||||
|
||||
def __next__(self)
|
||||
if self.counter > length(self.lst)
|
||||
self.counter = 0
|
||||
|
37
tests/practice/Q3/test_practice_questions.py
Normal file
37
tests/practice/Q3/test_practice_questions.py
Normal file
@ -0,0 +1,37 @@
|
||||
from practice_questions import is_word
|
||||
|
||||
def test_match():
|
||||
assert is_word("akataka") == True
|
||||
assert is_word("ububu") == True
|
||||
assert is_word("ikekezaza") == True
|
||||
|
||||
def test_extra():
|
||||
assert is_word("akatakaa") == False
|
||||
assert is_word("uububu") == False
|
||||
|
||||
def test_bad_letter():
|
||||
assert is_word("yakataka") == False
|
||||
assert is_word("akatakala") == False
|
||||
|
||||
def test_consonant_start():
|
||||
assert is_word("kakataka") == False
|
||||
assert is_word("bububu") == False
|
||||
|
||||
|
||||
from practice_questions import cycle
|
||||
def test_small():
|
||||
lst = [1,2,3]
|
||||
g = cycle(lst)
|
||||
assert next(g) == lst
|
||||
assert next(g) == [2,3,1]
|
||||
assert next(g) == [3,1,2]
|
||||
|
||||
def test_big():
|
||||
n = 5000
|
||||
lst = list(range(n))
|
||||
g = cycle(lst)
|
||||
for j in range(n):
|
||||
lst2 = next(g)
|
||||
assert lst2[0] == n-1
|
||||
lst3 = next(g)
|
||||
assert lst3==lst
|
Reference in New Issue
Block a user