2024-06-14 05:57:38 +00:00
|
|
|
// compile all test files using:
|
|
|
|
// ls Test/JavaSources/*.java | grep -v ".*Main.java" | xargs -I {} cabal run compiler {}
|
2024-06-14 06:11:58 +00:00
|
|
|
// compile (in project root) using:
|
2024-06-21 05:37:25 +00:00
|
|
|
// pushd Test/JavaSources; javac -g:none Main.java; popd
|
2024-06-14 05:57:38 +00:00
|
|
|
// afterwards, run using
|
|
|
|
// java -ea -cp Test/JavaSources/ Main
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
public static void main(String[] args)
|
|
|
|
{
|
|
|
|
TestEmpty empty = new TestEmpty();
|
|
|
|
TestFields fields = new TestFields();
|
|
|
|
TestConstructor constructor = new TestConstructor(42);
|
2024-06-21 06:07:20 +00:00
|
|
|
TestArithmetic arithmetic = new TestArithmetic();
|
2024-06-14 05:57:38 +00:00
|
|
|
TestMultipleClasses multipleClasses = new TestMultipleClasses();
|
|
|
|
TestRecursion recursion = new TestRecursion(10);
|
|
|
|
TestMalicious malicious = new TestMalicious();
|
2024-06-26 07:42:07 +00:00
|
|
|
TestLoop loop = new TestLoop();
|
2024-06-14 05:57:38 +00:00
|
|
|
|
|
|
|
// constructing a basic class works
|
|
|
|
assert empty != null;
|
|
|
|
// initializers (and default initializers to 0/null) work
|
|
|
|
assert fields.a == 0 && fields.b == 42;
|
|
|
|
// constructor parameters override initializers
|
|
|
|
assert constructor.a == 42;
|
2024-06-21 06:07:20 +00:00
|
|
|
// basic arithmetics
|
|
|
|
assert arithmetic.basic(1, 2, 3) == 2;
|
|
|
|
// we have boolean logic as well
|
2024-06-21 06:49:55 +00:00
|
|
|
assert arithmetic.logic(false, false, true) == true;
|
2024-06-14 05:57:38 +00:00
|
|
|
// multiple classes within one file work. Referencing another classes fields/methods works.
|
|
|
|
assert multipleClasses.a.a == 42;
|
|
|
|
// self-referencing classes work.
|
|
|
|
assert recursion.child.child.child.child.child.value == 5;
|
|
|
|
// self-referencing methods work.
|
|
|
|
assert recursion.fibonacci(15) == 610;
|
2024-06-26 07:42:07 +00:00
|
|
|
assert loop.factorial(5) == 120;
|
2024-06-14 05:57:38 +00:00
|
|
|
// intentionally dodgy expressions work
|
|
|
|
assert malicious.assignNegativeIncrement(42) == -42;
|
|
|
|
assert malicious.tripleAddition(1, 2, 3) == 6;
|
2024-06-14 06:11:58 +00:00
|
|
|
for(int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
assert malicious.cursedFormatting(i) == i;
|
|
|
|
}
|
2024-06-14 05:57:38 +00:00
|
|
|
}
|
|
|
|
}
|