Module clintest.assertion
The abstract class Assertion and classes extending it.
Classes
class And (*args: Assertion)-
Expand source code
class And(Assertion): """The conjunction of a list of given assertions. This assertion holds if all `args` hold. Parameters ---------- Args: The `Assertion`s to be combined. """ def __init__(self, *args: Assertion) -> None: self.__operands = args def __repr__(self): name = self.__class__.__name__ operands = ", ".join(repr(operand) for operand in self.__operands) return f"{name}({operands})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return all((operand.holds_for(model) for operand in self.__operands))The conjunction of a list of given assertions.
This assertion holds if all
argshold.Parameters
Args
The
Assertions to be combined.Ancestors
- Assertion
- abc.ABC
Inherited members
class Assertion-
Expand source code
class Assertion(ABC): """An assertion is a statement that may or may not hold for a certain `clingo.model.Model`. As such, one is necessary to assemble the `clintest.test.Assert` test. """ @abstractmethod def holds_for(self, model: Model) -> bool: """Returns whether this assertions holds for `model`. Parameters ---------- model A `clingo.model.Model`. Returns: ------- Whether this assertions holds for `model`. """An assertion is a statement that may or may not hold for a certain
clingo.model.Model.As such, one is necessary to assemble the
Asserttest.Ancestors
- abc.ABC
Subclasses
Methods
def holds_for(self,
model: Model) ‑> bool-
Expand source code
@abstractmethod def holds_for(self, model: Model) -> bool: """Returns whether this assertions holds for `model`. Parameters ---------- model A `clingo.model.Model`. Returns: ------- Whether this assertions holds for `model`. """Returns whether this assertions holds for
model.Parameters
model- A
clingo.model.Model.
Returns:
Whether this assertions holds for
model.
class Contains (symbol: clingo.symbol.Symbol | str)-
Expand source code
class Contains(Assertion): """An assertion that holds if a model contains a given `symbol`. Parameters ---------- symbol The `clingo.symbol.Symbol` or a `str` that can be parsed into a `clingo.symbol.Symbol` with `clingo.symbol.parse_term`. """ def __init__(self, symbol: Union[Symbol, str]) -> None: self.__symbol = _into_symbol(symbol) def __repr__(self): name = self.__class__.__name__ return f'{name}("{self.__symbol}")' @override def holds_for(self, model: Model) -> bool: # noqa: D102 return model.contains(self.__symbol)An assertion that holds if a model contains a given
symbol.Parameters
symbol- The
clingo.symbol.Symbolor astrthat can be parsed into aclingo.symbol.Symbolwithclingo.symbol.parse_term.
Ancestors
- Assertion
- abc.ABC
Inherited members
class Equals (symbols: Set[clingo.symbol.Symbol | str])-
Expand source code
class Equals(Assertion): """An assertion that holds if the symbols of a model are equals to a given set of `symbols`. Parameters ---------- symbols A set of `clingo.symbol.Symbol`s or `str`s that can be parsed into a `clingo.symbol.Symbol`s with `clingo.symbol.parse_term`. """ def __init__(self, symbols: Set[Union[Symbol, str]]) -> None: self.__symbols = {_into_symbol(s) for s in symbols} def __repr__(self): name = self.__class__.__name__ symbols = {str(symbol) for symbol in self.__symbols} return f"{name}({symbols})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return self.__symbols == set(model.symbols(shown=True))An assertion that holds if the symbols of a model are equals to a given set of
symbols.Parameters
symbols- A set of
clingo.symbol.Symbols orstrs that can be parsed into aclingo.symbol.Symbols withclingo.symbol.parse_term.
Ancestors
- Assertion
- abc.ABC
Inherited members
class Equivalent (*args: Assertion)-
Expand source code
class Equivalent(Assertion): """The equivalence of a list of given assertions. This assertion holds if all `args` simultaneously hold or not hold. Parameters ---------- Args: The `Assertion`s to be combined. """ def __init__(self, *args: Assertion) -> None: self.__operands = args def __repr__(self): name = self.__class__.__name__ operands = ", ".join(repr(operand) for operand in self.__operands) return f"{name}({operands})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 operands = iter(self.__operands) try: first = next(operands).holds_for(model) except StopIteration: return True return all((first == operand.holds_for(model) for operand in operands))The equivalence of a list of given assertions.
This assertion holds if all
argssimultaneously hold or not hold.Parameters
Args
The
Assertions to be combined.Ancestors
- Assertion
- abc.ABC
Inherited members
class False_-
Expand source code
class False_(Assertion): """The assertion that is false for each model.""" def __repr__(self): return f"{self.__class__.__name__}()" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return FalseThe assertion that is false for each model.
Ancestors
- Assertion
- abc.ABC
Inherited members
class Implies (antecedent: Assertion,
consequent: Assertion)-
Expand source code
class Implies(Assertion): """The implication of two given assertions. This assertion holds if `antecedent` holds implies that `consequent` holds. In other words, this assertion holds if `antecedent` does not hold or `consequent` holds. Parameters ---------- antecedent The `Assertion` to be the antecedent of the implication consequent The `Assertion` to be the consequent of the implication """ def __init__(self, antecedent: Assertion, consequent: Assertion) -> None: self.__antecedent = antecedent self.__consequent = consequent def __repr__(self): name = self.__class__.__name__ antecedent = repr(self.__antecedent) consequent = repr(self.__consequent) return f"{name}({antecedent}, {consequent})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return not self.__antecedent.holds_for(model) or self.__consequent.holds_for(model)The implication of two given assertions.
This assertion holds if
antecedentholds implies thatconsequentholds. In other words, this assertion holds ifantecedentdoes not hold orconsequentholds.Parameters
Ancestors
- Assertion
- abc.ABC
Inherited members
class Not (operand: Assertion)-
Expand source code
class Not(Assertion): """The negation of a given assertion. This assertion holds if `operand` does not hold and vice versa. Parameters ---------- operand The `Assertion` to be negated. """ def __init__(self, operand: Assertion) -> None: self.__operand = operand def __repr__(self): name = self.__class__.__name__ operand = repr(self.__operand) return f"{name}({operand})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return not self.__operand.holds_for(model)The negation of a given assertion.
This assertion holds if
operanddoes not hold and vice versa.Parameters
operand- The
Assertionto be negated.
Ancestors
- Assertion
- abc.ABC
Inherited members
class Optimal-
Expand source code
class Optimal(Assertion): """An assertion that holds if the optimality of a model is proven.""" def __repr__(self): return f"{self.__class__.__name__}()" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return model.optimality_provenAn assertion that holds if the optimality of a model is proven.
Ancestors
- Assertion
- abc.ABC
Inherited members
class Or (*args: Assertion)-
Expand source code
class Or(Assertion): """The disjunction of a list of given assertions. This assertion holds if any `args` hold. Parameters ---------- Args: The `Assertion`s to be combined. """ def __init__(self, *args: Assertion) -> None: self.__operands = args def __repr__(self): name = self.__class__.__name__ operands = ", ".join(repr(operand) for operand in self.__operands) return f"{name}({operands})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return any((operand.holds_for(model) for operand in self.__operands))The disjunction of a list of given assertions.
This assertion holds if any
argshold.Parameters
Args
The
Assertions to be combined.Ancestors
- Assertion
- abc.ABC
Inherited members
class SubsetOf (symbols: Set[clingo.symbol.Symbol | str])-
Expand source code
class SubsetOf(Assertion): """An assertion that holds if the symbols of a model are a subset of a given set of `symbols`. Parameters ---------- symbols A set of `clingo.symbol.Symbol`s or `str`s that can be parsed into a `clingo.symbol.Symbol`s with `clingo.symbol.parse_term`. """ def __init__(self, symbols: Set[Union[Symbol, str]]) -> None: self.__symbols = {_into_symbol(s) for s in symbols} def __repr__(self): name = self.__class__.__name__ symbols = {str(symbol) for symbol in self.__symbols} return f"{name}({symbols})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return set(model.symbols(shown=True)).issubset(self.__symbols)An assertion that holds if the symbols of a model are a subset of a given set of
symbols.Parameters
symbols- A set of
clingo.symbol.Symbols orstrs that can be parsed into aclingo.symbol.Symbols withclingo.symbol.parse_term.
Ancestors
- Assertion
- abc.ABC
Inherited members
class SupersetOf (symbols: Set[clingo.symbol.Symbol | str])-
Expand source code
class SupersetOf(Assertion): """An assertion that holds if the symbols of a model are a superset of a given set of `symbols`. Parameters ---------- symbols A set of `clingo.symbol.Symbol`s or `str`s that can be parsed into a `clingo.symbol.Symbol`s with `clingo.symbol.parse_term`. """ def __init__(self, symbols: Set[Union[Symbol, str]]) -> None: self.__symbols = {_into_symbol(s) for s in symbols} def __repr__(self): name = self.__class__.__name__ symbols = {str(symbol) for symbol in self.__symbols} return f"{name}({symbols})" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return set(model.symbols(shown=True)).issuperset(self.__symbols)An assertion that holds if the symbols of a model are a superset of a given set of
symbols.Parameters
symbols- A set of
clingo.symbol.Symbols orstrs that can be parsed into aclingo.symbol.Symbols withclingo.symbol.parse_term.
Ancestors
- Assertion
- abc.ABC
Inherited members
class True_-
Expand source code
class True_(Assertion): """The assertion that is true for each model.""" def __repr__(self): return f"{self.__class__.__name__}()" @override def holds_for(self, model: Model) -> bool: # noqa: D102 return TrueThe assertion that is true for each model.
Ancestors
- Assertion
- abc.ABC
Inherited members