/python/

Python Dictionary

2014-03-11 21:28:35

def test_dictionary_3(self):
        smalla = {"a": 1, "b": 2}
        smallb = {"a": 3, "d": 4}
        smalla.update(smallb)
        self.assertEqual(smalla, {"a": 3, "b": 2, "d": 4})

    def test_dictionary_2(self):
        small = {"a": 1}
        self.assertEqual(small, {"a": 1})
        small["b"] = 2
        self.assertEqual(small, {"a": 1, "b": 2})

    def test_dictionary(self):
        lorems = {
            "lorem": 5,
            "ipsum": "-5-",
            "dolor": ["d", "o", "l", "o", "r"],
            "sith":
                {
                    "jedi": False
                },
            "amet": True,
            "consectetur": 11,
            "adipiscing": 10,
            "elit": 4
        }

        self.assertEqual(lorems["lorem"], 5)
        self.assertEqual(lorems["ipsum"], "-5-")
        self.assertEqual(lorems["dolor"], ["d", "o", "l", "o", "r"])
        self.assertEqual(lorems["sith"], {"jedi": False})
        self.assertEqual(lorems["sith"]["jedi"], False)
        self.assertEqual(lorems["amet"], True)
        self.assertEqual("adipiscing" in lorems, True)
        self.assertEqual("xxxxxxxxxx" in lorems, False)