Skip to content
LIBRARY
Examples.Integrator.ResetValueTrackerTest.md

Examples.Integrator.ResetValueTrackerTest ​

Test component that validates ResetValueTracker latches a NONZERO initial condition on the first tick. A constant ic is sampled onto a periodic clock and fed to the tracker; the tracked resetvalue must equal that nonzero ic. Regression guard for JuliaComputing/DiscreteComponents#71: before the fix the tracker initialized resetvalue@(clk-1) to 0.0 (not NaN), so the isnan_wrapper latch never fired and resetvalue stayed 0 forever instead of latching ic.

Usage ​

DiscreteComponents.Examples.Integrator.ResetValueTrackerTest()

Behavior ​

Behavior of this component cannot be rendered because it includes path variables.

Source ​

dyad
"""
Test component that validates ResetValueTracker latches a NONZERO initial
condition on the first tick. A constant `ic` is sampled onto a periodic clock
and fed to the tracker; the tracked `resetvalue` must equal that nonzero `ic`.
Regression guard for JuliaComputing/DiscreteComponents#71: before the fix the
tracker initialized `resetvalue@(clk-1)` to 0.0 (not NaN), so the
`isnan_wrapper` latch never fired and `resetvalue` stayed 0 forever instead of
latching `ic`.
"""
test component ResetValueTrackerTest
  tracker = DiscreteComponents.Examples.Integrator.ResetValueTracker() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 370, "y1": 450, "x2": 470, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  ic = BlockComponents.Sources.Constant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 450, "x2": 120, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  sampler = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 450, "x2": 300, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 600, "x2": 300, "y2": 700, "rot": 0}
      },
      "tags": []
    }
  }
  terminator = BlockComponents.Routing.Terminator() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 540, "y1": 450, "x2": 640, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(ic.y, sampler.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sampler.y, tracker.initialcondition, periodicclock.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(tracker.resetvalue, terminator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["tracker.resetvalue"], "final": {"tracker.resetvalue": 5}}
      }
    },
    "doc": {"behavior": false}
  }
}
end
Flattened Source
dyad
"""
Test component that validates ResetValueTracker latches a NONZERO initial
condition on the first tick. A constant `ic` is sampled onto a periodic clock
and fed to the tracker; the tracked `resetvalue` must equal that nonzero `ic`.
Regression guard for JuliaComputing/DiscreteComponents#71: before the fix the
tracker initialized `resetvalue@(clk-1)` to 0.0 (not NaN), so the
`isnan_wrapper` latch never fired and `resetvalue` stayed 0 forever instead of
latching `ic`.
"""
test component ResetValueTrackerTest
  tracker = DiscreteComponents.Examples.Integrator.ResetValueTracker() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 370, "y1": 450, "x2": 470, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  ic = BlockComponents.Sources.Constant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 450, "x2": 120, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  sampler = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 450, "x2": 300, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 600, "x2": 300, "y2": 700, "rot": 0}
      },
      "tags": []
    }
  }
  terminator = BlockComponents.Routing.Terminator() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 540, "y1": 450, "x2": 640, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(ic.y, sampler.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sampler.y, tracker.initialcondition, periodicclock.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(tracker.resetvalue, terminator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["tracker.resetvalue"], "final": {"tracker.resetvalue": 5}}
      }
    },
    "doc": {"behavior": false}
  }
}
end


Test Cases ​

Test Case case1 ​

julia
plt