Test_ShiftLeft Icon
Test_ShiftLeft
Usage
PrimitiveComponents.Test_ShiftLeft()
Behavior
\[ \begin{equation} \left[ \begin{array}{c} \mathrm{connect}\left( constant_{int\_output\_3_{+}y(t)}, shiftleft_{3_{+}u(t)} \right) \\ \mathrm{connect}\left( constant_{int\_output\_2_{+}y(t)}, shiftleft_{2_{+}u(t)} \right) \\ \mathrm{connect}\left( constant_{int\_output\_1_{+}y(t)}, shiftleft_{1_{+}u(t)} \right) \\ \mathrm{connect}\left( constant_{int\_output\_4_{+}y(t)}, shiftleft_{4_{+}u(t)} \right) \\ \mathrm{connect}\left( constant_{int\_output\_5_{+}y(t)}, shiftleft_{5_{+}u(t)} \right) \\ \mathtt{shiftleft\_1.y}\left( t \right) = shiftleft\left( \mathtt{shiftleft\_1.u}\left( t \right), \mathtt{shiftleft\_1.shift\_amount} \right) \\ \mathtt{shiftleft\_2.y}\left( t \right) = shiftleft\left( \mathtt{shiftleft\_2.u}\left( t \right), \mathtt{shiftleft\_2.shift\_amount} \right) \\ \mathtt{shiftleft\_3.y}\left( t \right) = shiftleft\left( \mathtt{shiftleft\_3.u}\left( t \right), \mathtt{shiftleft\_3.shift\_amount} \right) \\ \mathtt{shiftleft\_4.y}\left( t \right) = shiftleft\left( \mathtt{shiftleft\_4.u}\left( t \right), \mathtt{shiftleft\_4.shift\_amount} \right) \\ \mathtt{shiftleft\_5.y}\left( t \right) = shiftleft\left( \mathtt{shiftleft\_5.u}\left( t \right), \mathtt{shiftleft\_5.shift\_amount} \right) \\ \mathtt{constant\_int\_output\_1.y}\left( t \right) = \mathtt{constant\_int\_output\_1.k} \\ \mathtt{constant\_int\_output\_2.y}\left( t \right) = \mathtt{constant\_int\_output\_2.k} \\ \mathtt{constant\_int\_output\_3.y}\left( t \right) = \mathtt{constant\_int\_output\_3.k} \\ \mathtt{constant\_int\_output\_4.y}\left( t \right) = \mathtt{constant\_int\_output\_4.k} \\ \mathtt{constant\_int\_output\_5.y}\left( t \right) = \mathtt{constant\_int\_output\_5.k} \\ \end{array} \right] \end{equation} \]
Source
# This test demonstrates the behavior of the `ShiftLeft` block with various integer inputs
# and shift amounts, including positive, zero, and negative shifts.
#
# Example usage and expected outputs:
#
# 1. Positive shifts (normal left shift):
# - u = 3, shift_amount = 2 → y = 12 (binary 11 becomes 1100)
# - u = -7, shift_amount = 1 → y = -14 (binary -111 becomes -1110)
#
# 2. Zero shift (no change):
# - u = 5, shift_amount = 0 → y = 5
#
# 3. Negative shifts (arithmetic right shift):
# - u = 3, shift_amount = -2 → y = 0 (3 >> 2 = 0)
# - u = -7, shift_amount = -2 → y = -2 (-7 >> 2 = -2, sign preserved)
component Test_ShiftLeft
shiftleft_1 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 300, "y1": 90, "x2": 400, "y2": 190, "rot": 0}
}
}
}
shiftleft_2 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 320, "y1": 350, "x2": 420, "y2": 450, "rot": 0}
}
}
}
shiftleft_3 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 330, "y1": 620, "x2": 430, "y2": 720, "rot": 0}
}
}
}
shiftleft_4 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = -2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 820, "y1": 110, "x2": 920, "y2": 210, "rot": 0}
}
}
}
shiftleft_5 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = -2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 810, "y1": 360, "x2": 910, "y2": 460, "rot": 0}
}
}
}
constant_int_output_1 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 80, "y1": 90, "x2": 180, "y2": 190, "rot": 0}
}
}
}
constant_int_output_2 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = -7) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 80, "y1": 350, "x2": 180, "y2": 450, "rot": 0}
}
}
}
constant_int_output_3 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = 5) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 80, "y1": 620, "x2": 180, "y2": 720, "rot": 0}
}
}
}
constant_int_output_4 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 580, "y1": 110, "x2": 680, "y2": 210, "rot": 0}
}
}
}
constant_int_output_5 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = -7) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 590, "y1": 360, "x2": 690, "y2": 460, "rot": 0}
}
}
}
relations
connect(constant_int_output_3.y, shiftleft_3.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(constant_int_output_2.y, shiftleft_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(constant_int_output_1.y, shiftleft_1.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(shiftleft_4.u, constant_int_output_4.y) {"Dyad": {"edges": [{"S": 1, "E": 2, "M": []}]}}
connect(constant_int_output_5.y, shiftleft_5.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
metadata {
"Dyad": {
"experiments": {"Test_ShiftLeft_": {"stop": 2}},
"tests": {
"case1": {
"stop": 2,
"abstol": 0.00001,
"reltol": 0.00001,
"expect": {
"signals": [
"shiftleft_1.y",
"shiftleft_2.y",
"shiftleft_3.y",
"shiftleft_4.y",
"shiftleft_5.y"
]
}
}
}
}
}
end
Flattened Source
component Test_ShiftLeft
shiftleft_1 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 300, "y1": 90, "x2": 400, "y2": 190, "rot": 0}
}
}
}
shiftleft_2 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 320, "y1": 350, "x2": 420, "y2": 450, "rot": 0}
}
}
}
shiftleft_3 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = 0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 330, "y1": 620, "x2": 430, "y2": 720, "rot": 0}
}
}
}
shiftleft_4 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = -2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 820, "y1": 110, "x2": 920, "y2": 210, "rot": 0}
}
}
}
shiftleft_5 = PrimitiveComponents.Mathematical.ShiftLeft(shift_amount = -2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 810, "y1": 360, "x2": 910, "y2": 460, "rot": 0}
}
}
}
constant_int_output_1 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 80, "y1": 90, "x2": 180, "y2": 190, "rot": 0}
}
}
}
constant_int_output_2 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = -7) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 80, "y1": 350, "x2": 180, "y2": 450, "rot": 0}
}
}
}
constant_int_output_3 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = 5) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 80, "y1": 620, "x2": 180, "y2": 720, "rot": 0}
}
}
}
constant_int_output_4 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 580, "y1": 110, "x2": 680, "y2": 210, "rot": 0}
}
}
}
constant_int_output_5 = PrimitiveComponents.Sources.ConstantIntegerOutput(k = -7) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 590, "y1": 360, "x2": 690, "y2": 460, "rot": 0}
}
}
}
relations
connect(constant_int_output_3.y, shiftleft_3.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(constant_int_output_2.y, shiftleft_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(constant_int_output_1.y, shiftleft_1.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
connect(shiftleft_4.u, constant_int_output_4.y) {"Dyad": {"edges": [{"S": 1, "E": 2, "M": []}]}}
connect(constant_int_output_5.y, shiftleft_5.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}]}}
metadata {
"Dyad": {
"experiments": {"Test_ShiftLeft_": {"stop": 2}},
"tests": {
"case1": {
"stop": 2,
"abstol": 0.00001,
"reltol": 0.00001,
"expect": {
"signals": [
"shiftleft_1.y",
"shiftleft_2.y",
"shiftleft_3.y",
"shiftleft_4.y",
"shiftleft_5.y"
]
}
}
}
}
}
endTest Cases
Test Case case1
pltpltpltpltpltRelated
- Examples
- Experiments
- Analyses