Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(* Self-contained test for testing mathicscript <file> | ||
Recursive GCD from https://mathematica.stackexchange.com/questions/156990/gcd-using-euclidean-algorithm | ||
Test harness is the same used in Gries Schnieder testing. | ||
*) | ||
|
||
ClearAll[expect, totalRight, totalWrong, totalTests]; | ||
SetAttributes[ expect, HoldAllComplete ]; | ||
totalRight = totalWrong = totalTests = 0; | ||
expect[expected_, actual_] := (* <~~~ Here's the API *) | ||
Module[{evalActualOnce = actual, | ||
evalExpectedOnce = expected}, | ||
totalTests += 1; | ||
Print[ {"Test[" <> ToString[totalTests] <> "]:=\n", | ||
HoldForm[actual], | ||
"\nexpected", HoldForm[expected], | ||
"\neval'd expected", evalExpectedOnce, | ||
"\neval'd actual ", evalActualOnce, | ||
"\nright?", evalExpectedOnce === evalActualOnce} ]; | ||
Print[ "" ]; (* newline *) | ||
If[ evalExpectedOnce === evalActualOnce, | ||
totalRight += 1, | ||
totalWrong += 1 ]; | ||
{"total right", totalRight, "total wrong", totalWrong} | ||
]; | ||
|
||
RecursiveGCD[a_, 0] := a; | ||
RecursiveGCD[a_, b_] := RecursiveGCD[b, Mod[a, b]]; | ||
|
||
expect[6, RecursiveGCD[24, 18]] | ||
expect[1, RecursiveGCD[3, 5]] | ||
|
||
x = RandomInteger[{-100, 100}] | ||
expect[x, RecursiveGCD[x, 0]] | ||
expect[x, RecursiveGCD[2 x, x]] | ||
expect[x, RecursiveGCD[x 2, x]] | ||
(** uncomment to see a failure **) | ||
(*** expect[3 x, RecursiveGCD[x 2, x]] ***) | ||
Print["Total right: ", totalRight, ". Total wrong: ", totalWrong, ". Total tests: ", totalTests] | ||
If[ Or[totalTests <= 0, totalTests != totalRight], Quit[1], Quit[0]] |
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,18 @@ | ||
import subprocess | ||
|
||
import os.path as osp | ||
|
||
def get_testdir(): | ||
filename = osp.normcase(osp.dirname(osp.abspath(__file__))) | ||
return osp.realpath(filename) | ||
|
||
def test_returncode(): | ||
assert subprocess.run(["mathics", "-e", "Quit[5]"]).returncode == 5 | ||
assert subprocess.run(["mathics", "-e", "1 + 2'"]).returncode == 0 | ||
assert subprocess.run(["mathics", "-e", "Quit[0]"]).returncode == 0 | ||
|
||
gcd_file = osp.join(get_testdir(), "data", "recursive-gcd.m") | ||
assert subprocess.run(["mathics", "-f", gcd_file]).returncode == 0 | ||
|
||
if __name__ == "__main__": | ||
test_returncode() |