/**
* Quick manual test to verify safety limits work correctly
* Run with: node dist/test-safety-limits.js
*/
import { TruthTableGenerator } from './systems/visualization/propositional/TruthTableGenerator.js';
import { TemporalValidator } from './validators/temporalValidator.js';
import { FuzzyValidator } from './validators/fuzzyValidator.js';
console.log('=== Testing Safety Limits ===\n');
// Test 1: Truth Table Safety Limit (12 variables)
console.log('1. Testing Truth Table Generator (max 12 variables)...');
const ttGen = new TruthTableGenerator();
try {
// Create formula with 13 variables (should fail)
const variables = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'];
ttGen.generateAssignments(variables);
console.log(' ❌ FAILED: Should have thrown error for 13 variables');
} catch (err: any) {
console.log(' ✅ PASSED: Caught error for 13 variables');
console.log(` Message: ${err.message.substring(0, 80)}...`);
}
// Should work with 12 variables
try {
const variables = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'];
const assignments = ttGen.generateAssignments(variables);
console.log(` ✅ PASSED: 12 variables generated ${assignments.length} assignments`);
} catch (err: any) {
console.log(` ❌ FAILED: 12 variables should work: ${err.message}`);
}
// Test 2: Temporal Validator Safety Limits
console.log('\n2. Testing Temporal Validator (max 5 atoms)...');
const tempValidator = new TemporalValidator();
try {
// Create formula with 6 atoms (should fail)
const formula = {
type: 'temporal' as const,
operator: 'G',
operands: [
{
type: 'and' as const,
left: { type: 'atom' as const, name: 'p1' },
right: {
type: 'and' as const,
left: { type: 'atom' as const, name: 'p2' },
right: {
type: 'and' as const,
left: { type: 'atom' as const, name: 'p3' },
right: {
type: 'and' as const,
left: { type: 'atom' as const, name: 'p4' },
right: {
type: 'and' as const,
left: { type: 'atom' as const, name: 'p5' },
right: { type: 'atom' as const, name: 'p6' }
}
}
}
}
}
]
};
tempValidator.findCounterexample(formula as any);
console.log(' ❌ FAILED: Should have thrown error for 6 atoms');
} catch (err: any) {
console.log(' ✅ PASSED: Caught error for 6 atoms');
console.log(` Message: ${err.message.substring(0, 80)}...`);
}
// Test 3: Fuzzy Validator Safety Limits
console.log('\n3. Testing Fuzzy Validator (max 100 inference rules)...');
const fuzzyValidator = new FuzzyValidator();
try {
// Create 101 rules (should fail)
const rules = Array.from({ length: 101 }, (_, i) => ({
condition: { type: 'atom' as const, atom: `cond${i}`, degree: 0.5 },
consequence: { type: 'atom' as const, atom: `result${i}` }
}));
fuzzyValidator.inference(rules, new Map());
console.log(' ❌ FAILED: Should have thrown error for 101 rules');
} catch (err: any) {
console.log(' ✅ PASSED: Caught error for 101 rules');
console.log(` Message: ${err.message.substring(0, 80)}...`);
}
// Should work with 100 rules
try {
const rules = Array.from({ length: 100 }, (_, i) => ({
condition: { type: 'atom' as const, atom: `cond${i}`, degree: 0.5 },
consequence: { type: 'atom' as const, atom: `result${i}` }
}));
const result = fuzzyValidator.inference(rules, new Map());
console.log(` ✅ PASSED: 100 rules processed successfully (${result.size} outputs)`);
} catch (err: any) {
console.log(` ❌ FAILED: 100 rules should work: ${err.message}`);
}
console.log('\n=== All Safety Limit Tests Complete ===');