test-oracle-generator — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited test-oracle-generator (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Generate automated test oracles to verify correct software behavior across multiple oracle types.
Understand what the function does and its expected behavior.
Checklist:
Example Analysis:
# Python
def calculate_discount(price: float, discount_percent: int) -> float:
"""Calculate discounted price.
Args:
price: Original price (must be positive)
discount_percent: Discount percentage (0-100)
Returns:
Discounted price
"""
return price * (1 - discount_percent / 100)Analysis:
price (float, must be > 0), discount_percent (int, 0-100)Create explicit expected value assertions for common cases.
Template:
# Python (pytest)
def test_<function>_<scenario>():
# Arrange
input1 = <value>
input2 = <value>
expected = <calculated_expected_value>
# Act
actual = function_under_test(input1, input2)
# Assert
assert actual == expected, f"Expected {expected}, got {actual}"// Java (JUnit)
@Test
public void test<Function><Scenario>() {
// Arrange
Type input1 = <value>;
Type input2 = <value>;
Type expected = <calculated_expected_value>;
// Act
Type actual = functionUnderTest(input1, input2);
// Assert
assertEquals(expected, actual, "Expected and actual should match");
}Example:
def test_calculate_discount_50_percent():
# Arrange
price = 100.0
discount = 50
expected = 50.0
# Act
actual = calculate_discount(price, discount)
# Assert
assert actual == expected
assert abs(actual - expected) < 0.01 # For floating pointGenerate oracles for:
Identify invariants and properties that should always hold.
Common Properties:
Template (Python with hypothesis):
from hypothesis import given, strategies as st
@given(st.floats(min_value=0.01, max_value=10000),
st.integers(min_value=0, max_value=100))
def test_discount_properties(price, discount_percent):
result = calculate_discount(price, discount_percent)
# Property: Result should never exceed original price
assert result <= price, "Discount should not increase price"
# Property: Result should be non-negative
assert result >= 0, "Price cannot be negative"
# Property: 0% discount returns original price
if discount_percent == 0:
assert abs(result - price) < 0.01
# Property: 100% discount returns 0
if discount_percent == 100:
assert abs(result) < 0.01Template (Java with JUnit Theories):
@Theory
public void discountProperties(
@ForAll @InRange(min = "0.01", max = "10000") double price,
@ForAll @InRange(min = "0", max = "100") int discountPercent) {
double result = calculateDiscount(price, discountPercent);
// Property: Result should never exceed original price
assertTrue(result <= price, "Discount should not increase price");
// Property: Result should be non-negative
assertTrue(result >= 0, "Price cannot be negative");
}Identify properties by asking:
For detailed property patterns, see references/property_patterns.md.
Compare new implementation against reference implementation.
Use Cases:
Template:
# Python
def test_new_vs_legacy_implementation():
# Test data
test_cases = [
(100.0, 10),
(50.0, 25),
(200.0, 0),
(75.0, 100),
]
for price, discount in test_cases:
# Compare outputs
legacy_result = legacy_calculate_discount(price, discount)
new_result = calculate_discount(price, discount)
assert abs(legacy_result - new_result) < 0.01, \
f"Mismatch for ({price}, {discount}): " \
f"legacy={legacy_result}, new={new_result}"// Java
@Test
public void testNewVsLegacyImplementation() {
Object[][] testCases = {
{100.0, 10},
{50.0, 25},
{200.0, 0},
{75.0, 100}
};
for (Object[] testCase : testCases) {
double price = (double) testCase[0];
int discount = (int) testCase[1];
double legacyResult = LegacyClass.calculateDiscount(price, discount);
double newResult = calculateDiscount(price, discount);
assertEquals(legacyResult, newResult, 0.01,
String.format("Mismatch for (%f, %d)", price, discount));
}
}Best Practices:
Create test pairs where input transformation produces predictable output transformation.
Metamorphic Relations:
Example for discount function:
# Python
def test_discount_metamorphic_double_price():
"""If price doubles, discount amount doubles."""
price = 100.0
discount_percent = 20
result1 = calculate_discount(price, discount_percent)
result2 = calculate_discount(price * 2, discount_percent)
discount_amount1 = price - result1
discount_amount2 = (price * 2) - result2
# Metamorphic relation: doubling price doubles discount amount
assert abs(discount_amount2 - 2 * discount_amount1) < 0.01
def test_discount_metamorphic_additive():
"""Applying discount to sum equals sum of individual discounts."""
price1 = 50.0
price2 = 30.0
discount_percent = 15
# Method 1: Discount on combined price
combined_result = calculate_discount(price1 + price2, discount_percent)
# Method 2: Sum of individual discounts
individual_sum = (calculate_discount(price1, discount_percent) +
calculate_discount(price2, discount_percent))
# Metamorphic relation: Should be equivalent
assert abs(combined_result - individual_sum) < 0.01Example for sorting function:
def test_sort_metamorphic_reverse():
"""Reversing then sorting gives same result as sorting."""
input_list = [3, 1, 4, 1, 5, 9, 2, 6]
result1 = sort(input_list)
result2 = sort(list(reversed(input_list)))
assert result1 == result2
def test_sort_metamorphic_duplicate():
"""Sorting list with duplicated elements maintains order."""
input_list = [3, 1, 4]
duplicated = input_list + input_list
result = sort(duplicated)
# Should be sorted version of original, doubled
expected = sorted(input_list) + sorted(input_list)
assert result == sorted(expected)For more metamorphic relation patterns, see references/metamorphic_patterns.md.
Use multiple oracle types together for robust verification.
Example: Complete test suite for calculate_discount:
import pytest
from hypothesis import given, strategies as st
# Assertion-based oracles
class TestDiscountAssertions:
def test_50_percent_discount(self):
assert calculate_discount(100.0, 50) == 50.0
def test_no_discount(self):
assert calculate_discount(100.0, 0) == 100.0
def test_full_discount(self):
assert calculate_discount(100.0, 100) == 0.0
# Property-based oracles
class TestDiscountProperties:
@given(st.floats(min_value=0.01, max_value=10000),
st.integers(min_value=0, max_value=100))
def test_result_within_bounds(self, price, discount):
result = calculate_discount(price, discount)
assert 0 <= result <= price
@given(st.floats(min_value=0.01, max_value=10000),
st.integers(min_value=0, max_value=100))
def test_monotonic_in_discount(self, price, discount):
"""Higher discount percentage means lower price."""
if discount < 100:
result1 = calculate_discount(price, discount)
result2 = calculate_discount(price, discount + 1)
assert result2 <= result1
# Differential oracles
class TestDiscountDifferential:
@pytest.mark.parametrize("price,discount", [
(100.0, 10), (50.0, 25), (200.0, 50)
])
def test_vs_manual_calculation(self, price, discount):
result = calculate_discount(price, discount)
expected = price * (1 - discount / 100)
assert abs(result - expected) < 0.01
# Metamorphic oracles
class TestDiscountMetamorphic:
def test_double_price_doubles_discount_amount(self):
price = 100.0
discount = 20
discount_amt1 = price - calculate_discount(price, discount)
discount_amt2 = (price * 2) - calculate_discount(price * 2, discount)
assert abs(discount_amt2 - 2 * discount_amt1) < 0.01Ensure oracles are correct and well-documented.
Oracle Documentation Template:
def test_function_oracle_type():
"""Brief description of what this oracle verifies.
Oracle Type: [Assertion-based|Property-based|Differential|Metamorphic]
Rationale: Explain why this property/assertion should hold.
Edge Cases Covered:
- Case 1
- Case 2
"""
# Test implementation
passValidation Checklist:
Mutation Testing (validate oracle effectiveness):
# Introduce deliberate bug to verify oracle catches it
def calculate_discount_buggy(price, discount_percent):
# BUG: Wrong formula
return price * discount_percent / 100 # Should be: price * (1 - discount_percent / 100)
# Oracle should fail on buggy version
def test_oracle_detects_bug():
"""Verify oracle catches the bug."""
with pytest.raises(AssertionError):
assert calculate_discount_buggy(100, 50) == 50.0 # This should failChoose Assertion-based when:
Choose Property-based when:
Choose Differential when:
Choose Metamorphic when:
For detailed oracle patterns organized by domain, see:
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.