25: Add logic for handling float in function calls
This commit is contained in:
@@ -12,6 +12,16 @@ int argumentTest(char* name, int expected, int result) {
|
||||
}
|
||||
}
|
||||
|
||||
int argumentTest_f(char* name, int expected, int result) {
|
||||
if (expected == result) {
|
||||
succ_f(name, expected, result);
|
||||
return 0;
|
||||
} else {
|
||||
err_f(name, expected, result);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int runFunctionCallTests () {
|
||||
printf("\nFunction Call Tests \n");
|
||||
// Checks that parameters are correctly passed from gcc to functions
|
||||
@@ -36,4 +46,27 @@ int runFunctionCallTests () {
|
||||
argumentTest("get8(...args)", 8, get8());
|
||||
argumentTest("get9(...args)", 9, get9());
|
||||
argumentTest("get10(...args)", 10, get10());
|
||||
|
||||
printf("\nFunction Call Tests With Floats \n");
|
||||
argumentTest_f("farg1(...args)", 1.0, farg1(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg2(...args)", 2.0, farg2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg3(...args)", 3.0, farg3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg4(...args)", 4.0, farg4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg5(...args)", 5.0, farg5(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg6(...args)", 6.0, farg6(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg7(...args)", 7.0, farg7(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg8(...args)", 8.0, farg8(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg9(...args)", 9.0, farg9(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
argumentTest_f("farg10(...args)", 10.0, farg10(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
|
||||
// Checks that parameters are correctly passed from klang to functions
|
||||
argumentTest_f("fget1(...args)", 1.0, fget1());
|
||||
argumentTest_f("fget2(...args)", 2.0, fget2());
|
||||
argumentTest_f("fget3(...args)", 3.0, fget3());
|
||||
argumentTest_f("fget4(...args)", 4.0, fget4());
|
||||
argumentTest_f("fget5(...args)", 5.0, fget5());
|
||||
argumentTest_f("fget6(...args)", 6.0, fget6());
|
||||
argumentTest_f("fget7(...args)", 7.0, fget7());
|
||||
argumentTest_f("fget8(...args)", 8.0, fget8());
|
||||
argumentTest_f("fget9(...args)", 9.0, fget9());
|
||||
argumentTest_f("fget10(...args)", 10.0, fget10());
|
||||
}
|
||||
@@ -18,4 +18,26 @@ int get6();
|
||||
int get7();
|
||||
int get8();
|
||||
int get9();
|
||||
int get10();
|
||||
int get10();
|
||||
|
||||
double farg1(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg2(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg3(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg4(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg5(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg6(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg7(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg8(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg9(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
double farg10(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j);
|
||||
|
||||
double fget1();
|
||||
double fget2();
|
||||
double fget3();
|
||||
double fget4();
|
||||
double fget5();
|
||||
double fget6();
|
||||
double fget7();
|
||||
double fget8();
|
||||
double fget9();
|
||||
double fget10();
|
||||
@@ -28,6 +28,16 @@ void err(char* name, int expected, int result) {
|
||||
printf("\033[0;31mERROR:\t\t%s:\tGOT: %d\tExpected: %d\033[0;0m\n", name, result, expected);
|
||||
}
|
||||
|
||||
void succ_f(char* name, double expected, double result) {
|
||||
incSuccess();
|
||||
printf("\033[0;32mSUCCESS:\t%s:\tGOT: %f\tExpected: %f\033[0;0m\n", name, result, expected);
|
||||
}
|
||||
|
||||
void err_f(char* name, double expected, double result) {
|
||||
incFailure();
|
||||
printf("\033[0;31mERROR:\t\t%s:\tGOT: %f\tExpected: %f\033[0;0m\n", name, result, expected);
|
||||
}
|
||||
|
||||
void succPrefixOne(char* name, int x, int expected, int result) {
|
||||
incSuccess();
|
||||
printf("\033[0;32mSUCCESS:\t%s(%d)\tGOT: %d\tExpected: %d\033[0;0m\n", name, x, result, expected);
|
||||
|
||||
@@ -6,6 +6,9 @@ void incFailure();
|
||||
void succ(char* name, int expected, int result);
|
||||
void err(char* name, int expected, int result);
|
||||
|
||||
void succ_f(char* name, double expected, double result);
|
||||
void err_f(char* name, double expected, double result);
|
||||
|
||||
void succPrefixOne(char* name, int x, int expected, int result);
|
||||
void errPrefixOne(char* name, int x, int expected, int result);
|
||||
|
||||
|
||||
@@ -102,6 +102,90 @@ function get10(): int {
|
||||
return arg10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||
}
|
||||
|
||||
// FLOATS
|
||||
|
||||
function farg1(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return a;
|
||||
}
|
||||
|
||||
function fget1(): float {
|
||||
return farg1(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg2(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return b;
|
||||
}
|
||||
|
||||
function fget2(): float {
|
||||
return farg2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg3(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return c;
|
||||
}
|
||||
|
||||
function fget3(): float {
|
||||
return farg3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg4(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return d;
|
||||
}
|
||||
|
||||
function fget4(): float {
|
||||
return farg4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg5(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return e;
|
||||
}
|
||||
|
||||
function fget5(): float {
|
||||
return farg5(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg6(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return f;
|
||||
}
|
||||
|
||||
function fget6(): float {
|
||||
return farg6(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg7(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return g;
|
||||
}
|
||||
|
||||
function fget7(): float {
|
||||
return farg7(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg8(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return h;
|
||||
}
|
||||
|
||||
function fget8(): float {
|
||||
return farg8(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg9(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return i;
|
||||
}
|
||||
|
||||
function fget9(): float {
|
||||
return farg9(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
function farg10(a: float, b: float, c: float, d: float, e: float, f: float, g: float, h: float, i: float ,j: float): float {
|
||||
return j;
|
||||
}
|
||||
|
||||
function fget10(): float {
|
||||
return farg10(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0);
|
||||
}
|
||||
|
||||
// END FLOATS
|
||||
|
||||
function fac(x: int): int {
|
||||
if (x) {
|
||||
return (x * fac((x - 1)));
|
||||
|
||||
Reference in New Issue
Block a user