@@ 28,7 28,7 @@ def add_n_stuff(p_d=0.9, n_max=4, min=-10, max=10,
if r < 0:
try: # Should automatically skip it if not possible.
args = [randint(min, max) for i in range(n - 1)]
- val = fun(val, *args)
+ val = fun(val, *args) # Update value and code to test.
s += ' ' + ' '.join(map(str, args)) + ' ' + k
break
except:
@@ 41,8 41,12 @@ from type_stack_calc.intro import intro
from type_stack_calc.util.scopify import scopify
def ignore(_x): pass
-
vs = scopify(intro)
+assert vs.get('Set')
+
+for i in range(10):
+ got, = StackCalc().tp_calc(parser(f"{i}"), vs, [], ignore)
+ assert got.single(i), (i, got)
# Introduce this function.
StackCalc().tp_calc(parser("(x) {x x *}.fun sqr.set ;"), vs, [], ignore)
@@ 13,11 13,11 @@ from type_stack_calc.tp.other_sets import Range
from type_stack_calc.tp.str import ConstStr
import re
-def check_no_none(in_gen, *ctx):
+def assert_acceptable_vals(in_gen, *ctx):
ctx = '\n'.join(map(repr, ctx))
for i, el in enumerate(in_gen):
- assert el is not None, \
- f"Expected no none, but got for {i}\nctx: {ctx}"
+ assert type(el) not in {type(None), float, int}, \
+ f"Expected no `{el}`({type(el)}), but got for {i}\n ctx: {ctx}"
def interpret_num_word(word):
if re.match("-?\d+", word): # Plain integer.
@@ 26,10 26,12 @@ def interpret_num_word(word):
return int(word[2:], 16)
elif re.match("\d+\.\d*", word): # Floating point number.
return float(word)
+ assert word not in "0123456789"
def interpret_word(word):
"""Interprets constant values."""
- if x := interpret_num_word(word):
+ x = interpret_num_word(word)
+ if x is not None:
return Range(x, x) # TODO for integers might want to indicate that.
elif word[0] == '"': # Constant string.
return ConstStr(word[1:])
@@ 91,11 93,11 @@ class StackCalc:
assert type(el) not in {str, int, float}, el
el.relevant_comp = relevant_comp
- check_no_none(rest, rest)
- check_no_none(stack, rest)
+ assert_acceptable_vals(rest, rest)
+ assert_acceptable_vals(stack, rest)
return (rest + stack, *tc_code)
- check_no_none(stack, val)
+ assert_acceptable_vals(stack, val)
return stack[:-1] + [var], var # No calculation needed.
@@ 144,4 146,4 @@ class StackCalc:
assert el is not None, \
f"Expected no None objects {otp}\n (from {got})"
into(el)
- check_no_none(stack, got, code)
+ assert_acceptable_vals(stack, got, code)