Mercurial > public > simoleon
comparison SimoleonTests/SimoleonTests.swift @ 157:8c3bbd640103
Implement Currency Selector
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sat, 28 Aug 2021 11:15:41 +0100 |
parents | 8afba86ab8dd |
children | 0c589138a6f3 |
comparison
equal
deleted
inserted
replaced
156:84137052813d | 157:8c3bbd640103 |
---|---|
1 // | 1 // |
2 // SimoleonTests.swift | 2 // SimoleonTests.swift |
3 // SimoleonTests | 3 // SimoleonTests |
4 // | 4 // |
5 // Created by Dennis Concepción Martín on 08/07/2021. | 5 // Created by Dennis Concepción Martín on 27/8/21. |
6 // | 6 // |
7 | 7 |
8 import XCTest | 8 import XCTest |
9 @testable import Simoleon | 9 @testable import Simoleon |
10 | 10 |
11 class SimoleonTests: XCTestCase { | 11 class SimoleonTests: XCTestCase { |
12 let fileController = FileController() | |
13 | 12 |
14 override func setUpWithError() throws { | 13 override func setUpWithError() throws { |
15 // Put setup code here. This method is called before the invocation of each test method in the class. | 14 // Put setup code here. This method is called before the invocation of each test method in the class. |
16 continueAfterFailure = false | |
17 } | 15 } |
18 | 16 |
19 override func tearDownWithError() throws { | 17 override func tearDownWithError() throws { |
20 // Put teardown code here. This method is called after the invocation of each test method in the class. | 18 // Put teardown code here. This method is called after the invocation of each test method in the class. |
21 } | 19 } |
22 | 20 |
23 func testReadJson() throws { | 21 func testGetAllCurrencies() throws { |
24 let currencyPairsSupported: [String]? = try? fileController.read(json: "CurrencyPairsSupported.json") | 22 // Create test cases |
25 XCTAssertNotNil(currencyPairsSupported, "An error occurred while reading CurrencyPairsSupported.json") | 23 let testCases = [1: ["USD/GBP", "EUR/AED"], 2: ["USD/GBP", "USD/EUR"]] |
24 let expectedResults = [1: ["USD", "EUR"], 2: ["USD"]] | |
26 | 25 |
27 let currencyDetails: [String: CurrencyDetailsModel]? = try? fileController.read(json: "CurrencyDetails.json") | 26 // Test |
28 XCTAssertNotNil(currencyDetails, "An error occurred while reading CurrencyDetails.json") | 27 let currencySelector = CurrencySelector(currencyPair: CurrencyPairModel(baseSymbol: "USD", quoteSymbol: "EUR")) |
28 for testCaseNumber in testCases.keys { | |
29 print("Testing case: \(testCaseNumber)") | |
30 let mockData = testCases[testCaseNumber]! | |
31 let allCurrencies = currencySelector.get(currencyType: .all, from: mockData) | |
32 | |
33 // Assert | |
34 XCTAssertEqual(allCurrencies, expectedResults[testCaseNumber]) | |
35 } | |
29 } | 36 } |
30 | 37 |
31 func testCurrencyExistence() throws { | 38 func testGetCompatibleCurrencies() throws { |
32 let currencyDetails: [String: CurrencyDetailsModel] = try! fileController.read(json: "CurrencyDetails.json") | 39 // Create test cases |
40 let testCases = [1: ["USD/GBP", "EUR/AED"], 2: ["USD/GBP", "USD/EUR"], 3: ["EUR/AED"]] | |
41 let expectedResults = [1: ["GBP"], 2: ["GBP", "EUR"], 3: []] | |
33 | 42 |
34 // Remove duplicates from currency pairs supported | 43 // Test |
35 let currencyPairsSupported: [String] = try! fileController.read(json: "CurrencyPairsSupported.json") | 44 let currencySelector = CurrencySelector(currencyPair: CurrencyPairModel(baseSymbol: "USD", quoteSymbol: "EUR")) |
36 var currenciesSupported = Set<String>() | 45 for testCaseNumber in testCases.keys { |
37 | 46 print("Testing case: \(testCaseNumber)") |
38 for currencyPairSupported in currencyPairsSupported { | 47 let mockData = testCases[testCaseNumber]! |
39 let symbols = currencyPairSupported.components(separatedBy: "/") | 48 let compatibleCurrencies = |
40 for symbol in symbols { | 49 currencySelector.get( |
41 currenciesSupported.insert(symbol) | 50 currencyType: .compatible(with: currencySelector.currencyPair.baseSymbol), from: mockData |
42 XCTAssertNotNil(currencyDetails[symbol], "Currency details of symbol: \(symbol) can't be found") | 51 ) |
43 XCTAssertTrue((UIImage(named: currencyDetails[symbol]!.flag) != nil), "Flag of symbol: \(symbol) can't be found") | 52 |
44 } | 53 // Assert |
54 XCTAssertEqual(compatibleCurrencies, expectedResults[testCaseNumber]) | |
45 } | 55 } |
46 | |
47 // Check if there are same number of currencies | |
48 XCTAssertEqual(currencyDetails.keys.count, currenciesSupported.count) | |
49 } | 56 } |
50 | 57 |
51 func testPerformanceExample() throws { | 58 func testPerformanceExample() throws { |
52 // This is an example of a performance test case. | 59 // This is an example of a performance test case. |
53 self.measure { | 60 measure { |
54 // Put the code you want to measure the time of here. | 61 // Put the code you want to measure the time of here. |
55 } | 62 } |
56 } | 63 } |
64 | |
57 } | 65 } |