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