@@ -13,6 +13,9 @@ final class PlutusFinancialReportSlicerTests: XCTestCase {
13
13
[ " Switzerland (CHF) " , " 29 " , " 33.15 " , " 33.15 " , " 0 " , " 0 " , " 0 " , " 33.15 " , " 0.80030 " , " 26.53 " , " EUR " , " " ] ,
14
14
[ " Euro-Zone (EUR) " , " 19 " , " 206.89 " , " 206.89 " , " 0 " , " 0 " , " 0 " , " 206.89 " , " 1.00000 " , " 206.89 " , " EUR " , " " ] ,
15
15
[ " Japan (JPY) " , " 2 " , " 179 " , " 179 " , " 0 " , " 0 " , " -37 " , " 142 " , " 0.00817 " , " 1.16 " , " EUR " , " " ] ,
16
+ [ " Americas (USD) " , " 42 " , " 336.78 " , " 336.78 " , " 0 " , " 0 " , " 0 " , " 336.78 " , " 0.91956 " , " 309.69 " , " EUR " , " " ] ,
17
+ [ " Latin America and the Caribbean (USD) " , " 1 " , " 5.09 " , " 5.09 " , " 0 " , " 0 " , " 0 " , " 5.09 " , " 0.91945 " , " 4.68 " , " EUR " , " " ] ,
18
+ [ " Rest of World (USD) " , " 1 " , " 4.95 " , " 4.95 " , " 0 " , " 0 " , " 0 " , " 4.95 " , " 0.91919 " , " 4.55 " , " EUR " , " " ] ,
16
19
[ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ,
17
20
[ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " 234.58 EUR " , " " , " " ] ,
18
21
[ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " Paid to FICTIONAL BANK -****1299 " , " " , " " ] ,
@@ -39,19 +42,15 @@ final class PlutusFinancialReportSlicerTests: XCTestCase {
39
42
let splits = try PlutusFinancialReportSlicer . splitSalesByCorporation ( sales: financialReportsData. sales, dateRange: dateRange, currencyData: currencyData)
40
43
print ( splits)
41
44
42
- XCTAssertEqual ( splits. count, 2 )
43
- guard splits. count == 2 else { return }
45
+ XCTAssertEqual ( splits. count, 4 )
46
+ guard splits. count == 4 else { return }
44
47
45
- let jpCorp = splits. first ( where: { $0. recipient. adress. contains ( " Japan " ) } ) !
46
- let euCorp = splits. first ( where: { $0. recipient. adress. contains ( " Ireland " ) } ) !
47
-
48
- XCTAssertEqual ( jpCorp. recipient, . japan)
49
- XCTAssertEqual ( euCorp. recipient, . europe)
48
+ let jpCorp = splits. first ( where: { $0. recipient == . japan } ) !
49
+ let euCorp = splits. first ( where: { $0. recipient == . europe } ) !
50
50
51
51
XCTAssertEqual ( jpCorp. totalInLocalCurrency, 1.16 , accuracy: 0.000001 )
52
- XCTAssertEqual ( euCorp. totalInLocalCurrency, 233.42 , accuracy: 0.000001 )
52
+ XCTAssertEqual ( euCorp. totalInLocalCurrency, 237.97 , accuracy: 0.000001 )
53
53
54
- // TODO: improve floating points only for 3 digits
55
54
AssertSameCountrySplitting ( jpCorp. countrySplitting, [
56
55
Invoice . SubInvoice ( country: " Japan " , countryCode: " JP " , countryCurrency: " JPY " , invoiceItems: [
57
56
Invoice . InvoiceItem ( quantity: 1 , product: " Example App 3 " , amount: 94.4022346368715 , exchangeRate: 0.008169014084507042 , amountInLocalCurrency: 0.7711731843575418 , dateRange: dateRange) ,
@@ -76,6 +75,9 @@ final class PlutusFinancialReportSlicerTests: XCTestCase {
76
75
Invoice . InvoiceItem ( quantity: 2 , product: " Example App 6 " , amount: 24.34 , exchangeRate: 1.0 , amountInLocalCurrency: 24.34 , dateRange: dateRange) ,
77
76
Invoice . InvoiceItem ( quantity: 15 , product: " Example App 5 " , amount: 158.21 , exchangeRate: 1.0 , amountInLocalCurrency: 158.21 , dateRange: dateRange) ,
78
77
] ) ,
78
+ Invoice . SubInvoice ( country: " Ukraine " , countryCode: " UA " , countryCurrency: " USD - RoW " , invoiceItems: [
79
+ Invoice . InvoiceItem ( quantity: 1 , product: " Example App 5 " , amount: 4.95 , exchangeRate: 0.9191919191919191 , amountInLocalCurrency: 4.55 , dateRange: dateRange) ,
80
+ ] ) ,
79
81
] )
80
82
}
81
83
@@ -94,12 +96,21 @@ final class PlutusFinancialReportSlicerTests: XCTestCase {
94
96
case " JPY " :
95
97
XCTAssertEqual ( data. exchangeRate, 0.008169014084507042253521126761 , accuracy: 0.000001 )
96
98
XCTAssertEqual ( data. taxFactor, 0.7932960893854748603351955307 , accuracy: 0.000001 )
99
+ case " USD " :
100
+ XCTAssertEqual ( data. exchangeRate, 0.9195617316942812 , accuracy: 0.000001 )
101
+ XCTAssertEqual ( data. taxFactor, 1 , accuracy: 0.000001 )
102
+ case " USD - RoW " :
103
+ XCTAssertEqual ( data. exchangeRate, 0.9191919191919191 , accuracy: 0.000001 )
104
+ XCTAssertEqual ( data. taxFactor, 1 , accuracy: 0.000001 )
105
+ case " USD - LatAm " :
106
+ XCTAssertEqual ( data. exchangeRate, 0.91944990176817287 , accuracy: 0.000001 )
107
+ XCTAssertEqual ( data. taxFactor, 1 , accuracy: 0.000001 )
97
108
default :
98
- XCTFail ( )
109
+ XCTFail ( data . currency )
99
110
}
100
111
}
101
112
102
- XCTAssertEqual ( currencyData. count, 3 )
113
+ XCTAssertEqual ( currencyData. count, 6 )
103
114
}
104
115
105
116
func testParseFinancialReports( ) throws {
@@ -131,23 +142,32 @@ final class PlutusFinancialReportSlicerTests: XCTestCase {
131
142
case " FR " :
132
143
AssertSameProductSales ( countrySales. sales, [ ProductSale ( product: " Example App 5 " , quantity: 1 , amount: 12.17 ) ] )
133
144
XCTAssertEqual ( countrySales. currency, " EUR " )
145
+ case " CA " :
146
+ AssertSameProductSales ( countrySales. sales, [ ProductSale ( product: " Example App 5 " , quantity: 1 , amount: 10.2 ) ] )
147
+ XCTAssertEqual ( countrySales. currency, " USD " )
148
+ case " UA " :
149
+ AssertSameProductSales ( countrySales. sales, [ ProductSale ( product: " Example App 5 " , quantity: 1 , amount: 4.95 ) ] )
150
+ XCTAssertEqual ( countrySales. currency, " USD - RoW " )
151
+ case " CR " :
152
+ AssertSameProductSales ( countrySales. sales, [ ProductSale ( product: " Example App 5 " , quantity: 1 , amount: 5.09 ) ] )
153
+ XCTAssertEqual ( countrySales. currency, " USD - LatAm " )
134
154
default :
135
- XCTFail ( )
155
+ XCTFail ( countrySales . countryCode )
136
156
}
137
157
}
138
158
139
- XCTAssertEqual ( financialReportsData. sales. count, 5 )
159
+ XCTAssertEqual ( financialReportsData. sales. count, 8 )
140
160
let dateFormatter = DateFormatter ( )
141
161
dateFormatter. dateFormat = " MM/dd/yyyy "
142
162
XCTAssertEqual ( financialReportsData. dateRange, DateInterval ( start: dateFormatter. date ( from: " 08/31/2014 " ) !, end: dateFormatter. date ( from: " 09/27/2014 " ) !) )
143
163
}
144
164
145
- fileprivate func AssertSameCountrySplitting( _ a: [ Invoice . SubInvoice ] , _ b: [ Invoice . SubInvoice ] ) {
146
- XCTAssertEqual ( Set ( a) , Set ( b) )
165
+ fileprivate func AssertSameCountrySplitting( _ a: [ Invoice . SubInvoice ] , _ b: [ Invoice . SubInvoice ] , file : StaticString = #file , line : UInt = #line ) {
166
+ XCTAssertEqual ( Set ( a) , Set ( b) , file : file , line : line )
147
167
}
148
168
149
- fileprivate func AssertSameProductSales( _ a: [ ProductSale ] , _ b: [ ProductSale ] ) {
150
- XCTAssertEqual ( Set ( a) , Set ( b) )
169
+ fileprivate func AssertSameProductSales( _ a: [ ProductSale ] , _ b: [ ProductSale ] , file : StaticString = #file , line : UInt = #line ) {
170
+ XCTAssertEqual ( Set ( a) , Set ( b) , file : file , line : line )
151
171
}
152
172
153
173
fileprivate func readFile( url: URL ) throws -> String {
0 commit comments