Cotton code
63 lines · 3.8 KB · SwiftRaw
// The amount in words a cheque writes, the Indian way, and the core's said// amount read back into the figures a period object types.@testable import CottonFacesimport XCTestfinal class RupeeWordsTests: XCTestCase {    /// RULE: Rupees are written in words the Indian way (crore, lakh, thousand, hundred), "and" before the last tens, the tens hyphenated, a capital first and "only" last.    func testRupeesAreWrittenTheIndianWay() {        XCTAssertEqual(RupeeWords.written(rupees: 2_340), "Two thousand three hundred and forty only")        XCTAssertEqual(RupeeWords.written(rupees: 1_24_500), "One lakh twenty-four thousand five hundred only")        XCTAssertEqual(RupeeWords.written(rupees: 1_80_000), "One lakh eighty thousand only")        XCTAssertEqual(RupeeWords.written(rupees: 16_01_625), "Sixteen lakh one thousand six hundred and twenty-five only")        XCTAssertEqual(RupeeWords.written(rupees: 3_25_00_000), "Three crore twenty-five lakh only")        XCTAssertEqual(RupeeWords.written(rupees: 1_000_00_00_000), "One thousand crore only")        XCTAssertEqual(RupeeWords.written(rupees: 7), "Seven only")        XCTAssertEqual(RupeeWords.written(rupees: 19), "Nineteen only")        XCTAssertEqual(RupeeWords.written(rupees: 90), "Ninety only")        XCTAssertEqual(RupeeWords.written(rupees: 100), "One hundred only")        XCTAssertEqual(RupeeWords.written(rupees: 1_005), "One thousand and five only")        XCTAssertEqual(RupeeWords.written(rupees: 10_10_101), "Ten lakh ten thousand one hundred and one only")    }    /// RULE: Paise follow the rupees in words; paise alone are written alone; nought is "Nil only".    func testPaiseAndNought() {        XCTAssertEqual(RupeeWords.written(rupees: 12, paise: 50), "Twelve rupees and fifty paise only")        XCTAssertEqual(RupeeWords.written(rupees: 340, paise: 5), "Three hundred and forty rupees and five paise only")        XCTAssertEqual(RupeeWords.written(rupees: 0, paise: 75), "Seventy-five paise only")        XCTAssertEqual(RupeeWords.written(rupees: 0), "Nil only")        XCTAssertEqual(RupeeWords.written(rupees: -2_340), "Two thousand three hundred and forty only", "a negative amount is written as its size")    }    /// RULE: The core's said amount reads back into its mark, grouped units and minor part, and is typed with two places as grouped.    func testASaidAmountIsTypedWithTwoPlaces() throws {        let grocer = try XCTUnwrap(SaidAmount("\u{20B9}1,24,500"))        XCTAssertEqual(grocer.units, 1_24_500)        XCTAssertTrue(grocer.isRupees)        XCTAssertEqual(grocer.typed, "1,24,500.00")        let paise = try XCTUnwrap(SaidAmount("\u{20B9}16,01,625.50"))        XCTAssertEqual(paise.units, 16_01_625)        XCTAssertEqual(paise.hundredths, 50)        XCTAssertEqual(paise.typed, "16,01,625.50")        let overdrawn = try XCTUnwrap(SaidAmount("\u{2212}\u{20B9}500"))        XCTAssertTrue(overdrawn.negative)        XCTAssertEqual(overdrawn.typed, "\u{2212}500.00")        XCTAssertEqual(overdrawn.signedHundredths, -50_000)        let dollars = try XCTUnwrap(SaidAmount("$12.5"))        XCTAssertEqual(dollars.mark, "$")        XCTAssertEqual(dollars.hundredths, 50)        XCTAssertFalse(dollars.isRupees)        XCTAssertNil(SaidAmount("no figure"))    }    /// RULE: An object types rupees as "Rs" and writes their words; another currency keeps its own mark and is written in no words.    func testTheMarkAndTheWords() throws {        let rupees = try XCTUnwrap(SaidAmount("\u{20B9}2,340"))        XCTAssertEqual(MoneyReading.typed(rupees), "Rs 2,340.00")        XCTAssertEqual(MoneyReading.words(rupees), "Two thousand three hundred and forty only")        let dollars = try XCTUnwrap(SaidAmount("$12.50"))        XCTAssertEqual(MoneyReading.typed(dollars), "$ 12.50")        XCTAssertNil(MoneyReading.words(dollars))    }}