mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
2707c1eec3
* Fix #54: Add bitwise OR operator and make it available in PKVM Like the bitwise AND, this is an implementation for pocketlang to support the bitwise OR operation. In addition, updated "value" -> "result" in other operation to correctly reflect the container's purpose. It's indeed the result after the operation, which is a value too. In addition, add tests for bitwise AND (&) and bitwise OR (|). Add a print statement in test file with message that all tests passed with no errors. * Fix typo in comment * Cleanup fixes
49 lines
1.2 KiB
Plaintext
49 lines
1.2 KiB
Plaintext
## Core builtin functions and attribute tests.
|
|
|
|
assert(hex(12648430) == '0xc0ffee')
|
|
assert(hex(255) == '0xff' and hex(10597059) == '0xa1b2c3')
|
|
assert(hex(-4294967295) == '-0xffffffff') ## the largest.
|
|
|
|
## string attributes.
|
|
assert(''.length == 0)
|
|
assert('test'.length == 4)
|
|
assert(''.lower == '' and ''.upper == '')
|
|
assert('already+lower '.lower == 'already+lower ')
|
|
assert('ALREADY+UPPER '.upper == 'ALREADY+UPPER ')
|
|
assert('tEST+InG'.lower == 'test+ing')
|
|
assert('tEST+InG'.upper == 'TEST+ING')
|
|
|
|
assert(' trim '.strip == 'trim')
|
|
assert(''.strip == '')
|
|
|
|
## List attribute
|
|
assert([].length == 0)
|
|
assert([1, 2, 3].length == 3)
|
|
|
|
## Function
|
|
assert(print.arity == -1)
|
|
assert(hex.arity == 1)
|
|
assert(func(a, b)end .arity == 2)
|
|
assert(print.name == "print")
|
|
def fn(p1, p2, p3) end
|
|
assert(fn.name == "fn")
|
|
assert(fn.arity == 3)
|
|
|
|
## Math functions
|
|
from math import PI, sin, cos, tan, abs
|
|
|
|
assert(sin(0) == 0)
|
|
assert(sin(PI/2) == 1)
|
|
|
|
threshold = 0.0000000000001
|
|
|
|
assert(abs(cos(PI/3) - 0.5) < threshold )
|
|
assert(abs(tan(PI/4) - 1.0) < threshold )
|
|
for i in 0..1000
|
|
assert(abs(sin(i) / cos(i) - tan(i)) < threshold)
|
|
end
|
|
|
|
# If we got here with no errors, then all test passed
|
|
print('All tests PASSED (100%)')
|
|
|