From 9fdafdfae90e85ced5a44bcda727f949cc25ea58 Mon Sep 17 00:00:00 2001 From: MstrPikachu <31784486+MstrPikachu@users.noreply.github.com> Date: Sun, 30 Jan 2022 22:47:14 -0500 Subject: [PATCH] A1 P1 Q2 Fix all pyta errors except forbidden import --- assignments/A1/a1_part1_test.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/assignments/A1/a1_part1_test.py b/assignments/A1/a1_part1_test.py index f763189..27db764 100644 --- a/assignments/A1/a1_part1_test.py +++ b/assignments/A1/a1_part1_test.py @@ -29,37 +29,43 @@ from a1_part1 import MoveToFrontLinkedList, SwapLinkedList, CountLinkedList def test_movetofront_true() -> None: + """Test MoveToFrontLinkedList contains with elements in the linked list""" 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))) def test_swap_true() -> None: + """Test SwapLinkedList contains with elements in the linked list""" 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))) def test_count_true() -> None: + """Test CountLinkedList contains with elements in the linked list""" 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))) def test_movetofront_false() -> None: + """Test MoveToFrontLinkedList contains with elements not in the linked list""" 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))) def test_swap_false() -> None: + """Test SwapLinkedList contains with elements not in the linked list""" 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))) def test_count_false() -> None: + """Test CountLinkedList contains with elements not in the linked list""" 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))) -def generate_ordering(n: int): - """generates a pseudorandom ordering of n integers from 0 to n-1, inclusive +def generate_ordering(n: int) -> list[int]: + """Generates a pseudorandom ordering of n integers from 0 to n-1, inclusive Preconditions: - n is prime @@ -71,7 +77,7 @@ def generate_ordering(n: int): 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)) arr = list(range(101)) operations = generate_ordering(101) @@ -80,13 +86,13 @@ def test_movetofront_mutation() -> None: for x in operations: i = arr.index(x) # find index arr.insert(0, arr.pop(i)) # simulate moving to front - x in lst + lst.__contains__(x) bools.append(lst.to_list() == arr) assert all(bools) 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)) arr = list(range(101)) operations = generate_ordering(101) @@ -98,21 +104,21 @@ def test_swap_mutation() -> None: temp = arr[i] arr[i] = arr[i - 1] arr[i - 1] = temp - x in lst + lst.__contains__(x) bools.append(lst.to_list() == arr) assert all(bools) def test_count_mutation() -> None: - """Tests the mutation of a CountLinkedList by searching for every number from 0-100 inclusive, and then - every number from 0-49 inclusive.""" + """Tests the mutation of a CountLinkedList by searching for every number from 0-100, + and then every number from 0-49 inclusive.""" lst = CountLinkedList(generate_ordering(101)) 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 - x in lst + lst.__contains__(x) assert lst.to_list() == list(reversed(range(50))) + list(range(50, 101)) @@ -126,4 +132,4 @@ if __name__ == '__main__': 'disable': ['E1136'], 'extra-imports': ['a1_linked_list'], 'max-nested-blocks': 4 - }, output='pyta_report.html') + })