A1 P1 Q2 Fix all pyta errors except forbidden import
This commit is contained in:
@@ -29,37 +29,43 @@ from a1_part1 import MoveToFrontLinkedList, SwapLinkedList, CountLinkedList
|
|||||||
|
|
||||||
|
|
||||||
def test_movetofront_true() -> None:
|
def test_movetofront_true() -> None:
|
||||||
|
"""Test MoveToFrontLinkedList contains with elements in the linked list"""
|
||||||
lst = [MoveToFrontLinkedList(range(i)) for i in range(100)]
|
lst = [MoveToFrontLinkedList(range(i)) for i in range(100)]
|
||||||
assert(all(all(x in lst[i] for x in range(i)) for i in range(100)))
|
assert(all(all(x in lst[i] for x in range(i)) for i in range(100)))
|
||||||
|
|
||||||
|
|
||||||
def test_swap_true() -> None:
|
def test_swap_true() -> None:
|
||||||
|
"""Test SwapLinkedList contains with elements in the linked list"""
|
||||||
lst = [SwapLinkedList(range(i)) for i in range(100)]
|
lst = [SwapLinkedList(range(i)) for i in range(100)]
|
||||||
assert(all(all(x in lst[i] for x in range(i)) for i in range(100)))
|
assert(all(all(x in lst[i] for x in range(i)) for i in range(100)))
|
||||||
|
|
||||||
|
|
||||||
def test_count_true() -> None:
|
def test_count_true() -> None:
|
||||||
|
"""Test CountLinkedList contains with elements in the linked list"""
|
||||||
lst = [CountLinkedList(range(i)) for i in range(100)]
|
lst = [CountLinkedList(range(i)) for i in range(100)]
|
||||||
assert(all(all(x in lst[i] for x in range(i)) for i in range(100)))
|
assert(all(all(x in lst[i] for x in range(i)) for i in range(100)))
|
||||||
|
|
||||||
|
|
||||||
def test_movetofront_false() -> None:
|
def test_movetofront_false() -> None:
|
||||||
|
"""Test MoveToFrontLinkedList contains with elements not in the linked list"""
|
||||||
lst = [MoveToFrontLinkedList(range(i)) for i in range(100)]
|
lst = [MoveToFrontLinkedList(range(i)) for i in range(100)]
|
||||||
assert(all(all(x not in lst[i] for x in range(i, i + 100)) for i in range(100)))
|
assert(all(all(x not in lst[i] for x in range(i, i + 100)) for i in range(100)))
|
||||||
|
|
||||||
|
|
||||||
def test_swap_false() -> None:
|
def test_swap_false() -> None:
|
||||||
|
"""Test SwapLinkedList contains with elements not in the linked list"""
|
||||||
lst = [SwapLinkedList(range(i)) for i in range(100)]
|
lst = [SwapLinkedList(range(i)) for i in range(100)]
|
||||||
assert(all(all(x not in lst[i] for x in range(i, i + 100)) for i in range(100)))
|
assert(all(all(x not in lst[i] for x in range(i, i + 100)) for i in range(100)))
|
||||||
|
|
||||||
|
|
||||||
def test_count_false() -> None:
|
def test_count_false() -> None:
|
||||||
|
"""Test CountLinkedList contains with elements not in the linked list"""
|
||||||
lst = [CountLinkedList(range(i)) for i in range(100)]
|
lst = [CountLinkedList(range(i)) for i in range(100)]
|
||||||
assert(all(all(x not in lst[i] for x in range(i, i + 100)) for i in range(100)))
|
assert(all(all(x not in lst[i] for x in range(i, i + 100)) for i in range(100)))
|
||||||
|
|
||||||
|
|
||||||
def generate_ordering(n: int):
|
def generate_ordering(n: int) -> list[int]:
|
||||||
"""generates a pseudorandom ordering of n integers from 0 to n-1, inclusive
|
"""Generates a pseudorandom ordering of n integers from 0 to n-1, inclusive
|
||||||
|
|
||||||
Preconditions:
|
Preconditions:
|
||||||
- n is prime
|
- n is prime
|
||||||
@@ -71,7 +77,7 @@ def generate_ordering(n: int):
|
|||||||
|
|
||||||
|
|
||||||
def test_movetofront_mutation() -> None:
|
def test_movetofront_mutation() -> None:
|
||||||
"""Tests the mutation of a MoveToFrontLinkedList by searching for every number from 0-100 inclusive."""
|
"""Tests the mutation of a MoveToFrontLinkedList by searching for every number from 0-100."""
|
||||||
lst = MoveToFrontLinkedList(range(101))
|
lst = MoveToFrontLinkedList(range(101))
|
||||||
arr = list(range(101))
|
arr = list(range(101))
|
||||||
operations = generate_ordering(101)
|
operations = generate_ordering(101)
|
||||||
@@ -80,13 +86,13 @@ def test_movetofront_mutation() -> None:
|
|||||||
for x in operations:
|
for x in operations:
|
||||||
i = arr.index(x) # find index
|
i = arr.index(x) # find index
|
||||||
arr.insert(0, arr.pop(i)) # simulate moving to front
|
arr.insert(0, arr.pop(i)) # simulate moving to front
|
||||||
x in lst
|
lst.__contains__(x)
|
||||||
bools.append(lst.to_list() == arr)
|
bools.append(lst.to_list() == arr)
|
||||||
assert all(bools)
|
assert all(bools)
|
||||||
|
|
||||||
|
|
||||||
def test_swap_mutation() -> None:
|
def test_swap_mutation() -> None:
|
||||||
"""Tests the mutation of a SwapLinkedList by searching for every number from 0-100 inclusive."""
|
"""Tests the mutation of a SwapLinkedList by searching for every number from 0-100."""
|
||||||
lst = SwapLinkedList(range(101))
|
lst = SwapLinkedList(range(101))
|
||||||
arr = list(range(101))
|
arr = list(range(101))
|
||||||
operations = generate_ordering(101)
|
operations = generate_ordering(101)
|
||||||
@@ -98,21 +104,21 @@ def test_swap_mutation() -> None:
|
|||||||
temp = arr[i]
|
temp = arr[i]
|
||||||
arr[i] = arr[i - 1]
|
arr[i] = arr[i - 1]
|
||||||
arr[i - 1] = temp
|
arr[i - 1] = temp
|
||||||
x in lst
|
lst.__contains__(x)
|
||||||
bools.append(lst.to_list() == arr)
|
bools.append(lst.to_list() == arr)
|
||||||
assert all(bools)
|
assert all(bools)
|
||||||
|
|
||||||
|
|
||||||
def test_count_mutation() -> None:
|
def test_count_mutation() -> None:
|
||||||
"""Tests the mutation of a CountLinkedList by searching for every number from 0-100 inclusive, and then
|
"""Tests the mutation of a CountLinkedList by searching for every number from 0-100,
|
||||||
every number from 0-49 inclusive."""
|
and then every number from 0-49 inclusive."""
|
||||||
lst = CountLinkedList(generate_ordering(101))
|
lst = CountLinkedList(generate_ordering(101))
|
||||||
|
|
||||||
for x in list(range(101)): # reorder the linked list to natural ordering
|
for x in list(range(101)): # reorder the linked list to natural ordering
|
||||||
x in lst
|
lst.__contains__(x)
|
||||||
|
|
||||||
for x in reversed(range(50)): # reverse the first 50 numbers
|
for x in reversed(range(50)): # reverse the first 50 numbers
|
||||||
x in lst
|
lst.__contains__(x)
|
||||||
assert lst.to_list() == list(reversed(range(50))) + list(range(50, 101))
|
assert lst.to_list() == list(reversed(range(50))) + list(range(50, 101))
|
||||||
|
|
||||||
|
|
||||||
@@ -126,4 +132,4 @@ if __name__ == '__main__':
|
|||||||
'disable': ['E1136'],
|
'disable': ['E1136'],
|
||||||
'extra-imports': ['a1_linked_list'],
|
'extra-imports': ['a1_linked_list'],
|
||||||
'max-nested-blocks': 4
|
'max-nested-blocks': 4
|
||||||
}, output='pyta_report.html')
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user