upd: add exit on error in examples
This commit is contained in:
+16
-7
@@ -7,12 +7,11 @@ fn doSome(A a) A
|
||||
{
|
||||
// NOTE: section below won't change `a.some` value
|
||||
|
||||
// if (a.some < 1)
|
||||
// {
|
||||
// a.some = 1;
|
||||
// return a;
|
||||
// }
|
||||
if (a.some < 1)
|
||||
{
|
||||
a.some = 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
@@ -27,10 +26,20 @@ fn doSomeNew() A
|
||||
|
||||
A a = new A;
|
||||
a.some = 0;
|
||||
printline(a);
|
||||
if (a.some != 0)
|
||||
{
|
||||
printline("Test failed (first a.some != 0)");
|
||||
exit(1);
|
||||
}
|
||||
else printline(a);
|
||||
|
||||
a = doSome(a);
|
||||
printline(a);
|
||||
if (a.some != 1)
|
||||
{
|
||||
printline("Test failed (2nd a.some != 1)");
|
||||
exit(1);
|
||||
}
|
||||
else printline(a);
|
||||
|
||||
A b = doSomeNew();
|
||||
printline(b);
|
||||
|
||||
+5
-1
@@ -28,5 +28,9 @@ printline(obj.y);
|
||||
|
||||
if (obj.x == 10 && obj.y == 10)
|
||||
printline("Test passed");
|
||||
else printline("Test failed");
|
||||
else
|
||||
{
|
||||
printline("Test failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
bool flag = true;
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
printline("buhhh, flag is not true");
|
||||
exit(1);
|
||||
}
|
||||
else if (2 + 2 >= 4)
|
||||
{
|
||||
printline ("two plus two is four");
|
||||
}
|
||||
else {
|
||||
printline("gotcha");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
+10
-2
@@ -15,10 +15,18 @@ printline("Test #1: fibonacci");
|
||||
int result = fib(7);
|
||||
if (result == 13)
|
||||
printline("Recurse test passed");
|
||||
else printline("Recurse test failed");
|
||||
else
|
||||
{
|
||||
printline("Recurse test failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printline("Test #2: sum");
|
||||
if (sum(2, 2) == 4)
|
||||
printline("Sum test passed");
|
||||
else printline("Sum test failed");
|
||||
else
|
||||
{
|
||||
printline("Sum test failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -58,5 +58,9 @@ printline(total);
|
||||
|
||||
if (total == 16)
|
||||
printline("Tests passed!");
|
||||
else printline("Tests failed");
|
||||
else
|
||||
{
|
||||
printline("Tests failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
+14
-2
@@ -21,14 +21,26 @@ a.name = "Buryatka";
|
||||
a.age = 5;
|
||||
|
||||
Animal b = a.copy();
|
||||
a.name = "Gavryusha";
|
||||
a.age = 10;
|
||||
b.name = "Gavryusha";
|
||||
b.age = 10;
|
||||
|
||||
printline(a);
|
||||
printline(b);
|
||||
|
||||
printline("Types are same:");
|
||||
printline(a.type == b.type);
|
||||
|
||||
printline("Names are NOT the same");
|
||||
printline(a.name != b.name);
|
||||
|
||||
printline("1st age less than 2nd");
|
||||
printline(a.age < b.age);
|
||||
|
||||
if (a.type == b.type && a.name != b.name && a.age < b.age)
|
||||
printline("Test passed");
|
||||
else
|
||||
{
|
||||
printline("Test failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user