Skip to content
This repository has been archived by the owner on Jul 2, 2018. It is now read-only.

Rewrite for Xcode 9 & Swift 3.2 #84

Open
wants to merge 22 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0753ad6
[MNY-79]: Removes old sources
danthorpe Sep 15, 2017
1c210a9
[MNY-79]: Adds new files with support for basic functions
danthorpe Sep 15, 2017
75c63f3
[MNY-79]: Reorgs tests; adds Comparable
danthorpe Sep 15, 2017
56449a8
[MNY-79]: Removes unneeded overrides
danthorpe Sep 15, 2017
c739d7b
[MNY-79]: Adds division operator and more floating point conformance
danthorpe Sep 20, 2017
88aff2b
[MNY-79]: Adds tests for ISOMoney
danthorpe Sep 20, 2017
a6bdee0
[MNY-79]: Adds currencies & money
danthorpe Sep 20, 2017
3452b07
[MNY-79]: Moves BaseCurrency
danthorpe Sep 20, 2017
b465429
[MNY-79]: Updates fastlane
danthorpe Sep 20, 2017
4cdd71b
[MNY-79]: Fixies iOS currencySymbol issue.
danthorpe Sep 20, 2017
202ef80
[MNY-79]: Fixes AppleTV sdk version in fastlane
danthorpe Sep 20, 2017
385fadc
[MNY-79]: Adds init(minorUnits:)
danthorpe Sep 21, 2017
cd9c72d
[MNY-79]: Adds amount property
danthorpe Sep 21, 2017
dd2f3d9
[MNY-79]: Makes types public
danthorpe Sep 21, 2017
795ac15
[MNY-79]: Adds formatting styles
danthorpe Sep 24, 2017
7e06233
[MNY-79]: Fixes Mac tests
danthorpe Sep 24, 2017
bd4d2f4
[MNY-79]: Fixes issue with extra )
danthorpe Sep 27, 2017
bd1b6f5
[MNY-79]: Adds a failing test where the number formatter scale is not…
danthorpe Sep 27, 2017
08d79ee
[MNY-79]: Fixes failing test for the currency maximum fraction digits
danthorpe Sep 27, 2017
2987735
[MNY-79]: Fixes issue with fractional units
danthorpe Sep 27, 2017
ed9ae11
[MNY-79]: Removes `.device` currency
danthorpe Oct 1, 2017
49d693d
[MNY-79]: Works around intValue NSDecimalNumber bug
danthorpe Feb 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[MNY-79]: Reorgs tests; adds Comparable
  • Loading branch information
danthorpe committed Sep 15, 2017
commit 75c63f3aa5261d400fe282d706b36f563ef3ba83
26 changes: 21 additions & 5 deletions Money.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
657FA5301F6C7DF6005B0CE9 /* MoneyProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA52B1F6C7DF6005B0CE9 /* MoneyProtocol.swift */; };
657FA5311F6C7DF6005B0CE9 /* Money.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA52C1F6C7DF6005B0CE9 /* Money.swift */; };
657FA5321F6C7DF6005B0CE9 /* CurrencyProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA52D1F6C7DF6005B0CE9 /* CurrencyProtocol.swift */; };
657FA5351F6C7E02005B0CE9 /* MoneyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA5331F6C7E02005B0CE9 /* MoneyTests.swift */; };
657FA5351F6C7E02005B0CE9 /* InitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA5331F6C7E02005B0CE9 /* InitTests.swift */; };
657FA5361F6C7E02005B0CE9 /* MoneyTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA5341F6C7E02005B0CE9 /* MoneyTestCase.swift */; };
657FA5381F6C80FA005B0CE9 /* AdditionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA5371F6C80FA005B0CE9 /* AdditionTests.swift */; };
657FA53A1F6C8114005B0CE9 /* SubtractionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA5391F6C8114005B0CE9 /* SubtractionTests.swift */; };
657FA53C1F6C811F005B0CE9 /* MultiplicationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA53B1F6C811F005B0CE9 /* MultiplicationTests.swift */; };
657FA53E1F6C812C005B0CE9 /* ComparisonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 657FA53D1F6C812C005B0CE9 /* ComparisonTests.swift */; };
65ECB2B11DB3DC9900F96F46 /* Money.h in Headers */ = {isa = PBXBuildFile; fileRef = 65599E6A1DB3CFD300EC123C /* Money.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -56,8 +60,12 @@
657FA52B1F6C7DF6005B0CE9 /* MoneyProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoneyProtocol.swift; sourceTree = "<group>"; };
657FA52C1F6C7DF6005B0CE9 /* Money.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Money.swift; sourceTree = "<group>"; };
657FA52D1F6C7DF6005B0CE9 /* CurrencyProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyProtocol.swift; sourceTree = "<group>"; };
657FA5331F6C7E02005B0CE9 /* MoneyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoneyTests.swift; sourceTree = "<group>"; };
657FA5331F6C7E02005B0CE9 /* InitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InitTests.swift; sourceTree = "<group>"; };
657FA5341F6C7E02005B0CE9 /* MoneyTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoneyTestCase.swift; sourceTree = "<group>"; };
657FA5371F6C80FA005B0CE9 /* AdditionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdditionTests.swift; sourceTree = "<group>"; };
657FA5391F6C8114005B0CE9 /* SubtractionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtractionTests.swift; sourceTree = "<group>"; };
657FA53B1F6C811F005B0CE9 /* MultiplicationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiplicationTests.swift; sourceTree = "<group>"; };
657FA53D1F6C812C005B0CE9 /* ComparisonTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparisonTests.swift; sourceTree = "<group>"; };
65AA39ED1DFEF418000942A7 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = "<group>"; };
65ECB2BF1DB4134C00F96F46 /* Autogenerate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Autogenerate.h; sourceTree = "<group>"; };
65ECB2C01DB4134C00F96F46 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -94,9 +102,13 @@
655155141DB3D59900368D35 /* Tests */ = {
isa = PBXGroup;
children = (
657FA5341F6C7E02005B0CE9 /* MoneyTestCase.swift */,
657FA5331F6C7E02005B0CE9 /* MoneyTests.swift */,
6551551A1DB3D59900368D35 /* Info.plist */,
657FA5371F6C80FA005B0CE9 /* AdditionTests.swift */,
657FA5331F6C7E02005B0CE9 /* InitTests.swift */,
657FA5341F6C7E02005B0CE9 /* MoneyTestCase.swift */,
657FA5391F6C8114005B0CE9 /* SubtractionTests.swift */,
657FA53B1F6C811F005B0CE9 /* MultiplicationTests.swift */,
657FA53D1F6C812C005B0CE9 /* ComparisonTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -300,8 +312,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
657FA53E1F6C812C005B0CE9 /* ComparisonTests.swift in Sources */,
657FA5361F6C7E02005B0CE9 /* MoneyTestCase.swift in Sources */,
657FA5351F6C7E02005B0CE9 /* MoneyTests.swift in Sources */,
657FA5381F6C80FA005B0CE9 /* AdditionTests.swift in Sources */,
657FA53C1F6C811F005B0CE9 /* MultiplicationTests.swift in Sources */,
657FA53A1F6C8114005B0CE9 /* SubtractionTests.swift in Sources */,
657FA5351F6C7E02005B0CE9 /* InitTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 10 additions & 2 deletions Sources/ISOMoney.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,25 @@ struct ISOMoney<C: ISOCurrencyProtocol>: MoneyProtocol {

extension ISOMoney: Equatable {

static func ==<C>(lhs: ISOMoney<C>, rhs: ISOMoney<C>) -> Bool {
static func ==(lhs: ISOMoney<C>, rhs: ISOMoney<C>) -> Bool {
return lhs.decimal == rhs.decimal
&& lhs.currency.code == rhs.currency.code
&& lhs.currency.scale == rhs.currency.scale
&& lhs.currency.symbol == rhs.currency.symbol
}
}

extension ISOMoney: ExpressibleByFloatLiteral { }
extension ISOMoney: Comparable {

static func <(lhs: ISOMoney<C>, rhs: ISOMoney<C>) -> Bool {

if lhs.currency.code != rhs.currency.code {
return lhs.currency.code < rhs.currency.code
}

return lhs.decimal < rhs.decimal
}
}



Expand Down
11 changes: 11 additions & 0 deletions Sources/Money.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,14 @@ extension Money: Equatable {
}
}

extension Money: Comparable {

static func <(lhs: Money, rhs: Money) -> Bool {

if lhs.currency.code != rhs.currency.code {
return lhs.currency.code < rhs.currency.code
}

return lhs.decimal < rhs.decimal
}
}
55 changes: 55 additions & 0 deletions Tests/AdditionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Money
// File created on 15/09/2017.
//
// Copyright (c) 2015-2017 Daniel Thorpe
//
// Money is licensed under the MIT License. Read the full license at
// https://github.com/danthorpe/Money/blob/master/LICENSE
//

import XCTest

@testable import Money

extension MoneyTestCase {

func test__money_addition() {
money = 10
let result = money + Money(decimal: Decimal(integerLiteral: 10))
XCTAssertEqual(result, 20)
}

func test__money_addition_by_integer_literals() {
money = 10
let result = 3 + money + 2
XCTAssertEqual(result, 15)
}

func test__money_addition_by_float_literals() {
money = 10
let result = 3.5 + money + 2.5
XCTAssertEqual(result, 16)
}
}

extension MoneyTestCase {

func test__iso_addition() {
gbp = 10
let result = gbp + GBP(decimal: Decimal(integerLiteral: 10))
XCTAssertEqual(result, 20)
}

func test__iso_addition_by_integer_literals() {
gbp = 10
let result = 3 + gbp + 2
XCTAssertEqual(result, 15)
}

func test__iso_addition_by_float_literals() {
gbp = 10
let result = 3.5 + gbp + 2.5
XCTAssertEqual(result, 16)
}
}
39 changes: 39 additions & 0 deletions Tests/ComparisonTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Money
// File created on 15/09/2017.
//
// Copyright (c) 2015-2017 Daniel Thorpe
//
// Money is licensed under the MIT License. Read the full license at
// https://github.com/danthorpe/Money/blob/master/LICENSE
//

import XCTest

@testable import Money

extension MoneyTestCase {

func test__less_than() {
money = 10
XCTAssertLessThan(money, 11)
}

func test__greater_than() {
money = 10
XCTAssertGreaterThan(money, 9)
}
}

extension MoneyTestCase {

func test__iso_less_than() {
gbp = 10
XCTAssertLessThan(gbp, 11)
}

func test__iso_greater_than() {
gbp = 10
XCTAssertGreaterThan(gbp, 9)
}
}
39 changes: 39 additions & 0 deletions Tests/InitTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Money
// File created on 15/09/2017.
//
// Copyright (c) 2015-2017 Daniel Thorpe
//
// Money is licensed under the MIT License. Read the full license at
// https://github.com/danthorpe/Money/blob/master/LICENSE
//

import XCTest

@testable import Money

extension MoneyTestCase {

func test__Given_initialized_with_no_argument__Then_money_is_zero() {
money = Money()
XCTAssertEqual(money, .makeZero())
XCTAssertEqual(money, 0)
}

func test__Given_initialized_with_no_argument__Then_gbp_is_zero() {
gbp = GBP()
XCTAssertEqual(gbp, 0)
}

func test__Given_initialized_with_one__Then_gbp_is_one() {
gbp = GBP(integerLiteral: 1)
XCTAssertEqual(gbp, 1)
}

func test__Given_initialized_with_double__Then_gbp_is_one() {
gbp = GBP(floatLiteral: 10.0)
XCTAssertEqual(gbp, 10.0)
}

}

Loading