Class Restrictor
java.lang.Object
io.zucchini.circuitsimtester.api.Restrictor
Validates a subcircuit by checking for issues such as banned
components. Example:
@DisplayName("Toy ALU") @ExtendWith(CircuitSimExtension.class) @SubcircuitTest(file="toy-alu.sim", subcircuit="ALU", restrictors={ToyALUTests.BannedGates.class}) public class ToyALUTests { public static class BannedGates extends Restrictor { @Override public void validate(Subcircuit subcircuit) throws AssertionError { blacklistComponents(subcircuit, "XOR"); } } // ... }
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
blacklistComponents
(Subcircuit subcircuit, String... componentNames) Fail the whole test if the subcircuit contains any of these components or component categories.abstract void
validate
(Subcircuit subcircuit) Validates this subcircuit, throwing anAssertionError
if any issues are found.protected void
whitelistComponents
(Subcircuit subcircuit, String... componentNames) Fail the whole test if the subcircuit contains any components other than these components or categories.
-
Constructor Details
-
Restrictor
public Restrictor()
-
-
Method Details
-
validate
Validates this subcircuit, throwing anAssertionError
if any issues are found. (The subcircuit name will automatically be included in the exception, so don't worry about that.) Subclasses should override this method with one that calls the protected helper methods in this class as needed.- Parameters:
subcircuit
- the subcircuit to validate- Throws:
AssertionError
- on validation error. Do not worry about including the subcircuit name
-
whitelistComponents
protected void whitelistComponents(Subcircuit subcircuit, String... componentNames) throws AssertionError Fail the whole test if the subcircuit contains any components other than these components or categories.Automatically includes Input Pins, Output Pins, Constants, Tunnels, Probes, and Text. But other components will be allowed only if you specify them here, including other Wiring components. Please consider starting off with
"Wiring", "Text"
, or you will risk frustrating students.- Parameters:
subcircuit
- Subcircuit to validatecomponentNames
- component names or category names to whitelist- Throws:
AssertionError
-
blacklistComponents
protected void blacklistComponents(Subcircuit subcircuit, String... componentNames) throws AssertionError Fail the whole test if the subcircuit contains any of these components or component categories.- Parameters:
subcircuit
- Subcircuit to validatecomponentNames
- component names or category names to blacklist- Throws:
AssertionError
-