Added a few basic tests

This commit is contained in:
Productive2 2021-01-05 14:02:04 +01:00
parent fb9bfd18e4
commit 5aef0654dc
6 changed files with 120 additions and 0 deletions

View File

@ -17,3 +17,18 @@ print(8+2**4);//output:24
print(2+7*2+4);//output:20
print(1-2**2*5);//output:-19
print(7*-2**3+4*7);//output:-28
print(-2**2);//output:-4
print((-2)**2);//output:4
print(-2**3);//output:-8
print((-2)**3);//output:-8
print((2+3)*4);//output:20
print(2*(2+2)*2);//output:16
print(2*(2*2)*2);//output:16
print(8%5);//output:3
print(4%3);//output:1
print(8/4);//output:2.0
print(28/7/4);//output:1.0
print(64/-64);//output:-1.0
print(8/0);//output:inf
print(8/-0);//output:inf
print(-8/0);//output:-inf

21
tests/japl/booleans.jpl Normal file
View File

@ -0,0 +1,21 @@
print(2 or 3);//output:2
print(2 and 3);//output:3
print(false or true);//output:true
print(true or false);//output:true
print(true and false);//output:false
print(false and 3 or 4);//output:4
print(true and 3 or 4);//output:3
print(true and 2);//output:2
print(false or 5);//output:5
print(0 or 4);//output:4
print(0 and true);//output:0
print("" and true);//output:
print("" or true);//output:true
print(1 or 2 or 3 or 4);//output:1
print(1 and 2 and 3 and 4);//output:4
print(1 and 2 or 3 and 4);//output:2
print(1 and false or 3 and 4);//output:4
print(!0);//output:true
print(!1);//output:false
print(!1 and !2);//output:false
print(!(1 and 0));//output:true

6
tests/japl/for.jpl Normal file
View File

@ -0,0 +1,6 @@
for (var x = 0; x < 2; x = x + 1)
{
print(x);
//output:0
//output:1
}

28
tests/japl/if.jpl Normal file
View File

@ -0,0 +1,28 @@
var x = 5;
if (x > 2)
{
print("large");//output:large
}
else
{
print("smol");//won't run
}
if (x < 4)
{
print("large");//won't run
}
print("beep");//output:beep
if (x == 5)
print("equal to 5");//output:equal to 5
if (2 != x)
print("not 2");//output:not 2
else
print("2");
if (2 == x)
print("2");
else
print("not 2");//output:not 2

30
tests/japl/vars.jpl Normal file
View File

@ -0,0 +1,30 @@
var x = 1;
var y = 2;
print(x);//output:1
print(y);//output:2
{
var x = 4;
var y = 5;
print(x);//output:4
print(y);//output:5
{
var z = 6;
var y = 2;
print(x);//output:4
print(y);//output:2
}
print(x);//output:4
print(y);//output:5
}
print(x);//output:1
print(y);//output:2
var longName;
print(longName); //output:nil
longName = 5;
print(longName); //output:5
longName = "hello";
print(longName); //output:hello
longName = longName + " world";
print(longName); //output:hello world

20
tests/japl/while.jpl Normal file
View File

@ -0,0 +1,20 @@
var x = 5;
while (x > 0)
{
x = x - 1;
print(x);
//output:4
//output:3
//output:2
//output:1
//output:0
}
var string = "h";
while (x < 10)
{
x = x + 1;
string = string + "A";
}
print(string);//output:hAAAAAAAAAA