Round #256
07 May 2026, 21:04· csharp· meta/llama-3.3-70b-instruct· r13-clean-hints
- Complexity
- band 0
- ZP / UO / OBS
- 6 / 0 / 0
- Journey weight
- 474
- Lightshift ΔL
- +0.50
Prompt
Implement a business rule validator that checks account balance before transfer
Zero-point index (what the engine surfaced)
ZPI-ZPI-0020 | 2026-05-07T21:04:20Z
Implement a business rule validator that checks account balance before transfer
ZERO POINT — 6 entries (structural invariants)
● hsl(159.80, 100%, 21%) IValidator<T> [contract]
● hsl(240.67, 100%, 21%) AbstractValidator<T> [contract]
● hsl(175.80, 100%, 21%) IValidatableObject [contract]
● hsl(328.68, 100%, 21%) IValidatorFactory [contract]
● hsl(145.31, 100%, 21%) ValidationResult [contract]
● hsl(39.29, 100%, 21%) ValidationContext<T> [contract]
UNOBSERVED — 0 entries (implied truths)
OBSERVED — 0 entries (explicit in request)
COMPLEXITY │ 6 entries │ spread: 0° │ band: LOW
Baseline response (no ZPI)
**Business Rule Validator Implementation**
==========================================
Below is a C# implementation of a business rule validator that checks the account balance before a transfer.
```csharp
using System;
// Define an enum for transfer status
public enum TransferStatus
{
Success,
InsufficientBalance,
InvalidAmount
}
// Define a class for account
public class Account
{
public decimal Balance { get; set; }
public string AccountNumber { get; set; }
public Account(string accountNumber, decimal balance)
{
AccountNumber = accountNumber;
Balance = balance;
}
}
// Define a class for transfer
public class Transfer
{
public decimal Amount { get; set; }
public Account SourceAccount { get; set; }
public Account DestinationAccount { get; set; }
public Transfer(decimal amount, Account sourceAccount, Account destinationAccount)
{
Amount = amount;
SourceAccount = sourceAccount;
DestinationAccount = destinationAccount;
}
}
// Define a class for business rule validator
public class BusinessRuleValidator
{
public TransferStatus ValidateTransfer(Transfer transfer)
{
// Check if transfer amount is valid (greater than zero)
if (transfer.Amount <= 0)
{
return TransferStatus.InvalidAmount;
}
// Check if source account has sufficient balance
if (transfer.SourceAccount.Balance < transfer.Amount)
{
return TransferStatus.InsufficientBalance;
}
// If all checks pass, return success
return TransferStatus.Success;
}
public void PerformTransfer(Transfer transfer)
{
var transferStatus = ValidateTransfer(transfer);
switch (transferStatus)
{
case TransferStatus.Success:
// Update account balances
transfer.SourceAccount.Balance -= transfer.Amount;
transfer.DestinationAccount.Balance += transfer.Amount;
Console.WriteLine("Transfer successful.");
break;
case TransferStatus.InsufficientBalance:
Console.WriteLine("Insufficient balance in source account.");
break;
case TransferStatus.InvalidAmount:
Console.WriteLine("Invalid transfer amount.");
break;
default:
throw new Exception("Unknown transfer status.");
}
}
}
class Program
{
static void Main()
{
// Create accounts
var sourceAccount = new Account("12345", 1000);
var destinationAccount = new Account("67890", 500);
// Create transfer
var transfer = new Transfer(200, sourceAccount, destinationAccount);
// Create business rule validator
var validator = new BusinessRuleValidator();
// Perform transfer
validator.PerformTransfer(transfer);
// Print final account balances
Console.WriteLine($"Source account balance: {sourceAccount.Balance}");
Console.WriteLine($"Destination account balance: {destinationAccount.Balance}");
}
}
```
**Explanation**
---------------
1. We define an enum `TransferStatus` to represent the status of a transfer (success, insufficient balance, or invalid amount).
2. We create classes for `Account` and `Transfer` to represent the account and transfer details, respectively.
3. The `BusinessRuleValidator` class contains methods to validate a transfer and perform the transfer if it is valid.
4. In the `ValidateTransfer` method, we check if the transfer amount is valid (greater than zero) and if the source account has sufficient balance.
5. If the transfer is valid, we update the account balances in the `PerformTransfer` method.
6. In the `Main` method, we demonstrate the usage of the business rule validator by creating accounts, a transfer, and performing the transfer.
**Example Use Cases**
--------------------
* **Valid Transfer**: Create a transfer with a valid amount (e.g., 200) and sufficient balance in the source account (e.g., 1000). The transfer should be successful, and the account balances should be updated accordingly.
* **Insufficient Balance**: Create a transfer with an amount greater than the source account balance (e.g., 1500). The transfer should fail due to insufficient balance.
* **Invalid Amount**: Create a transfer with an invalid amount (e.g., -200 or 0). The transfer should fail due to an invalid amount.
Enhanced response (with ZPI)
```csharp
using System;
using System.ComponentModel.DataAnnotations;
using FluentValidation;
using FluentValidation.Results;
// Define a class to represent an account
public class Account
{
public decimal Balance { get; set; }
public decimal TransferAmount { get; set; }
}
// Define a validator for the account
public class AccountValidator : AbstractValidator<Account>
{
public AccountValidator()
{
RuleFor(account => account.TransferAmount)
.Must(BeLessThanBalance)
.WithMessage("Transfer amount cannot exceed account balance");
}
private bool BeLessThanBalance(Account account, decimal transferAmount)
{
return transferAmount <= account.Balance;
}
}
// Define a service to handle account transfers
public class AccountTransferService
{
private readonly IValidator<Account> _validator;
public AccountTransferService(IValidator<Account> validator)
{
_validator = validator;
}
public ValidationResult ValidateTransfer(Account account)
{
return _validator.Validate(account);
}
public void Transfer(Account account)
{
var result = ValidateTransfer(account);
if (!result.IsValid)
{
throw new ValidationException(result.Errors);
}
// Perform the transfer
account.Balance -= account.TransferAmount;
}
}
class Program
{
static void Main()
{
// Create an instance of the account validator
var validator = new AccountValidator();
// Create an instance of the account transfer service
var service = new AccountTransferService(validator);
// Create an account
var account = new Account
{
Balance = 100,
TransferAmount = 50
};
try
{
// Attempt to transfer funds
service.Transfer(account);
Console.WriteLine("Transfer successful");
}
catch (ValidationException ex)
{
// Handle validation errors
foreach (var error in ex.Errors)
{
Console.WriteLine(error.ErrorMessage);
}
}
}
}
```
This implementation uses the `AbstractValidator<T>` class from the FluentValidation library to define a validator for the `Account` class. The validator checks that the transfer amount does not exceed the account balance. The `AccountTransferService` class uses the validator to validate the transfer before performing it. If the validation fails, a `ValidationException` is thrown with the validation errors.
The `AccountValidator` class defines a single rule using the `RuleFor` method, which specifies that the `TransferAmount` property must be less than or equal to the `Balance` property. The `BeLessThanBalance` method is used to implement this rule.
The `AccountTransferService` class takes an instance of the `IValidator<Account>` interface in its constructor, which is used to validate the transfer. The `ValidateTransfer` method returns a `ValidationResult` object, which contains the validation errors if any. The `Transfer` method performs the transfer if the validation is successful, otherwise it throws a `ValidationException`.
In the `Main` method, an instance of the `AccountValidator` is created and used to create an instance of the `AccountTransferService`. An `Account` object is created and an attempt is made to transfer funds. If the validation fails, the error messages are printed to the console.
Grader chain
Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.
V1claude-haiku-4-5-20251001
WorseV4qwen2.5-coder-7b-instruct
BetterComments
Our grader said what it said. What do you say? Comment as a guest below.
No comments yet. Be the first to say what you make of this round.