'--no-direct-mode --file TEST.TXT
DEF MAXMINTEST
 ASSERT__ MAX(0,1,2,3,4,5,4,3,2,1,0)==5,"MAX"
 ASSERT__ MIN(5,4,3,2,1,0,1,2,3,4,5)==0,"MIN"
 DIM A[5]
 FOR I=0 TO LEN(A)-1
  A[I]=I+1
 NEXT
 ASSERT__ MAX(A)==5,"MAX"
 ASSERT__ MIN(A)==1,"MIN"
 ASSERT__ MAX(2,0)*&H7FFFFFFF==-2,"MAX"
 ASSERT__ MAX(2,0,0)*&H7FFFFFFF==4294967294,"MAX"
 ASSERT__ MIN(2,4)*&H7FFFFFFF==-2,"MIN"
 ASSERT__ MIN(2,4,4)*&H7FFFFFFF==4294967294,"MIN"
END
MAXMINTEST

DEF SORTTEST
 DIM A[4]
 DIM B$[4]
 DIM C$[4]
 A[0]=3
 A[1]=2
 A[2]=1
 A[3]=0
 B$[0]="0"
 B$[1]="1"
 B$[2]="2"
 B$[3]="3"
 C$[0]="A"
 C$[1]="B"
 C$[2]="C"
 C$[3]="D"
 SORT A,B$,C$
 ASSERT__ A[0]==0,"SORT"
 ASSERT__ B$[0]=="3","SORT"
 ASSERT__ C$[0]=="D","SORT"
 RSORT A,B$,C$
 ASSERT__ A[3]==0,"RSORT"
 ASSERT__ B$[3]=="3","RSORT"
 ASSERT__ C$[3]=="D","RSORT"
 SORTTEST2
END
DEF SORTTEST2
 DIM A[10]
 DIM B[10]
 A[9]=-1
 B[9]=12345
 SORT 1,9,A,B
 ASSERT__ A[1]==-1,"SORT"
 ASSERT__ B[1]==12345,"SORT"
 RSORT 1,8,A,B
 ASSERT__ A[8]==-1,"RSORT"
 ASSERT__ B[8]==12345,"RSORT"
END
SORTTEST
'SWAP TEST
SWAPTEST
DEF SWAPTEST
 VAR A=1
 VAR B=2
 SWAP A,B
 ASSERT__ B==1, "SWAP1"
 ASSERT__ A==2, "SWAP2"
 VAR A$="1
 VAR B$="2
 SWAP A$,B$
 ASSERT__ B$=="1", "SWAP3"
 ASSERT__ A$=="2", "SWAP4"
 VAR A%=1
 VAR B#=2.34567
 SWAP A%,B#
 ASSERT__ B#==1, "SWAP5"
 ASSERT__ A%==2, "SWAP6"
END

'REPEAT TEST
?"REPEAT(1)"
VAR REPEATTEST
REPEAT
 REPEATTEST=TRUE
 BREAK
 ASSERT__ FALSE, "REPEAT"
UNTIL FALSE
ASSERT__ REPEATTEST, "REPEAT"

?"REPEAT(2)"
VAR REPEATTEST2
REPEAT
 REPEATTEST2=1
 CONTINUE
 ASSERT__ FALSE, "REPEAT"
UNTIL REPEATTEST2
ASSERT__ REPEATTEST2, "REPEAT"

?"REPEAT(3)"
REPEAT
 CONTINUE
 ASSERT__ FALSE, "REPEAT"
UNTIL TRUE

?"REPEAT(4)"
VAR REPEATTEST4
REPEAT
 REPEATTEST4=TRUE
UNTIL TRUE
ASSERT__ REPEATTEST4, "REPEAT"


VAR IFTEST=FALSE
IF TRUE THEN
 IFTEST=TRUE
ENDIF
ASSERT__  IFTEST, "IF"

VAR IFTEST2=FALSE
IF TRUE THEN IFTEST2=TRUE
ASSERT__  IFTEST2, "IF"

VAR ELSETEST=FALSE
IF FALSE THEN
ELSE
 ELSETEST=TRUE
ENDIF
ASSERT__  ELSETEST, "ELSE"

VAR ELSETEST2=FALSE
IF FALSE THEN ELSE ELSETEST2=TRUE:ENDIF
ASSERT__  ELSETEST2, "ELSE"


VAR ELSEIFTEST=FALSE
IF FALSE THEN
 ELSEIFTEST=FALSE
ELSEIF FALSE THEN
 ELSEIFTEST=FALSE
ELSEIF TRUE THEN
 ELSEIFTEST=TRUE
ELSEIF FALSE THEN
 ELSEIFTEST=FALSE
ELSE
 ELSEIFTEST=FALSE
ENDIF
ASSERT__  ELSEIFTEST, "ELSEIFTEST"

VAR ELSEIFTEST2=FALSE
IF FALSE THEN ELSEIFTEST2=FALSE ELSEIF FALSE THEN ELSEIFTEST2=FALSE ELSEIF TRUE THEN ELSEIFTEST2=TRUE ELSEIF FALSE THEN ELSEIFTEST2=FALSE ELSE ELSEIFTEST2=FALSE ENDIF
ASSERT__  ELSEIFTEST2, "ELSEIFTEST"

DEF CALLTEST(V)
 RETURN V
END
CALL "SPDEF",1192 OUT A,B

ASSERT__ A==464, "CALLTEST"
ASSERT__ B==384, "CALLTEST"
ASSERT__ CALL("CALLTEST", TRUE), "CALLTEST"
DEF TESST X,A$
 IF Y<0 THEN Y=28
 IF X<0 THEN X=20-(LEN(A$)/2)
 AA
 ?X
 END
 DEF AA
  X=999
 END
 TESST -1,"AAAAAAAAAAAAAAAAAAAA"
ASSERT__ FLOOR(0.5)==0, "FLOOR"
ASSERT__ FLOOR(1)==1, "FLOOR"
ASSERT__ FLOOR(1.5)==1, "FLOOR"
ASSERT__ CEIL(0.5)==1, "CEIL"
ASSERT__ CEIL(1)==1, "CEIL"
ASSERT__ CEIL(1.25)==2, "CEIL"
ASSERT__ CEIL(1.5)==2, "CEIL"
ASSERT__ ROUND(0.5)==1, "ROUND"
ASSERT__ ROUND(1)==1, "ROUND"
ASSERT__ ROUND(1.25)==1, "ROUND"
ASSERT__ ROUND(1.5)==2, "ROUND"

ASSERT__ FLOOR(-0.5)==-1, "FLOOR"
ASSERT__ FLOOR(-1)==-1, "FLOOR"
ASSERT__ FLOOR(-1.5)==-2, "FLOOR"
ASSERT__ CEIL(-0.5)==-0, "CEIL"
ASSERT__ CEIL(-1)==-1, "CEIL"
ASSERT__ CEIL(-1.25)==-1, "CEIL"
ASSERT__ CEIL(-1.5)==-1, "CEIL"
ASSERT__ ROUND(-0.5)==-1, "ROUND"
ASSERT__ ROUND(-1)==-1, "ROUND"
ASSERT__ ROUND(-1.25)==-1, "ROUND"
ASSERT__ ROUND(-1.5)==-2, "ROUND"

ASSERT__ VAL("0")==0, "VAL"
ASSERT__ VAL("1")==1, "VAL"
ASSERT__ VAL("-1")==-1, "VAL"
ASSERT__ VAL("&HA")==10, "VAL"
ASSERT__ VAL("&H-A")==0, "VAL"
ASSERT__ VAL("&B10")==2, "VAL"
ASSERT__ VAL("aa")==0, "VAL"

ASSERT__ RAD(180)==PI(), "RAD"
ASSERT__ DEG(RAD(180)), "DEG"
ASSERT__ HEX$(65535, 8)=="0000FFFF", "HEX$"
ASSERT__ SUBST$("0123456789",0,"B")=="B","SUBST$"
ASSERT__ SUBST$("0123456789",0,4,"B")=="B456789","SUBST$"
ASSERT__ SUBST$("",0,4,"B")=="B","SUBST$"
WHILE 1
WEND
FOR I=0TO 511'-500
 SPSET I,I'304'-I+304
 SPOFS I, (I*16) MOD 400, FLOOR((I*16)/400)*16
 'SPOFS I, 100,100
NEXT
WHILE TRUE
WEND
WHILE TRUE
FOR I=0TO 511
 SPOFS I, RND(400), RND(240)
 GPSET RND(400), RND(240), -1
NEXT
WEND
DIM ARRY[10]
?ARRY[0],FORMAT$("%D",100)
GOSUB@A
GOTO@B
'A=SIN(B) 
'?Y2,SIN(DAY * 2 * 3.141 / BDAY),LINEH,LINEC
@A
Y2 = LINEC - SIN(DAY * 2 * 3 / BDAY) * LINEH
RETURN
@B
?DATE$, TIME$
DTREAD "2014/10/12" OUT Y,M,D
?Y,M,D
?SIN(1)
'COMMENT'
ASSERT__ 1, "TRUE"
A$="A"
ASSERT__ A$=="A", "A$==A"
A$=A$+"B"
ASSERT__ A$=="AB", "A$==AA"
A=0
INC A
ASSERT__ A==1, "A==1"
INC A, 3
ASSERT__ A==4, "A==4"
DEC A, 3
ASSERT__ A==1, "A==1"
DEC A
ASSERT__ A==0, "A==0"
INCTEST 10
DEF INCTEST A
 INC A
 ASSERT__ A==11, "A==11"
 INC A, 3
 ASSERT__ A==14, "A==14"
 DEC A, 3
 ASSERT__ A==11, "A==11"
 DEC A
 ASSERT__ A==10, "A==10"
END
GOTOTEST
GOTO@SKIP
@LOCAL
ASSERT__ 0, "LOCAL LABEL"
@SKIP
DEF GOTOTEST
 GOTO @LOCAL
 ASSERT__ 0, "LOCAL LABEL"
 @LOCAL
END

ON 1 GOTO @0,@1,@2,@3
@0
 ASSERT__ 0, "ON GOTO"
@2
 ASSERT__ 0, "ON GOTO"
@3
 ASSERT__ 0, "ON GOTO"
@1
ONGOTOTEST
DEF ONGOTOTEST
 ON 1 GOTO @0,@1,@2,@3
 @0
  ASSERT__ 0, "LOCAL ON GOTO"
 @2
  ASSERT__ 0, "LOCAL ON GOTO"
 @3
  ASSERT__ 0, "LOCAL ON GOTO"
 @1
END
ON 1 GOSUB @ONGOSUB0,@ONGOSUB1,@ONGOSUB2,@ONGOSUB3
GOTO@ONGOSUB4
@ONGOSUB0
 ASSERT__ 0, "ON GOSUB"
@ONGOSUB2
 ASSERT__ 0, "ON GOSUB"
@ONGOSUB3
 ASSERT__ 0, "ON GOSUB"
@ONGOSUB1
RETURN
@ONGOSUB4
ONGOSUBTEST
DEF ONGOSUBTEST
 ON 1 GOTO @0,@1,@2,@3
 GOTO@4
 @0
  ASSERT__ 0, "ON ONGOSUB"
 @2
  ASSERT__ 0, "ON ONGOSUB"
 @3
  ASSERT__ 0, "ON ONGOSUB"
 @1
 RETURN
 @4
END
@DATA_1
DIM ARY[2]
DATA "A",1,2,3,4,5
READ DATA$,_1,_2
READ _3,_4
READ ARY[_1]
ASSERT__ DATA$=="A", "DATA"
ASSERT__ _1==1, "DATA"
ASSERT__ _2==2, "DATA"
ASSERT__ _3==3, "DATA"
ASSERT__ _4==4, "DATA"
ASSERT__ ARY[1]==5, "DATA"
?ARY[_1]
INPUT$="HELLO"
INPUT INPUT$,IN
?INPUT$,IN
LOCATE 10,
COLOR 1,15
PRINT "テスト正常終了"
