Skip to content
LIBRARY
Math.Tests.Exponentiation.md

Math.Tests.Exponentiation

Tests the Exponentiation block with multiple exponent values.

Mirrors the MSL Exponentiation test structure: a ramp from -2 to 2 feeds blocks with even (2), odd (3), unit (1), and zero (0) exponents. The zero-exponent case uses a Max block to ensure positive input for the inverse exponent test.

Usage

BlockComponents.Math.Tests.Exponentiation()

Behavior

Source

dyad
"""
Tests the Exponentiation block with multiple exponent values.

Mirrors the MSL Exponentiation test structure: a ramp from -2 to 2 feeds
blocks with even (2), odd (3), unit (1), and zero (0) exponents.
The zero-exponent case uses a Max block to ensure positive input for the
inverse exponent test.
"""
test component Exponentiation
  "Ramp from -2 to 2 over 1 second"
  ramp = BlockComponents.Sources.Ramp(height = 4, duration = 1, offset = -2, start_time = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "u^2: even exponent"
  even_exp = BlockComponents.Math.Exponentiation(exponent = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "u^3: odd exponent"
  odd_exp = BlockComponents.Math.Exponentiation(exponent = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "u^1: identity"
  one_exp = BlockComponents.Math.Exponentiation(exponent = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 260, "x2": 260, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "u^0: always 1 for nonzero input"
  zero_exp = BlockComponents.Math.Exponentiation(exponent = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 250, "x2": 400, "y2": 350, "rot": 0}
      },
      "tags": []
    }
  }
  "Ensures positive input for inverse exponent"
  max_block = BlockComponents.Math.Max() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 380, "x2": 260, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant 0.1 floor for inverse"
  floor_val = BlockComponents.Sources.Constant(k = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 410, "x2": 120, "y2": 510, "rot": 0}
      },
      "tags": []
    }
  }
  "u^(-1): inverse"
  inverse_exp = BlockComponents.Math.Exponentiation(exponent = -1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 380, "x2": 400, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(ramp.y, even_exp.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 70}], "E": 2}],
      "junctions": [{"x": 140, "y": 310}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, odd_exp.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 310}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 140, "y": 190}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, one_exp.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(ramp.y, max_block.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 310}, {"x": 140, "y": 400}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(floor_val.y, max_block.u2) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(max_block.y, zero_exp.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 280, "y": 300}], "E": 2}],
      "junctions": [{"x": 280, "y": 430}],
      "renderStyle": "standard"
    }
  }
  connect(max_block.y, inverse_exp.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {
          "signals": [
            "ramp.y",
            "even_exp.y",
            "odd_exp.y",
            "one_exp.y",
            "zero_exp.y",
            "inverse_exp.y"
          ]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Tests the Exponentiation block with multiple exponent values.

Mirrors the MSL Exponentiation test structure: a ramp from -2 to 2 feeds
blocks with even (2), odd (3), unit (1), and zero (0) exponents.
The zero-exponent case uses a Max block to ensure positive input for the
inverse exponent test.
"""
test component Exponentiation
  "Ramp from -2 to 2 over 1 second"
  ramp = BlockComponents.Sources.Ramp(height = 4, duration = 1, offset = -2, start_time = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "u^2: even exponent"
  even_exp = BlockComponents.Math.Exponentiation(exponent = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "u^3: odd exponent"
  odd_exp = BlockComponents.Math.Exponentiation(exponent = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "u^1: identity"
  one_exp = BlockComponents.Math.Exponentiation(exponent = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 260, "x2": 260, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "u^0: always 1 for nonzero input"
  zero_exp = BlockComponents.Math.Exponentiation(exponent = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 250, "x2": 400, "y2": 350, "rot": 0}
      },
      "tags": []
    }
  }
  "Ensures positive input for inverse exponent"
  max_block = BlockComponents.Math.Max() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 380, "x2": 260, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant 0.1 floor for inverse"
  floor_val = BlockComponents.Sources.Constant(k = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 410, "x2": 120, "y2": 510, "rot": 0}
      },
      "tags": []
    }
  }
  "u^(-1): inverse"
  inverse_exp = BlockComponents.Math.Exponentiation(exponent = -1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 380, "x2": 400, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(ramp.y, even_exp.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 70}], "E": 2}],
      "junctions": [{"x": 140, "y": 310}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, odd_exp.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 310}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 140, "y": 190}],
      "renderStyle": "standard"
    }
  }
  connect(ramp.y, one_exp.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(ramp.y, max_block.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 310}, {"x": 140, "y": 400}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(floor_val.y, max_block.u2) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(max_block.y, zero_exp.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 280, "y": 300}], "E": 2}],
      "junctions": [{"x": 280, "y": 430}],
      "renderStyle": "standard"
    }
  }
  connect(max_block.y, inverse_exp.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {
          "signals": [
            "ramp.y",
            "even_exp.y",
            "odd_exp.y",
            "one_exp.y",
            "zero_exp.y",
            "inverse_exp.y"
          ]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt