module main;
import std.stdio;
interface AbsCalculator {
int abs(int n)
out (result) {
assert(result >= 0);
}
}
class CorrectAbsCalculator : AbsCalculator {
int abs(int n) {
return n < 0 ? -n : n;
}
}
class BuggyAbsCalculator : AbsCalculator {
int abs(int n) {
return n;
}
}
void main() {
auto a = new CorrectAbsCalculator();
writeln(a.abs(-1));
auto b = new BuggyAbsCalculator();
writeln(b.abs(-1));
}
bW9kdWxlIG1haW47CmltcG9ydCBzdGQuc3RkaW87CgppbnRlcmZhY2UgQWJzQ2FsY3VsYXRvciB7CglpbnQgYWJzKGludCBuKQoJb3V0IChyZXN1bHQpIHsKCQlhc3NlcnQocmVzdWx0ID49IDApOwoJfQp9CgpjbGFzcyBDb3JyZWN0QWJzQ2FsY3VsYXRvciA6IEFic0NhbGN1bGF0b3IgewoJaW50IGFicyhpbnQgbikgewoJCXJldHVybiBuIDwgMCA/IC1uIDogbjsKCX0KfQoKY2xhc3MgQnVnZ3lBYnNDYWxjdWxhdG9yIDogQWJzQ2FsY3VsYXRvciB7CglpbnQgYWJzKGludCBuKSB7CgkJcmV0dXJuIG47Cgl9Cn0KCnZvaWQgbWFpbigpIHsKCWF1dG8gYSA9IG5ldyBDb3JyZWN0QWJzQ2FsY3VsYXRvcigpOwoJd3JpdGVsbihhLmFicygtMSkpOwoJYXV0byBiID0gbmV3IEJ1Z2d5QWJzQ2FsY3VsYXRvcigpOwoJd3JpdGVsbihiLmFicygtMSkpOwp9
core.exception.AssertError@prog.d(7): Assertion failure
----------------
./prog(main+0) [0x8073498]
./prog(_D4main13AbsCalculator3absMFiZ8__ensureMFKxiZv+0x18) [0x8072f68]
./prog(int main.BuggyAbsCalculator.abs(int)+0x2d) [0x8072fed]
./prog(_Dmain+0x34) [0x8073034]
./prog(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x12) [0x807556a]
./prog(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80754e0]
./prog(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x27) [0x807552f]
./prog(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80754e0]
./prog(_d_run_main+0x166) [0x8075476]
./prog(main+0x14) [0x80734ac]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0xb7623723]