示例#1
0
    def test_magic_dict_get_first(self):
        magic_dict = MagicDict()
        test_list = ["b", "c", "d"]
        for item in test_list:
            magic_dict.add("a", item)

        self.assertEqual(magic_dict.get_first("a"), test_list[0])
示例#2
0
 def test_magic_dict_delitem_method(self):
     magic_dict = MagicDict()
     magic_dict.add("a", "b")
     magic_dict.add("a", "c")
     magic_dict.add("a", "d")
     del magic_dict["a"]
     self.assertNotIn("a", magic_dict)
示例#3
0
    def test_magic_dict_iter_method(self):
        magic_dict = MagicDict()
        magic_dict.add("a", "c")
        magic_dict.add("a", "d")
        magic_dict.add("b", "e")

        result_set = set()

        for key in iter(magic_dict):
            result_set.add(key)

        self.assertEqual(result_set, set(["a", "b"]))
示例#4
0
    def test_magic_dict_keys(self):
        magic_dict = MagicDict()
        test_set = set(["d", "e", "f"])
        for item in test_set:
            magic_dict.add("a", item)
            magic_dict.add("b", item)
            magic_dict.add("c", item)

        result_set = set()

        for key in magic_dict.keys():
            result_set.add(key)

        self.assertEqual(result_set, set(["a", "b", "c"]))
示例#5
0
    def test_magic_dict_values(self):
        magic_dict = MagicDict()
        test_set = set(["d", "e", "f"])
        for item in test_set:
            magic_dict.add("a", item)
            magic_dict.add("b", item)
            magic_dict.add("c", item)

        result_dict = {"d": 0, "e": 0, "f": 0}

        for value in magic_dict.values():
            result_dict[value] += 1

        self.assertEqual(result_dict["d"], 3)
        self.assertEqual(result_dict["e"], 3)
        self.assertEqual(result_dict["f"], 3)
示例#6
0
    def test_magic_dict_items(self):
        magic_dict = MagicDict()
        test_set = set(["d", "e", "f"])
        for item in test_set:
            magic_dict.add("a", item)
            magic_dict.add("b", item)
            magic_dict.add("c", item)

        result_dict = {"a": set(), "b": set(), "c": set()}

        for key, value in magic_dict.items():
            result_dict[key].add(value)

        self.assertEqual(result_dict["a"], test_set)
        self.assertEqual(result_dict["b"], test_set)
        self.assertEqual(result_dict["c"], test_set)
示例#7
0
 def test_magic_dict_copy(self):
     magic_dict = MagicDict()
     magic_dict.add("a", "b")
     copied_magic_dict = magic_dict.copy()
     self.assertEqual(magic_dict, copied_magic_dict)
示例#8
0
    def test_magic_dict_str_method(self):
        magic_dict = MagicDict()
        magic_dict.add("a", "b")

        self.assertEqual(str(magic_dict), "MagicDict([('a', 'b')])")
示例#9
0
 def test_magic_dict_len_method(self):
     magic_dict = MagicDict()
     magic_dict.add("a", "c")
     magic_dict.add("a", "d")
     magic_dict.add("b", "e")
     self.assertEqual(len(magic_dict), 3)
示例#10
0
 def test_magic_dict_getitem_method(self):
     magic_dict = MagicDict()
     magic_dict.add("a", "b")
     magic_dict.add("a", "c")
     magic_dict.add("a", "d")
     self.assertEqual(magic_dict["a"], "b")
示例#11
0
 def test_magic_dict_add(self):
     magic_dict = MagicDict()
     self.assertNotIn("a", magic_dict)
     magic_dict.add("a", "b")
     self.assertIn("a", magic_dict)
     self.assertEqual("b", magic_dict["a"])