Skip to content
Add3Test.md

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

julia
using BlockComponents #hide
using ModelingToolkit #hide
@named sys = Add3Test() #hide
full_equations(sys) #hide
<< @example-block not executed in draft mode >>

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

julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
<< @setup-block not executed in draft mode >>

Test Case case1

julia
@mtkbuild model_case1 = Add3Test()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 5))
sol_case1 = solve(prob_case1)
<< @setup-block not executed in draft mode >>