pocketlang/tests/modules/math.pk
Thakee Nathees 168f365cde import statements are refactored.
- all import statement (native or script file) have the same syntax
- allow relative (including parent directory) imports
- cyclic imports are handled by caching the scripts
- `import foo` can potentially import `<searchpath>/foo/_init.pk`
- * import are not supported anymore
2022-05-06 11:16:48 +05:30

69 lines
1.9 KiB
Plaintext

## `from math import *` not supported anymore
import math as m
from math import abs, round, log10,
floor, ceil
assert(ceil(1.1) == floor(2.9))
## FIXME:
## temproarly modules cannot define globals via native interface
## and it'll be fixed soon.
PI = 3.14159265358979323846
assert(m.sin(0) == 0)
assert(m.sin(PI/2) == 1)
threshold = 0.0000000000001
assert(abs(m.cos(PI/3) - 0.5) < threshold )
assert(abs(m.tan(PI/4) - 1.0) < threshold )
for i in 0..1000
assert(abs(m.sin(i) / m.cos(i) - m.tan(i)) < threshold)
end
assert((m.cosh(.5) - 1.1276259652063807) < threshold)
assert((m.tanh(0.5) - 1.127625965206) < threshold)
for i in 0..100
assert(abs(m.sinh(i) / m.cosh(i) - m.tanh(i)) < threshold)
end
assert(abs(m.acos(PI/4) - 0.5) < 0.35)
assert(abs(m.atan(PI/4) - 0.5) < 0.2)
assert((m.acos(0.5) - 1.1276259652063807) < threshold)
assert((m.atan(0.3) - 1.1276259652063807) < threshold)
x = -1; interval = 1000
for i in 0..interval-1
x += 2/interval
assert(abs(m.sin(m.asin(x)) - x) < threshold)
assert(abs(m.cos(m.acos(x)) - x) < threshold)
assert(abs(m.tan(m.atan(x)) - x) < threshold)
end
assert(abs(log10(2) - 0.3010299956639812) < threshold)
assert(round(1.4) == 1)
assert(round(1.5) == 2)
assert(round(-1.5) == -2)
## Note that these mathe functions are removed temproarly from the core
## For more information see PR #201
##
##assert(abs(log2(2) - 1) < threshold)
##assert(abs(log2(1) - 0) < threshold)
##assert(abs(log2(5) - 2.321928094887362) < threshold)
##
##assert(abs(hypot(1,1) - 1.414213562373095) < threshold)
##assert(abs(hypot(3,5) - 5.830951894845301) < threshold)
##
##assert(abs(cbrt(27) - 3) < threshold)
##assert(abs(cbrt(9) - 2.080083823051904) < threshold)
##
##assert(abs(gamma(5) - 24) < threshold)
##assert(abs(gamma(2.2) - 1.101802490879713) < threshold)
# If we got here, that means all test were passed.
print('All TESTS PASSED')