This repository has been archived on 2024-09-22. You can view files and clone it, but cannot push or open issues or pull requests.
pbi-core/unittests.bs1

248 lines
3.2 KiB
Plaintext
Raw Permalink Normal View History

' {$STAMP BS1}
DEBUG CR,"test references and composition.."
SYMBOL new = NEW 16
SYMBOL big = W0
SYMBOL small_right = B0
SYMBOL small_left = B1
SYMBOL tiny_beg = BIT0
SYMBOL tiny_end = BIT7
SYMBOL int1 = W0
SYMBOL int2 = B2
SYMBOL int3 = new
SYMBOL counter = W0
SYMBOL bool = BIT11
ASSERT new = 0
ASSERT big = 0
ASSERT small_left = 0
ASSERT small_right = 0
'BREAKPOINT
new = 1
W0 = new
ASSERT big = new
ASSERT small_left = 0
ASSERT small_right = 1
ASSERT tiny_beg = 1
ASSERT tiny_end = 0
'BREAKPOINT
DEBUG "test comments.." 'test
'test
'BREAKPOINT
DEBUG "test arithmetics.."
int1 = 1
int2 = 2
int3 = 3
int1 = int1 + int2 * int3 MAX 5 / 3 MIN int1 // 2 & 1 - 1 + 65000 ** 65000 - 64467 | 0
'result= 3 9 9 3 1 1 1 0 65000 64468 1 1
ASSERT int1 = 1
'BREAKPOINT
DEBUG "test control-commands.."
counter = 0
label:
IF counter = 10 THEN fin
counter = counter + 1
GOTO label
fin:
ASSERT counter = 10
'BREAKPOINT
counter = 0
branch_start:
BRANCH counter, (test1,test2,test3,branch_end)
test1:
counter = 1
GOTO branch_start
test2:
counter = 2
GOTO branch_start
test3:
counter = 3
GOTO branch_start
branch_end:
ASSERT counter = 3
'BREAKPOINT
DEBUG "test subroutines.."
GOSUB subroutine
ASSERT counter = 5
'BREAKPOINT
DEBUG "test power/time-commands.."
NAP 1
SLEEP 1
PAUSE 500
'BREAKPOINT
DEBUG "test io-commands.."
HIGH 1
ASSERT PIN1 = 1
ASSERT DIR1 = 1
'BREAKPOINT
LOW 1
ASSERT PIN1 = 0
ASSERT DIR1 = 1
'BREAKPOINT
OUTPUT 1
ASSERT DIR1 = 1
'BREAKPOINT
INPUT 1
ASSERT DIR1 = 0
'BREAKPOINT
TOGGLE 1
ASSERT PIN1 = 1
ASSERT DIR1 = 1
'BREAKPOINT
TOGGLE 1
ASSERT PIN1 = 0
ASSERT DIR1 = 1
'BREAKPOINT
REVERSE 1
ASSERT DIR1 = 0
'BREAKPOINT
REVERSE 1
ASSERT DIR1 = 1
'BREAKPOINT
SOUND 1, (80,50)
ASSERT DIR1 = 1
'BREAKPOINT
DEBUG "test loops"
bool = 1
FOR counter = 0 TO 10
IF bool = 1 THEN check_init
inside_for:
NEXT
ASSERT counter = 10
'BREAKPOINT
FOR counter = 10 TO 0 STEP -1
NEXT
ASSERT counter = 0
'BREAKPOINT
FOR int3 = 0 TO 9
FOR int2 = 0 TO 9
counter = counter + 1
NEXT
NEXT
ASSERT int3 = 9
ASSERT int2 = 9
ASSERT counter = 100
'BREAKPOINT
DEBUG "test numeric commands.."
int1 = 3
LOOKUP int1, ("ABRAKADABRA"), int2
ASSERT int1 = 3
ASSERT int2 = 65
'BREAKPOINT
LOOKDOWN int2, ("ABRAKADABRA"), int1
ASSERT int1 = 3
ASSERT int2 = 65
'BREAKPOINT
LOOKUP int1, (0,1,2,3), int2
ASSERT int1 = 3
ASSERT int2 = 3
'BREAKPOINT
LOOKDOWN int2, (0,1,2,3), int1
ASSERT int1 = 3
ASSERT int2 = 3
'BREAKPOINT
RANDOM new
'DEBUG "a random value: ", #new
'BREAKPOINT
DEBUG "test storage-modifying-commands.."
READ 0, int1
ASSERT int1 = 0
WRITE 0, int2
READ 0, int1
ASSERT int1 = 3
EEPROM int1, (3,4)
READ 4, int1
ASSERT int1 = 4
EEPROM (0,1,2)
READ 0, int1
ASSERT int1 = 0
DEBUG EEPROM
'BREAKPOINT
DEBUG "test debug.."
DEBUG CR,"text",W0," ",#W0," ",%W0," ",$W0, 0, @68
SEROUT 1, 1, ("text", W0, "text")
'BREAKPOINT
DEBUG "test formatters.."
DIRS = %00000011
PINS = $FF
new = @A + 1
ASSERT DIRS = 3
ASSERT PINS = 255
ASSERT new = 66
'BREAKPOINT
END
check_init:
bool = 0
ASSERT counter = 0
GOTO inside_for
subroutine:
'BREAKPOINT
counter = counter + 1
GOSUB subsubroutine 'test nested subroutines
RETURN
subsubroutine:
'BREAKPOINT
counter = counter + 1
RETURN