-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.go
72 lines (61 loc) · 1.25 KB
/
test.go
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
package main
func assert(expected int, actual int, code string) {
if expected == actual {
println("ok")
} else {
println(code)
}
}
// TODO: add return type
func ret3() {
return 3
}
func ret5() {
return 5
}
func add(x int, y int) {
return x + y
}
func sub(x int, y int) {
return x - y
}
func add6(a int, b int, c int, d int, e int, f int) {
return a + b + c + d + e + f
}
func fib(x int) {
if x <= 1 {
return 1
}
return fib(x-1) + fib(x-2)
}
func main() {
println("simple arithmetic")
assert(0, 0, "0")
assert(42, 42, "42")
assert(5, 5, "0")
assert(21, 5+20-4, "5+20-4")
assert(41, 12+34-5, "12+34-5")
assert(15, 5*(9-6), "5*(9-6)")
assert(4, (3+5)/2, "(3+5)/2")
assert(10, -10+20, "-10+20")
assert(10, - -10, "- -10")
assert(10, - -+10, "- - +10")
println("equality operators")
assert(0, 0 == 1, "0==1")
assert(1, 42 == 42, "42==42")
assert(1, 0 != 1, "0!=1")
assert(0, 42 != 42, "42!=42")
println("relational operators")
assert(1, 0 < 1, "0<1")
assert(0, 1 < 1, "1<1")
assert(0, 2 < 1, "2<1")
assert(1, 0 <= 1, "0<=1")
assert(1, 1 <= 1, "1<=1")
assert(0, 2 <= 1, "2<=1")
assert(1, 1 > 0, "1>0")
assert(0, 1 > 1, "1>1")
assert(0, 1 > 2, "1>2")
assert(1, 1 >= 0, "1>=0")
assert(1, 1 >= 1, "1>=1")
assert(0, 1 >= 2, "1>=2")
}