2021-04-12 18:53:35 +01:00
|
|
|
# test cases for boolean expressions
|
|
|
|
|
|
|
|
assert(1 != false && 1 != true)
|
|
|
|
assert(0 != false && 0 != true)
|
|
|
|
assert(!!1 == true)
|
|
|
|
assert(!!0 == false)
|
|
|
|
|
|
|
|
a = true
|
|
|
|
b = false
|
|
|
|
assert(!!list == true)
|
|
|
|
assert(a && b == false)
|
|
|
|
assert(!(a && b))
|
|
|
|
def test(a, b)
|
|
|
|
while !(a && b)
|
|
|
|
assert(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
test(true, true)
|
2021-11-27 17:47:24 +00:00
|
|
|
|
|
|
|
# bug in unary
|
|
|
|
def f(i)
|
|
|
|
var j = !i # bug if i is erroneously modified
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
assert(f(1) == 1)
|
|
|
|
|
|
|
|
#- addind bool() function -#
|
|
|
|
assert(bool() == false)
|
|
|
|
assert(bool(0) == false)
|
|
|
|
assert(bool(0.0) == false)
|
|
|
|
assert(bool(false) == false)
|
|
|
|
assert(bool(nil) == false)
|
|
|
|
|
|
|
|
assert(bool(-1) == true)
|
|
|
|
assert(bool(3.5) == true)
|
2022-06-24 22:17:33 +01:00
|
|
|
assert(bool('') == false) # changed behavior
|
2021-11-27 17:47:24 +00:00
|
|
|
assert(bool('a') == true)
|
|
|
|
assert(bool(list) == true)
|
2023-06-27 21:07:13 +01:00
|
|
|
assert(bool(list()) == false) # changed behavior
|
|
|
|
assert(bool([]) == false) # changed behavior
|
|
|
|
assert(bool([0]) == true)
|
|
|
|
assert(bool(map()) == false) # changed behavior
|
|
|
|
assert(bool({}) == false) # changed behavior
|
|
|
|
assert(bool({false:false}) == true)
|
|
|
|
assert(bool({nil:nil}) == false)# changed behavior - `nil` key is ignored so the map is empty
|
2022-06-24 22:17:33 +01:00
|
|
|
|
|
|
|
import introspect
|
|
|
|
assert(bool(introspect.toptr(0x1000)) == true)
|
|
|
|
assert(bool(introspect.toptr(0)) == false)
|