// // ContextBudgetTests.swift // PocheTests // // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // import Testing @testable import Poche struct ContextBudgetTests { let budget = ContextBudget() @Test func reservesAtLeastThirtyPercentForResponse() { #expect(budget.responseReserve >= budget.windowSize * 3 / 10) #expect(budget.sendableLimit == budget.windowSize - budget.responseReserve) } @Test func condensesAtSeventyPercent() { #expect(!budget.needsCondensation(estimatedTokens: budget.condenseThreshold - 1)) #expect(budget.needsCondensation(estimatedTokens: budget.condenseThreshold)) } @Test func aFullPromptCannotBeSent() { // A prompt at 4092/4096 still fails: no room left for the answer. #expect(!budget.canSend(estimatedTokens: budget.windowSize - 4)) } @Test func usageRatioIsClamped() { #expect(budget.usageRatio(estimatedTokens: budget.windowSize * 2) == 1) #expect(budget.usageRatio(estimatedTokens: 0) == 0) } @Test func estimatorOvercountsRatherThanUndercounts() { // ~3 chars/token is pessimistic for French (~3.5–4 real). let text = String(repeating: "bonjour tout le monde ", count: 50) #expect(TokenEstimator.tokens(in: text) >= text.count / 4) } }