-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hashtable.py
More file actions
107 lines (85 loc) · 2.62 KB
/
Copy pathtest_hashtable.py
File metadata and controls
107 lines (85 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pytest
from data_structures.hashtable import Hashtable
def test_exists():
assert Hashtable
# @pytest.mark.skip("TODO")
def test_hash():
"""
intentionally breaks encapsulation by accessing internal attriubutes
"""
hashtable = Hashtable()
actual = hashtable._hash("Lana")
assert 0 <= actual < hashtable._size
# @pytest.mark.skip("TODO")
def test_hash_twice():
"""
intentionally breaks encapsulation by accessing internal attriubutes
"""
hashtable = Hashtable()
first = hashtable._hash("Lana")
second = hashtable._hash("Lana")
assert first == second
# @pytest.mark.skip("TODO")
def test_apple():
hashtable = Hashtable()
hashtable.set("apple", "can make apple sauce")
actual = hashtable.get("apple")
expected = "can make apple sauce"
assert actual == expected
# @pytest.mark.skip("TODO")
def test_apple_again():
hashtable = Hashtable()
hashtable.set("apple", "can make apple sauce")
hashtable.set("apple", "has a worm")
actual = hashtable.get("apple")
expected = "has a worm"
assert actual == expected
# @pytest.mark.skip("TODO")
def test_key_not_exists():
hashtable = Hashtable()
actual = hashtable.get("key is not there")
expected = None
assert actual == expected
# @pytest.mark.skip("TODO")
def test_key_not_exists_again():
"""
requires that act & cat hash the same
"""
hashtable = Hashtable()
hashtable.set("cat", "meow")
actual = hashtable.get("act")
expected = None
assert actual == expected
# @pytest.mark.skip("TODO")
def test_keys():
hashtable = Hashtable()
hashtable.set("apple", "can make apple sauce")
hashtable.set("banana", "great in banana bread")
actual = hashtable.keys()
expected = ["apple", "banana"]
assert sorted(actual) == sorted(expected)
# @pytest.mark.skip("TODO")
def test_has():
hashtable = Hashtable()
hashtable.set("apple", "can make apple sauce")
hashtable.set("banana", "great in a banana bread")
assert hashtable.has("apple")
assert hashtable.has("banana")
assert not hashtable.has("cucumber")
# @pytest.mark.skip("TODO")
def test_keys_repeats():
hashtable = Hashtable()
hashtable.set("apple", "can make apple sauce")
hashtable.set("apple", "has a worm")
hashtable.set("banana", "great in a banana bread")
actual = hashtable.keys()
expected = ["apple", "banana"]
assert sorted(actual) == sorted(expected)
@pytest.mark.skip("TODO")
def test_internals():
"""
there's a test_internals in your DSA repo that isn't a great fit.
Feel free to ignore it
Or tweak it as a STRETCH
"""
pass