Class Restrictor


  • public abstract class Restrictor
    extends Object
    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:
    SubcircuitTest.restrictors()
    • Constructor Detail

      • Restrictor

        public Restrictor()
    • Method Detail

      • validate

        public abstract void validate​(Subcircuit subcircuit)
                               throws AssertionError
        Validates this subcircuit, throwing an AssertionError 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 validate
        componentNames - 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 validate
        componentNames - component names or category names to blacklist
        Throws:
        AssertionError