#!/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()