Skip to content
LIBRARY
Examples.TestNDelay.md

Examples.TestNDelay ​

Test component that validates the NDelay component.

This component validates that a single NDelay block is equivalent to a chain of UnitDelay blocks.

Usage ​

DiscreteComponents.Examples.TestNDelay()

Variables ​

NameDescriptionUnits
ud1equalsnd–
ud2equalsnd1–

Behavior ​

Source ​

dyad
"""
Test component that validates the NDelay component.

This component validates that a single `NDelay` block is equivalent to a chain of `UnitDelay` blocks.
"""
test component TestNDelay
  ramp = BlockComponents.Sources.Ramp(duration = 10, height = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  sampler = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 90, "y1": 450, "x2": 190, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 90, "y1": 600, "x2": 190, "y2": 700, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 340, "x2": 350, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay1 = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 380, "y1": 340, "x2": 480, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay2 = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 510, "y1": 340, "x2": 610, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  ndelay = DiscreteComponents.NDelay(n = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 530, "x2": 350, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  ndelay1 = DiscreteComponents.NDelay(n = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 670, "x2": 350, "y2": 770, "rot": 0}
      },
      "tags": []
    }
  }
  variable ud1equalsnd::Boolean
  variable ud2equalsnd1::Boolean
relations
  ud1equalsnd = unitdelay.y == ndelay.y
  ud2equalsnd1 = unitdelay1.y == ndelay1.y
  connect(ramp.y, sampler.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(sampler.y, ndelay.u, ndelay1.u, unitdelay.u, periodicclock.y) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 221, "y": 500}, {"x": 221, "y": 580}], "E": 2}]
    }
  }
  connect(unitdelay.y, unitdelay1.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(unitdelay1.y, unitdelay2.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
metadata {
  "Dyad": {
    "experiments": {},
    "tests": {
      "case1": {
        "solver": "Auto",
        "start": 0,
        "stop": 10,
        "params": {},
        "initial": {},
        "atol": {},
        "rtol": {},
        "abstol": 0.000001,
        "reltol": 0.000001,
        "expect": {
          "initial": {},
          "final": {},
          "signals": ["ramp.y", "ndelay.y", "ndelay1.y", "unitdelay1.y", "unitdelay2.y"]
        }
      }
    },
    "labels": [
      {
        "label": "This chain of unit delays approximates the n-delay blocks",
        "x": 430,
        "y": 240,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "black",
          "font-size": "20",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "== ndelay",
        "x": 430,
        "y": 320,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "black",
          "font-size": "20",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "== ndelay1",
        "x": 560,
        "y": 320,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "black",
          "font-size": "20",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      }
    ],
    "icons": {"default": "dyad://Dyad/Default.svg"},
    "path": {},
    "doc": {"behavior": true}
  }
}
end
Flattened Source
dyad
"""
Test component that validates the NDelay component.

This component validates that a single `NDelay` block is equivalent to a chain of `UnitDelay` blocks.
"""
test component TestNDelay
  ramp = BlockComponents.Sources.Ramp(duration = 10, height = 10) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  sampler = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 90, "y1": 450, "x2": 190, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 90, "y1": 600, "x2": 190, "y2": 700, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 340, "x2": 350, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay1 = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 380, "y1": 340, "x2": 480, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  unitdelay2 = DiscreteComponents.UnitDelay() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 510, "y1": 340, "x2": 610, "y2": 440, "rot": 0}
      },
      "tags": []
    }
  }
  ndelay = DiscreteComponents.NDelay(n = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 530, "x2": 350, "y2": 630, "rot": 0}
      },
      "tags": []
    }
  }
  ndelay1 = DiscreteComponents.NDelay(n = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 250, "y1": 670, "x2": 350, "y2": 770, "rot": 0}
      },
      "tags": []
    }
  }
  variable ud1equalsnd::Boolean
  variable ud2equalsnd1::Boolean
relations
  ud1equalsnd = unitdelay.y == ndelay.y
  ud2equalsnd1 = unitdelay1.y == ndelay1.y
  connect(ramp.y, sampler.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(sampler.y, ndelay.u, ndelay1.u, unitdelay.u, periodicclock.y) {
    "Dyad": {
      "renderStyle": "standard",
      "edges": [{"S": 1, "M": [{"x": 221, "y": 500}, {"x": 221, "y": 580}], "E": 2}]
    }
  }
  connect(unitdelay.y, unitdelay1.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(unitdelay1.y, unitdelay2.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
metadata {
  "Dyad": {
    "experiments": {},
    "tests": {
      "case1": {
        "solver": "Auto",
        "start": 0,
        "stop": 10,
        "params": {},
        "initial": {},
        "atol": {},
        "rtol": {},
        "abstol": 0.000001,
        "reltol": 0.000001,
        "expect": {
          "initial": {},
          "final": {},
          "signals": ["ramp.y", "ndelay.y", "ndelay1.y", "unitdelay1.y", "unitdelay2.y"]
        }
      }
    },
    "labels": [
      {
        "label": "This chain of unit delays approximates the n-delay blocks",
        "x": 430,
        "y": 240,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "black",
          "font-size": "20",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "== ndelay",
        "x": 430,
        "y": 320,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "black",
          "font-size": "20",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "== ndelay1",
        "x": 560,
        "y": 320,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "black",
          "font-size": "20",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      }
    ],
    "icons": {"default": "dyad://Dyad/Default.svg"},
    "path": {},
    "doc": {"behavior": true}
  }
}
end


Test Cases ​

Test Case case1 ​

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt