master-thesis/package/test/ExpressionProcessingTests.jl
Daniel 3145691d27
Some checks failed
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Has been cancelled
tried storing data in CuArray. Weird type error is happening
2024-07-14 15:08:05 +02:00

39 lines
1.3 KiB
Julia

using .ExpressionProcessing
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
@testset "Test symtable construction" begin
symtable = construct_symtable(expressions, variables, parameters)
@test haskey(symtable, (expressions[1], :x1))
@test haskey(symtable, (expressions[1], :x2))
@test haskey(symtable, (expressions[1], :p1))
@test symtable[(expressions[1], :x1)] 2.0 atol=0.01
@test symtable[(expressions[1], :x2)] 3.0 atol=0.01
@test symtable[(expressions[1], :p1)] 5.0 atol=0.01
end
@testset "Test variable replacement in expression" begin
symtable = construct_symtable(expressions, variables, parameters)
exprCopy = deepcopy(expressions[1])
replace_variables!(exprCopy, symtable, expressions[1])
@test eval(exprCopy) == 10 # If it can be evaluated, it means all variables have been replaced, as there are no globally defined variables
end
@testset "Test conversion to postfix" begin
reference = PostfixType()
append!(reference, [:x1, 1.0, :x2, Multiply, Add, :p1, Add])
postfix = expr_to_postfix(expressions[1])
@test isequal(reference, postfix)
end