MemoryTest.py
Go to the documentation of this file.
00001 # Copyright (c) 2013, Felix Kolbe
00002 # All rights reserved. BSD License
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 # * Redistributions of source code must retain the above copyright
00009 #   notice, this list of conditions and the following disclaimer.
00010 #
00011 # * Redistributions in binary form must reproduce the above copyright
00012 #   notice, this list of conditions and the following disclaimer in the
00013 #   documentation and/or other materials provided with the distribution.
00014 #
00015 # * Neither the name of the {organization} nor the names of its
00016 #   contributors may be used to endorse or promote products derived
00017 #   from this software without specific prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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     #import sys;sys.argv = ['', 'Test.testMemory']
00093     unittest.main()


rgoap
Author(s): Felix Kolbe
autogenerated on Sun Oct 5 2014 23:53:02