Exemple #1
0
def test(text):
    code, comment = ([x.strip() for x in text.split(u"#")] + [None])[:2]
    expected = (comment[1:].strip()
                if (comment and comment.startswith(u"="))
                else None)
    if code:
        print u"%s>>> %s%s" % (C_PLAIN, C_INPUT, code)
        global N_TESTS, N_FAILED
        N_TESTS += 1
        failed = False
        r = APL(code)
        if PARSE_ONLY:
            print(C_INFO + "Parsed: " + C_OUTPUT + pformat(r))
        else:
            if r is not None:
                print C_OUTPUT + display(r)
                print C_INFO + lispify(r)
            if UNIT_TESTS and expected and expected != display(r):
                failed = True
                print C_ERROR + "************ Expected: %s" % expected
        x = get_unparsed_input()
        if x:
            failed = True
            print C_ERROR + "************ Not parsed:", x
        if failed:
            N_FAILED += 1
Exemple #2
0
○2          #= 6.28318530718
6⍴5         #= 5 5 5 5 5 5
""")

tests(1, u"""
'Operators'
+/⍳5     #= 10
+/⍳10    #= 45
*¨⍳4     #= 1.0 2.71828182846 7.38905609893 20.0855369232
#֬1 2 3 4 5 10    #= 1.0 0.5 0.333333333333 0.25 0.2 0.1
+/5 4 3         #= 12
#1↓⍳6            #= 1 2 3 4 5
#×/1↓⍳6          #= 120
""")

tests(1, u"""
'Harder'
2×(9÷3)-1
""")

if UNIT_TESTS:
    print C_INFO + "***** %d OF %d TESTS FAILED *****" % (N_FAILED, N_TESTS)

print C_PLAIN

if 0:
    print "VARIABLES:"
    for k,v in apl_globals.iteritems():
        print u"%s ← %s" % (k, display(v))