diff 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
line wrap: on
line diff
--- a/SimoleonTests/SimoleonTests.swift	Sat Aug 28 11:15:25 2021 +0100
+++ b/SimoleonTests/SimoleonTests.swift	Sat Aug 28 11:15:41 2021 +0100
@@ -2,56 +2,64 @@
 //  SimoleonTests.swift
 //  SimoleonTests
 //
-//  Created by Dennis Concepción Martín on 08/07/2021.
+//  Created by Dennis Concepción Martín on 27/8/21.
 //
 
 import XCTest
 @testable import Simoleon
 
 class SimoleonTests: XCTestCase {
-    let fileController = FileController()
 
     override func setUpWithError() throws {
         // Put setup code here. This method is called before the invocation of each test method in the class.
-        continueAfterFailure = false
     }
 
     override func tearDownWithError() throws {
         // Put teardown code here. This method is called after the invocation of each test method in the class.
     }
     
-    func testReadJson() throws {
-        let currencyPairsSupported: [String]? = try? fileController.read(json: "CurrencyPairsSupported.json")
-        XCTAssertNotNil(currencyPairsSupported, "An error occurred while reading CurrencyPairsSupported.json")
+    func testGetAllCurrencies() throws {
+        // Create test cases
+        let testCases = [1: ["USD/GBP", "EUR/AED"], 2: ["USD/GBP", "USD/EUR"]]
+        let expectedResults = [1: ["USD", "EUR"], 2: ["USD"]]
         
-        let currencyDetails: [String: CurrencyDetailsModel]? = try? fileController.read(json: "CurrencyDetails.json")
-        XCTAssertNotNil(currencyDetails, "An error occurred while reading CurrencyDetails.json")
+        // Test
+        let currencySelector = CurrencySelector(currencyPair: CurrencyPairModel(baseSymbol: "USD", quoteSymbol: "EUR"))
+        for testCaseNumber in testCases.keys {
+            print("Testing case: \(testCaseNumber)")
+            let mockData = testCases[testCaseNumber]!
+            let allCurrencies = currencySelector.get(currencyType: .all, from: mockData)
+            
+            // Assert
+            XCTAssertEqual(allCurrencies, expectedResults[testCaseNumber])
+        }
     }
     
-    func testCurrencyExistence() throws {
-        let currencyDetails: [String: CurrencyDetailsModel] = try! fileController.read(json: "CurrencyDetails.json")
-        
-        // Remove duplicates from currency pairs supported
-        let currencyPairsSupported: [String] = try! fileController.read(json: "CurrencyPairsSupported.json")
-        var currenciesSupported = Set<String>()
+    func testGetCompatibleCurrencies() throws {
+        // Create test cases
+        let testCases = [1: ["USD/GBP", "EUR/AED"], 2: ["USD/GBP", "USD/EUR"], 3: ["EUR/AED"]]
+        let expectedResults = [1: ["GBP"], 2: ["GBP", "EUR"], 3: []]
         
-        for currencyPairSupported in currencyPairsSupported {
-            let symbols = currencyPairSupported.components(separatedBy: "/")
-            for symbol in symbols {
-                currenciesSupported.insert(symbol)
-                XCTAssertNotNil(currencyDetails[symbol], "Currency details of symbol: \(symbol) can't be found")
-                XCTAssertTrue((UIImage(named: currencyDetails[symbol]!.flag) != nil), "Flag of symbol: \(symbol) can't be found")
-            }
+        // Test
+        let currencySelector = CurrencySelector(currencyPair: CurrencyPairModel(baseSymbol: "USD", quoteSymbol: "EUR"))
+        for testCaseNumber in testCases.keys {
+            print("Testing case: \(testCaseNumber)")
+            let mockData = testCases[testCaseNumber]!
+            let compatibleCurrencies =
+                currencySelector.get(
+                    currencyType: .compatible(with: currencySelector.currencyPair.baseSymbol), from: mockData
+                )
+            
+            // Assert
+            XCTAssertEqual(compatibleCurrencies, expectedResults[testCaseNumber])
         }
-        
-        // Check if there are same number of currencies
-        XCTAssertEqual(currencyDetails.keys.count, currenciesSupported.count)
     }
 
     func testPerformanceExample() throws {
         // This is an example of a performance test case.
-        self.measure {
+        measure {
             // Put the code you want to measure the time of here.
         }
     }
+
 }