2024-07-14 15:08:05 +02:00
|
|
|
using .ExpressionProcessing
|
|
|
|
|
2024-07-11 15:44:22 +02:00
|
|
|
expressions = Vector{Expr}(undef, 1)
|
2024-11-01 11:23:58 +01:00
|
|
|
variables = Matrix{Float32}(undef, 1,2)
|
|
|
|
parameters = Vector{Vector{Float32}}(undef, 1)
|
2024-07-11 15:44:22 +02:00
|
|
|
|
|
|
|
# Resulting value should be 10
|
|
|
|
expressions[1] = :(x1 + 1 * x2 + p1)
|
|
|
|
variables[1,1] = 2
|
|
|
|
variables[1,2] = 3
|
2024-11-01 11:23:58 +01:00
|
|
|
parameters[1] = Vector{Float32}(undef, 1)
|
2024-07-11 15:44:22 +02:00
|
|
|
parameters[1][1] = 5
|
|
|
|
|
2024-07-19 14:32:09 +02:00
|
|
|
@testset "Test conversion expression element" begin
|
2024-11-01 11:23:58 +01:00
|
|
|
reference1 = ExpressionElement(FLOAT32, reinterpret(Int32, 1f0))
|
|
|
|
reference2 = ExpressionElement(INDEX, reinterpret(Int32, Int32(1)))
|
|
|
|
reference3 = ExpressionElement(OPERATOR, reinterpret(Int32, 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
|