implement integer division tests
This commit is contained in:
@@ -19,6 +19,10 @@ long cModulo(long x, long y)
|
|||||||
{
|
{
|
||||||
return x % y;
|
return x % y;
|
||||||
}
|
}
|
||||||
|
long cDiv(long x, long y)
|
||||||
|
{
|
||||||
|
return x / y;
|
||||||
|
}
|
||||||
long cNeg(long x)
|
long cNeg(long x)
|
||||||
{
|
{
|
||||||
return -x;
|
return -x;
|
||||||
@@ -173,6 +177,15 @@ int runMathTests()
|
|||||||
math_test("mul", cMul, mul, 1, 5);
|
math_test("mul", cMul, mul, 1, 5);
|
||||||
math_test("mul", cMul, mul, -1, -1);
|
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");
|
printf("\nModulo Tests \n");
|
||||||
math_test("modulo", cModulo, modulo, 1, 1);
|
math_test("modulo", cModulo, modulo, 1, 1);
|
||||||
math_test("modulo", cModulo, modulo, 1, 5);
|
math_test("modulo", cModulo, modulo, 1, 5);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
long add(long x, long y);
|
long add(long x, long y);
|
||||||
long sub(long x, long y);
|
long sub(long x, long y);
|
||||||
long mul(long x, long y);
|
long mul(long x, long y);
|
||||||
|
long div(long x, long y);
|
||||||
long modulo(long x, long y);
|
long modulo(long x, long y);
|
||||||
long neg(long x);
|
long neg(long x);
|
||||||
long id(long x);
|
long id(long x);
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ function mul(x: int, y: int): int {
|
|||||||
return (x * y);
|
return (x * y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function div(x: int, y: int): int {
|
||||||
|
return (x / y);
|
||||||
|
}
|
||||||
|
|
||||||
function modulo(x: int, y: int): int {
|
function modulo(x: int, y: int): int {
|
||||||
return (x % y);
|
return (x % y);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user