Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 import unittest
00033
00034 from rgoap.memory import Memory
00035
00036
00037 class MemoryTest(unittest.TestCase):
00038
00039 def setUp(self):
00040 self.mem = Memory()
00041
00042 def test_fresh(self):
00043 self.assertRaises(KeyError, self.mem.get_value, 'undef_var')
00044
00045 def test_unset_var(self):
00046 name = 'declared_only'
00047 self.mem.declare_state(name)
00048 self.assertIsNone(self.mem.get_value(name), 'Undeclared state should give None?')
00049
00050 def test_consistency(self):
00051 name = "var_GHJKKL"
00052 value = "val_ASDFGHJ"
00053 self.mem.declare_state(name, value)
00054 self.assertEqual(self.mem.get_value(name), value, 'Memory state not consistent')
00055
00056 def test_declare_none_after_value(self):
00057 name = "var_GHJKKL"
00058 value = "val_ASDFGHJ"
00059 self.mem.declare_state(name, value)
00060 self.mem.declare_state(name)
00061 self.assertEqual(self.mem.get_value(name), value, 'Memory state not consistent')
00062
00063
00064 @unittest.skip('removed feature')
00065 class MemoryTestSingletons(unittest.TestCase):
00066
00067 def setUp(self):
00068 self.mem1 = Memory()
00069 self.mem2 = Memory()
00070
00071 def test_Memory_singleton_inst(self):
00072 self.assertIs(self.mem1, self.mem2, 'Memory objects not same object')
00073
00074 def test_Memory_singleton_mem_inst(self):
00075 self.assertIs(self.mem1._memory, self.mem2._memory, 'Memory objects dicts not same object')
00076
00077 def test_Memory_singleton_values(self):
00078 name = "var_GHJKKL"
00079 value = "val_ASDFGHJ"
00080 self.mem1.declare_state(name, value)
00081 self.assertEqual(self.mem2.get_value(name), value, 'Nonempty Memory objects not equal')
00082
00083 def test_Memory_singleton_itm_equ(self):
00084 self.mem1.declare_state('a', '1')
00085 self.mem1.declare_state('b', '2')
00086 self.mem2.declare_state('c', '3')
00087 self.mem2.declare_state('d', '4')
00088 self.assertDictEqual(self.mem1._memory, self.mem2._memory, 'Nonempty Memory objects not equal')
00089
00090
00091 if __name__ == "__main__":
00092
00093 unittest.main()