def test_eq_method(): my_dict1, my_dict2 = MyDict(5), MyDict(10) keys_values = [ ('key1', 1), ('key2', 2), ('key3', 3), ] for key, value in keys_values: my_dict1[key] = value my_dict2[key] = value assert my_dict1 == my_dict2
class TestRL_NN(TestCase): params = MyDict() params.log = MyDict() params.log.debug = do_nothing params.states_list = [['A', 'B'], ['C', 'D'], ['E', 'F', 'G']] params.num_substates = 7 params.display = None params.tensorboard = False states = StatesCombiner(params) NN = RL_NN(params, None) def test_onehot(self): enc = self.NN.onehot('A_C_E', self.states.state_list) self.assertListEqual(list(enc[0]), [1, 0, 1, 0, 1, 0, 0]) enc = self.NN.onehot('B_D_G', self.states.state_list) self.assertListEqual(list(enc[0]), [0, 1, 0, 1, 0, 0, 1]) # Negative case try: self.NN.onehot('A_B_C', self.states.state_list) except Exception as e: self.assertIsInstance(e, ValueError)
def _initialize_dicts(): my_dict, python_dict = MyDict(5), {} keys_values = [ ('key1', 1), ('key2', 2), ('key3', 3), ('key3', 4), # same key as previous ('key4', 5), ('key5', 6), ('key5', 7), # same key as previous ('key6', 8), # more values than space in MyDict, collision guarantee ] for key, value in keys_values: my_dict[key], python_dict[key] = value, value return my_dict, python_dict
def test_attr_error(self): my_dict = MyDict() with self.assertRaises(AttributeError): value = my_dict.empty
def test_key_error(self): my_dict = MyDict() with self.assertRaises(KeyError): value = my_dict['empty']
def test_attr(self): my_dict = MyDict() my_dict.key = 'value' self.assertTrue('key' in my_dict) self.assertEqual(my_dict['key'], 'value')
def test_key(self): my_dict = MyDict() my_dict['key'] = 'value' self.assertEqual(my_dict.key, 'value')
def test_init(self): my_dict = MyDict(a=1, b='test') self.assertEqual(my_dict.a, 1) self.assertEqual(my_dict.b, 'test') self.assertTrue(isinstance(my_dict, dict))
def test_ne_method(): my_dict1, my_dict2 = MyDict(5), MyDict(5) my_dict2[1], my_dict2[1] = False, True assert my_dict1 != my_dict2