Add3Test
Test the functionality of the Add3 block by connecting three constant inputs.
This test harness connects three constant sources (with values 1, 2, and 3) to an Add3 component and verifies that the output equals the sum of the inputs (6). The test case simulates for 5 seconds and checks the final value of the output.
Usage
Add3Test()
Behavior
Source
dyad
# Test the functionality of the Add3 block by connecting three constant inputs.
#
# This test harness connects three constant sources (with values 1, 2, and 3) to an Add3 component and verifies
# that the output equals the sum of the inputs (6). The test case simulates for 5 seconds and checks the final
# value of the output.
test component Add3Test
# Constant source with value 1
c1 = Constant(k=1)
# Constant source with value 2
c2 = Constant(k=2)
# Constant source with value 3
c3 = Constant(k=3)
# Component that adds three inputs
add3 = Add3()
relations
connect(add3.u1, c1.y)
connect(add3.u2, c2.y)
connect(add3.u3, c3.y)
metadata {"Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"add3.y": 6}}}}}}
end
Flattened Source
dyad
# Test the functionality of the Add3 block by connecting three constant inputs.
#
# This test harness connects three constant sources (with values 1, 2, and 3) to an Add3 component and verifies
# that the output equals the sum of the inputs (6). The test case simulates for 5 seconds and checks the final
# value of the output.
test component Add3Test
# Constant source with value 1
c1 = Constant(k=1)
# Constant source with value 2
c2 = Constant(k=2)
# Constant source with value 3
c3 = Constant(k=3)
# Component that adds three inputs
add3 = Add3()
relations
connect(add3.u1, c1.y)
connect(add3.u2, c2.y)
connect(add3.u3, c3.y)
metadata {"Dyad": {"tests": {"case1": {"stop": 5, "expect": {"final": {"add3.y": 6}}}}}}
end
Test Cases
This is setup code, that must be run before each test case.
julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"
Test Case case1
julia
@mtkbuild model_case1 = Add3Test()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 5))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 1st order linear
t: 2-element Vector{Float64}:
0.0
5.0
u: 2-element Vector{Vector{Float64}}:
[]
[]