2024-07-14 15:08:05 +02:00
|
|
|
using .ExpressionProcessing
|
|
|
|
|
2024-07-11 15:44:22 +02:00
|
|
|
expressions = Vector{Expr}(undef, 1)
|
|
|
|
variables = Matrix{Float64}(undef, 1,2)
|
|
|
|
parameters = Vector{Vector{Float64}}(undef, 1)
|
|
|
|
|
|
|
|
# Resulting value should be 10
|
|
|
|
expressions[1] = :(x1 + 1 * x2 + p1)
|
|
|
|
variables[1,1] = 2
|
|
|
|
variables[1,2] = 3
|
|
|
|
parameters[1] = Vector{Float64}(undef, 1)
|
|
|
|
parameters[1][1] = 5
|
|
|
|
|
2024-07-19 14:32:09 +02:00
|
|
|
@testset "Test conversion expression element" begin
|
|
|
|
reference1 = ExpressionElement(FLOAT64, reinterpret(Int64, 1.0))
|
2024-08-03 12:11:43 +02:00
|
|
|
reference2 = ExpressionElement(INDEX, reinterpret(Int64, 1))
|
2024-07-21 13:45:57 +02:00
|
|
|
reference3 = ExpressionElement(OPERATOR, reinterpret(Int64, ADD))
|
2024-07-19 14:32:09 +02:00
|
|
|
|
|
|
|
@test isequal(reference1, ExpressionProcessing.convert_to_ExpressionElement(1.0))
|
|
|
|
@test isequal(reference2, ExpressionProcessing.convert_to_ExpressionElement(1))
|
2024-07-21 13:45:57 +02:00
|
|
|
@test isequal(reference3, ExpressionProcessing.convert_to_ExpressionElement(ADD))
|
2024-07-12 15:27:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@testset "Test conversion to postfix" begin
|
2024-07-14 15:08:05 +02:00
|
|
|
reference = PostfixType()
|
2024-09-08 11:52:10 +02:00
|
|
|
|
2024-07-21 13:45:57 +02:00
|
|
|
append!(reference, [ExpressionProcessing.convert_to_ExpressionElement(1), ExpressionProcessing.convert_to_ExpressionElement(1.0), ExpressionProcessing.convert_to_ExpressionElement(2), ExpressionProcessing.convert_to_ExpressionElement(MULTIPLY),
|
|
|
|
ExpressionProcessing.convert_to_ExpressionElement(ADD), ExpressionProcessing.convert_to_ExpressionElement(-1), ExpressionProcessing.convert_to_ExpressionElement(ADD)])
|
2024-07-14 15:08:05 +02:00
|
|
|
postfix = expr_to_postfix(expressions[1])
|
2024-07-12 15:27:13 +02:00
|
|
|
|
|
|
|
@test isequal(reference, postfix)
|
2024-09-08 11:52:10 +02:00
|
|
|
|
|
|
|
# TODO: Do more complex expressions because these have led to errors in the past
|
2024-07-11 15:44:22 +02:00
|
|
|
end
|