September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
21
Task/Assertions/AWK/assertions.awk
Normal file
21
Task/Assertions/AWK/assertions.awk
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
BEGIN {
|
||||
meaning = 6 * 7
|
||||
assert(meaning == 42, "Integer mathematics failed")
|
||||
assert(meaning == 42)
|
||||
meaning = strtonum("42 also known as forty-two")
|
||||
assert(meaning == 42, "Built-in function failed")
|
||||
meaning = "42"
|
||||
assert(meaning == 42, "Dynamic type conversion failed")
|
||||
meaning = 6 * 9
|
||||
assert(meaning == 42, "Ford Prefect's experiment failed")
|
||||
print "That's all folks"
|
||||
exit
|
||||
}
|
||||
|
||||
# Errormsg is optional, displayed if assertion fails
|
||||
function assert(cond, errormsg){
|
||||
if (!cond) {
|
||||
if (errormsg != "") print errormsg
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
24
Task/Assertions/BaCon/assertions.bacon
Normal file
24
Task/Assertions/BaCon/assertions.bacon
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
' Assertions
|
||||
answer = assertion(42)
|
||||
PRINT "The ultimate answer is indeed ", answer
|
||||
|
||||
PRINT "Now, expect a failure, unless NDEBUG defined at compile time"
|
||||
answer = assertion(41)
|
||||
PRINT answer
|
||||
END
|
||||
|
||||
' Ensure the given number is the ultimate answer
|
||||
FUNCTION assertion(NUMBER i)
|
||||
|
||||
' BaCon can easily be intimately integrated with C
|
||||
USEH
|
||||
#include <assert.h>
|
||||
END USEH
|
||||
|
||||
' If the given expression is not true, abort the program
|
||||
USEC
|
||||
assert(i == 42);
|
||||
END USEC
|
||||
|
||||
RETURN i
|
||||
END FUNCTION
|
||||
|
|
@ -1,8 +1,16 @@
|
|||
public static void main(String[] args){
|
||||
int a;
|
||||
//...input or change a here
|
||||
assert a == 42;//throws an AssertionError when a is not 42
|
||||
assert a == 42 : "Error message"; //throws an AssertionError
|
||||
//when a is not 42 with "Error message" for the message
|
||||
//the error message can be any non-void expression
|
||||
public class Assertions {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int a = 13;
|
||||
|
||||
// ... some real code here ...
|
||||
|
||||
assert a == 42;
|
||||
// Throws an AssertionError when a is not 42.
|
||||
|
||||
assert a == 42 : "Error message";
|
||||
// Throws an AssertionError when a is not 42,
|
||||
// with "Error message" for the message.
|
||||
// The error message can be any non-void expression.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
Task/Assertions/Kotlin/assertions.kotlin
Normal file
6
Task/Assertions/Kotlin/assertions.kotlin
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// version 1.0.6 (assert.kt)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = 42
|
||||
assert(a == 43)
|
||||
}
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
var a = 42
|
||||
assert(a == 42)
|
||||
assert(a == 42, "Not 42!")
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
var a = 42
|
||||
assert(a == 42)
|
||||
1
Task/Assertions/SETL/assertions.setl
Normal file
1
Task/Assertions/SETL/assertions.setl
Normal file
|
|
@ -0,0 +1 @@
|
|||
assert( n = 42 );
|
||||
1
Task/Assertions/Stata/assertions-1.stata
Normal file
1
Task/Assertions/Stata/assertions-1.stata
Normal file
|
|
@ -0,0 +1 @@
|
|||
assert x<y if z>0
|
||||
1
Task/Assertions/Stata/assertions-2.stata
Normal file
1
Task/Assertions/Stata/assertions-2.stata
Normal file
|
|
@ -0,0 +1 @@
|
|||
confirm file titanium.dta
|
||||
2
Task/Assertions/Stata/assertions-3.stata
Normal file
2
Task/Assertions/Stata/assertions-3.stata
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
if (`n'==42) error 3
|
||||
* Will print "no dataset in use"
|
||||
4
Task/Assertions/Stata/assertions-4.stata
Normal file
4
Task/Assertions/Stata/assertions-4.stata
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
if (`n'==42) {
|
||||
display as error "The correct answer is not 42."
|
||||
exit 54
|
||||
}
|
||||
2
Task/Assertions/Zkl/assertions.zkl
Normal file
2
Task/Assertions/Zkl/assertions.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
n:=42; (n==42) or throw(Exception.AssertionError);
|
||||
n=41; (n==42) or throw(Exception.AssertionError("I wanted 42!"));
|
||||
Loading…
Add table
Add a link
Reference in a new issue