def test_deep_find_all_bfs_when_found_more_keys_then_return_them_all(self):
        data = {1: 'first', 2: 'second', 3: {4: {2: 'third'}}}
        key = 2

        data2 = {1: {2: {3: 'second'}}, 3: 'first'}
        key2 = 3

        data3 = {1: {4: {5: 'third'}}, 2: {6: 'first', 5: 'second'}}
        key3 = 5

        data4 = {
            1: 'first',
            2: {
                1: 'second',
                4: {
                    1: 'fourth'
                }
            },
            3: {
                1: 'third'
            }
        }
        key4 = 1

        self.assertEqual(deep_find_all_bfs(data, key), ['second', 'third'])
        self.assertEqual(deep_find_all_bfs(data2, key2), ['first', 'second'])
        self.assertEqual(deep_find_all_bfs(data3, key3), ['second', 'third'])
        self.assertEqual(deep_find_all_bfs(data4, key4),
                         ['first', 'second', 'third', 'fourth'])
Пример #2
0
    def test_find_all_keys_with_simple_dictionary(self):
        root = {
            'a': {
                'aa': 2,
                'aaa': {
                    'ani': 23,
                    'pesho': ['p', 'e', 's', 'h', 'o']
                }
            },
            'b': 2,
            'c': 3
        }

        res = deep_find_all_bfs(root, 'aa')

        self.assertEqual(res, [2])
Пример #3
0
    def test_find_all_whean_there_is_no_occurence(self):
        root = {
            'a': {
                'aa': 2,
                'aaa': {
                    'ani': 23,
                    'pesho': ['p', 'e', 's', 'h', 'o']
                }
            },
            'b': 2,
            'c': 3
        }

        res = deep_find_all_bfs(root, 'Yoanna')

        self.assertEqual(res, [])
    def test_deep_find_all_bfs_when_only_one_key_is_found_on_deeper_level(
            self):
        data = {
            1: 'first',
            2: 'second',
            3: {
                4: 'third'
            },
            5: {
                6: {
                    7: 'fourth'
                }
            }
        }
        key = 7

        self.assertEqual(deep_find_all_bfs(data, key), ['fourth'])
Пример #5
0
    def test_deep_find_dfs_with_more_occurances_in_the_dictionary_returns_all_values(
            self):
        root = {
            'a': {
                'aa': 2,
                'aaa': {
                    'ani': 23,
                    'pesho': ['p', 'e', 's', 'h', 'o']
                }
            },
            'aa': ['doggy', 'catty'],
            'b': 2,
            'c': 3
        }

        res = deep_find_all_bfs(root, 'aa')

        self.assertEqual(res, [['doggy', 'catty'], 2])
Пример #6
0
    def test_bfs_finds_all_values_in_the_correct_order(self):
        data = {
            'keys1': {
                'key1': 'val3',
                'keys2': {
                    'key1': 'val4'
                }
            },
            'key1': 'val1',
            'keys2': {
                'key1': 'val5'
            }
        }
        key = 'key1'

        expected = ['val1', 'val3', 'val5', 'val4']
        result = deep_find_all_bfs(data, key)

        self.assertEqual(result, expected)
Пример #7
0
    def test_deep_find_dfs_with_more_occurances_in_the_dictionary_and_more_nested_structeres_returns_al_values(
            self):
        root = {
            'a': {
                'aa': 2,
                'aaa': {
                    'ani': 23,
                    'pesho': ['p', 'e', 's', 'h', 'o']
                },
                'ani': 'panda'
            },
            'aa': ['doggy', 'catty'],
            'ani': 'girl',
            'b': 2,
            'c': 3
        }

        res = deep_find_all_bfs(root, 'ani')

        self.assertEqual(res, ['girl', 'panda', 23])
    def test_deep_find_all_bfs_when_value_is_tuple(self):
        data = {1: ({2: 'second'}, {3: {4: 'third'}}), 2: 'first'}
        key = 2

        self.assertEqual(deep_find_all_bfs(data, key), ['first', 'second'])
    def test_deep_find_all_bfs_when_no_keys_found_then_return_false(self):
        data = {1: 'first', 2: 'second'}
        key = 4

        self.assertFalse(deep_find_all_bfs(data, key))
Пример #10
0
    def test_deep_find_all_bfs_when_only_one_key_is_found_on_second_level(
            self):
        data = {1: 'first', 2: 'second', 3: {4: 'third'}}
        key = 4

        self.assertEqual(deep_find_all_bfs(data, key), ['third'])