-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize kg_equal and add more tests
- Loading branch information
Showing
8 changed files
with
106 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
:" access the len function of the Python object " | ||
|
||
a:::{[1 2]} | ||
len::.pya(a;"__len__") | ||
|
||
t("a.__len__ == 1"; len(); 1) | ||
|
||
t("a.__doc__ starts with dict"; 4#.pya(a;"__doc__"); "dict") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
:" import the numpy.random module " | ||
t(".pyf(""numpy"";""random"")"; .pyf("numpy";"random"); 1) | ||
|
||
rns::.pya(random;"seed") | ||
rns(0) | ||
rnd::.pya(random;"random") | ||
|
||
expected::[[0.5488135039273248 0.7151893663724195] [0.6027633760716439 0.5448831829968969] [0.4236547993389047 0.6458941130666561] [0.4375872112626925 0.8917730007820798]] | ||
|
||
t("rnd([4 2])=expected"; rnd([4 2]); expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
t(".pyf(""numpy"";""mean"")"; .pyf("numpy";"mean"); 1) | ||
|
||
:" this should fail " | ||
:" use the numpy mean function " | ||
t("mean(!100)"; mean(!100); 49.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import glob | ||
import math | ||
import os | ||
import unittest | ||
|
||
from utils import * | ||
|
||
import timeit | ||
|
||
def parse_suite_file(fname, number=10): | ||
klong = KlongInterpreter() | ||
with open(fname, "r") as f: | ||
d = f.read() | ||
b = len(d) * number | ||
r = timeit.timeit(lambda: klong(d), number=number) | ||
return b, r, int(b / r), r / number | ||
|
||
|
||
def test_kgtests(): | ||
""" | ||
Recursively run all tests under the kgtests folder that begin with "test" and end with ".kg". | ||
""" | ||
root_dir = os.path.join(os.getcwd(), "tests", "kgtests") | ||
|
||
for dirpath, _, filenames in os.walk(root_dir): | ||
for fname in filenames: | ||
if (fname.startswith("gen")) and fname.endswith(".kg"): | ||
ran_tests = True | ||
klong = KlongInterpreter() | ||
fullpath = os.path.join(dirpath, fname) | ||
klong['fullpath'] = fullpath | ||
klong('.l("tests/kgtests/runner.kg")') | ||
if fname.startswith("gen"): | ||
r = parse_suite_file(fullpath) | ||
print(f"total: {r[1]} iter: {r[-1]}") | ||
|
||
if __name__ == "__main__": | ||
test_kgtests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters