Skip to content

Approach #10: Constraint Satisfaction - Hard Rules Enforcement #15

@ikennaokpala

Description

@ikennaokpala

Constraint Satisfaction: Define Hard Constraints

System must satisfy constraints. Reject any implementation that violates them.

Constraints

constraints:
  - id: C1
    rule: trip.availableSeats >= 0
    severity: critical
    
  - id: C2
    rule: SUM(booking.seats) <= trip.capacity
    severity: critical
    
  - id: C3
    rule: valid_state_transitions_only
    severity: high

Runtime Checking

fn approve_booking(trip: &mut Trip, booking: &Booking) -> Result<()> {
    // Tentative new state
    let mut new_state = trip.clone();
    new_state.available_seats -= booking.seats;
    
    // Check constraints
    checker.check_all(&new_state)?;
    
    // Only commit if constraints satisfied
    *trip = new_state;
    Ok(())
}

Strengths

✅ Explicit requirements
✅ Automated verification
✅ Prevents regressions

Rating: ⭐⭐⭐⭐ (4/5) Very effective for business rules

Agent: QA-10-Constraint-Satisfaction

Related: #4, #9

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions