Reward¶
coleman4hcs.reward ¶
Reward functions for bandit-based test case prioritization.
Defines reward functions for agents in a multi-armed bandit framework in the context of software testing. These reward functions help agents to prioritize software test cases based on various strategies.
The module provides an abstract base class Reward that serves as a blueprint for all
reward functions. Derived classes implement specific reward strategies based on the number
of failures and the order of test cases.
Classes:
| Name | Description |
|---|---|
Reward |
An abstract base class that defines the structure and interface of a reward function. |
TimeRankReward |
A reward function that considers the order of test cases and the number of failures. |
RNFailReward |
A reward function that rewards based on the number of failures associated with test cases. |
Notes
Reward functions are essential components of the bandit-based test case prioritization framework. They guide agents to make better decisions about which test cases to prioritize. Ensure that the evaluation metric provides necessary details like detection ranks for the reward functions to work correctly.
RNFailReward ¶
Bases: Reward
Reward Based on Failures (RNFail).
This reward function is based on the number of failures associated with test cases t' in T': 1 if t' failed; 0 otherwise.
__str__ ¶
Return a string representation of the reward function.
Returns:
| Type | Description |
|---|---|
str
|
The reward function name. |
evaluate ¶
Evaluate rewards based on failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reward
|
EvaluationMetric
|
Evaluation metric containing detection ranks and scheduled test cases. |
required |
last_prioritization
|
list of str
|
Test case names in prioritization order. |
required |
Returns:
| Type | Description |
|---|---|
list of float
|
List of rewards for each test case in the prioritization. |
get_name ¶
Return the identifier of the reward function.
Returns:
| Type | Description |
|---|---|
str
|
The reward function identifier. |
Reward ¶
Bases: ABC
Abstract base class for reward functions.
A reward function is used by the agent in the observe method to evaluate bandit results and return a reward.
evaluate
abstractmethod
¶
Evaluate a bandit result and return a reward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reward
|
EvaluationMetric
|
The evaluation metric result. |
required |
last_prioritization
|
list of str
|
The last prioritized test suite list. |
required |
Returns:
| Type | Description |
|---|---|
list of float
|
The computed rewards for each test case. |
get_name ¶
Retrieve the name or identifier of the reward function.
Returns:
| Type | Description |
|---|---|
str
|
The name or identifier of the reward function. |
TimeRankReward ¶
Bases: Reward
Time-ranked Reward (TimeRank).
This reward function explicitly includes the order of test cases and rewards each test case based on its rank in the test schedule and whether it failed. As a good schedule executes failing test cases early, every passed test case reduces the schedule's quality if it precedes a failing test case. Each test case is rewarded by the total number of failed test cases; for failed test cases it is the same as reward function 'RNFailReward'. For passed test cases, the reward is further decreased by the number of failed test cases ranked after the passed test case to penalize scheduling passing test cases early.
__str__ ¶
Return a string representation of the reward function.
Returns:
| Type | Description |
|---|---|
str
|
The reward function name. |
evaluate ¶
Evaluate rewards based on the prioritization rank of test cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reward
|
EvaluationMetric
|
The evaluation metric containing detection ranks and scheduled test cases. |
required |
last_prioritization
|
list of str
|
The list of test case names in the prioritization order. |
required |
Returns:
| Type | Description |
|---|---|
list of float
|
A list of rewards for each test case in the prioritization. |
get_name ¶
Return the identifier of the reward function.
Returns:
| Type | Description |
|---|---|
str
|
The reward function identifier. |