master-thesis/package/test/ExpressionProcessingTests.jl
Daniel 2c8a9cd2d8
Some checks are pending
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Waiting to run
added support for variables and parameters as array. also improved conversion of variables and parameters into Expressionelement
2025-05-09 11:04:10 +02:00

30 lines
1.4 KiB
Julia

using .ExpressionProcessing
expressions = Vector{Expr}(undef, 2)
expressions[1] = :(x1 + 1 * x2 + p1)
expressions[2] = :(x[1] + 1 * x[2] + p[1])
@testset "Test conversion expression element" begin
reference1 = ExpressionElement(FLOAT32, reinterpret(Int32, 1f0))
reference2 = ExpressionElement(VARIABLE, Int32(1))
reference3 = ExpressionElement(OPERATOR, reinterpret(Int32, ADD))
@test isequal(reference1, ExpressionProcessing.convert_to_ExpressionElement(1.0))
@test isequal(reference2, ExpressionProcessing.convert_to_ExpressionElement(:x1))
@test isequal(reference3, ExpressionProcessing.convert_to_ExpressionElement(ADD))
end
@testset "Test conversion to postfix" begin
reference = PostfixType()
append!(reference, [ExpressionProcessing.convert_to_ExpressionElement(:x1), ExpressionProcessing.convert_to_ExpressionElement(1.0), ExpressionProcessing.convert_to_ExpressionElement(:x2), ExpressionProcessing.convert_to_ExpressionElement(MULTIPLY),
ExpressionProcessing.convert_to_ExpressionElement(ADD), ExpressionProcessing.convert_to_ExpressionElement(:p1), ExpressionProcessing.convert_to_ExpressionElement(ADD)])
postfixVarsAsSymbol = expr_to_postfix(expressions[1], Dict{Expr, PostfixType}())
postfixVarsAsArray = expr_to_postfix(expressions[2], Dict{Expr, PostfixType}())
@test isequal(reference, postfixVarsAsSymbol)
@test isequal(reference, postfixVarsAsArray)
# TODO: Do more complex expressions because these have led to errors in the past
end