implement integer division tests

This commit is contained in:
2020-03-05 17:21:08 +01:00
parent a8b093a005
commit 333475f27b
3 changed files with 18 additions and 0 deletions

View File

@@ -19,6 +19,10 @@ long cModulo(long x, long y)
{
return x % y;
}
long cDiv(long x, long y)
{
return x / y;
}
long cNeg(long x)
{
return -x;
@@ -173,6 +177,15 @@ int runMathTests()
math_test("mul", cMul, mul, 1, 5);
math_test("mul", cMul, mul, -1, -1);
printf("\nDivision Tests\n");
math_test("div", cDiv, div, 10, 2);
math_test("div", cDiv, div, 8, 4);
math_test("div", cDiv, div, 6, -2);
math_test("div", cDiv, div, -9, 3);
math_test("div", cDiv, div, 9, 2);
math_test("div", cDiv, div, 9, -2);
math_test("div", cDiv, div, -9, 2);
printf("\nModulo Tests \n");
math_test("modulo", cModulo, modulo, 1, 1);
math_test("modulo", cModulo, modulo, 1, 5);

View File

@@ -5,6 +5,7 @@
long add(long x, long y);
long sub(long x, long y);
long mul(long x, long y);
long div(long x, long y);
long modulo(long x, long y);
long neg(long x);
long id(long x);

View File

@@ -10,6 +10,10 @@ function mul(x: int, y: int): int {
return (x * y);
}
function div(x: int, y: int): int {
return (x / y);
}
function modulo(x: int, y: int): int {
return (x % y);
}