From 1057ec28b78d8c25128faa620295d1f017321d7a Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Wed, 20 Nov 2019 01:08:09 -0500 Subject: [PATCH] Updated test programs conds, echo, echohex, hello, loops --- test/conds.c02 | 104 +++++++++++------------- test/echo.c02 | 2 + test/echohex.c02 | 4 + test/hello.c02 | 11 +-- test/loops.c02 | 205 +++++++++++++++++++++++------------------------ 5 files changed, 156 insertions(+), 170 deletions(-) diff --git a/test/conds.c02 b/test/conds.c02 index 1515457..6652aec 100644 --- a/test/conds.c02 +++ b/test/conds.c02 @@ -3,65 +3,57 @@ ****************************************/ //Specify System Header using -H option -#include -#include -#include char allok; +void passed() {putstr(" PASS");} +void passln() {passed(); newlin();} +void failed() {putstr(" FAIL"); allok = $00;} +void failln() {failed(); newlin();} + main: -allok = #TRUE; + allok = $FF; //TRUE + + putstr("TEST CONDITIONALS"); newlin(); + + putstr(" 1<>1"); if (1<>1) failed(); else passed(); + putstr(" 1<>2"); if (1<>2) passln(); else failln(); + putstr(" 1==1"); if (1==1) passed(); else failed(); + putstr(" 1==2"); if (1==2) failln(); else passln(); + putstr("1+1=2"); if (1+1 == 2) passed(); else failed(); + putstr(" 2<1"); if (2<1) failln(); else passln(); + putstr(" 1<1"); if (1<1) failed(); else passed(); + putstr(" 1<2"); if (1<2) passln(); else failln(); + + putstr(" 1<=1"); if (1<=1) passed(); else failed(); + putstr(" 1<=2"); if (1<=2) passln(); else failln(); + putstr(" 2<=1"); if (2<=1) failed(); else passed(); + putstr(" 2>1"); if (2>1) passln(); else failln(); + putstr(" 1>1"); if (1>1) failed(); else passed(); + putstr(" 1>2"); if (1>2) failln(); else passln(); + putstr(" 1>=1"); if (1>=1) passed(); else failed(); + putstr(" 1>=2"); if (1>=2) failln(); else passln(); + putstr(" 2>=1"); if (2>=1) passed(); else failed(); + putstr(" !0:+"); if (!0:+) failln(); else passln(); + + putstr("$FF:+"); if ($FF:+) failed(); else passed(); + putstr(" $FF"); if ($FF) passln(); else failln(); + putstr("$FF:-"); if ($FF:-) passed(); else failed(); + putstr(" !$FF"); if (!$FF) failln(); else passln(); + putstr("$00:+"); if ($00:+) passed(); else failed(); + putstr(" $00"); if ($00) failln(); else passln(); + putstr("$00:-"); if ($00:-) failed(); else passed(); + putstr(" !$00"); if (!$00) passln(); else failln(); + + putstr(" 1!0"); if (1|0) passed(); else failed(); + putstr(" !1!0"); if (!1|0) failln(); else passln(); + putstr(" 1&0"); if (1&0) failed(); else passed(); + putstr(" !1&0"); if (!1&0) passln(); else failln(); + putstr(" 1^1"); if (1^1) failed(); else passed(); + putstr(" !1^1"); if (!1^1) passln(); else failln(); + + if (allok) putstr("ALL TESTS PASSED"); newlin(); + getchr(); + goto exit; -putln("Test Conditionals"); - -puts(" 1<>1"); if (1<>1) failed(); else passed(); -puts(" 1<>2"); if (1<>2) passln(); else failln(); -puts(" 1==1"); if (1==1) passed(); else failed(); -puts(" 1==2"); if (1==2) failln(); else passln(); -puts("1+1=2"); if (1+1 == 2) passed(); else failed(); -puts(" 2<1"); if (2<1) failln(); else passln(); -puts(" 1<1"); if (1<1) failed(); else passed(); -puts(" 1<2"); if (1<2) passln(); else failln(); - -puts(" 1<=1"); if (1<=1) passed(); else failed(); -puts(" 1<=2"); if (1<=2) passln(); else failln(); -puts(" 2<=1"); if (2<=1) failed(); else passed(); -puts(" 2>1"); if (2>1) passln(); else failln(); -puts(" 1>1"); if (1>1) failed(); else passed(); -puts(" 1>2"); if (1>2) failln(); else passln(); -puts(" 1>=1"); if (1>=1) passed(); else failed(); -puts(" 1>=2"); if (1>=2) failln(); else passln(); -puts(" 2>=1"); if (2>=1) passed(); else failed(); -puts(" !0:+"); if (!0:+) failln(); else passln(); - -puts("$FF:+"); if ($FF:+) failed(); else passed(); -puts(" $FF"); if ($FF) passln(); else failln(); -puts("$FF:-"); if ($FF:-) passed(); else failed(); -puts(" !$FF"); if (!$FF) failln(); else passln(); -puts("$00:+"); if ($00:+) passed(); else failed(); -puts(" $00"); if ($00) failln(); else passln(); -puts("$00:-"); if ($00:-) failed(); else passed(); -puts(" !$00"); if (!$00) passln(); else failln(); - -puts(" 1!0"); if (1|0) passed(); else failed(); -puts(" !1!0"); if (!1|0) failln(); else passln(); -puts(" 1&0"); if (1&0) failed(); else passed(); -puts(" !1&0"); if (!1&0) passln(); else failln(); -puts(" 1^1"); if (1^1) failed(); else passed(); -puts(" !1^1"); if (!1^1) passln(); else failln(); - -puts(" atoc(\"0\")"); if (atoc("0")) failln(); else passln(); -puts(" atoc(\"1\")"); if (atoc("1")) passln(); else failln(); -puts(" atoc(\"127\"):+"); if (atoc("127"):+) passln(); else failln(); -puts(" atoc(\"128\"):-"); if (atoc("128"):-) passln(); else failln(); - -if (allok) putln("All Tests Passed"); -getc(); - -goto exit; - -void passed() {puts(" Pass");} -void passln() {passed(); newlin();} -void failed() {puts(" Fail"); allok = #FALSE;} -void failln() {failed(); newlin();} diff --git a/test/echo.c02 b/test/echo.c02 index f38e4c9..19b33d0 100644 --- a/test/echo.c02 +++ b/test/echo.c02 @@ -11,6 +11,8 @@ char key; //Key value main: + putstr("TYPE KEYS TO ECHO"); newlin(); + putstr("ESCAPE/STOP TO END"); newlin(); while() { key = getchr(); select (key) { diff --git a/test/echohex.c02 b/test/echohex.c02 index 8a7b8f5..cce90b7 100644 --- a/test/echohex.c02 +++ b/test/echohex.c02 @@ -1,6 +1,7 @@ /******************************************************* * ECHOHEX - Test/Demo program for C02 Standard Header * * Displays ASCII Code of Typed Keys to Screen * + * RETURN/ENTER moves to new line * * ESCAPE/STOP key Ends Program * *******************************************************/ @@ -9,9 +10,12 @@ char key; //Key value main: + putstr("PRESS KEYS TO DISPLAY"); newlin(); + putstr("ESCAPE/STOP TO END"); newlin(); while() { key = getchr(); prbyte(key); putchr(' '); + if (key==#RTNKEY) newlin(); if (key==#ESCKEY) goto exit; } diff --git a/test/hello.c02 b/test/hello.c02 index f232218..39f192f 100644 --- a/test/hello.c02 +++ b/test/hello.c02 @@ -5,17 +5,8 @@ //Specify System Header using -H option -char key; //Key value - -const char hello = "HELLO WORLD"; -char i; - main: - i = 0; - while (hello[i]) { - putchr(hello[i]); - i++; - } + putstr("HELLO WORLD"); newlin(); goto exit; diff --git a/test/loops.c02 b/test/loops.c02 index 69350dc..222801f 100644 --- a/test/loops.c02 +++ b/test/loops.c02 @@ -6,118 +6,115 @@ #include #include -char i, b; -const char failed = " Test Failed!"; +char aa,ii; //Function Variables +char b; //Comparison Variable +char i; //Loop Counter + +void putlin() {putstr(); newlin();} +void failed() {putlin(" FAILED");} +void passed() {putlin(" PASSED");} main: + putlin("TESTING LOOPS"); -/* Test If/Goto Loop */ -puts("IF "); -i = 0; -ifloop: - prbyte(i); - putc(' '); - i++; - if (i < 10) goto ifloop; -newlin(); + /* Test If/Goto Loop */ + putstr("IF "); + i = 0; + ifloop: + putchr('0'+i); + i++; + if (i < 8) goto ifloop; + if (i=8) passed(); else failed(); -/* Test While Loop */ -puts("WHILE "); -i = 0; -while (i < 10) { - prbyte(i); - putc(' '); - i++; -} -newlin(); + /* Test Block If */ + putstr("BLOCK "); + b = 1; + if (b>0) { + prhex(b); + putstr(" > "); + prhex(0); + passed(); + } + else failed(); -/* Test Do Loop */ -puts("DO "); -i = 0; -do { - prbyte(i); - putc(' '); - i++; -} while (i<10); -newlin(); + putstr(" IF "); + b = 0; + if (b>0) failed(); + else { + putchr('0'+i); + putstr(" = "); + prhex(0); + passed(); + } -/* Test For Loop */ -puts("FOR "); -i = 0; -for (i=0;i<10;i++) { - prbyte(i); - putc(' '); -} -newlin(); + /* Test While Loop */ + putstr("WHILE "); + i = 0; + while (i < 8) { + putchr('0'+i); + i++; + } + if (i=8) passed(); else failed(); -/* While with Break */ -puts("BREAK "); -i = 0; -while ($FF) { - if (i = 10) break; - prbyte(i); - putc(' '); - i++; -} -newlin(); + /* Test Do Loop */ + putstr("DO "); + i = 0; + do { + putchr('0'+i); + i++; + } while (i<8); + if (i=8) passed(); else failed(); -/* For with Continue */ -puts("CONT "); -for (i=0;i<10;i++) { - if (i & 1) continue; - prbyte(i); - putc(' '); -} -newlin(); + /* Test For Loop */ + putstr("FOR "); + i = 0; + for (i=0;i<8;i++) { + putchr('0'+i); + } + if (i=8) passed(); else failed(); + + /* While with Break */ + putstr("BREAK "); + i = 0; + while ($FF) { + if (i = 8) break; + putchr('0'+i); + i++; + } + if (i=8) passed(); else failed(); + + /* For with Continue */ + putstr("CONT "); + for (i=0;i<16;i++) { + if (i & 1) { continue; i=$FF;} + putchr('A'+i); + } + if (i=16) passed(); else failed(); /* Test Do with Break and Continue*/ -i = 0; -puts("DO BC "); -do { - i++; - if (!i&1) continue; - if (i>15) break; - prbyte(i); - putc(' '); -} while ($FF); -newlin(); + i = 0; + putstr("DO BC "); + do { + i++; + if (!i&1) {continue; i=$FF;} + if (i>16) break; + putchr('A'+i); + } while ($FF); + if (i=17) passed(); else failed(); - -newlin(); - -/* Test Block If */ -putln("BLOCK IF"); -b = 1; -if (b>0) { - prbyte(b); - puts(" is greater than "); - prbyte(0); - newlin(); -} -else - putln(&failed); -b = 0; -if (b>0) { - putln(&failed); -} -else { - prbyte(b); - puts(" is equal to "); - prbyte(0); - newlin(); -} -newlin(); - -/* Test If/Else in For Loop */ -putln("FOR/IF/ELSE"); -for(i = 0;i<4;i++) { - prbyte(i); - if (i & 1) - putln(" is odd"); - else - putln(" is even"); -} -newlin(); - - -goto exit; + /* Test If/Else, Select in For Loop */ + for(i = 0;i<4;i++) { + select (i) { + case 0: putstr("FOR "); b=0; + case 1: putstr(" IF "); b=1; + case 2: putstr(" ELSE "); b=2; + case 3: putstr(" SELECT "); b=3; + default: putstr(" ERROR! "); b=$FF; + } + putchr('0'+i); + if (i & 1) putstr("-ODD "); else putstr("-EVEN"); + if (i=b) passed(); else failed(); + } + + putlin("ALL TESTS COMPLETE"); + goto exit;