LIBRARY
Math.Tests.Add3
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
BlockComponents.Math.Tests.Add3()
Behavior
julia
using BlockComponents #hide
using ModelingToolkit #hide
@named sys = BlockComponents.Math.Tests.Add3() #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 Add3
"Constant source with value 1"
c1 = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 260, "x2": 500, "y2": 360, "rot": 0}
}
}
}
"Constant source with value 2"
c2 = BlockComponents.Sources.Constant(k = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 450, "x2": 500, "y2": 550, "rot": 0}
}
}
}
"Constant source with value 3"
c3 = BlockComponents.Sources.Constant(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 660, "x2": 500, "y2": 760, "rot": 0}
}
}
}
"Component that adds three inputs"
add3 = BlockComponents.Math.Add3() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 640, "y1": 450, "x2": 740, "y2": 550, "rot": 0}
}
}
}
relations
connect(add3.u1, c1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 590, "y": 470}, {"x": 590, "y": 310}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3.u2, c2.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(add3.u3, c3.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 600, "y": 530}, {"x": 600, "y": 710}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 5, "expect": {"final": {"add3.y": 6}}}}
}
}
endFlattened 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 Add3
"Constant source with value 1"
c1 = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 260, "x2": 500, "y2": 360, "rot": 0}
}
}
}
"Constant source with value 2"
c2 = BlockComponents.Sources.Constant(k = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 450, "x2": 500, "y2": 550, "rot": 0}
}
}
}
"Constant source with value 3"
c3 = BlockComponents.Sources.Constant(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 660, "x2": 500, "y2": 760, "rot": 0}
}
}
}
"Component that adds three inputs"
add3 = BlockComponents.Math.Add3() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 640, "y1": 450, "x2": 740, "y2": 550, "rot": 0}
}
}
}
relations
connect(add3.u1, c1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 590, "y": 470}, {"x": 590, "y": 310}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3.u2, c2.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(add3.u3, c3.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 600, "y": 530}, {"x": 600, "y": 710}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 5, "expect": {"final": {"add3.y": 6}}}}
}
}
endTest Cases
julia
using BlockComponents
using DyadInterface: TransientAnalysis, rebuild_sol, ODEAlg
using ModelingToolkit: toggle_namespacing, get_initial_conditions, @named
using CSV, DataFrames, Plots
snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")<< @setup-block not executed in draft mode >>Test Case case1
julia
@named model_case1 = BlockComponents.Math.Tests.Add3()
model_case1 = toggle_namespacing(model_case1, false)
model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = ODEAlg.Auto(), start = 0e+0, stop = 5e+0, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)<< @setup-block not executed in draft mode >>