LIBRARY
Continuous.Tests.TransferFunction
Tests for TransferFunction block covering:
case1: MSL ramp test (original)
case2: Step response vs analytical y(t) = 1 - exp(-t)
case3: SteadyState init with constant input, y(0) = 2.0
case4: InitialOutput init, y(0) = 0.5
case5: InitialState with explicit x0 via enum, y(0) = 0.5
Usage
BlockComponents.Continuous.Tests.TransferFunction()
Behavior
Source
dyad
"""
Tests for TransferFunction block covering:
- case1: MSL ramp test (original)
- case2: Step response vs analytical y(t) = 1 - exp(-t)
- case3: SteadyState init with constant input, y(0) = 2.0
- case4: InitialOutput init, y(0) = 0.5
- case5: InitialState with explicit x0 via enum, y(0) = 0.5
"""
test component TransferFunction
ramp = BlockComponents.Sources.Ramp(offset = 0.5, start_time = 0.5, duration = 2.0, height = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
tf = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialState(x0 = [0.0])) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
step = BlockComponents.Sources.Step(height = 1.0, offset = 0.0, start_time = 0.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 540, "y1": 180, "x2": 640, "y2": 280, "rot": 0}
},
"tags": []
}
}
tf_step = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialState(x0 = [0.0])) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 780, "y1": 80, "x2": 880, "y2": 180, "rot": 0}
},
"tags": []
}
}
constant_src = BlockComponents.Sources.Constant(k = 2.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 240, "x2": 120, "y2": 340, "rot": 0}
},
"tags": []
}
}
tf_ss = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.SteadyState()) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 240, "x2": 260, "y2": 340, "rot": 0}
},
"tags": []
}
}
tf_io = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialOutput(y_start = 0.5)) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 790, "y1": 250, "x2": 890, "y2": 350, "rot": 0}
},
"tags": []
}
}
tf_x0 = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialState(x0 = [0.5])) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 790, "y1": 400, "x2": 890, "y2": 500, "rot": 0}
},
"tags": []
}
}
relations
connect(ramp.y, tf.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(step.y, tf_step.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 720, "y": 230}, {"x": 720, "y": 130}], "E": 2}],
"renderStyle": "standard"
}
}
connect(constant_src.y, tf_ss.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(step.y, tf_io.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 720, "y": 230}, {"x": 720, "y": 300}], "E": 2}],
"renderStyle": "standard"
}
}
connect(step.y, tf_x0.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 720, "y": 230}, {"x": 720, "y": 450}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 1.1,
"atol": {"tf.y": 0.001},
"expect": {"initial": {"tf.y": 0}, "final": {"tf.y": 0.408}, "signals": ["tf.y"]}
},
"case2": {
"stop": 5,
"atol": {"tf_step.y": 0.001},
"expect": {
"initial": {"tf_step.y": 0},
"final": {"tf_step.y": 0.9932},
"signals": ["tf_step.y"]
}
},
"case3": {
"stop": 1,
"atol": {"tf_ss.y": 0.001},
"expect": {"initial": {"tf_ss.y": 2}, "final": {"tf_ss.y": 2}, "signals": ["tf_ss.y"]}
},
"case4": {
"stop": 5,
"atol": {"tf_io.y": 0.001},
"expect": {
"initial": {"tf_io.y": 0.5},
"final": {"tf_io.y": 0.9966},
"signals": ["tf_io.y"]
}
},
"case5": {
"stop": 5,
"atol": {"tf_x0.y": 0.001},
"expect": {
"initial": {"tf_x0.y": 0.5},
"final": {"tf_x0.y": 0.9966},
"signals": ["tf_x0.y"]
}
}
}
}
}
endFlattened Source
dyad
"""
Tests for TransferFunction block covering:
- case1: MSL ramp test (original)
- case2: Step response vs analytical y(t) = 1 - exp(-t)
- case3: SteadyState init with constant input, y(0) = 2.0
- case4: InitialOutput init, y(0) = 0.5
- case5: InitialState with explicit x0 via enum, y(0) = 0.5
"""
test component TransferFunction
ramp = BlockComponents.Sources.Ramp(offset = 0.5, start_time = 0.5, duration = 2.0, height = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
tf = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialState(x0 = [0.0])) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
},
"tags": []
}
}
step = BlockComponents.Sources.Step(height = 1.0, offset = 0.0, start_time = 0.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 540, "y1": 180, "x2": 640, "y2": 280, "rot": 0}
},
"tags": []
}
}
tf_step = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialState(x0 = [0.0])) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 780, "y1": 80, "x2": 880, "y2": 180, "rot": 0}
},
"tags": []
}
}
constant_src = BlockComponents.Sources.Constant(k = 2.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 240, "x2": 120, "y2": 340, "rot": 0}
},
"tags": []
}
}
tf_ss = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.SteadyState()) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 240, "x2": 260, "y2": 340, "rot": 0}
},
"tags": []
}
}
tf_io = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialOutput(y_start = 0.5)) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 790, "y1": 250, "x2": 890, "y2": 350, "rot": 0}
},
"tags": []
}
}
tf_x0 = BlockComponents.Continuous.TransferFunction(a = [1.0, 1.0], b = [1.0], init_mode = BlockComponents.Continuous.BlockInitMode.InitialState(x0 = [0.5])) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 790, "y1": 400, "x2": 890, "y2": 500, "rot": 0}
},
"tags": []
}
}
relations
connect(ramp.y, tf.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(step.y, tf_step.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 720, "y": 230}, {"x": 720, "y": 130}], "E": 2}],
"renderStyle": "standard"
}
}
connect(constant_src.y, tf_ss.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(step.y, tf_io.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 720, "y": 230}, {"x": 720, "y": 300}], "E": 2}],
"renderStyle": "standard"
}
}
connect(step.y, tf_x0.u) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 720, "y": 230}, {"x": 720, "y": 450}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 1.1,
"atol": {"tf.y": 0.001},
"expect": {"initial": {"tf.y": 0}, "final": {"tf.y": 0.408}, "signals": ["tf.y"]}
},
"case2": {
"stop": 5,
"atol": {"tf_step.y": 0.001},
"expect": {
"initial": {"tf_step.y": 0},
"final": {"tf_step.y": 0.9932},
"signals": ["tf_step.y"]
}
},
"case3": {
"stop": 1,
"atol": {"tf_ss.y": 0.001},
"expect": {"initial": {"tf_ss.y": 2}, "final": {"tf_ss.y": 2}, "signals": ["tf_ss.y"]}
},
"case4": {
"stop": 5,
"atol": {"tf_io.y": 0.001},
"expect": {
"initial": {"tf_io.y": 0.5},
"final": {"tf_io.y": 0.9966},
"signals": ["tf_io.y"]
}
},
"case5": {
"stop": 5,
"atol": {"tf_x0.y": 0.001},
"expect": {
"initial": {"tf_x0.y": 0.5},
"final": {"tf_x0.y": 0.9966},
"signals": ["tf_x0.y"]
}
}
}
}
}
endTest Cases
Test Case case1
julia
pltTest Case case2
julia
pltTest Case case3
julia
pltTest Case case4
julia
pltTest Case case5
julia
pltRelated
Examples
Experiments
Analyses
Tests