145 lines
5.8 KiB
Python
Executable File
145 lines
5.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import signal
|
|
import subprocess
|
|
import os
|
|
import sys
|
|
import time
|
|
import platform
|
|
|
|
class TestFailedException(Exception):
|
|
pass
|
|
|
|
def do_test(text, expect, title='(unnamed)'):
|
|
os.environ["LERPN_TEST_PRINT"] = "1"
|
|
p=subprocess.Popen(
|
|
[sys.executable, '-m', 'LerpnApp'],
|
|
stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE
|
|
)
|
|
p.stdin.write(text)
|
|
p.stdin.write(b"\x03")
|
|
p.stdin.close()
|
|
stdout = p.stdout.read()
|
|
p.send_signal(signal.SIGINT)
|
|
curses_garbage, _, output = stdout.partition(b"BEGIN_PRINT\n")
|
|
|
|
if expect != output:
|
|
print("Test failed: %s" % title)
|
|
print("Sent: %r" % text)
|
|
print("Expected: %r" % expect)
|
|
print("Got: %r" % output)
|
|
#raise TestFailedException()
|
|
else:
|
|
print("Test passed: %s" % title)
|
|
|
|
print("Testing under Python: %s" % platform.python_version())
|
|
print()
|
|
print("===INPUT===")
|
|
do_test(b"7\n3*\n+", b"42\n", "basic arithmetic")
|
|
do_test(b"999\n4'divmod\n", b"249\n3\n","divmod")
|
|
do_test(b"42\"tag\n", b"42\n", "tag")
|
|
do_test(b"1 k\n", b"1000\n", "eng")
|
|
do_test(b"0x10\n", b"16\n", "hex")
|
|
do_test(b"0xabcdef\n", b"1.12594e7\n", "hex a-f") # see bugfix e1d372d6
|
|
do_test(b"0o10\n", b"8\n", "oct")
|
|
do_test(b"0b10\n", b"2\n", "bin")
|
|
do_test(b"4:20\n", b"260\n", "duration 1")
|
|
do_test(b"4:20:\n", b"15600\n", "duration 2")
|
|
do_test(b"4:20:69\n", b"15669\n", "duration 3")
|
|
do_test(b"1::\n", b"3600\n", "duration 4")
|
|
do_test(b"1:::\n", b"86400\n", "duration 5")
|
|
do_test(b"1::::\n", b"Too many fields in :-delimited value (d:h:m:s)\n", "bad duration")
|
|
|
|
do_test(b"1\n2+u", b"1\n2\n", "undo")
|
|
do_test(b"1\n2+uR", b"3\n", "redo")
|
|
do_test(b"1\n2+u3\nR", b"1\n2\n3\n", "redo blocking")
|
|
|
|
print()
|
|
print("===DISPLAY===")
|
|
do_test(b"1234'eng\n'str\n", b"'1.234 k'\n", "eng")
|
|
do_test(b"1234'sci\n'str\n", b"'1.234e3'\n", "sci")
|
|
do_test(b"1234'fix\n'str\n", b"'1234.000000'\n", "fix")
|
|
do_test(b"1234'nat\n'str\n", b"'1234'\n", "natural")
|
|
do_test(b"1234'hex\n'str\n", b"'0x4d2'\n", "hex")
|
|
do_test(b"1234'oct\n'str\n", b"'0o2322'\n", "oct")
|
|
do_test(b"1234'bin\n'str\n", b"'0b10011010010'\n", "bin")
|
|
do_test(b"1.2'hex\n'str\n", b"'1.2'\n", "floats in integer mode")
|
|
do_test(b"1234'fix 2\n'str\n", b"'1234.00'\n", "argument to display mode") # see bugfix e0e051aa
|
|
|
|
print()
|
|
print("===TRIGONOMETRY===")
|
|
do_test(b"1'sin\n", b"0.841471\n", "sin(float)")
|
|
do_test(b"1'cos\n", b"0.540302\n", "cos(float)")
|
|
do_test(b"1'tan\n", b"1.55741\n", "tan(float)")
|
|
do_test(b"1'sind\n", b"0.017452\n", "sind(float)")
|
|
do_test(b"1'cosd\n", b"0.999848\n", "cosd(float)")
|
|
do_test(b"1'tand\n", b"0.017455\n", "tand(float)")
|
|
do_test(b"1j1'sin\n", b"1.29846 j 0.634964\n", "sin(complex)")
|
|
do_test(b"1j1'sind\n", b"0.017455 j 0.017451\n", "sind(complex)")
|
|
do_test(b"0.5'asin\n", b"0.523599\n", "asin(float)")
|
|
do_test(b"1j1'asin\n", b"0.666239 j 1.06128\n", "asin(complex)")
|
|
do_test(b"0.5'acos\n", b"1.0472\n", "acos(float)")
|
|
do_test(b"0.5'atan\n", b"0.463648\n", "atan(float)")
|
|
do_test(b"0.5'asind\n", b"30.\n", "asind(float)")
|
|
do_test(b"0.5'acosd\n", b"60.\n", "acosd(float)")
|
|
do_test(b"0.5'atand\n", b"26.565\n", "atand(float)")
|
|
do_test(b"'pi\n'deg\n", b"180\n", "deg(float)")
|
|
do_test(b"180'rad\n", b"3.14159\n", "rad(float)")
|
|
|
|
print()
|
|
print("===HYPERBOLICS===")
|
|
do_test(b"1'sinh\n", b"1.1752\n", "sinh(float)")
|
|
do_test(b"1'cosh\n", b"1.54308\n", "cosh(float)")
|
|
do_test(b"1'tanh\n", b"0.761594\n", "tanh(float)")
|
|
do_test(b"1'asinh\n", b"0.881374\n", "asinh(float)")
|
|
do_test(b"1'acosh\n", b"0\n", "acosh(float)")
|
|
do_test(b"0.5'atanh\n", b"0.549306\n", "atanh(float)")
|
|
|
|
print()
|
|
print("===LOGARITHMS===")
|
|
do_test(b"1'exp\n", b"2.71828\n", "exp(float)")
|
|
do_test(b"'e\n'log\n", b"1\n", "log(float)")
|
|
do_test(b"10'log10\n", b"1\n", "log10(float)")
|
|
do_test(b"2'log2\n", b"1\n", "log2(float)")
|
|
|
|
print()
|
|
print("==COMPLEX==")
|
|
do_test(b"42j1337're\n42j1337'im\n", b"42\n1337\n", "re, im")
|
|
do_test(b"42j1337'conj\n", b"42 j -1337\n", "conj")
|
|
do_test(b"42j1337'reim\n", b"42\n1337\n", "reim")
|
|
do_test(b"42j1337'abs\n", b"1337.66\n", "abs(complex)")
|
|
do_test(b"_17'abs\n", b"17\n", "abs(float)")
|
|
do_test(b"42j1337'angle\n", b"1.53939\n", "angle(complex)")
|
|
do_test(b"_17'angle\n", b"3.14159\n", "angle(float)")
|
|
do_test(b"42j1337'polar\n", b"1337.66\n1.53939\n", "polar(complex)")
|
|
do_test(b"_17'polar\n", b"17\n3.141592653589793\n", "polar(float)")
|
|
do_test(b"42\n1337'fcart\n", b"42 j 1337\n", "fcart")
|
|
do_test(b"1337.66\n1.53939'fpolar\n", b"42.0041 j 1337.\n","fpolar")
|
|
|
|
print()
|
|
print("==CONSTANTS==")
|
|
do_test(b"'pi\n", b"3.14159\n", "pi")
|
|
do_test(b"'e\n", b"2.71828\n", "e")
|
|
do_test(b"'j\n", b"0 j 1\n", "imaginary unit")
|
|
do_test(b"'c\n", b"2.99792e8\n", "speed of light")
|
|
do_test(b"'h\n", b"6.62608e-34\n", "Planck constant")
|
|
do_test(b"'k\n", b"1.38066e-23\n", "Boltzmann constant")
|
|
do_test(b"'elec\n", b"1.60218e-19\n", "charge of electron")
|
|
do_test(b"'e0\n", b"8.85419e-12\n", "permittivity of vacuum")
|
|
do_test(b"'amu\n", b"1.66054e-27\n", "atomic mass unit")
|
|
do_test(b"'Na\n", b"6.02214e23\n", "Avogadro's number")
|
|
do_test(b"'atm\n", b"101325\n", "standard atmosphere")
|
|
|
|
print()
|
|
print("==FRACTIONS==")
|
|
do_test(b"2,3\n1,4+", b"11,12\n", "frac + frac")
|
|
do_test(b"2,3\n0.25+", b"11,12\n", "frac + dec")
|
|
do_test(b"2\n3/'f\n", b"2,3\n", "dec -> frac")
|
|
do_test(b"2,3'n\n", b"0.666667\n", "frac -> dec")
|
|
|
|
print()
|
|
print("==MISC==")
|
|
do_test(b"'sh echo 42\n\n", b"42\n", "shell")
|
|
do_test(b"'nat\n0.11111\n'prec 3\n", b"0.111\n", "precision")
|