Complete the code to define a test that checks if the sum of two numbers is correct.
def test_sum(): result = 2 + 3 assert result == [1]
The sum of 2 and 3 is 5, so the assertion should check if result equals 5.
Complete the code to test if a list contains a specific element.
def test_contains_element(): fruits = ['apple', 'banana', 'cherry'] assert 'banana' [1] fruits
To check if 'banana' is in the list fruits, use the 'in' keyword.
Fix the error in the test function that checks if a string is uppercase.
def test_is_uppercase(): text = 'HELLO' assert text.[1]()
The method isupper() checks if all letters in the string are uppercase.
Complete the code to create a test that checks if a list is sorted in ascending order.
def test_sorted_list(): numbers = [1, 2, 3, 4, 5] assert numbers == sorted(numbers) assert numbers[1] sorted(numbers)
The first assertion checks if numbers equals sorted(numbers) with no extra argument. The second assertion checks if numbers == sorted(numbers).
Fill both blanks to write a test that checks if a dictionary comprehension creates correct squares for numbers greater than 2.
def test_squares_dict(): numbers = [1, 2, 3, 4] squares = {n:: n[1] for n in numbers if n [2] 2} assert squares == {3: 9, 4: 16}
The dictionary comprehension uses ':' to separate keys and values, '**2' to square the number, and '>' to filter numbers greater than 2.