blob: 5cc74839b172eaee0974eac2b45e06cfe6810ea2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/usr/bin/python
from components.caretaker import Caretaker
import unittest
from random import randint
class CaretakerTest(unittest.TestCase):
def setUp(self):
"""
Init test
"""
self.c=Caretaker(1000)
def test___getitem__(self):
"""
Test if getitem operation follow Mic-1 rules
"""
toWrite=randint(0,126) # Only 7 bit for signed MBR (2^7=127)
self.c["MBR"]=-toWrite
self.assertEqual(self.c["MBRU"],toWrite,"Tested with {}".format(-toWrite))
self.assertEqual(self.c["MBR"],-(-((toWrite-1)^0xFF)),"Tested with {}".format(-toWrite))
self.c["MBR"]=toWrite
self.assertEqual(self.c["MBRU"],toWrite,"Tested with {}".format(toWrite))
self.assertEqual(self.c["MBR"],toWrite,"Tested with {}".format(toWrite))
with self.assertRaises(KeyError): # Check it returns a KeyError
self.c["kjhkjhkoih"+str(randint(0,7698))]
def test___setitem__(self):
"""
Test if getitem operation follow Mic-1 rules
"""
try:
self.c["RAM"]="Test"
except Exception:
self.fail("Failed to assign RAM to caretaker")
if __name__ == "__main__":
unittest.main()
|