def test_ab(self): input_ = {'a': 123, 'b.a': 212, 'b.b.a': 777} output = {'a': 123, 'b': {'a': 212, 'b': {'a': 777} }} self.assertEqual(output, solution.unflatten_dict(input_))
def test_unflatten_with_three_dicts_nesting(self): self.assertEqual({'b': { 'c': { 'd': { 'f': 2 } } }}, s.unflatten_dict({'b.c.d.f': 2}))
def test_games_type(self): input_ = {'moba': 'league_of_legends', 'fps.dota': 12, 'fps.call_of_duty.battlefield': 777} output = {'moba': 'league_of_legends', 'fps': {'dota': 12, 'call_of_duty': {'battlefield': 777} }} self.assertEqual(output, solution.unflatten_dict(input_))
def test_unflatten_with_one_dict_nesting(self): self.assertEqual({ 'a': 1, 'b': { 'c': 2 } }, s.unflatten_dict({ 'a': 1, 'b.c': 2 }))
def test_unflatten_with_two_dicts_nesting_third_level(self): self.assertEqual({'b': { 'c': { 'd': 2, 'f': 3 } }}, s.unflatten_dict({ 'b.c.d': 2, 'b.c.f': 3 }))
def test_fruits_three_levels(self): input_ = {'pineapple': 1, 'apple.orange': 2, 'apple.cherry': 2, 'apple.peach.apricot': 1, 'apple.peach.lemon': 1, 'kiwi': 3} output = {'pineapple': 1, 'apple': {'orange': 2, 'cherry': 2, 'peach': {'apricot': 1, 'lemon': 1}}, 'kiwi': 3} self.assertEqual(s.unflatten_dict(input_), output)
def test_names(self): input_ = {'steve': 12, 'jack.jess': 21, 'jack.karry': 31, 'jack.molly.peny': 33, 'jack.molly.john': 44, 'lily': 3} output = {'steve': 12, 'jack': {'jess': 21, 'karry': 31, 'molly': {'peny': 33, 'john': 44}}, 'lily': 3} self.assertEqual(solution.unflatten_dict(input_), output)
def test_automobile_manufacturers(self): input_ = {'Sweden': 'Volvo', 'Germany.Wolfsburg': 'VW', 'Germany.Munich': 'BMW', 'Germany.Stuttgart.east': 'Porsche', 'Germany.Stuttgart.west': 'Mercedes', 'Chemnitz': 'Audi'} output = {'Sweden': 'Volvo', 'Germany': {'Wolfsburg': 'VW', 'Munich': 'BMW', 'Stuttgart': {'east': 'Porsche', 'west': 'Mercedes'}}, 'Chemnitz': 'Audi'} self.assertEqual(s.unflatten_dict(input_), output)
def test_with_three_levels_of_nesting(self): self.assertEqual({ 'a': 1, 'b': { 'a': 2, 'b': { 'a': 1 } } }, s.unflatten_dict({ 'a': 1, 'b.a': 2, 'b.b.a': 1 }))
def test_three(self): self.assertEqual( { 'one': 1, 'three': { 'threeOne': { 'threeOneOne': 3.11 } }, 'two': { 'twoOne': 2.1 } }, solution.unflatten_dict({ 'three.threeOne.threeOneOne': 3.11, 'two.twoOne': 2.1, 'one': 1 }))
def test_with_three_levels(self): self.assertEqual( { 'g': 103, 'c': { 'd': { 'e': { 'f': 402 } } }, 'a': { 'b': 195 } }, solution.unflatten_dict({ 'g': 103, 'a.b': 195, 'c.d.e.f': 402 }))
def test_example(self): self.assertEqual( { 'a': 1, 'c': { 'a': 2, 'b': { 'x': 5, 'y': 9, } }, 'd': [1, 2, 3] }, s.unflatten_dict({ 'a': 1, 'c.a': 2, 'c.b.x': 5, 'c.b.y': 9, 'd': [1, 2, 3] }))
def test_automobile_manufacturers(self): input_ = { 'Sweden': 'Volvo', 'Germany.Wolfsburg': 'VW', 'Germany.Munich': 'BMW', 'Germany.Stuttgart.east': 'Porsche', 'Germany.Stuttgart.west': 'Mercedes', 'Chemnitz': 'Audi' } output = { 'Sweden': 'Volvo', 'Germany': { 'Wolfsburg': 'VW', 'Munich': 'BMW', 'Stuttgart': { 'east': 'Porsche', 'west': 'Mercedes' } }, 'Chemnitz': 'Audi' } self.assertEqual(s.unflatten_dict(input_), output)
def test_fruits_three_levels(self): input_ = { 'pineapple': 1, 'apple.orange': 2, 'apple.cherry': 2, 'apple.peach.apricot': 1, 'apple.peach.lemon': 1, 'kiwi': 3 } output = { 'pineapple': 1, 'apple': { 'orange': 2, 'cherry': 2, 'peach': { 'apricot': 1, 'lemon': 1 } }, 'kiwi': 3 } self.assertEqual(s.unflatten_dict(input_), output)
def test_with_three_levels(self): self.assertEqual({'g': 103, 'c': {'d': {'e': {'f': 402}}}, 'a': {'b': 195}}, s.unflatten_dict({'g': 103, 'a.b': 195, 'c.d.e.f': 402}))
def test_unflatten_with_two_dicts_nesting_second_level(self): self.assertEqual({'b': {'c': {'d': 2}, 'f': 3}}, s.unflatten_dict( {'b.c.d': 2, 'b.f': 3}))
def test_unflatten_with_two_dicts_nesting(self): self.assertEqual({'b': {'c': {'d': 2}}}, s.unflatten_dict( {'b.c.d': 2}))
def test_with_three_levels_of_nesting(self): self.assertEqual( {'a': 1, 'b': {'a': 2, 'b': {'a': 1}}}, s.unflatten_dict({'a': 1, 'b.a': 2, 'b.b.a': 1}) )
def test_with_three_levels(self): self.assertEqual( {"g": 103, "c": {"d": {"e": {"f": 402}}}, "a": {"b": 195}}, solution.unflatten_dict({"g": 103, "a.b": 195, "c.d.e.f": 402}), )
def test_three(self): self.assertEqual( {"one": 1, "three": {"threeOne": {"threeOneOne": 3.11}}, "two": {"twoOne": 2.1}}, solution.unflatten_dict({"three.threeOne.threeOneOne": 3.11, "two.twoOne": 2.1, "one": 1}), )
def test_unflatten_without_nesting(self): self.assertEqual({'a': 1, 'b': 2}, s.unflatten_dict({'a': 1, 'b': 2}))
def test_three(self): self.assertEqual({'one': 1, 'three': {'threeOne': {'threeOneOne': 3.11}}, 'two': {'twoOne': 2.1}}, s.unflatten_dict({'three.threeOne.threeOneOne': 3.11, 'two.twoOne': 2.1, 'one': 1}))
def test_with_already_unflatten_dict(self): unflatten = {'a': 1, 'b': 2, 'c': 3} self.assertEqual(unflatten, s.unflatten_dict(unflatten))
def test_example(self): self.assertEqual( {'a': 1, 'c': {'a': 2, 'b': {'x': 5, 'y': 9, }}, 'd': [1, 2, 3]}, s.unflatten_dict({'a': 1, 'c.a': 2, 'c.b.x': 5, 'c.b.y': 9, 'd': [1, 2, 3]}) )
def test_unflatten_with_one_dict_nesting(self): self.assertEqual({'a': 1, 'b': {'c': 2}}, s.unflatten_dict( {'a': 1, 'b.c': 2}))