Debug tests
This commit is contained in:
parent
041e5ba04d
commit
f947f82892
3 changed files with 32 additions and 29 deletions
|
@ -28,17 +28,9 @@ class Caretaker:
|
||||||
def __setitem__(self,key,value):
|
def __setitem__(self,key,value):
|
||||||
if key!="RAM":
|
if key!="RAM":
|
||||||
if ((-(2**7-1))>value or value>(2**8)-1) and (key=="MBR" or key=="MBRU"):
|
if ((-(2**7-1))>value or value>(2**8)-1) and (key=="MBR" or key=="MBRU"):
|
||||||
raise RuntimeError("Value {} cannot fit in MBR register (-2^7 minimum value)".format(value))
|
raise RuntimeError("Value {} cannot fit in {} register (-(2^7-1) minimum value and (2^7-1) maximum value)".format(value,key))
|
||||||
elif value>(2**32-1) and (key!="MBR" and key!="MBRU"):
|
elif (-(2**31-1)>value or value>(2**32)-1) and (key!="MBR" and key!="MBRU"):
|
||||||
raise RuntimeError("Value {} cannot fit in MBR register (2^32 minimum value)".format(value))
|
raise RuntimeError("Value {} cannot fit in {} register (2^32-1 maximum value)".format(value,key))
|
||||||
|
|
||||||
# if key!="RAM":
|
|
||||||
# if (value > (2**32) or value <(2**32)/2) and key!="MBR" and key!="MBRU": # Check value fit in word
|
|
||||||
# print("Warning word overflow: value {} on register {}".format(value,key))
|
|
||||||
# value=value%(2**32) # Force to fit in word
|
|
||||||
# elif (value > (2**8) or value <126) and key=="MBR" or key=="MBRU": # Check value fit in byte
|
|
||||||
# print("Warning byte overflow: value {} on register {}".format(value,key))
|
|
||||||
# value=abs(value)%256 # Force to fit in byte
|
|
||||||
self.objects[key]=value
|
self.objects[key]=value
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
|
|
|
@ -30,6 +30,16 @@ class CaretakerTest(unittest.TestCase):
|
||||||
with self.assertRaises(KeyError): # Check it returns a KeyError
|
with self.assertRaises(KeyError): # Check it returns a KeyError
|
||||||
self.c["kjhkjhkoih"+str(randint(0,7698))]
|
self.c["kjhkjhkoih"+str(randint(0,7698))]
|
||||||
|
|
||||||
|
# Check outside bound values
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.c["MBR"]=-128
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.c["MBR"]=256
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.c["PC"]=2**32
|
||||||
|
with self.assertRaises(Exception):
|
||||||
|
self.c["PC"]=-(2**31)
|
||||||
|
|
||||||
def test___setitem__(self):
|
def test___setitem__(self):
|
||||||
"""
|
"""
|
||||||
Test if getitem operation follow Mic-1 rules
|
Test if getitem operation follow Mic-1 rules
|
||||||
|
|
|
@ -72,30 +72,31 @@ class RamTest(unittest.TestCase):
|
||||||
self.caretaker["MAR"]=self.ramSize
|
self.caretaker["MAR"]=self.ramSize
|
||||||
ram.read()
|
ram.read()
|
||||||
with self.assertRaises(Exception):
|
with self.assertRaises(Exception):
|
||||||
self.caretaker["MAR"]=-1*randint(0,self.ramSize-1)
|
self.caretaker["MAR"]=-1*randint(1,self.ramSize-1)
|
||||||
ram.read()
|
ram.read()
|
||||||
|
|
||||||
def test_fetch(self):
|
def test_fetch(self):
|
||||||
"""
|
"""
|
||||||
Test fetch method
|
Test fetch method
|
||||||
"""
|
"""
|
||||||
# Test classical fetch
|
for q in range(0,1999):
|
||||||
ram=Ram(self.caretaker,self.ramSize)
|
# Test classical fetch
|
||||||
data=dict()
|
ram=Ram(self.caretaker,self.ramSize)
|
||||||
toWrite=randint(0,256-1)
|
data=dict()
|
||||||
for i in range(0,self.ramSize):
|
toWrite=randint(0,256-1)
|
||||||
data[i]=toWrite
|
for i in range(0,self.ramSize):
|
||||||
ram.setData(data)
|
data[i]=toWrite
|
||||||
for i in range(0,self.ramSize):
|
ram.setData(data)
|
||||||
self.caretaker["PC"]=i
|
for i in range(0,self.ramSize):
|
||||||
self.assertEqual(toWrite,ram.fetch())
|
self.caretaker["PC"]=i
|
||||||
# Test fetch outside of memory
|
self.assertEqual(toWrite,ram.fetch())
|
||||||
with self.assertRaises(Exception):
|
# Test fetch outside of memory
|
||||||
self.caretaker["PC"]=self.ramSize
|
with self.assertRaises(Exception):
|
||||||
ram.fetch()
|
self.caretaker["PC"]=self.ramSize
|
||||||
with self.assertRaises(Exception):
|
ram.fetch()
|
||||||
self.caretaker["PC"]=-1*randint(0,self.ramSize-1)
|
with self.assertRaises(Exception):
|
||||||
ram.fetch()
|
self.caretaker["PC"]=-1*randint(1,self.ramSize-1)
|
||||||
|
ram.fetch()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue