A "clamp" function is a function that takes three inputs: a lower bound, an upper bound, and the value that will be clamped. If this value is between the lower and upper bound, the original value is simply returned. If it is greater than the upper bound, the upper bound should be returned. Similarly, if it is less than the lower bound, the lower bound should be returned.
Write a function clamp
that takes three int
arguments: the value to be clamped, a lower bound, and an upper
bound, in this order. It should return the "clamped" value of the first argument. You can assume that the lower
bound will never be greater than the upper bound.
For example, clamp(6, 5, 10)
should return 6
while clamp(11, 5, 10)
should return 10
.
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: