import { expect, test } from 'bun:test'; import type { Candle } from '../types'; import { donchianHigh, donchianLow } from './donchian'; function c(h: number): Candle { return { ts: 0, open: h, high: h, low: h - 1, close: h, volume: 1 }; } test('donchianHigh: höchstes Hoch der letzten N Candles VOR i (i exklusiv)', () => { const candles = [c(10), c(12), c(11), c(9), c(15)]; const out = donchianHigh(candles, 3); expect(out.slice(0, 3).every(Number.isNaN)).toBe(true); expect(out[3]).toBe(12); // max(10,12,11) expect(out[4]).toBe(12); // max(12,11,9) — Candle 4 selbst zählt nicht }); test('donchianLow: tiefstes Tief der letzten N Candles VOR i (i exklusiv)', () => { // c(h) erzeugt low = h-1, daher: c(10)→low=9, c(12)→low=11, c(11)→low=10, c(9)→low=8, c(15)→low=14 const candles = [c(10), c(12), c(11), c(9), c(15)]; const out = donchianLow(candles, 3); expect(out.slice(0, 3).every(Number.isNaN)).toBe(true); expect(out[3]).toBe(9); // min(9,11,10) — lows von c(10),c(12),c(11) expect(out[4]).toBe(8); // min(11,10,8) — lows von c(12),c(11),c(9); Candle 4 selbst zählt nicht });