This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,2 @@
USING: kernel ;
42 assert=

View file

@ -0,0 +1,19 @@
# See section 7.5 of reference manual
# GAP has assertions levels. An assertion is tested if its level
# is less then the global level.
# Set global level
SetAssertionLevel(10);
a := 1;
Assert(20, a > 1, "a should be greater than one");
# nothing happens
a := 1;
Assert(4, a > 1, "a should be greater than one");
# error
# Show current global level
AssertionLevel();
# 10

View file

@ -0,0 +1,3 @@
def checkTheAnswer = {
assert it == 42 : "This: " + it + " is not the answer!"
}

View file

@ -0,0 +1,4 @@
println "before 42..."
checkTheAnswer(42)
println "before 'Hello Universe'..."
checkTheAnswer("Hello Universe")

View file

@ -0,0 +1,5 @@
...
runerr(n,( expression ,"Assertion/error - message.")) # Throw (and possibly trap) an error number n if expression succeeds.
...
stop(( expression ,"Assertion/stop - message.")) # Terminate program if expression succeeds.
...

View file

@ -0,0 +1,12 @@
$define DEBUG 1 # this allows the assertions to go through
procedure check (a)
if DEBUG then stop (42 = a, " is invalid value for 'a'")
write (a)
end
procedure main ()
check (10)
check (42)
check (12)
end

View file

@ -0,0 +1 @@
assert n = 42

View file

@ -0,0 +1,9 @@
#assert() function takes expression as 1st argument, failed-assertion message as optional 2nd argument
julia> assert(x==42,"x is not 42")
ERROR: assertion failed: x is not 42
#@assert macro checks the supplied conditional expression, with the expression returned in the failed-assertion message
julia> @assert x==42
ERROR: assertion failed: :((x==42))
#Julia also has type assertions of the form, x::Type which can be appended to a variable for type-checking at any point
julia> x::String
ERROR: type: typeassert: expected String, got Int32

View file

@ -0,0 +1 @@
? { n = 42 };

View file

@ -0,0 +1,3 @@
a := 5:
ASSERT( a = 42 );
ASSERT( a = 42, "a is not the answer to life, the universe, and everything" );

View file

@ -0,0 +1 @@
Assert[var===42]

View file

@ -0,0 +1 @@
def assert(expr t) = if not (t): errmessage("assertion failed") fi enddef;

View file

@ -0,0 +1,3 @@
n := 41;
assert(n=42);
message "ok";

View file

@ -0,0 +1 @@
<*ASSERT a = 42*>