-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTests.mag
More file actions
84 lines (77 loc) · 2.55 KB
/
UnitTests.mag
File metadata and controls
84 lines (77 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// This file is part of ExactpAdics
// Copyright (C) 2018 Christopher Doris
//
// ExactpAdics is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ExactpAdics is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ExactpAdics. If not, see <http://www.gnu.org/licenses/>.
// freeze;
tests := [*
<"fld/create/prime", procedure ()
for p in [2,5,101,0,-1,-3,4,100] do
if p gt 0 and IsPrime(p) then
K := ExactpAdicField(p);
assert Prime(K) eq p;
else
ok := true;
try
K := ExactpAdicField(p);
catch err
ok := false;
end try;
assert not ok;
end if;
end for;
end procedure>
*];
RESULT := recformat<test, pass, err>;
intrinsic ExactpAdics_RunUnitTests(:Prefix:="", Verbosity:=1, StopOnFirstFail:=false, NoCatch:=false) -> .
{Runs the unit tests for the ExactpAdics module. Prefix: only run tests whose name starts with this. Verbosity: 0 for no printing, 1 for basic reporting, 2 for detailed reporting. StopOnFirstFail: stops after the first test fails. NoCatch: Does not catch errors in tests, allows them to propagate so that you can use Magma debugging tools.}
results := [];
for test in tests do
if test[1][1..#Prefix] ne Prefix then
continue;
end if;
if Verbosity ge 1 then
printf "%o...", test[1];
end if;
r := rec<RESULT | test := test[1], pass := true>;
if NoCatch then
test[2]();
else
try
test[2]();
catch err
r`pass := false;
r`err := err;
end try;
end if;
if Verbosity ge 1 then
printf " %o\n", r`pass select "PASS" else "FAIL";
end if;
if (not r`pass) and Verbosity ge 2 then
print "ERROR MESSAGE:";
IndentPush();
print r`err;
IndentPop();
end if;
Append(~results, r);
end for;
nfail := #[r : r in results | not r`pass];
if Verbosity ge 1 then
if nfail eq 0 then
printf "ALL %o TESTS PASSED\n", #results;
else
printf "%o OF %o TESTS FAILED\n", nfail, #results;
end if;
end if;
return results;
end intrinsic;