const { deltaToSignal, directedDelta } = require('../../src/utils/signals');

describe('signals', () => {
  describe('deltaToSignal', () => {
    test('0.0-0.49 maps to neutral', () => {
      expect(deltaToSignal(0)).toBe('neutral');
      expect(deltaToSignal(0.3)).toBe('neutral');
      expect(deltaToSignal(0.49)).toBe('neutral');
    });

    test('0.5-1.99 maps to lean', () => {
      expect(deltaToSignal(0.5)).toBe('lean');
      expect(deltaToSignal(1.5)).toBe('lean');
      expect(deltaToSignal(1.99)).toBe('lean');
    });

    test('2.0-3.99 maps to bullish', () => {
      expect(deltaToSignal(2.0)).toBe('bullish');
      expect(deltaToSignal(3.5)).toBe('bullish');
    });

    test('>= 4.0 maps to strong_bullish', () => {
      expect(deltaToSignal(4.0)).toBe('strong_bullish');
      expect(deltaToSignal(7.0)).toBe('strong_bullish');
    });

    test('negative deltas map to bearish equivalents', () => {
      expect(deltaToSignal(-0.3)).toBe('neutral');
      expect(deltaToSignal(-1.0)).toBe('lean_bearish');
      expect(deltaToSignal(-2.5)).toBe('bearish');
      expect(deltaToSignal(-5.0)).toBe('strong_bearish');
    });
  });

  describe('directedDelta', () => {
    test('over: positive when avg > line', () => {
      expect(directedDelta(28, 26, 'over')).toBe(2);
    });

    test('over: negative when avg < line', () => {
      expect(directedDelta(24, 26, 'over')).toBe(-2);
    });

    test('under: inverts delta', () => {
      expect(directedDelta(28, 26, 'under')).toBe(-2);
      expect(directedDelta(24, 26, 'under')).toBe(2);
    });
  });
});
