Bird
0
0

Consider a function that filters out falsy values (like 0, '', None) from a list and returns a new list. Which unit test case best checks this behavior?

hard📝 Conceptual Q9 of 15
Testing Fundamentals - Testing Types and Levels
Consider a function that filters out falsy values (like 0, '', None) from a list and returns a new list. Which unit test case best checks this behavior?
AInput list with only falsy values, assert output equals input
BInput empty list, assert output raises an exception
CInput list with mixed truthy and falsy values, assert output contains only truthy values
DInput list with only truthy values, assert output is empty
Step-by-Step Solution
Solution:
  1. Step 1: Understand function filtering behavior

    The function removes falsy values and keeps truthy ones in the output list.
  2. Step 2: Choose test case that verifies filtering

    Input list with mixed truthy and falsy values, assert output contains only truthy values uses mixed input and asserts output has only truthy values, correctly testing filtering.
  3. Final Answer:

    Input list with mixed truthy and falsy values, assert output contains only truthy values -> Option C
  4. Quick Check:

    Test filters out falsy values correctly [OK]
Quick Trick: Test with mixed values to check filtering [OK]
Common Mistakes:
  • Expecting output equals input when filtering
  • Assuming exceptions on empty input
  • Confusing truthy and falsy values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes