Skip to content
LIBRARY
Math.Tests.Max.md

Math.Tests.Max

Computes the maximum of constant and time-varying inputs.

Connects constant sources with values 3 and 7 to a Max block and verifies that max(3, 7) = 7. A second Max block is driven by two sine waves of different frequencies so the selected (larger) input alternates over time.

Usage

BlockComponents.Math.Tests.Max()

Behavior

Source

dyad
"""
Computes the maximum of constant and time-varying inputs.

Connects constant sources with values 3 and 7 to a Max block and verifies
that max(3, 7) = 7. A second Max block is driven by two sine waves of
different frequencies so the selected (larger) input alternates over time.
"""
test component Max
  "Constant source providing the first input"
  c1 = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the second input"
  c2 = BlockComponents.Sources.Constant(k = 7) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Max block under test"
  max_block = BlockComponents.Math.Max() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 50, "x2": 260, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the first input of the second block"
  sine1 = BlockComponents.Sources.Sine(amplitude = 5, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 20, "x2": 390, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the second input of the second block"
  sine2 = BlockComponents.Sources.Sine(amplitude = 5, frequency = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 140, "x2": 390, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second Max block driven by the sine sources"
  max_block_2 = BlockComponents.Math.Max() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 440, "y1": 50, "x2": 540, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, max_block.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(c2.y, max_block.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 190}, {"x": 140, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(sine1.y, max_block_2.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine2.y, max_block_2.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 190}, {"x": 410, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["max_block.y", "max_block_2.y", "sine1.y", "sine2.y"]}
      }
    }
  }
}
end
Flattened Source
dyad
"""
Computes the maximum of constant and time-varying inputs.

Connects constant sources with values 3 and 7 to a Max block and verifies
that max(3, 7) = 7. A second Max block is driven by two sine waves of
different frequencies so the selected (larger) input alternates over time.
"""
test component Max
  "Constant source providing the first input"
  c1 = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the second input"
  c2 = BlockComponents.Sources.Constant(k = 7) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Max block under test"
  max_block = BlockComponents.Math.Max() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 50, "x2": 260, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the first input of the second block"
  sine1 = BlockComponents.Sources.Sine(amplitude = 5, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 20, "x2": 390, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source for the second input of the second block"
  sine2 = BlockComponents.Sources.Sine(amplitude = 5, frequency = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 290, "y1": 140, "x2": 390, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second Max block driven by the sine sources"
  max_block_2 = BlockComponents.Math.Max() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 440, "y1": 50, "x2": 540, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, max_block.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(c2.y, max_block.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 190}, {"x": 140, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(sine1.y, max_block_2.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine2.y, max_block_2.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 410, "y": 190}, {"x": 410, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["max_block.y", "max_block_2.y", "sine1.y", "sine2.y"]}
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt