2019-08-04 09:16:44 +02:00
|
|
|
const (
|
|
|
|
a = 3
|
2019-09-01 21:37:22 +02:00
|
|
|
u = u64(1)
|
|
|
|
)
|
2019-08-04 09:16:44 +02:00
|
|
|
|
|
|
|
fn test_const() {
|
2019-09-01 21:37:22 +02:00
|
|
|
b := (true && true) || false
|
|
|
|
assert b == true
|
|
|
|
assert a == 3
|
|
|
|
assert u == u64(1)
|
2019-09-23 01:14:10 +02:00
|
|
|
assert u == 1 // make sure this works without the cast
|
2019-09-01 21:37:22 +02:00
|
|
|
}
|
2019-08-05 16:57:54 +02:00
|
|
|
|
2019-09-29 17:27:53 +02:00
|
|
|
fn test_float_equal_operator() {
|
|
|
|
mut a := f32(1)
|
|
|
|
a += 0.000001
|
|
|
|
a -= 0.000001
|
|
|
|
assert a == 1
|
|
|
|
assert !a.eqbit(1)
|
2019-10-01 21:38:36 +02:00
|
|
|
assert !(a != 1)
|
|
|
|
assert a.nebit(1)
|
|
|
|
a += 0.000001
|
|
|
|
assert !(a < 1)
|
|
|
|
assert !a.ltbit(1)
|
|
|
|
assert !(a <= 1)
|
|
|
|
assert !a.lebit(1)
|
|
|
|
assert a > 1
|
|
|
|
assert a.gtbit(1)
|
|
|
|
assert a >= 1
|
|
|
|
assert a.gebit(1)
|
2019-09-29 17:27:53 +02:00
|
|
|
|
|
|
|
a = f64(1)
|
|
|
|
a += 0.000001
|
|
|
|
a -= 0.000001
|
|
|
|
assert a == 1
|
|
|
|
assert !a.eqbit(1)
|
2019-10-01 21:38:36 +02:00
|
|
|
assert !(a != 1)
|
|
|
|
a += 0.000001
|
|
|
|
assert !(a < 1)
|
|
|
|
assert !a.ltbit(1)
|
|
|
|
assert !(a <= 1)
|
|
|
|
assert !a.lebit(1)
|
|
|
|
assert a > 1
|
|
|
|
assert a.gtbit(1)
|
|
|
|
assert a >= 1
|
|
|
|
assert a.gebit(1)
|
2019-12-30 10:45:56 +01:00
|
|
|
|
|
|
|
f := 1.2
|
2020-02-07 22:16:14 +01:00
|
|
|
ab := int(f)
|
2019-12-30 10:45:56 +01:00
|
|
|
assert ab == 1
|
2019-09-29 17:27:53 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 01:58:08 +02:00
|
|
|
fn test_str_methods() {
|
|
|
|
assert i8(1).str() == '1'
|
|
|
|
assert i8(-1).str() == '-1'
|
|
|
|
assert i16(1).str() == '1'
|
|
|
|
assert i16(-1).str() == '-1'
|
2019-09-01 21:37:22 +02:00
|
|
|
assert int(1).str() == '1'
|
|
|
|
assert int(-1).str() == '-1'
|
2019-08-12 01:58:08 +02:00
|
|
|
assert i64(1).str() == '1'
|
|
|
|
assert i64(-1).str() == '-1'
|
|
|
|
|
2019-09-03 13:57:04 +02:00
|
|
|
// assert byte(1).str() == '1'
|
|
|
|
// assert byte(-1).str() == '255'
|
2019-08-12 01:58:08 +02:00
|
|
|
assert u16(1).str() == '1'
|
|
|
|
assert u16(-1).str() == '65535'
|
|
|
|
assert u32(1).str() == '1'
|
|
|
|
assert u32(-1).str() == '4294967295'
|
|
|
|
assert u64(1).str() == '1'
|
|
|
|
assert u64(-1).str() == '18446744073709551615'
|
|
|
|
}
|
|
|
|
|
2019-11-29 20:42:32 +01:00
|
|
|
fn test_and() {
|
|
|
|
c:=[1,2,3,4,5]
|
|
|
|
assert c[0] & 1 != 0
|
|
|
|
assert c[1] & 1 == 0
|
|
|
|
assert c[2] & 1 != 0
|
|
|
|
assert c[3] & 1 == 0
|
|
|
|
assert c[4] & 1 != 0
|
|
|
|
}
|
|
|
|
|
2019-12-03 14:09:37 +01:00
|
|
|
fn test_i8_print() {
|
|
|
|
b := i8(0)
|
|
|
|
println(b)
|
|
|
|
c := i16(7)
|
|
|
|
println(c)
|
|
|
|
d := u16(6)
|
|
|
|
println(d)
|
|
|
|
assert true
|
|
|
|
}
|
|
|
|
|
2019-08-09 10:21:21 +02:00
|
|
|
/*
|
2019-08-05 16:57:54 +02:00
|
|
|
fn test_cmp() {
|
|
|
|
assert 1 ≠ 2
|
|
|
|
assert 1 ⩽ 2
|
|
|
|
assert 1 ⩾ 0
|
2019-09-01 21:37:22 +02:00
|
|
|
}
|
2019-08-09 10:21:21 +02:00
|
|
|
*/
|
2019-12-05 16:47:29 +01:00
|
|
|
|
|
|
|
type myint int
|
|
|
|
type mystring string
|
|
|
|
|
|
|
|
fn test_int_alias() {
|
|
|
|
/*
|
|
|
|
i := myint(2)
|
|
|
|
s := mystring('hi')
|
|
|
|
ss := s + '!'
|
|
|
|
assert i + 10 == 12
|
|
|
|
*/
|
|
|
|
}
|
2020-02-04 17:44:39 +01:00
|
|
|
|
|
|
|
fn test_hex() {
|
|
|
|
x := u64(10)
|
2020-03-11 00:38:11 +01:00
|
|
|
assert x.hex() == 'a'
|
|
|
|
b := 1234
|
|
|
|
assert b.hex() == '4d2'
|
|
|
|
b1 := -1
|
|
|
|
assert b1.hex() == 'ffffffff'
|
2020-02-04 17:44:39 +01:00
|
|
|
}
|
2020-02-23 12:33:07 +01:00
|
|
|
|
|
|
|
fn test_oct() {
|
|
|
|
x1 := 0o12
|
|
|
|
assert x1 == 10
|
2020-02-23 23:43:04 +01:00
|
|
|
x2 := 00000o350
|
|
|
|
assert x2 == 232
|
|
|
|
x3 := 000o00073
|
|
|
|
assert x3 == 59
|
|
|
|
x4 := 00000000
|
|
|
|
assert x4 == 0
|
|
|
|
x5 := 00000195
|
|
|
|
assert x5 == 195
|
|
|
|
x6 := -0o744
|
|
|
|
assert x6 == -484
|
|
|
|
x7 := -000o000042
|
|
|
|
assert x7 == -34
|
|
|
|
x8 := -0000112
|
|
|
|
assert x8 == -112
|
|
|
|
x9 := -000
|
|
|
|
assert x9 == 0
|
2020-02-23 12:33:07 +01:00
|
|
|
}
|
2020-03-19 07:24:49 +01:00
|
|
|
|
|
|
|
fn test_int_decl() {
|
|
|
|
x1 := 0
|
|
|
|
x2 := 1333
|
|
|
|
x3 := -88955
|
|
|
|
x4 := 2000000000
|
|
|
|
x5 := -1999999999
|
|
|
|
assert typeof(x1) == 'int'
|
|
|
|
assert typeof(x2) == 'int'
|
|
|
|
assert typeof(x3) == 'int'
|
|
|
|
assert typeof(x4) == 'int'
|
|
|
|
assert typeof(x5) == 'int'
|
2020-03-23 20:05:37 +01:00
|
|
|
// integers are always 'int' by default
|
2020-03-19 07:24:49 +01:00
|
|
|
x6 := 989898932113111
|
2020-03-23 20:05:37 +01:00
|
|
|
x7 := u64(-321314588900011)
|
|
|
|
assert typeof(x6) == 'int'
|
2020-03-19 07:24:49 +01:00
|
|
|
assert typeof(x7) == 'u64'
|
|
|
|
}
|