Assertions: Difference between revisions

Content deleted Content added
Grondilu (talk | contribs)
→‎{{header|Perl}}: rearrangements
No edit summary
Line 134: Line 134:
MODULE Assertions;
MODULE Assertions;
VAR
VAR
x: INTEGER;
x: INTEGER;
PROCEDURE DoIt*;
PROCEDURE DoIt*;
BEGIN
BEGIN
x := 41;
x := 41;
ASSERT(x = 42);
ASSERT(x = 42);
END DoIt;
END DoIt;
END Assertions.
END Assertions.
Line 150: Line 150:
Assertions.DoIt [0000001DH]
Assertions.DoIt [0000001DH]
Kernel.Call [00001A7CH]
Kernel.Call [00001A7CH]
.adr INTEGER 1685454913
.adr INTEGER 1685454913
.kind INTEGER 0
.kind INTEGER 0
.n INTEGER 0
.n INTEGER 0
.p INTEGER 0
.p INTEGER 0
.par ARRAY 256 OF INTEGER elements
.par ARRAY 256 OF INTEGER elements
.r REAL 8.70603013185328E+175
.r REAL 8.70603013185328E+175
.sig POINTER [64760018H]
.sig POINTER [64760018H]
.size INTEGER 2287288
.size INTEGER 2287288
.sp INTEGER 256
.sp INTEGER 256
.typ POINTER NIL
.typ POINTER NIL
Meta.Item.ParamCallVal [00002B5EH]
Meta.Item.ParamCallVal [00002B5EH]
.adr INTEGER 1685454913
.adr INTEGER 1685454913
.data ARRAY 256 OF INTEGER elements
.data ARRAY 256 OF INTEGER elements
</pre>
</pre>
=={{header|D}}==
=={{header|D}}==
Line 429: Line 429:
before 'Hello Universe'...
before 'Hello Universe'...
java.lang.AssertionError: This: Hello Universe is not the answer!. Expression: (it == 42). Values: it = Hello Universe
java.lang.AssertionError: This: Hello Universe is not the answer!. Expression: (it == 42). Values: it = Hello Universe
at ConsoleScript80$_run_closure1.doCall(ConsoleScript80:2)
at ConsoleScript80$_run_closure1.doCall(ConsoleScript80:2)
at ConsoleScript80.run(ConsoleScript80:8)</pre>
at ConsoleScript80.run(ConsoleScript80:8)</pre>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 495: Line 495:
julia> x::String
julia> x::String
ERROR: type: typeassert: expected String, got Int32</lang>
ERROR: type: typeassert: expected String, got Int32</lang>

=={{header|Lasso}}==
<lang lasso>local(a) = 8
fail_if(
#a != 42,
error_code_runtimeAssertion,
error_msg_runtimeAssertion + ": #a is not 42"
)</lang>
{{out}}
<pre>-9945 Runtime assertion: #a is not 42</pre>

=={{header|Lisaac}}==
=={{header|Lisaac}}==
<lang Lisaac>? { n = 42 };</lang>
<lang Lisaac>? { n = 42 };</lang>
Line 566: Line 577:
class SampleClass
class SampleClass
{
{
public SomeMethod (input : list[int]) : int
public SomeMethod (input : list[int]) : int
requires input.Length > 0 // requires keyword indicates precondition,
requires input.Length > 0 // requires keyword indicates precondition,
// there can be more than one condition per method
// there can be more than one condition per method
{ ... }
{ ... }


public AnotherMethod (input : string) : list[char]
public AnotherMethod (input : string) : list[char]
ensures value.Length > 0 // ensures keyword indicates postcondition
ensures value.Length > 0 // ensures keyword indicates postcondition
{ ... } // value is a special symbol that indicates the method's return value
{ ... } // value is a special symbol that indicates the method's return value
}</lang>
}</lang>
The design by contract macros throw <tt>Nemerle.AssertionException</tt>'s unless another Exception is specified using the <tt>otherwise</tt> keyword after the <tt>requires/ensures</tt> statement.
The design by contract macros throw <tt>Nemerle.AssertionException</tt>'s unless another Exception is specified using the <tt>otherwise</tt> keyword after the <tt>requires/ensures</tt> statement.
Line 588: Line 599:
MODULE Assertions;
MODULE Assertions;
VAR
VAR
a: INTEGER;
a: INTEGER;
BEGIN
BEGIN
a := 40;
a := 40;
ASSERT(a = 42);
ASSERT(a = 42);
END Assertions.
END Assertions.
</lang>
</lang>
Line 990: Line 1,001:
====Definition====
====Definition====
<lang vb>sub Assert( boolExpr, strOnFail )
<lang vb>sub Assert( boolExpr, strOnFail )
if not boolExpr then
if not boolExpr then
Err.Raise vbObjectError + 99999, , strOnFail
Err.Raise vbObjectError + 99999, , strOnFail
end if
end if
end sub
end sub
</lang>
</lang>