//
//  CableTests.swift
//  CableTests
//
//  Created by Stefan Lange-Hegermann on 11.09.25.
//

import Testing
@testable import Cable

struct CableTests {

    @Test func metricWireSizingUsesNearestStandardSize() async throws {
        let calculator = CableCalculator()
        calculator.voltage = 12
        calculator.current = 5
        calculator.length = 10 // meters

        let crossSection = calculator.recommendedCrossSection(for: .metric)
        #expect(crossSection == 4.0)

        let voltageDrop = calculator.voltageDrop(for: .metric)
        #expect(abs(voltageDrop - 0.425) < 0.001)

        let dropPercentage = calculator.voltageDropPercentage(for: .metric)
        #expect(abs(dropPercentage - 3.5417) < 0.001)

        let powerLoss = calculator.powerLoss(for: .metric)
        #expect(abs(powerLoss - 2.125) < 0.001)
    }

    @Test func imperialWireSizingMatchesExpectedGauge() async throws {
        let calculator = CableCalculator()
        calculator.voltage = 120
        calculator.current = 15
        calculator.length = 25 // feet

        let awg = calculator.recommendedCrossSection(for: .imperial)
        #expect(awg == 18.0)

        let voltageDrop = calculator.voltageDrop(for: .imperial)
        #expect(abs(voltageDrop - 4.722) < 0.01)

        let dropPercentage = calculator.voltageDropPercentage(for: .imperial)
        #expect(abs(dropPercentage - 3.935) < 0.01)

        let powerLoss = calculator.powerLoss(for: .imperial)
        #expect(abs(powerLoss - 70.83) < 0.05)
    }
}
