2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,3 +1,8 @@
|
|||
Assertions are a way of breaking out of code when there is an error or an unexpected input. Some languages throw [[exceptions]] and some treat it as a break point.
|
||||
Assertions are a way of breaking out of code when there is an error or an unexpected input.
|
||||
|
||||
Show an assertion in your language by asserting that an integer variable is equal to 42.
|
||||
Some languages throw [[exceptions]] and some treat it as a break point.
|
||||
|
||||
|
||||
;Task:
|
||||
Show an assertion in your language by asserting that an integer variable is equal to '''42'''.
|
||||
<br><br>
|
||||
|
|
|
|||
11
Task/Assertions/Elixir/assertions.elixir
Normal file
11
Task/Assertions/Elixir/assertions.elixir
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
ExUnit.start
|
||||
|
||||
defmodule AssertionTest do
|
||||
use ExUnit.Case
|
||||
|
||||
def return_5, do: 5
|
||||
|
||||
test "not equal" do
|
||||
assert 42 == return_5
|
||||
end
|
||||
end
|
||||
2
Task/Assertions/Perl-6/assertions-1.pl6
Normal file
2
Task/Assertions/Perl-6/assertions-1.pl6
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
my $a = (1..100).pick;
|
||||
$a == 42 or die '$a ain\'t 42';
|
||||
|
|
@ -1,8 +1,3 @@
|
|||
my $a = (1..100).pick;
|
||||
|
||||
# with a (non-hygienic) macro
|
||||
macro assert ($x) { "$x or die 'assertion failed: $x'" }
|
||||
assert('$a == 42');
|
||||
|
||||
# but usually we just say
|
||||
$a == 42 or die '$a ain\'t 42';
|
||||
Loading…
Add table
Add a link
Reference in a new issue