def test_left_join_one(): map1 = { 'fond': 'enamored', 'wrath': 'anger', 'diligent': 'employed', 'outfit': 'garb', 'guide': 'usher', } map2 = { 'fond': 'averse', 'wrath': 'delight', 'diligent': 'idle', 'guide': 'follow', 'flow': 'jam', } actual = [] actual = left_join(map1, map2) expected = [ ['fond', 'enamored', 'averse'], ['wrath', 'anger', 'delight'], ['diligent', 'employed', 'idle'], ['outfit', 'garb', None], ['guide', 'usher', 'follow'] ] assert actual == expected
def test_left_join_two(): map1 = { 'happy': 'glad', 'sad': 'unhappy', 'busy': 'occupied', 'big': 'huge', 'small': 'tiny', } map2 = { 'small': 'big', 'big': 'small', 'nice': 'bad', 'fun': 'boring', 'bright': 'dim', } actual = [] actual = left_join(map1, map2) expected = [ ['happy', 'glad', None], ['sad', 'unhappy', None], ['busy', 'occupied', None], ['big', 'huge', 'small'], ['small', 'tiny', 'big'] ] assert actual == expected
def test_left_join(hash_one, hash_two, expected): """ Two hashmaps can be left joined. """ actual = left_join(hash_one, hash_two) assert actual == expected
def test_left_join_number(): map1 = { 1: 'glad', 3: 22.3, 6: 'occupied', 15: 'huge', 23: 'tiny', } map2 = { 3: 'big', 15: 44, 28: 'bad', 5: 'boring', 44: 'dim', } actual = [] actual = left_join(map1, map2) expected = [ [1, 'glad', None], [3, 22.3, 'big'], [6, 'occupied', None], [15, 'huge', 44], [23, 'tiny', None] ] assert actual == expected
def test_left_join_null(even_table_two, uneven_table): """Test left join with null values.""" result = left_join(even_table_two, uneven_table) assert result == { 'diligent': ['idle', 'NULL'], 'fond': ['averse', 'averse'], 'wrath': ['delight', 'delight'] }
def test_left_join_perfect(even_table_one, even_table_two): """Test left join with perfect matches.""" result = left_join(even_table_one, even_table_two) assert result == { 'diligent': ['employed', 'idle'], 'fond': ['enamored', 'averse'], 'wrath': ['anger', 'delight'] }
def test_left_join_small_lists(hash_table_filled_one_small, hash_table_filled_two_small): actual = left_join(hash_table_filled_one_small, hash_table_filled_two_small) expected = [ ['Max', 'Max Gunnar McFarland', None], ['John', 'John Hamm', 'John Wayne'], ['Mike', 'Michael Jordan', 'Michael Jackson'], ] assert actual == expected
def test_returns_map_of_both_hashmaps_in_one_data_structure( hashmap_one, hashmap_two): """Succesfully returns appended value from hashmap two to hashmap one""" actual = left_join(hashmap_one, hashmap_two) expected = [[['wrath', 'anger', 'delight']], None, [['fond', 'enamored', 'averse'], ['diligent', 'employed', 'idle']], [['outift', 'garb', None]], [['guide', 'usher', 'follow']]] assert actual == expected
def test_returns_None_in_bucket_if_key_is_not_preset(): """Successfull returns appended None to bucket if both keys are not present""" h1 = HashMap(1) h2 = HashMap(1) h1.add('wrath', 'anger') h2.add('flow', 'jam') expected = [[['wrath', 'anger', None]]] actual = left_join(h1, h2) assert actual == expected
def test_returns_values_if_both_keys_are_present(): """Successfull returns appended value to bucket if both keys are present""" h1 = HashMap(1) h2 = HashMap(1) h1.add('wrath', 'anger') h2.add('wrath', 'delight') expected = [[['wrath', 'anger', 'delight']]] actual = left_join(h1, h2) assert actual == expected
def test_no_repeats(): first = HashTable() first.add('cat', 'meow') first.add('dog', 'woof') second = HashTable() second.add('snake', 'hiss') actual = left_join(first, second) expected = [('cat', 'meow', None), ('dog', 'woof', None)] assert actual == expected
def test_2_dict_is_empty(sample_dict): t1 = sample_dict t2 = {} assert left_join(t1, t2) == { "fond": ["enamored", None], "wrath": ["anger", None], "diligent": ["employed", None], "outfit": ["garb", None], "guide": ["usher", None] }
def test_first_dict_is_empty(): t1 = {} t2 = { 'kind': 'averse', 'anger': 'delight', 'studious': 'idle', 'manual': 'follow', 'leak': 'jam' } assert left_join(t1, t2) == {}
def test_2nd_dict_is_empty(): d1 = {"cat": "100", "chair": "200", "Cat": "300"} d2 = {} assert left_join(d1, d2) == { "cat": ["100", None], "chair": ["200", None], "Cat": ["300", None] }
def test_different_case(): d1 = {"cat": "a", "dog": "b", "Cat": "c"} d2 = {"cat": "100", "chair": "200", "Cat": "300"} assert left_join(d1, d2) == { "cat": ["a", "100"], "dog": ["b", None], "Cat": ["c", "300"] }
def test_left_join_larger_second_table(default_tables): T1 = default_tables[0] T2 = default_tables[1] T2.set('hostile', 'friendly') T2.set('addicted', 'indifferent') T2.set('hypnotize', 'disenchant') result = left_join(T1, T2) assert ['dirty', 'filthy', 'clean'] in result assert ['wall', 'barricade', 'opening'] in result assert ['double', 'copy', None] in result assert ['comfortable', 'pleasant', 'disagreeable'] in result
def test_for_empty_map(small_table, empty_hash_table): """Test for items in second hash map.""" assert left_join(small_table, empty_hash_table) == [{ 'John': 1234 }, { 'Jane': '123456' }, { 'John': '123' }, { 'Jane': 'abc' }]
def test_happy_path(): t1 = HashTable(4) t2 = HashTable(3) t1.set('happy', 'excited') t2.set('happy', 'sad') t1.set('mad', 'angry') t2.set('mad', 'delighted') t1.set('lost', 'failed') t2.set('lost', 'won') t1.set('shark', 'tornado') results = left_join(t1, t2) assert ['lost', 'failed', 'won'] in results assert ['shark', 'tornado', None] in results assert ['happy', 'excited', 'sad'] in results assert ['mad', 'angry', 'delighted'] in results
def test_left_join_no_matches(): one = HashTable() one.add('pond','enamored') one.add('rath', 'anger') one.add('adiligent', 'employed') one.add('poutfit', 'garb') one.add('hangguide', 'usher') two = HashTable() two.add('fond', 'averse') two.add('wrath', 'delight') two.add('diligent', 'idle') two.add('guide', 'follow') two.add('flow', 'jam') assert left_join(one, two) == [['poutfit', 'garb', None], ['hangguide', 'usher', None], ['rath', 'anger', None], ['pond', 'enamored', None], ['adiligent', 'employed', None]]
def test_left_join_big_lists_reversed_three(hash_table_filled_two, hash_table_filled_one): actual = left_join(hash_table_filled_two, hash_table_filled_one) expected = [ ['Max', 'The Axe', 'Max Gunnar McFarland'], ['Mike', 'Michael Jackson', 'Michael Jordan'], ['John', 'John Wayne', 'John Hamm'], ['Charlie', 'Charlie Sheen', 'Tiger Blood'], ['Ben', 'Ben Allen', 'Ben Heimershmidt'], ['Charlize', 'Mr. F', 'Charlieze Theron'], ['Brian', 'Bad Luck', 'Brian Cranston'], ['J', 'Homer Simpson', 'J Christie'], ['Gary', 'Gary Johnson', None], ['Ruth', 'Ruth Bayner Ginsberg', None], ['Sonya', 'Sonya Sotomayor', None], ] assert expected[4] in actual
def test_different_keys(sample_dict): t1 = sample_dict t2 = { 'kind': 'averse', 'anger': 'delight', 'studious': 'idle', 'manual': 'follow', 'leak': 'jam' } assert left_join(t1, t2) == { "fond": ["enamored", None], "wrath": ["anger", None], "diligent": ["employed", None], "outfit": ["garb", None], "guide": ["usher", None] }
def test_left_join_big_lists_two(hash_table_filled_one, hash_table_filled_two): actual = left_join(hash_table_filled_one, hash_table_filled_two) expected = [ ['Max', 'Max Gunnar McFarland', 'The Axe'], ['Mike', 'Michael Jordan', 'Michael Jackson'], ['John', 'John Hamm', 'John Wayne'], ['Charlie', 'Tiger Blood', 'Charlie Sheen'], ['Ben', 'Ben Heimershmidt', 'Ben Allen'], ['Charlize', 'Charlieze Theron', 'Mr. F'], ['Brian', 'Brian Cranston', 'Bad Luck'], ['J', 'J Christie', 'Homer Simpson'], ['Alex', 'Alexander Stone', None], ['Barrack', 'Barrack Hussien Obama', None], ['Garp', 'Garp Taco Sanchez', None], ['Alf', 'Alf, from that TV show. You know the one.... what was it called?...... Oh yeah Alf.', None], ] assert expected[1] in actual
def test_left_join(left, right, known): result = left_join(left, right) result_values = [] known_values = [] for ll1 in result.table: if ll1 and ll1.head: current = ll1.head while current: result_values.append(current.data) current = current.next for ll2 in known.table: if ll2 and ll2.head: current = ll2.head while current: known_values.append(current.data) current = current.next assert result_values == known_values
def test_no_common_keys(my_dict): d1 = my_dict d2 = { 'car': 'averse', 'cat': 'delight', 'mouse': 'idle', 'table': 'follow', 'house': 'jam' } assert left_join(d1, d2) == { "fond": ["enamored", None], "wrath": ["anger", None], "diligent": ["employed", None], "outfit": ["garb", None], "guide": ["usher", None] }
def test_func_fullsample(): h1 = HashTable() h1.add('fond', 'enamored') h1.add('wrath', 'anger') h1.add('diligent', 'employed') h1.add('outfit', 'garb') h1.add('guide', 'usher') h2 = HashTable() h2.add('fond', 'averse') h2.add('wrath', 'delight') h2.add('diligent', 'idle') h2.add('guide', 'follow') h2.add('flow', 'jam') expected = [ { 'word': 'diligent', 'synonym': 'employed', 'antonym': 'idle', }, # noqa E202 { 'word': 'outfit', 'synonym': 'garb', 'antonym': None, }, # noqa E202 { 'word': 'fond', 'synonym': 'enamored', 'antonym': 'averse', }, # noqa E202 { 'word': 'guide', 'synonym': 'usher', 'antonym': 'follow', }, # noqa E202 { 'word': 'wrath', 'synonym': 'anger', 'antonym': 'delight', } # noqa E202 ] actual = left_join(h1, h2) assert expected == actual
def test_given_example(my_dict): dict1 = my_dict dict2 = { 'fond': 'averse', 'wrath': 'delight', 'diligent': 'idle', 'guide': 'follow', 'flow': 'jam' } assert left_join(dict1, dict2) == { "fond": ["enamored", "averse"], "wrath": ["anger", "delight"], "diligent": ["employed", "idle"], "outfit": ["garb", None], "guide": ["usher", "follow"] }
def test_one_overlap(): table1 = Hashtable() table1.add("fond", "enamored") table1.add("wrath", "anger") table1.add("diligent", "employed") table1.add("outfit", "garb") table1.add("guide", "usher") table2 = Hashtable() table2.add("fond", "averse") actual = left_join(table1, table2) assert actual == [ ["fond", "enamored", "averse"], ["guide", "usher", None], ["outfit", "garb", None], ["diligent", "employed", None], ["wrath", "anger", None], ]
def test_left_join_happy_test(): t_1 = HashTable() t_1.add('fond', 'enamored') t_1.add('wrath', 'anger') t_1.add('diligent', 'employed') t_1.add('outfit', 'garb') t_1.add('guide', 'usher') t_2 = HashTable() t_2.add('fond', 'averse') t_2.add('wrath', 'delight') t_2.add('diligent', 'idle') t_2.add('guide', 'follow') t_2.add('flow', 'jam') assert left_join(t_1, t_2) == [['diligent', 'employed', 'idle'], ['wrath', 'anger', 'delight'], ['guide', 'usher', 'follow'], ['fond', 'enamored', 'averse'], ['outfit', 'garb', None]]
def test_left_join_all_different(): t_1 = HashTable() t_1.add('james', 'agent') t_1.add('bond', 'surname') t_1.add('gun', 'tool') t_1.add('girl', 'bondgirl') t_1.add('car', 'speed') t_2 = HashTable() t_2.add('fond', 'averse') t_2.add('wrath', 'delight') t_2.add('diligent', 'idle') t_2.add('guide', 'follow') t_2.add('flow', 'jam') assert left_join(t_1, t_2) == [ ['gun', 'tool', None], ['james', 'agent', None], ['bond', 'surname', None], ['girl', 'bondgirl', None], ['car', 'speed', None], ]
def test_func_onematch_onedoesnt(): h1 = HashTable() h1.add('fond', 'enamored') h1.add('wrath', 'anger') h2 = HashTable() h2.add('fond', 'averse') expected = [ { 'word': 'fond', 'synonym': 'enamored', 'antonym': 'averse' }, # noqa: E202 { 'word': 'wrath', 'synonym': 'anger', 'antonym': None } # noqa: E202 ] actual = left_join(h1, h2) assert expected == actual