From 9d85ebc9171c9dfbc1fab569162279d931bb864c Mon Sep 17 00:00:00 2001 From: V P Date: Tue, 4 Jul 2023 15:17:56 +0200 Subject: [PATCH] tests, project --- .gitignore | 125 +++++++++++++++++++++++++++++++ Quanti test | 2 +- QuantiTests/RocketTests.swift | 125 +++++++++++++++++++++++++++---- QuantiTests/SpaceXAPITests.swift | 34 +++++++-- 4 files changed, 267 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index f7500447..5e300f54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,128 @@ +### OSX ### +# General .DS_Store +.AppleDouble +.LSOverride +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Swift ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ + +# CocoaPods +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# Pods/ +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + +### Xcode ### + +## Xcode 8 and earlier + +### Xcode Patch ### +*.xcodeproj/ +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno +**/xcshareddata/WorkspaceSettings.xcsettings + +# End of https://www.toptal.com/developers/gitignore/api/swift,xcode,Cobjective-c,osx diff --git a/Quanti test b/Quanti test index 5dbbde61..1c1a46e9 160000 --- a/Quanti test +++ b/Quanti test @@ -1 +1 @@ -Subproject commit 5dbbde61f8eaa213dcbc4f953d5f2f6abc038472 +Subproject commit 1c1a46e93ea02a08bf8610a6bb1576a67d32d085 diff --git a/QuantiTests/RocketTests.swift b/QuantiTests/RocketTests.swift index ff59021a..d568458b 100644 --- a/QuantiTests/RocketTests.swift +++ b/QuantiTests/RocketTests.swift @@ -6,6 +6,7 @@ // import XCTest +@testable import Quanti_test final class RocketTests: XCTestCase { @@ -22,20 +23,118 @@ final class RocketTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. } - func testExample() throws { - // UI tests must launch the application that they test. - let app = XCUIApplication() - app.launch() - - // Use XCTAssert and related functions to verify your tests produce the correct results. + func testSingleRocketDecode() throws { + let result = try JSONDecoder().decode([Rocket].self, from: jsonData) + XCTAssert(result.count == 1) } - func testLaunchPerformance() throws { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { - // This measures how long it takes to launch your application. - measure(metrics: [XCTApplicationLaunchMetric()]) { - XCUIApplication().launch() +} + + +let jsonData = """ +[ + { + "id": 1, + "active": false, + "stages": 2, + "boosters": 0, + "cost_per_launch": 6700000, + "success_rate_pct": 40, + "first_flight": "2006-03-24", + "country": "Republic of the Marshall Islands", + "company": "SpaceX", + "height": { + "meters": 22.25, + "feet": 73 + }, + "diameter": { + "meters": 1.68, + "feet": 5.5 + }, + "mass": { + "kg": 30146, + "lb": 66460 + }, + "payload_weights": [ + { + "id": "leo", + "name": "Low Earth Orbit", + "kg": 450, + "lb": 992 } - } + ], + "first_stage": { + "reusable": false, + "engines": 1, + "fuel_amount_tons": 44.3, + "burn_time_sec": 169, + "thrust_sea_level": { + "kN": 420, + "lbf": 94000 + }, + "thrust_vacuum": { + "kN": 480, + "lbf": 110000 + } + }, + "second_stage": { + "reusable": false, + "engines": 1, + "fuel_amount_tons": 3.38, + "burn_time_sec": 378, + "thrust": { + "kN": 31, + "lbf": 7000 + }, + "payloads": { + "option_1": "composite fairing", + "composite_fairing": { + "height": { + "meters": 3.5, + "feet": 11.5 + }, + "diameter": { + "meters": 1.5, + "feet": 4.9 + } + } + } + }, + "engines": { + "number": 1, + "type": "merlin", + "version": "1C", + "layout": "single", + "isp": { + "sea_level": 267, + "vacuum": 304 + }, + "engine_loss_max": 0, + "propellant_1": "liquid oxygen", + "propellant_2": "RP-1 kerosene", + "thrust_sea_level": { + "kN": 420, + "lbf": 94000 + }, + "thrust_vacuum": { + "kN": 480, + "lbf": 110000 + }, + "thrust_to_weight": 96 + }, + "landing_legs": { + "number": 0, + "material": null + }, + "flickr_images": [ + "https://imgur.com/DaCfMsj.jpg", + "https://imgur.com/azYafd8.jpg" + ], + "wikipedia": "https://en.wikipedia.org/wiki/Falcon_1", + "description": "The Falcon 1 was an expendable launch system privately developed and manufactured by SpaceX during 2006-2009. On 28 September 2008, Falcon 1 became the first privately-developed liquid-fuel launch vehicle to go into orbit around the Earth.", + "rocket_id": "falcon1", + "rocket_name": "Falcon 1", + "rocket_type": "rocket" } -} +] +""".data(using: .utf8)! diff --git a/QuantiTests/SpaceXAPITests.swift b/QuantiTests/SpaceXAPITests.swift index f1c57a72..c319008a 100644 --- a/QuantiTests/SpaceXAPITests.swift +++ b/QuantiTests/SpaceXAPITests.swift @@ -6,9 +6,13 @@ // import XCTest +@testable import Quanti_test +import Combine final class SpaceXAPITests: XCTestCase { + var cancellables = Set() + override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. } @@ -17,19 +21,39 @@ final class SpaceXAPITests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. } - func testExample() throws { + func testExample() async { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. // Any test you write for XCTest can be annotated as throws and async. // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + + + let api = SpaceXAPI() + let expectation = self.expectation(description: "Result") + let expectationFinished = self.expectation(description: "Finished") + api.getAllRockets().sink { completed in + switch completed { + case .failure(let error): + XCTFail("api error: \(error)") + case .finished: + expectationFinished.fulfill() + } + } receiveValue: { rockets in + print(rockets) + XCTAssert(rockets.count > 2) + expectation.fulfill() + } + .store(in: &cancellables) + + await waitForExpectations(timeout: 5, handler: nil) + } func testPerformanceExample() throws { - // This is an example of a performance test case. - measure { - // Put the code you want to measure the time of here. - } + } } + +