예제 #1
0
def test_reorderm(m):
    def invert_inner(d):
        return {k: u.invertm(v) for k, v in d.items()}

    flipped = u.flipm(m)

    # flipping the inner map.
    assert u.reorderm(m, (0, 2, 1)) == invert_inner(m)

    # Flipping the outer keys is equivalent to calling flipm once.
    assert u.reorderm(m, (1, 0, 2)) == flipped

    # Reordering the inner keys is equiv to flipping the outer keys the
    # flipping the new inner dictionary.
    assert u.reorderm(m, (1, 2, 0)) == invert_inner(flipped)

    # Flipping again brings the original list entry out.
    assert u.reorderm(m, (2, 1, 0)) == u.flipm(invert_inner(flipped))
예제 #2
0
  def test_flipm_unit(self):
    m = {"a": {1: "a_one", 2: "a_two"}, "b": {1: "b_one", 3: "b_three"}}
    expected = {
        1: {
            "a": "a_one",
            "b": "b_one"
        },
        2: {
            "a": "a_two"
        },
        3: {
            "b": "b_three"
        }
    }

    # Flipping does what we expect!
    self.assertDictEqual(u.flipm(m), expected)
예제 #3
0
def test_flipm_unit():
    m = {"a": {1: "a_one", 2: "a_two"}, "b": {1: "b_one", 3: "b_three"}}
    expected = {
        1: {
            "a": "a_one",
            "b": "b_one"
        },
        2: {
            "a": "a_two"
        },
        3: {
            "b": "b_three"
        }
    }

    # Flipping does what we expect!
    assert u.flipm(m) == expected
예제 #4
0
 def test_flipm_empty_values(self, ks):
   """Flipping a dictionary with empty values always equals the empty map."""
   m = u.dict_by(ks, lambda k: {})
   self.assertDictEqual({}, u.flipm(m))
예제 #5
0
 def test_flipm(self, m):
   # As long as an inner dictionary isn't empty, flipping is invertible.
   self.assertDictEqual(m, u.flipm(u.flipm(m)))
예제 #6
0
def test_flipm_empty_values(ks):
    """Flipping a dictionary with empty values always equals the empty map."""
    m = u.dict_by(ks, lambda k: {})
    assert {} == u.flipm(m)
예제 #7
0
def test_flipm(m):
    # As long as an inner dictionary isn't empty, flipping is invertible.
    assert m == u.flipm(u.flipm(m))