from hashtable import HashNode, HashTable

n = HashNode("k", "v")
assert(n is not None)
assert(hasattr(n, "key"))
assert(hasattr(n, "value"))
assert(hasattr(n, "next"))
assert(str(n) == "(k,v)")

t = HashTable(4)
assert(t is not None)
assert(hasattr(t, "nodes"))
assert(hasattr(t, "get"))
assert(hasattr(t, "set"))

t.set("Good", "1")
unempty_nodes = [node for node in t.nodes if node is not None]
assert(len(unempty_nodes) == 1)
assert(str(unempty_nodes[0]) == "(Good,1)")
assert(str(t) == "(Good,1)")

t.set("Bad", "3")
t_str = str(t)
assert("(Good,1)" in t_str)
assert("(Bad,3)" in t_str)
t_str = t_str.replace("(Good,1)", "")
t_str = t_str.replace("(Bad,3)", "")
assert(t_str == "")

t.set("Normal", "2")
t_str = str(t)
assert("(Good,1)" in t_str)
assert("(Bad,3)" in t_str)
assert("(Normal,2)" in t_str)
t_str = t_str.replace("(Good,1)", "")
t_str = t_str.replace("(Bad,3)", "")
t_str = t_str.replace("(Normal,2)", "")
assert(t_str == "")

t.set("Great", "4")
t_str = str(t)
assert("(Good,1)" in t_str)
assert("(Bad,3)" in t_str)
assert("(Normal,2)" in t_str)
assert("(Great,4)" in t_str)
t_str = t_str.replace("(Good,1)", "")
t_str = t_str.replace("(Bad,3)", "")
t_str = t_str.replace("(Normal,2)", "")
t_str = t_str.replace("(Great,4)", "")
assert(t_str == "")

t.set("Terrible", "-1")
t_str = str(t)
assert("(Good,1)" in t_str)
assert("(Bad,3)" in t_str)
assert("(Normal,2)" in t_str)
assert("(Great,4)" in t_str)
assert("(Terrible,-1)" in t_str)
t_str = t_str.replace("(Good,1)", "")
t_str = t_str.replace("(Bad,3)", "")
t_str = t_str.replace("(Normal,2)", "")
t_str = t_str.replace("(Great,4)", "")
t_str = t_str.replace("(Terrible,-1)", "")
assert(t_str == "")

assert(t.get("Terrible") == "-1")
assert(t.get("Good") == "1")
assert(t.get("Normal") == "2")
assert(t.get("Bad") == "3")
assert(t.get("Great") == "4")

t.set("Good", "2")
assert(t.get("Good") == "2")

t.set("Normal", "0")
assert(t.get("Normal") == "0")

t.set("Bad", "-1")
assert(t.get("Bad") == "-1")

t.set("Great", "2")
assert(t.get("Great") == "2")