Editor

Test a Clamp Function

Write the tests · Beginner · about 8 min

clamp(value, low, high) keeps a number inside a range. It returns value when it is between low and high (both ends count as inside), low when value is smaller than low, and high when value is bigger than high. low is never bigger than high.

Write test_ functions with assert that pass on a correct version and fail on broken ones.

Examples

clamp(5, 0, 10)     # 5
clamp(-3, 0, 10)    # 0
clamp(42, 0, 10)    # 10
def test_inside_the_range():
assert clamp(5, 0, 10) == 5
The solution opens after your first Check.