FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/test/generated-code-tests/entry/mainNumber.test.js at develop · husayt/mathjs · GitHub
husayt
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
test
/
generated-code-tests
/
entry
/
mainNumber.test.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
163 lines (128 loc) · 5.3 KB
Breadcrumbs
mathjs
/
test
/
generated-code-tests
/
entry
/
mainNumber.test.js
Copy path
File metadata and controls
163 lines (128 loc) · 5.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import
assert
from
'assert'
import
*
as
mainNumber
from
'../../../src/entry/mainNumber.js'
import
{
createSnapshotFromFactories
,
validateBundle
,
validateTypeOf
}
from
'../../../src/utils/snapshot.js'
import
*
as
factoriesNumber
from
'../../../src/factoriesNumber.js'
const
{
create
,
all
,
add
,
isObject
,
isNumber
,
pi
,
sqrt
,
evaluate
,
chain
,
Range
,
reviver
,
derivative
,
simplify
,
addDependencies
}
=
mainNumber
const
{
expectedInstanceStructure
,
expectedES6Structure
}
=
createSnapshotFromFactories
(
factoriesNumber
)
describe
(
'mainNumber'
,
function
(
)
{
it
(
'should export functions'
,
function
(
)
{
assert
.
strictEqual
(
add
(
2
,
3
)
,
5
)
assert
.
strictEqual
(
sqrt
(
4
)
,
2
)
}
)
it
(
'should export all functions and constants'
,
function
(
)
{
// snapshot testing
validateBundle
(
expectedES6Structure
,
mainNumber
)
}
)
it
(
'new instance should have all expected functions'
,
function
(
)
{
// snapshot testing
const
newMathInstance
=
create
(
all
)
validateBundle
(
expectedInstanceStructure
,
newMathInstance
)
}
)
it
(
'new instance should import some factory functions via import'
,
function
(
)
{
const
newMathInstance
=
create
(
)
newMathInstance
.
import
(
{
addDependencies
}
)
assert
.
strictEqual
(
newMathInstance
.
add
(
2
,
3
)
,
5
)
}
)
it
(
'new instance should import all factory functions via import'
,
function
(
)
{
// snapshot testing
const
newMathInstance
=
create
(
)
newMathInstance
.
import
(
all
)
validateBundle
(
expectedInstanceStructure
,
newMathInstance
)
}
)
it
(
'new instance should import some factory functions via import'
,
function
(
)
{
const
newMathInstance
=
create
(
)
newMathInstance
.
import
(
{
addDependencies
}
,
{
silent
:
true
}
)
assert
.
strictEqual
(
newMathInstance
.
add
(
2
,
3
)
,
5
)
}
)
it
(
'evaluate should contain all functions from mathWithTransform'
,
function
(
)
{
// snapshot testing
const
mathWithTransform
=
expectedInstanceStructure
.
expression
.
mathWithTransform
Object
.
keys
(
mathWithTransform
)
.
forEach
(
key
=>
{
if
(
key
===
'not'
)
{
// operator, special case
assert
.
strictEqual
(
evaluate
(
'not true'
)
,
false
)
}
else
if
(
key
===
'apply'
)
{
// TODO: special case, apply is not yet working in the expression parser due to security constraints
}
else
{
try
{
assert
.
strictEqual
(
validateTypeOf
(
evaluate
(
key
)
)
,
mathWithTransform
[
key
]
,
`Compare type of "
${
key
}
"`
)
}
catch
(
err
)
{
console
.
error
(
err
.
toString
(
)
)
assert
.
ok
(
false
,
`Missing or wrong type of entry in mathWithTransform: "
${
key
}
"`
)
}
}
}
)
}
)
it
(
'evaluate should not contain classes'
,
function
(
)
{
assert
.
throws
(
(
)
=>
{
evaluate
(
'Complex'
)
}
,
/
U
n
d
e
f
i
n
e
d
s
y
m
b
o
l
C
o
m
p
l
e
x
/
)
assert
.
throws
(
(
)
=>
{
evaluate
(
'SymbolNode'
)
}
,
/
U
n
d
e
f
i
n
e
d
s
y
m
b
o
l
S
y
m
b
o
l
N
o
d
e
/
)
}
)
it
(
'should export constants'
,
function
(
)
{
assert
.
strictEqual
(
pi
,
Math
.
PI
)
}
)
it
(
'should export type checking functions'
,
function
(
)
{
assert
.
strictEqual
(
isObject
(
{
}
)
,
true
)
assert
.
strictEqual
(
isObject
(
null
)
,
false
)
assert
.
strictEqual
(
isNumber
(
'23'
)
,
false
)
}
)
it
(
'should export evaluate having functions and constants'
,
function
(
)
{
assert
.
strictEqual
(
evaluate
(
'sqrt(4)'
)
,
2
)
assert
.
strictEqual
(
evaluate
(
'pi'
)
,
Math
.
PI
)
// TODO: should loop over all functions and constants
assert
.
strictEqual
(
typeof
evaluate
(
'help'
)
,
'function'
)
assert
.
strictEqual
(
typeof
evaluate
(
'parse'
)
,
'function'
)
assert
.
strictEqual
(
typeof
evaluate
(
'compile'
)
,
'function'
)
assert
.
strictEqual
(
typeof
evaluate
(
'evaluate'
)
,
'function'
)
assert
.
strictEqual
(
typeof
evaluate
(
'chain'
)
,
'function'
)
assert
.
strictEqual
(
typeof
evaluate
(
'simplify'
)
,
'function'
)
assert
.
strictEqual
(
typeof
evaluate
(
'derivative'
)
,
'function'
)
assert
.
strictEqual
(
typeof
evaluate
(
'rationalize'
)
,
'function'
)
}
)
it
(
'should export chain with all functions'
,
function
(
)
{
assert
.
strictEqual
(
chain
(
2
)
.
add
(
3
)
.
done
(
)
,
5
)
}
)
it
(
'derivative should work'
,
function
(
)
{
assert
.
strictEqual
(
derivative
(
'2x'
,
'x'
)
.
toString
(
)
,
'2'
)
}
)
it
(
'simplify should work'
,
function
(
)
{
assert
.
strictEqual
(
simplify
(
'2x + 3x'
)
.
toString
(
)
,
'5 * x'
)
}
)
it
(
'should export evaluate having help and embedded docs'
,
function
(
)
{
const
h
=
evaluate
(
'help(simplify)'
)
assert
(
h
.
toString
(
)
.
indexOf
(
'Name: simplify'
)
>=
0
,
true
)
}
)
it
(
'should get/set scope variables'
,
function
(
)
{
const
math
=
create
(
all
)
const
evaluate
=
math
.
evaluate
assert
.
strictEqual
(
evaluate
(
'b + 2'
,
{
b
:
3
}
)
,
5
)
const
scope
=
{
}
assert
.
strictEqual
(
evaluate
(
'b = 2'
,
scope
)
,
2
)
assert
.
deepStrictEqual
(
scope
,
{
b
:
2
}
)
}
)
it
(
'doe not support assignement and access right now'
,
function
(
)
{
// TODO: implement support for subset in number implementation
assert
.
throws
(
function
(
)
{
evaluate
(
'A[2]'
,
{
A
:
[
10
,
20
,
30
]
}
)
}
,
/
N
o
"
i
n
d
e
x
"
i
m
p
l
e
m
e
n
t
a
t
i
o
n
a
v
a
i
l
a
b
l
e
/
)
assert
.
throws
(
function
(
)
{
const
scope
=
{
A
:
[
10
,
20
,
30
]
}
evaluate
(
'A[2] = 200'
,
scope
)
}
,
/
N
o
"
i
n
d
e
x
"
i
m
p
l
e
m
e
n
t
a
t
i
o
n
a
v
a
i
l
a
b
l
e
/
)
}
)
it
(
'should export reviver'
,
function
(
)
{
const
json
=
'{"mathjs":"Range","start":2,"end":10}'
const
r
=
new
Range
(
2
,
10
)
const
obj
=
JSON
.
parse
(
json
,
reviver
)
assert
(
obj
instanceof
Range
)
assert
.
deepStrictEqual
(
obj
,
r
)
}
)
// TODO: test export of errors
// TODO: test export of classes
}
)
Back
|
FazBrowse Home
|
New Git URL