mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-04 21:05:02 +00:00
Add/update function test programs
This commit is contained in:
parent
74e43fe108
commit
f1b2ab3909
70
py65/funcs.c02
Normal file
70
py65/funcs.c02
Normal file
@ -0,0 +1,70 @@
|
||||
/*******************************
|
||||
* CONDS - Test Function Calls *
|
||||
*******************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdlib.h02>
|
||||
#include <stdio.h02>
|
||||
#include <stdiox.h02>
|
||||
|
||||
char i; //index value
|
||||
char n; //result of function call
|
||||
char s[128]; //for Numeric to String conversions
|
||||
char z; //Function Parameters
|
||||
|
||||
char passed = " Passed.";
|
||||
char failed = " Failed.";
|
||||
|
||||
main:
|
||||
|
||||
for (i=1;i<5;i++) test(i);
|
||||
putln("Testing complete.");
|
||||
|
||||
goto exit;
|
||||
|
||||
//Test Use of Variable as Parameter
|
||||
void test(z) {
|
||||
select(z) {
|
||||
case 1: test1();
|
||||
case 2: test2();
|
||||
case 3: test3();
|
||||
case 4: test4();
|
||||
default: printf(z, "Bad test value %d\n.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test1() {
|
||||
puts("atoc(\"1\") = ");
|
||||
n = atoc("1");
|
||||
prtnum(n); checkn(1);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
puts("atoc(\"2\") = ");
|
||||
n = atoc("2");
|
||||
prtnum(n); checkn(2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
puts("atoc(\"1\") + atoc(\"2\") = ");
|
||||
n = atoc("1") + atoc("2");
|
||||
prtnum(n); checkn(3);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
puts("abs(atoc(\"255\") + abs(atoc(\"7\")) = ");
|
||||
n = abs(atoc("255")) + abs(atoc("7"));
|
||||
prtnum(n); checkn(8);
|
||||
}
|
||||
|
||||
|
||||
//uses explicit passing of accumulator
|
||||
void checkn() {if (A == n) pass(); else fail();}
|
||||
|
||||
//uses implicit passing of accumulator
|
||||
void prtnum() {ctoa(&s); puts(&s); putc(':');}
|
||||
|
||||
//one more level of function calls - just because
|
||||
void pass() {putln(&passed);}
|
||||
void fail() {putln(&failed);}
|
@ -59,5 +59,7 @@ c, z[i], f = testfn(); //Return 3 Values with Array
|
||||
r[i], z[j] = testfn(); //Return 2 Values with Arrays
|
||||
r[i], z[j], f = testfn(); //Return 2 Values with Arrays
|
||||
|
||||
f = fnx(b) + fny(c); //Function in regular term
|
||||
|
||||
//A, Y = testfn(); //Error - Registers not Allowed when returning multiple values
|
||||
//r[i], z[j], f[b] = testfn(); //Error - Array Element not Allowed with STX assignment
|
||||
|
Loading…
Reference in New Issue
Block a user