comparison SimoleonTests/SimoleonTests.swift @ 153:2590ee472aa9

Add test to check currency existence
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Mon, 23 Aug 2021 17:14:47 +0100
parents bdedd0cc6cd1
children 8afba86ab8dd
comparison
equal deleted inserted replaced
152:2584fd74235a 153:2590ee472aa9
10 10
11 class SimoleonTests: XCTestCase { 11 class SimoleonTests: XCTestCase {
12 12
13 override func setUpWithError() throws { 13 override func setUpWithError() throws {
14 // 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.
15 continueAfterFailure = false
15 } 16 }
16 17
17 override func tearDownWithError() throws { 18 override func tearDownWithError() throws {
18 // Put teardown code here. This method is called after the invocation of each test method in the class. 19 // Put teardown code here. This method is called after the invocation of each test method in the class.
19 } 20 }
20 21
21 func testReadJson() throws { 22 func testReadJson() throws {
22 let currencyPairs: [CurrencyPairModel]? = try? read(json: "CurrencyPairs.json") 23 let currencyPairsSupported: [String]? = try? read(json: "CurrencyPairsSupported.json")
23 XCTAssertNotNil(currencyPairs) 24 XCTAssertNotNil(currencyPairsSupported, "An error occurred while reading CurrencyPairsSupported.json")
24 25
25 let currencyMetadata: [String: CurrencyMetadataModel]? = try? read(json: "CurrencyMetadata.json") 26 let currencyDetails: [String: CurrencyDetailsModel]? = try? read(json: "CurrencyDetails.json")
26 XCTAssertNotNil(currencyMetadata) 27 XCTAssertNotNil(currencyDetails, "An error occurred while reading CurrencyDetails.json")
27 } 28 }
28 29
29 func testFlagsExistence() throws { 30 func testCurrencyExistence() throws {
30 let currencyMetadata: [String: CurrencyMetadataModel]! = try! read(json: "CurrencyMetadata.json") 31 let currencyDetails: [String: CurrencyDetailsModel] = try! read(json: "CurrencyDetails.json")
31 32
32 for currencySymbol in currencyMetadata.keys { 33 // Remove duplicates from currency pairs supported
33 let flag = currencyMetadata[currencySymbol]!.flag 34 let currencyPairsSupported: [String] = try! read(json: "CurrencyPairsSupported.json")
34 XCTAssertTrue((UIImage(named: flag) != nil)) 35 var currenciesSupported = Set<String>()
36
37 for currencyPairSupported in currencyPairsSupported {
38 let symbols = currencyPairSupported.components(separatedBy: "/")
39 for symbol in symbols {
40 currenciesSupported.insert(symbol)
41 XCTAssertNotNil(currencyDetails[symbol], "Currency details of symbol: \(symbol) can't be found")
42 XCTAssertTrue((UIImage(named: currencyDetails[symbol]!.flag) != nil), "Flag of symbol: \(symbol) can't be found")
43 }
35 } 44 }
45
46 // Check if there are same number of currencies
47 XCTAssertEqual(currencyDetails.keys.count, currenciesSupported.count)
36 } 48 }
37 49
38 func testPerformanceExample() throws { 50 func testPerformanceExample() throws {
39 // This is an example of a performance test case. 51 // This is an example of a performance test case.
40 self.measure { 52 self.measure {