Skip to content
LIBRARY
Logical.Tests.LogicGates.md

Logical.Tests.LogicGates ​

Validation test for logic gate blocks: And, Or, Xor, Nand, Nor.

Uses a Ramp source with height=4, duration=4: ramp(t) = offset + t. Two GreaterThreshold blocks convert ramp to Boolean by comparing against thresholds at -100 (always true) or 100 (always false).

Four test cases cover the full truth table by overriding thresholds:

  • TT (both true): bool1.threshold=-100, bool2.threshold=-100

  • TF (true,false): bool1.threshold=-100, bool2.threshold=100

  • FT (false,true): bool1.threshold=100, bool2.threshold=-100

  • FF (both false): bool1.threshold=100, bool2.threshold=100

Usage ​

BlockComponents.Logical.Tests.LogicGates()

Behavior ​

Source ​

dyad
"""
Validation test for logic gate blocks: And, Or, Xor, Nand, Nor.

Uses a Ramp source with height=4, duration=4: ramp(t) = offset + t.
Two GreaterThreshold blocks convert ramp to Boolean by comparing against
thresholds at -100 (always true) or 100 (always false).

Four test cases cover the full truth table by overriding thresholds:
- TT (both true):  bool1.threshold=-100, bool2.threshold=-100
- TF (true,false): bool1.threshold=-100, bool2.threshold=100
- FT (false,true): bool1.threshold=100,  bool2.threshold=-100
- FF (both false): bool1.threshold=100,  bool2.threshold=100
"""
test component LogicGates
  "Ramp: ramp(t) = offset + t for t in [0, 4]"
  ramp = BlockComponents.Sources.Ramp(height = 4, duration = 4, offset = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 230, "x2": 120, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Boolean input 1: threshold=-100 means always true by default"
  bool1 = BlockComponents.Logical.GreaterThreshold(threshold = -100.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 161, "y1": 230, "x2": 261, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Boolean input 2: threshold=-100 means always true by default"
  bool2 = BlockComponents.Logical.GreaterThreshold(threshold = -100.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 161, "y1": 406, "x2": 261, "y2": 506, "rot": 0}
      },
      "tags": []
    }
  }
  "Logic gates under test"
  and1 = BlockComponents.Logical.And() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 380, "x2": 411, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
  or1 = BlockComponents.Logical.Or() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 500, "x2": 411, "y2": 600, "rot": 0}
      },
      "tags": []
    }
  }
  xor1 = BlockComponents.Logical.Xor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 20, "x2": 420, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  nand1 = BlockComponents.Logical.Nand() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 140, "x2": 411, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  nor1 = BlockComponents.Logical.Nor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 260, "x2": 411, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
relations
  # Boolean signal generation from ramp
  connect(ramp.y, bool1.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(ramp.y, bool2.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 456}], "E": 2}],
      "junctions": [{"x": 140, "y": 280}],
      "renderStyle": "standard"
    }
  }
  # All gates: bool1 → u1, bool2 → u2
  connect(bool1.y, and1.u1) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [], "E": -2},
        {"S": -2, "M": [], "E": 2}
      ],
      "junctions": [{"x": 291, "y": 280}, {"x": 291, "y": 400}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, and1.u2) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(bool1.y, or1.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 291, "y": 280}, {"x": 291, "y": 520}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, or1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 281, "y": 576}], "E": 2}],
      "junctions": [{"x": 281, "y": 456}],
      "renderStyle": "standard"
    }
  }
  connect(bool1.y, xor1.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 291, "y": 280}, {"x": 291, "y": 40}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, xor1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 281, "y": 456}, {"x": 281, "y": 96}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(bool1.y, nand1.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 291, "y": 280}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 291, "y": 160}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, nand1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 281, "y": 456}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 281, "y": 216}],
      "renderStyle": "standard"
    }
  }
  connect(bool1.y, nor1.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(bool2.y, nor1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 281, "y": 456}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 281, "y": 336}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "TT": {
        "stop": 1,
        "params": {"bool1.threshold": -100, "bool2.threshold": -100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      },
      "TF": {
        "stop": 1,
        "params": {"bool1.threshold": -100, "bool2.threshold": 100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      },
      "FT": {
        "stop": 1,
        "params": {"bool1.threshold": 100, "bool2.threshold": -100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      },
      "FF": {
        "stop": 1,
        "params": {"bool1.threshold": 100, "bool2.threshold": 100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Validation test for logic gate blocks: And, Or, Xor, Nand, Nor.

Uses a Ramp source with height=4, duration=4: ramp(t) = offset + t.
Two GreaterThreshold blocks convert ramp to Boolean by comparing against
thresholds at -100 (always true) or 100 (always false).

Four test cases cover the full truth table by overriding thresholds:
- TT (both true):  bool1.threshold=-100, bool2.threshold=-100
- TF (true,false): bool1.threshold=-100, bool2.threshold=100
- FT (false,true): bool1.threshold=100,  bool2.threshold=-100
- FF (both false): bool1.threshold=100,  bool2.threshold=100
"""
test component LogicGates
  "Ramp: ramp(t) = offset + t for t in [0, 4]"
  ramp = BlockComponents.Sources.Ramp(height = 4, duration = 4, offset = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 230, "x2": 120, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Boolean input 1: threshold=-100 means always true by default"
  bool1 = BlockComponents.Logical.GreaterThreshold(threshold = -100.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 161, "y1": 230, "x2": 261, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Boolean input 2: threshold=-100 means always true by default"
  bool2 = BlockComponents.Logical.GreaterThreshold(threshold = -100.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 161, "y1": 406, "x2": 261, "y2": 506, "rot": 0}
      },
      "tags": []
    }
  }
  "Logic gates under test"
  and1 = BlockComponents.Logical.And() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 380, "x2": 411, "y2": 480, "rot": 0}
      },
      "tags": []
    }
  }
  or1 = BlockComponents.Logical.Or() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 500, "x2": 411, "y2": 600, "rot": 0}
      },
      "tags": []
    }
  }
  xor1 = BlockComponents.Logical.Xor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 20, "x2": 420, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  nand1 = BlockComponents.Logical.Nand() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 140, "x2": 411, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  nor1 = BlockComponents.Logical.Nor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 311, "y1": 260, "x2": 411, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
relations
  # Boolean signal generation from ramp
  connect(ramp.y, bool1.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(ramp.y, bool2.u) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 456}], "E": 2}],
      "junctions": [{"x": 140, "y": 280}],
      "renderStyle": "standard"
    }
  }
  # All gates: bool1 → u1, bool2 → u2
  connect(bool1.y, and1.u1) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [], "E": -2},
        {"S": -2, "M": [], "E": 2}
      ],
      "junctions": [{"x": 291, "y": 280}, {"x": 291, "y": 400}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, and1.u2) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(bool1.y, or1.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 291, "y": 280}, {"x": 291, "y": 520}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, or1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 281, "y": 576}], "E": 2}],
      "junctions": [{"x": 281, "y": 456}],
      "renderStyle": "standard"
    }
  }
  connect(bool1.y, xor1.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 291, "y": 280}, {"x": 291, "y": 40}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, xor1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 281, "y": 456}, {"x": 281, "y": 96}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(bool1.y, nand1.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 291, "y": 280}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 291, "y": 160}],
      "renderStyle": "standard"
    }
  }
  connect(bool2.y, nand1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 281, "y": 456}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 281, "y": 216}],
      "renderStyle": "standard"
    }
  }
  connect(bool1.y, nor1.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(bool2.y, nor1.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 281, "y": 456}], "E": -1}, {"S": -1, "M": [], "E": 2}],
      "junctions": [{"x": 281, "y": 336}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "TT": {
        "stop": 1,
        "params": {"bool1.threshold": -100, "bool2.threshold": -100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      },
      "TF": {
        "stop": 1,
        "params": {"bool1.threshold": -100, "bool2.threshold": 100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      },
      "FT": {
        "stop": 1,
        "params": {"bool1.threshold": 100, "bool2.threshold": -100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      },
      "FF": {
        "stop": 1,
        "params": {"bool1.threshold": 100, "bool2.threshold": 100},
        "expect": {
          "signals": ["bool1.y", "bool2.y", "and1.y", "or1.y", "xor1.y", "nand1.y", "nor1.y"]
        }
      }
    }
  }
}
end


Test Cases ​

Test Case TT ​

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

Test Case TF ​

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

Test Case FT ​

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

Test Case FF ​

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt