//
//  DoubleExtensionsTests.swift
//  honeyDueTests
//
//  Unit tests for Double, Int number formatting extensions.
//

import Testing
@testable import honeyDue

// MARK: - Double.toCurrency Tests

struct DoubleCurrencyTests {

    @Test func wholeNumberCurrency() {
        let result = 100.0.toCurrency()
        #expect(result.contains("100"))
        #expect(result.contains("$"))
    }

    @Test func decimalCurrency() {
        let result = 49.99.toCurrency()
        #expect(result.contains("49.99"))
    }

    @Test func zeroCurrency() {
        let result = 0.0.toCurrency()
        #expect(result.contains("0"))
        #expect(result.contains("$"))
    }

    @Test func largeNumberCurrency() {
        let result = 1234567.89.toCurrency()
        #expect(result.contains("1,234,567"))
    }
}

// MARK: - Double.toFileSize Tests

struct FileSizeTests {

    @Test func bytesSize() {
        let result = 512.0.toFileSize()
        #expect(result == "512.0 B")
    }

    @Test func kilobytesSize() {
        let result = 2048.0.toFileSize()
        #expect(result == "2.0 KB")
    }

    @Test func megabytesSize() {
        let result = (5.0 * 1024 * 1024).toFileSize()
        #expect(result == "5.0 MB")
    }

    @Test func gigabytesSize() {
        let result = (2.5 * 1024 * 1024 * 1024).toFileSize()
        #expect(result == "2.5 GB")
    }

    @Test func zeroBytes() {
        let result = 0.0.toFileSize()
        #expect(result == "0.0 B")
    }
}

// MARK: - Double.rounded Tests

struct DoubleRoundedTests {

    @Test func roundToTwoPlaces() {
        #expect(3.14159.rounded(to: 2) == 3.14)
    }

    @Test func roundToZeroPlaces() {
        #expect(3.7.rounded(to: 0) == 4.0)
    }

    @Test func roundToOnePlaceDown() {
        #expect(3.14.rounded(to: 1) == 3.1)
    }

    @Test func roundToOnePlaceUp() {
        #expect(3.15.rounded(to: 1) == 3.2)
    }

    @Test func zeroRoundsToZero() {
        #expect(0.0.rounded(to: 3) == 0.0)
    }
}

// MARK: - Double.toPercentage Tests

struct PercentageTests {

    @Test func fiftyPercent() {
        let result = 50.0.toPercentage()
        #expect(result.contains("50"))
        #expect(result.contains("%"))
    }

    @Test func zeroPercent() {
        let result = 0.0.toPercentage()
        #expect(result.contains("0"))
        #expect(result.contains("%"))
    }

    @Test func hundredPercent() {
        let result = 100.0.toPercentage()
        #expect(result.contains("100"))
    }
}

// MARK: - Int.pluralSuffix Tests

struct PluralSuffixTests {

    @Test func singularNoSuffix() {
        #expect(1.pluralSuffix() == "")
    }

    @Test func pluralDefaultSuffix() {
        #expect(2.pluralSuffix() == "s")
    }

    @Test func zeroIsPlural() {
        #expect(0.pluralSuffix() == "s")
    }

    @Test func customSuffixes() {
        #expect(1.pluralSuffix("y", "ies") == "y")
        #expect(3.pluralSuffix("y", "ies") == "ies")
    }
}

// MARK: - Int.toFileSize Tests

struct IntFileSizeTests {

    @Test func intBytesToFileSize() {
        let result = 1024.toFileSize()
        #expect(result == "1.0 KB")
    }

    @Test func intZeroBytes() {
        let result = 0.toFileSize()
        #expect(result == "0.0 B")
    }
}
