package main import "fmt2" func shortCircuit() bool { i := 1 assert(i == 0) return true } func shortCircuit2() BOOL_ { i := 1 assert(i == 0) return BOOL_(true) } func test1() { var i, j = 80, 8 assert( i + j == 88) assert( i - j == 72) assert( i * j == 640) assert( i / j == 10) assert( i % j == 0) var k = i k += j assert(k == i + j) k = i k -= j assert(k == i - j) k = i k *= j assert(k == i * j) k = i k /= j assert(k == i / j) k = i k %= j assert(k == i % j) { var i, j = 80.0, 0.1 assert( i + j == 80.1) assert( i - j == 79.9) assert( i * j == 8.0) assert( i / j == 800.0) var k = i k += j assert(k == i + j) k = i k -= j assert(k == i - j) k = i k *= j assert(k == i * j) k = i k /= j assert(k == i / j) } { type S1 struct {i, j int} var s S1 s.i = 1 s.j = 2000000000 s.i-- s.j++ assert(s.i == 0) assert(s.j == 2000000001) } { var a = [3]int{1, 8} f := uint(2) i := 1 <>f a[0] <<= 2 a[1] >>= 2 assert(i == 4) assert(j == 2) assert(a[0] == 4) assert(a[1] == 2) } { i := 1 i ++ assert(i == 2) type S1 struct {i, j int} var s S1 s.i++ assert(s.i == 1) p := &i; *p++ assert(i == 3) } { t := true f := false assert(!(t&&f)) assert(t&&t) assert(t&&t||f) assert(!(t&&t&&f)) assert(t||shortCircuit()) assert(!(f&&shortCircuit())) } } type INT_ int type BOOL_ bool type FLOAT_ float32 func test2() { var i, j INT_ = 80, 8 fmt2.Println(i + j) assert (i != j) assert (i == j + 72) assert( i + j == 88) assert( i - j == 72) assert( i * j == 640) assert( i / j == 10) assert( i % j == 0) var k = i k += j assert(k == i + j) k = i k -= j assert(k == i - j) k = i k *= j assert(k == i * j) k = i k /= j assert(k == i / j) k = i k %= j assert(k == i % j) { var i, j FLOAT_ = 80.0, 0.1 assert( i + j == 80.1) assert( i - j == 79.9) assert( i * j == 8.0) assert( i / j == 800.0) var k = i k += j assert(k == i + j) k = i k -= j assert(k == i - j) k = i k *= j assert(k == i * j) k = i k /= j assert(k == i / j) } { type S1 struct {i, j INT_} var s S1 s.i = 1 s.j = 2000000000 s.i-- s.j++ assert(s.i == 0) assert(s.j == 2000000001) } { var a = [3]INT_{1, 8} f := uint(2) i := INT_(1) <>f a[0] <<= 2 a[1] >>= 2 assert(i == 4) assert(j == 2) assert(a[0] == 4) assert(a[1] == 2) } { i := INT_(1) i ++ assert(i == 2) type S1 struct {i, j INT_} var s S1 s.i++ assert(s.i == 1) p := &i; *p++ assert(i == 3) } { var t BOOL_ = true var f BOOL_ = false assert(!(t&&f)) assert(t&&t) assert(t&&t||f) assert(!(t&&t&&f)) assert(t||shortCircuit2()) assert(!(f&&shortCircuit2())) } } func main() { test1() test2() }