hbutils.testing.generator.aetg
AETG (Automatic Efficient Test Generator) implementation for combinatorial testing.
This module provides a greedy AETG-based generator that constructs test cases to cover required parameter combinations (pairs or higher-order tuples). The generator iteratively selects parameter values that maximize coverage of uncovered combinations, yielding a compact suite of test cases.
The main public component is:
AETGGenerator- Generator that yields test cases covering required pairs
Note
The algorithm includes randomized selection for tie-breaking. For reproducible
results, provide a deterministic random seed or a random.Random instance
to AETGGenerator.
Example:
>>> from hbutils.testing import AETGGenerator
>>> generator = AETGGenerator({'a': (1, 2), 'b': (3, 4), 'c': (5, 6)}, rnd=123)
>>> for case in generator.cases():
... print(case)
{'a': 1, 'b': 3, 'c': 5}
{'a': 2, 'b': 4, 'c': 6}
...
__all__
- hbutils.testing.generator.aetg.__all__ = ['AETGGenerator']
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
AETGGenerator
- class hbutils.testing.generator.aetg.AETGGenerator(values: Mapping[str, object], names: List[str] | None = None, pairs: List[Tuple[str, ...]] | None = None, rnd: Random | int | None = None)[source]
AETG generator that ensures all required parameter combinations are covered.
The AETG (Automatic Efficient Test Generator) algorithm generates test cases that cover required parameter combinations. It uses a greedy strategy that attempts to maximize coverage of currently uncovered combinations, with a randomized tie-breaking mechanism.
- Example::
>>> from hbutils.testing import AETGGenerator >>> gene = AETGGenerator({'a': (1, 2), 'b': (3, 4), 'c': (5, 6)}, rnd=0) >>> for case in gene.cases(): ... print(case) {'a': 1, 'b': 3, 'c': 5} {'a': 2, 'b': 4, 'c': 6} ...
- __init__(values: Mapping[str, object], names: List[str] | None = None, pairs: List[Tuple[str, ...]] | None = None, rnd: Random | int | None = None) None[source]
Constructor of the
hbutils.testing.AETGGeneratorclass.- Parameters:
values (Mapping[str, object]) – Selection values, such as
{'a': [2, 3], 'b': ['b', 'c']}.names (Optional[List[str]]) – Names of the given generator, default is
Nonewhich means use the sorted key set of the values.pairs (Optional[List[Tuple[str, ...]]]) – Pairs required to be all tested, default is
Nonewhich means all the binary pairs will be included.rnd (Optional[Union[random.Random, int]]) – Random object or int-formatted random seed, default is
Nonewhich means the default random object will be used.
- cases() Iterator[Mapping[str, object]][source]
Get the cases in this AETG model.
Generates test cases using the AETG algorithm, ensuring all required parameter combinations are covered. The algorithm uses a greedy approach to select values that cover the most uncovered pairs. The order of generated cases can vary due to random tie-breaking.
- Returns:
Iterator yielding test case dictionaries.
- Return type:
Iterator[Mapping[str, object]]
- Examples::
>>> from hbutils.testing import AETGGenerator >>> gene = AETGGenerator({'a': (1, 2), 'b': (3, 4), 'c': (5, 6), 'd': (7, 8), 'e': (9, 10)}) >>> for p in gene.cases(): ... print(p) {'a': 1, 'b': 3, 'c': 6, 'd': 8, 'e': 10} {'a': 2, 'b': 4, 'c': 5, 'd': 7, 'e': 9} {'a': 2, 'b': 3, 'c': 6, 'd': 7, 'e': 9} {'a': 2, 'b': 4, 'c': 6, 'd': 8, 'e': 10} {'a': 1, 'b': 3, 'c': 5, 'd': 7, 'e': 10} {'a': 1, 'b': 4, 'c': 5, 'd': 8, 'e': 9} >>> gene = AETGGenerator( ... {'a': (1, 2), 'b': (3, 4), 'c': (5, 6), 'd': (7, 8), 'e': (9, 10)}, ... pairs=[('a', 'c'), ('b', 'd'), ('e',)] ... ) >>> for p in gene.cases(): ... print(p) {'a': 2, 'b': 3, 'c': 6, 'd': 8, 'e': 9} {'a': 1, 'b': 4, 'c': 5, 'd': 7, 'e': 10} {'a': 2, 'b': 4, 'c': 5, 'd': 8, 'e': 9} {'a': 1, 'b': 3, 'c': 6, 'd': 7, 'e': 10}
- property pairs: List[Tuple[str, ...]]
Pairs required to be all tested.
- Returns:
List of parameter name tuples that must be covered.
- Return type:
List[Tuple[str, …]]