21 lines
555 B
Python
21 lines
555 B
Python
import unittest
|
|
from clamp import clamp
|
|
|
|
|
|
class TestClamp(unittest.TestCase):
|
|
def test_basic(self):
|
|
self.assertEqual(clamp(5, 0, 10), 5)
|
|
self.assertEqual(clamp(-3, 0, 10), 0)
|
|
self.assertEqual(clamp(15, 0, 10), 10)
|
|
def test_bounds_equal(self):
|
|
self.assertEqual(clamp(5, 7, 7), 7)
|
|
def test_lo_gt_hi_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
clamp(5, 10, 0)
|
|
def test_floats(self):
|
|
self.assertEqual(clamp(1.5, 0.0, 1.0), 1.0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|