1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
global testno, passes, failures
function test (v,n1,n2) {
if (n1 == n2) {
passes ++
result = "pass"
} else {
failures ++
result = "fail"
}
println ("test " . (sprint (++testno)) . " [" . v . "]\t" . result)
}
function stest (v,n1,n2) {
if (n1 == n2) {
passes ++
result = "pass"
} else {
failures ++
result = "fail"
}
println ("test " . (sprint (++testno)) . " [" . v . "]\t" . result)
}
probe begin {
test ("+", 0, 0+0)
test ("+", 33339999, 33330000+9999)
test ("-", -1, 2-3)
test ("==", 1, -1==-1)
test ("!=", 1, -1!=1)
test (">", 1, 2>1)
test (">= (=)", 1, 1>=1)
test (">= (>)", 1, 2>=1)
test ("<", 1, -1<1)
test ("<= (=)", 1, 1<=1)
test ("<= (<)", 1, -1<=1)
test ("== s", 1, "foobar"=="foobar")
test (">= s (=)", 1, "foobar">="foobar")
test ("<= s (=)", 1, "foobar"<="foobar")
test ("<= s (<)", 1, "fooban"<="foobar")
test (">= s (>)", 1, "xxx">="aaa")
test ("> s", 1, "xxx">"aaa")
test ("< s", 1, "aaa"<"xxx")
test ("!= s", 1, "aaa"!="xxx")
test ("<", 1, -1<0)
test ("<", 1, 85723838<8273823892)
test ("*", 100300400500, 1003004005 * 100)
test ("*", -1*-500, 500)
test ("/", 1003004005/1000, 1003004)
test ("%", 1003004005%1000, 5)
test ("/", -1/-1, 1)
test ("%", -1%-1, 0)
test ("/", 0/-100, 0)
test ("%", 0%-100, 0)
test ("/", (-2147483647-1)/-1, 2147483648)
test ("%", (-2147483647-1)%-1, 0)
# but (-9223372036854775807-1)/-1 may overflow
test ("%", (-9223372036854775807-1)%-1, 0)
test ("&", 0x555&0xaaa, 0)
test ("|", 0x555|0xaaa, 0xfff)
test ("^", 0x55f^0xaaf, 0xff0)
test ("&&", 0x555&&0xaaa, 1)
test ("||", 0x555||0xaaa, 1)
test ("<<", 0<<5, 0)
test ("<<", 1<<8, 0x100)
test ("<<", 120<<-2, 120)
test ("<<", 120<<0, 120)
test ("<<", -4096<<-3, -4096)
test (">>", -4096>>3, -512)
test (">>", -4096>>-3, -4096)
test (">>", 120>>-2, 120)
test (">>", 120>>0, 120)
i=1; test ("--i", --i, 0)
i=1; test ("++i", ++i, 2)
i=1; test ("i--", i--, 1)
i=1; test ("i++", i++, 1)
i=1; test ("+=", i+=4, 5) test ("after +=", i, 5)
i=2; test ("*=", i-=1, 1) test ("after -=", i, 1)
i=5; test ("/=", i/=2, 2) test ("after /=", i, 2)
i=2; test ("*=", i*=2, 4) test ("after *=", i, 4)
i=3; test ("*=", i%=2, 1) test ("after %=", i, 1)
i=0xf; test (">>=", i>>=1, 7) test ("after >>=", i, 7)
i=0xf; test ("<<=", i<<=1, 30) test ("after <<=", i, 30)
i=0xf; test ("&=", i&=1, 1) test ("after &=", i, 1)
i=0xf; test ("^=", i^=1, 14) test ("after ^=", i, 14)
i=0xf; test ("|=", i|=1, 15) test ("after |=", i, 15)
i=+5; test ("+", i+5, 10)
i=-5; test ("+", i+5, 0)
i=5; test ("!", !i, 0)
i=0xf; test ("~", ~i, -16)
a="1" b="2"; stest (".=", a .= b, "12") stest ("after .=", a, "12")
test ("?:", 5==5?1:2, 1)
}
probe timer.sec(1) { # some time after all the begin probes
exit ()
}
probe end {
printf ("passes: %d failures: %d\n", passes, failures)
}
|