import { describe, it, expect } from 'vitest';
import {
  determineStructureClass,
  calculateS2,
  calculateVk,
  calculateDynamicPressure,
  calculateS3ByGroup,
  calculateS3ByPmAndLife,
} from '../wind-kernel';

describe('NBR 6123 — Motor Matemático', () => {
  describe('determineStructureClass (sec. 5.3.2)', () => {
    it('Classe A para dimensão ≤ 20 m', () => {
      expect(determineStructureClass(10)).toBe('A');
      expect(determineStructureClass(20)).toBe('A');
    });
    it('Classe B para 20 < dim ≤ 50 m', () => {
      expect(determineStructureClass(21)).toBe('B');
      expect(determineStructureClass(50)).toBe('B');
    });
    it('Classe C para dim > 50 m', () => {
      expect(determineStructureClass(51)).toBe('C');
      expect(determineStructureClass(150)).toBe('C');
    });
  });

  describe('calculateS2 (Tab. 3)', () => {
    it('S₂(z=10m, Cat. II, A) ≈ 1.00', () => {
      const s2 = calculateS2(10, 'II', 'A');
      expect(s2).toBeGreaterThan(0.95);
      expect(s2).toBeLessThan(1.05);
    });
    it('S₂(z=5m, Cat. V, A) é menor que Cat. II', () => {
      expect(calculateS2(5, 'V', 'A')).toBeLessThan(calculateS2(5, 'II', 'A'));
    });
    it('S₂ cresce com altura (mesma cat/classe)', () => {
      expect(calculateS2(50, 'II', 'A')).toBeGreaterThan(calculateS2(10, 'II', 'A'));
    });
  });

  describe('calculateVk (sec. 5)', () => {
    it('V₀·S₁·S₂·S₃ com 40·1·1·1 = 40', () => {
      expect(calculateVk(40, 1, 1, 1)).toBe(40);
    });
    it('V₀=30, S₁=1.1, S₂=1.0, S₃=0.95 → 31.35', () => {
      expect(calculateVk(30, 1.1, 1, 0.95)).toBe(31.35);
    });
  });

  describe('calculateDynamicPressure (q = 0.613·Vk²)', () => {
    it('Vₖ=40 → q = 0.981 kN/m²', () => {
      const q = calculateDynamicPressure(40);
      expect(q).toBeCloseTo(0.981, 2);
    });
    it('q aumenta com Vₖ²', () => {
      expect(calculateDynamicPressure(50)).toBeGreaterThan(calculateDynamicPressure(40));
    });
  });

  describe('calculateS3ByGroup (Tab. 4)', () => {
    it('Grupo 1 = 1,11 (NBR 6123:2023 p. 15)', () => {
      expect(calculateS3ByGroup(1)).toBe(1.11);
    });
    it('Grupo 2 = 1,06 (NBR 6123:2023 p. 15)', () => {
      expect(calculateS3ByGroup(2)).toBe(1.06);
    });
    it('Grupo 3 = 1,00', () => {
      expect(calculateS3ByGroup(3)).toBe(1.0);
    });
    it('Grupo 5 = 0,83', () => {
      expect(calculateS3ByGroup(5)).toBe(0.83);
    });
  });

  describe('calculateS3ByPmAndLife (Tab. B.1)', () => {
    it('Pₘ=0,63, vida=50 anos → S₃=1,00', () => {
      expect(calculateS3ByPmAndLife(0.63, 50)).toBe(1.0);
    });
    it('Pₘ=0,63, vida=2 anos → S₃≈0,60 (baixo)', () => {
      expect(calculateS3ByPmAndLife(0.63, 2)).toBe(0.60);
    });
  });
});