FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
expr/optimizer/sum_array_test.go at master · expr-lang/expr · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
expr-lang
/
expr
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
526
Star
8k
Code
Issues
57
Pull requests
34
Discussions
Actions
Security and quality
2
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
expr
/
optimizer
/
sum_array_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (57 loc) · 1.52 KB
Breadcrumbs
expr
/
optimizer
/
sum_array_test.go
Copy path
File metadata and controls
72 lines (57 loc) · 1.52 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
package
optimizer_test
import
(
"testing"
"github.com/expr-lang/expr/internal/testify/assert"
"github.com/expr-lang/expr/internal/testify/require"
"github.com/expr-lang/expr"
"github.com/expr-lang/expr/ast"
"github.com/expr-lang/expr/optimizer"
"github.com/expr-lang/expr/parser"
"github.com/expr-lang/expr/vm"
)
func
BenchmarkSumArray
(
b
*
testing.
B
) {
env
:=
map
[
string
]
any
{
"a"
:
1
,
"b"
:
2
,
"c"
:
3
,
"d"
:
4
,
}
program
,
err
:=
expr
.
Compile
(
`sum([a, b, c, d])`
,
expr
.
Env
(
env
))
require
.
NoError
(
b
,
err
)
var
out
any
b
.
ResetTimer
()
for
n
:=
0
;
n
<
b
.
N
;
n
++
{
out
,
err
=
vm
.
Run
(
program
,
env
)
}
b
.
StopTimer
()
require
.
NoError
(
b
,
err
)
require
.
Equal
(
b
,
10
,
out
)
}
func
TestOptimize_sum_array
(
t
*
testing.
T
) {
tree
,
err
:=
parser
.
Parse
(
`sum([a, b])`
)
require
.
NoError
(
t
,
err
)
err
=
optimizer
.
Optimize
(
&
tree
.
Node
,
nil
)
require
.
NoError
(
t
,
err
)
expected
:=
&
ast.
BinaryNode
{
Operator
:
"+"
,
Left
:
&
ast.
IdentifierNode
{
Value
:
"a"
},
Right
:
&
ast.
IdentifierNode
{
Value
:
"b"
},
}
assert
.
Equal
(
t
,
ast
.
Dump
(
expected
),
ast
.
Dump
(
tree
.
Node
))
}
func
TestOptimize_sum_array_3
(
t
*
testing.
T
) {
tree
,
err
:=
parser
.
Parse
(
`sum([a, b, c])`
)
require
.
NoError
(
t
,
err
)
err
=
optimizer
.
Optimize
(
&
tree
.
Node
,
nil
)
require
.
NoError
(
t
,
err
)
expected
:=
&
ast.
BinaryNode
{
Operator
:
"+"
,
Left
:
&
ast.
IdentifierNode
{
Value
:
"a"
},
Right
:
&
ast.
BinaryNode
{
Operator
:
"+"
,
Left
:
&
ast.
IdentifierNode
{
Value
:
"b"
},
Right
:
&
ast.
IdentifierNode
{
Value
:
"c"
},
},
}
assert
.
Equal
(
t
,
ast
.
Dump
(
expected
),
ast
.
Dump
(
tree
.
Node
))
}
Back
|
FazBrowse Home
|
New Git URL