Sobes.tech
Junior — Senior

Search for listings within the specified price range

livecode

Task condition

There is an array of real estate listings. It is required to implement a function that filters only those listings whose price falls within a specified range (inclusive of the minimum and maximum values). In addition to implementing the function, you need to write a set of unit tests that confirm its correctness.

ads = [
    {"title": "3-room apartment, 80m², 13/22 floor", "rooms": 3, "price": 70000, "petFriendly": True},
    {"title": "2-room apartment, 45m², 5/5 floor", "rooms": 2, "price": 60000, "petFriendly": False, "deposit": 60000},
    {"title": "2-room apartment, 44m², 4/4 floor", "rooms": 2, "price": 45000, "petFriendly": True, "agency": True},
    {"title": "2-room apartment, 44m², 4/4 floor", "rooms": 2, "price": 45000, "petFriendly": True, "agency": True, "fee": 45000},
    # ...
]

Requirements:

  1. The function should accept three arguments: minimum price, maximum price, and the list of listings.
  2. The return value should be a list of listings whose prices are within the specified range.
  3. Write several tests (for example, using unittest or pytest) that check boundary cases, an empty list, and a normal scenario.