Skip to content

Commit 45a49e0

Browse files
authored
Merge pull request #12 from SymbolicML/compathelper/new_version/2023-01-16-17-12-40-775-02289120110
CompatHelper: bump compat for SymbolicUtils to 1, (keep existing compat)
2 parents 7e0305b + 3ef08f0 commit 45a49e0

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
1818
LoopVectorization = "0.12"
1919
Reexport = "1"
2020
SnoopPrecompile = "1"
21-
SymbolicUtils = "0.19"
21+
SymbolicUtils = "0.19, ^1.0.5"
2222
Zygote = "0.6"
2323
julia = "1.6"
2424

test/test_simplification.jl

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ include("test_params.jl")
22
using DynamicExpressions, Test
33
import SymbolicUtils: simplify, Symbolic
44
import Random: MersenneTwister
5+
import Base:
6+
7+
function Base.:(a::String, b::String)
8+
a = replace(a, r"\s+" => "")
9+
b = replace(b, r"\s+" => "")
10+
return a == b
11+
end
512

613
simplify_tree = DynamicExpressions.SimplifyEquationModule.simplify_tree
714
combine_operators = DynamicExpressions.SimplifyEquationModule.combine_operators
@@ -33,10 +40,10 @@ tree = convert(Node, eqn2, operators)
3340
# that SymbolicUtils does not convert it to a power:
3441
tree = Node("x1") * Node("x1")
3542
eqn = convert(Symbolic, tree, operators)
36-
@test repr(eqn) == "x1*x1"
43+
@test repr(eqn) "x1*x1"
3744
# Test converting back:
3845
tree_copy = convert(Node, eqn, operators)
39-
@test repr(tree_copy) == "(x1 * x1)"
46+
@test repr(tree_copy) "(x1*x1)"
4047

4148
# Let's test a much more complex function,
4249
# with custom operators, and unary operators:
@@ -105,42 +112,42 @@ x1, x2, x3 = [Node(; feature=i) for i in 1:3]
105112

106113
# unary operator applied to constant => constant:
107114
tree = Node(1, Node(; val=0.0))
108-
@test repr(tree) == "cos(0.0)"
109-
@test repr(simplify_tree(tree, operators)) == "1.0"
115+
@test repr(tree) "cos(0.0)"
116+
@test repr(simplify_tree(tree, operators)) "1.0"
110117

111118
# except when the result is a NaN, then we don't change it:
112119
tree = Node(1, Node(; val=NaN))
113-
@test repr(tree) == "cos(NaN)"
114-
@test repr(simplify_tree(tree, operators)) == "cos(NaN)"
120+
@test repr(tree) "cos(NaN)"
121+
@test repr(simplify_tree(tree, operators)) "cos(NaN)"
115122

116123
# the same as above, but inside a binary tree.
117124
tree =
118125
Node(1, Node(1, Node(; val=0.1), Node(; val=0.2)) + Node(; val=0.2)) + Node(; val=2.0)
119-
@test repr(tree) == "(cos((0.1 + 0.2) + 0.2) + 2.0)"
120-
@test repr(combine_operators(tree, operators)) == "(cos(0.4 + 0.1) + 2.0)"
126+
@test repr(tree) "(cos((0.1 + 0.2) + 0.2) + 2.0)"
127+
@test repr(combine_operators(tree, operators)) "(cos(0.4 + 0.1) + 2.0)"
121128

122129
# left is constant:
123130
tree = Node(; val=0.5) + (Node(; val=0.2) + x1)
124-
@test repr(tree) == "(0.5 + (0.2 + x1))"
125-
@test repr(combine_operators(tree, operators)) == "(x1 + 0.7)"
131+
@test repr(tree) "(0.5 + (0.2 + x1))"
132+
@test repr(combine_operators(tree, operators)) "(x1 + 0.7)"
126133

127134
# (const - (const - var)) => (var - const)
128135
tree = Node(2, Node(; val=0.5), Node(; val=0.2) - x1)
129-
@test repr(tree) == "(0.5 - (0.2 - x1))"
130-
@test repr(combine_operators(tree, operators)) == "(x1 - -0.3)"
136+
@test repr(tree) "(0.5 - (0.2 - x1))"
137+
@test repr(combine_operators(tree, operators)) "(x1 - -0.3)"
131138

132139
# ((const - var) - const) => (const - var)
133140
tree = Node(2, Node(; val=0.5) - x1, Node(; val=0.2))
134-
@test repr(tree) == "((0.5 - x1) - 0.2)"
135-
@test repr(combine_operators(tree, operators)) == "(0.3 - x1)"
141+
@test repr(tree) "((0.5 - x1) - 0.2)"
142+
@test repr(combine_operators(tree, operators)) "(0.3 - x1)"
136143

137144
# (const - (var - const)) => (const - var)
138145
tree = Node(2, Node(; val=0.5), x1 - Node(; val=0.2))
139-
@test repr(tree) == "(0.5 - (x1 - 0.2))"
140-
@test repr(combine_operators(tree, operators)) == "(0.7 - x1)"
146+
@test repr(tree) "(0.5 - (x1 - 0.2))"
147+
@test repr(combine_operators(tree, operators)) "(0.7 - x1)"
141148

142149
# ((var - const) - const) => (var - const)
143150
tree = ((x1 - 0.2) - 0.6)
144-
@test repr(tree) == "((x1 - 0.2) - 0.6)"
145-
@test repr(combine_operators(tree, operators)) == "(x1 - 0.8)"
151+
@test repr(tree) "((x1 - 0.2) - 0.6)"
152+
@test repr(combine_operators(tree, operators)) "(x1 - 0.8)"
146153
###############################################################################

0 commit comments

Comments
 (0)