From fb741b32be75f4ac82334722e8173b28d3ea227f Mon Sep 17 00:00:00 2001 From: Oliver Jones Date: Mon, 9 Mar 2020 13:40:24 +1100 Subject: [PATCH] Add a simple unit test to project This test has no relevance to the actual app built as the app has no functionality. --- .../Example-iOS.xcodeproj/project.pbxproj | 16 ++-- .../xcschemes/Example-iOS.xcscheme | 89 +++++++++++++++++++ Example-iOS/Example-iOS/Fibonacci.swift | 12 +++ .../Example-iOSTests/Example_iOSTests.swift | 34 ------- .../Example-iOSTests/FibonacciTests.swift | 27 ++++++ 5 files changed, 138 insertions(+), 40 deletions(-) create mode 100644 Example-iOS/Example-iOS.xcodeproj/xcshareddata/xcschemes/Example-iOS.xcscheme create mode 100644 Example-iOS/Example-iOS/Fibonacci.swift delete mode 100644 Example-iOS/Example-iOSTests/Example_iOSTests.swift create mode 100644 Example-iOS/Example-iOSTests/FibonacciTests.swift diff --git a/Example-iOS/Example-iOS.xcodeproj/project.pbxproj b/Example-iOS/Example-iOS.xcodeproj/project.pbxproj index 3b77aed..973d6f8 100644 --- a/Example-iOS/Example-iOS.xcodeproj/project.pbxproj +++ b/Example-iOS/Example-iOS.xcodeproj/project.pbxproj @@ -13,7 +13,8 @@ A731AC8B23E01F830090DE52 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A731AC8923E01F830090DE52 /* Main.storyboard */; }; A731AC8D23E01F850090DE52 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A731AC8C23E01F850090DE52 /* Assets.xcassets */; }; A731AC9023E01F850090DE52 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A731AC8E23E01F850090DE52 /* LaunchScreen.storyboard */; }; - A731AC9B23E01F850090DE52 /* Example_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A731AC9A23E01F850090DE52 /* Example_iOSTests.swift */; }; + A731AC9B23E01F850090DE52 /* FibonacciTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A731AC9A23E01F850090DE52 /* FibonacciTests.swift */; }; + A7FEE32D241205E100B8F42D /* Fibonacci.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7FEE32C241205E100B8F42D /* Fibonacci.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -36,8 +37,9 @@ A731AC8F23E01F850090DE52 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; A731AC9123E01F850090DE52 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A731AC9623E01F850090DE52 /* Example-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Example-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - A731AC9A23E01F850090DE52 /* Example_iOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Example_iOSTests.swift; sourceTree = ""; }; + A731AC9A23E01F850090DE52 /* FibonacciTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FibonacciTests.swift; sourceTree = ""; }; A731AC9C23E01F850090DE52 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + A7FEE32C241205E100B8F42D /* Fibonacci.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fibonacci.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -86,6 +88,7 @@ A731AC8C23E01F850090DE52 /* Assets.xcassets */, A731AC8E23E01F850090DE52 /* LaunchScreen.storyboard */, A731AC9123E01F850090DE52 /* Info.plist */, + A7FEE32C241205E100B8F42D /* Fibonacci.swift */, ); path = "Example-iOS"; sourceTree = ""; @@ -93,7 +96,7 @@ A731AC9923E01F850090DE52 /* Example-iOSTests */ = { isa = PBXGroup; children = ( - A731AC9A23E01F850090DE52 /* Example_iOSTests.swift */, + A731AC9A23E01F850090DE52 /* FibonacciTests.swift */, A731AC9C23E01F850090DE52 /* Info.plist */, ); path = "Example-iOSTests"; @@ -200,6 +203,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A7FEE32D241205E100B8F42D /* Fibonacci.swift in Sources */, A731AC8823E01F830090DE52 /* ViewController.swift in Sources */, A731AC8423E01F830090DE52 /* AppDelegate.swift in Sources */, A731AC8623E01F830090DE52 /* SceneDelegate.swift in Sources */, @@ -210,7 +214,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - A731AC9B23E01F850090DE52 /* Example_iOSTests.swift in Sources */, + A731AC9B23E01F850090DE52 /* FibonacciTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -401,7 +405,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ER9FN723RR; - INFOPLIST_FILE = "Example iOSTests/Info.plist"; + INFOPLIST_FILE = "Example-iOSTests/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 13.2; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -423,7 +427,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ER9FN723RR; - INFOPLIST_FILE = "Example iOSTests/Info.plist"; + INFOPLIST_FILE = "Example-iOSTests/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 13.2; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/Example-iOS/Example-iOS.xcodeproj/xcshareddata/xcschemes/Example-iOS.xcscheme b/Example-iOS/Example-iOS.xcodeproj/xcshareddata/xcschemes/Example-iOS.xcscheme new file mode 100644 index 0000000..d5f5b12 --- /dev/null +++ b/Example-iOS/Example-iOS.xcodeproj/xcshareddata/xcschemes/Example-iOS.xcscheme @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example-iOS/Example-iOS/Fibonacci.swift b/Example-iOS/Example-iOS/Fibonacci.swift new file mode 100644 index 0000000..8aacdfe --- /dev/null +++ b/Example-iOS/Example-iOS/Fibonacci.swift @@ -0,0 +1,12 @@ +// Copyright © 2020 Oliver Jones. All rights reserved. +// + +import Foundation + +func fibonacci(_ n: Int) -> Int { + guard n > 1 else { + return (n == 0 ? 0 : 1) + } + + return fibonacci(n-1) + fibonacci(n-2) +} diff --git a/Example-iOS/Example-iOSTests/Example_iOSTests.swift b/Example-iOS/Example-iOSTests/Example_iOSTests.swift deleted file mode 100644 index 940160f..0000000 --- a/Example-iOS/Example-iOSTests/Example_iOSTests.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// Example_iOSTests.swift -// Example iOSTests -// -// Created by Oliver Jones on 28/1/20. -// Copyright © 2020 Oliver Jones. All rights reserved. -// - -import XCTest -@testable import Example_iOS - -class Example_iOSTests: XCTestCase { - - override func setUp() { - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. - } - } - -} diff --git a/Example-iOS/Example-iOSTests/FibonacciTests.swift b/Example-iOS/Example-iOSTests/FibonacciTests.swift new file mode 100644 index 0000000..db2ceaf --- /dev/null +++ b/Example-iOS/Example-iOSTests/FibonacciTests.swift @@ -0,0 +1,27 @@ +// +// Example_iOSTests.swift +// Example iOSTests +// +// Created by Oliver Jones on 28/1/20. +// Copyright © 2020 Oliver Jones. All rights reserved. +// + +import XCTest +@testable import Example_iOS + +class FibonacciTests: XCTestCase { + + func testFibonacci() { + XCTAssertEqual(0, fibonacci(0)) + XCTAssertEqual(1, fibonacci(1)) + XCTAssertEqual(1, fibonacci(2)) + XCTAssertEqual(2, fibonacci(3)) + XCTAssertEqual(3, fibonacci(4)) + XCTAssertEqual(5, fibonacci(5)) + XCTAssertEqual(8, fibonacci(6)) + XCTAssertEqual(13, fibonacci(7)) + XCTAssertEqual(21, fibonacci(8)) + XCTAssertEqual(34, fibonacci(9)) + XCTAssertEqual(55, fibonacci(10)) + } +}