Added BoundedIntTester
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
from test12 import BoundedInt
|
||||||
|
|
||||||
|
class BoundedIntTester:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
def test1(self):
|
||||||
|
bi1 = BoundedInt(0xdeadbeef, max = 0, min = 10)
|
||||||
|
if int(bi1) == 0xdeadbeef:
|
||||||
|
print(f"✅ Test 1 passed!")
|
||||||
|
else:
|
||||||
|
print(f"❌ Test 1 failed, int(bi1) = {int(bi1)}, expected 0xdeadbeef")
|
||||||
|
|
||||||
|
def test2(self):
|
||||||
|
bi2 = BoundedInt(1, min = 0, max = 1)
|
||||||
|
bi3 = BoundedInt(1, min = 0, max = 1)
|
||||||
|
try:
|
||||||
|
bi4 = bi2 + bi3 # 1 + 1 = 2, which is more than max = 1
|
||||||
|
print(f"❌ Test 2 failed!")
|
||||||
|
except ValueError as err:
|
||||||
|
print(f"✅ Test 2 passed!")
|
||||||
|
|
||||||
|
def test3(self):
|
||||||
|
bi4 = BoundedInt(1, min = 0, max = 1)
|
||||||
|
bi5 = BoundedInt(2, min = 0, max = 1)
|
||||||
|
try:
|
||||||
|
bi6 = bi4 - bi5 # 1 - 2 = (-1), which is less than min = 0
|
||||||
|
print(f"❌ Test 3 failed!")
|
||||||
|
except ValueError as err:
|
||||||
|
print(f"✅ Test 3 passed!")
|
||||||
|
|
||||||
|
tester = BoundedIntTester()
|
||||||
|
tester.test1()
|
||||||
|
tester.test2()
|
||||||
|
tester.test3()
|
||||||
Reference in New Issue
Block a user