aboutsummaryrefslogtreecommitdiff
path: root/MicSim/test/test_caretaker.py
blob: 414bf37a1874619497faf586c68cb10b29a3ff1c (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
46
47
48
#!/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
		"""
		for toWrite in range(0,127):# 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,"Tested with {}".format(-toWrite))
			
		for toWrite in range(0,255):# Only 2^8 value for unsigned
			self.c["MBR"]=toWrite
			self.assertEqual(self.c["MBRU"],toWrite,"Tested with {}".format(toWrite))
			if toWrite>127: # We enter in the zone of negative number at 127
				self.assertEqual(self.c["MBR"],-((toWrite-1)^0xFF),"Tested with {}".format(toWrite)) # Check if we get the reverse complement

		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()