🐐 Hash tables
This commit is contained in:
@@ -189,3 +189,34 @@ class TestDictDisplay(unittest.TestCase):
|
||||
@parameterized.expand(dict_display_tests)
|
||||
def test_dict_display(self, source, nodes, value, output):
|
||||
run_test(self, source, nodes, value, output)
|
||||
|
||||
|
||||
class TestDictGrowth(unittest.TestCase):
|
||||
def test_dict_growth_preserves_order_and_lookup(self):
|
||||
# Inserts XX entries via PER; pushes the compiled dict through
|
||||
# multiple rehashes (initial cap=4) and verifies that lookup, length,
|
||||
# and insertion-order iteration all still hold afterwards.
|
||||
source = (
|
||||
"DESIGNA d VT TABVLA {}\n"
|
||||
"PER i IN [I VSQVE XX] FAC {\n"
|
||||
"DESIGNA d[i] VT i * II\n"
|
||||
"}\n"
|
||||
"DIC(d[X])\n"
|
||||
"DIC(LONGITVDO(d))\n"
|
||||
"DIC(CLAVES(d))"
|
||||
)
|
||||
nodes = Program([], [
|
||||
Designa(ID("d"), DataDict([])),
|
||||
PerStatement(
|
||||
DataRangeArray(Numeral("I"), Numeral("XX")),
|
||||
ID("i"),
|
||||
[DesignaIndex(ID("d"), [ID("i")],
|
||||
BinOp(ID("i"), Numeral("II"), "SYMBOL_TIMES"))],
|
||||
),
|
||||
ExpressionStatement(BuiltIn("DIC", [ArrayIndex(ID("d"), Numeral("X"))])),
|
||||
ExpressionStatement(BuiltIn("DIC", [BuiltIn("LONGITVDO", [ID("d")])])),
|
||||
ExpressionStatement(BuiltIn("DIC", [BuiltIn("CLAVES", [ID("d")])])),
|
||||
])
|
||||
keys_str = "[" + " ".join(int_to_num(i, False) for i in range(1, 21)) + "]"
|
||||
output = f"XX\nXX\n{keys_str}\n"
|
||||
run_test(self, source, nodes, ValStr(keys_str), output)
|
||||
|
||||
Reference in New Issue
Block a user