示例#1
0
  def testRCopyNestedDict(self):
    d = {"a": {"b": {"c": 1}}}
    self.assertDictEqual(d, rCopy(d))

    def f(value, _keys):
      return value * 2
    expected = {"a": {"b": {"c": 2}}}
    self.assertDictEqual(expected, rCopy(d, f))
示例#2
0
  def testRCopyFlatDict(self):
    d = {"a": 1, "b": 2, "c": 3}
    self.assertDictEqual(d, rCopy(d))

    def f(value, _keys):
      return value * 2
    expected = {"a": 2, "b": 4, "c": 6}
    self.assertDictEqual(expected, rCopy(d, f))
示例#3
0
    def testRCopyNestedDict(self):
        d = {"a": {"b": {"c": 1}}}
        self.assertDictEqual(d, rCopy(d))

        def f(value, _keys):
            return value * 2

        expected = {"a": {"b": {"c": 2}}}
        self.assertDictEqual(expected, rCopy(d, f))
示例#4
0
    def testRCopyFlatDict(self):
        d = {"a": 1, "b": 2, "c": 3}
        self.assertDictEqual(d, rCopy(d))

        def f(value, _keys):
            return value * 2

        expected = {"a": 2, "b": 4, "c": 6}
        self.assertDictEqual(expected, rCopy(d, f))
示例#5
0
  def testRCopyComplexNestedDict(self):
    d = {"a": {"b": {"c": [1, 2, 3]}, "d": "Hello", "e": 17}}
    self.assertDictEqual(d, rCopy(d))

    def f(value, _keys):
      return value * 2
    expected = {"a": {"b": {"c": [1, 2, 3, 1, 2, 3]},
                      "d": "HelloHello", "e": 34}}
    self.assertDictEqual(expected, rCopy(d, f))
示例#6
0
    def testRCopyComplexNestedDict(self):
        d = {"a": {"b": {"c": [1, 2, 3]}, "d": "Hello", "e": 17}}
        self.assertDictEqual(d, rCopy(d))

        def f(value, _keys):
            return value * 2

        expected = {
            "a": {
                "b": {
                    "c": [1, 2, 3, 1, 2, 3]
                },
                "d": "HelloHello",
                "e": 34
            }
        }
        self.assertDictEqual(expected, rCopy(d, f))
示例#7
0
 def testRCopyEmpty(self):
     d = {}
     self.assertDictEqual(d, rCopy(d))
     self.assertDictEqual(d, rCopy(d, lambda x: 2 * x))
示例#8
0
 def testRCopyEmpty(self):
   d = {}
   self.assertDictEqual(d, rCopy(d))
   self.assertDictEqual(d, rCopy(d, lambda x: 2* x))