OSDN Git Service

通常戦闘の昼戦の被ダメ計算のテストを追加
authormasakih <masakih@users.sourceforge.jp>
Fri, 20 Oct 2017 14:47:12 +0000 (23:47 +0900)
committermasakih <masakih@users.sourceforge.jp>
Fri, 20 Oct 2017 14:47:12 +0000 (23:47 +0900)
KCD.xcodeproj/project.pbxproj
KCDTests/BattleAPIsTest.swift [new file with mode: 0644]

index a7a0437..749d5f4 100644 (file)
                F4FC3E901E437E1F00E41228 /* JSONReciever.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FC3E8F1E437E1F00E41228 /* JSONReciever.swift */; };
                F4FC3E941E44A5D600E41228 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FC3E931E44A5D600E41228 /* AppDelegate.swift */; };
                F4FC3E961E46AC3000E41228 /* TSVSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FC3E951E46AC3000E41228 /* TSVSupport.swift */; };
+               F4FF44C71F98DA6600039F21 /* BattleAPIsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF44C61F98DA6600039F21 /* BattleAPIsTest.swift */; };
+               F4FF44C81F98DB1D00039F21 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4EFBCA21E7D439A00DE4A58 /* SwiftyJSON.framework */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                F4FC3E8F1E437E1F00E41228 /* JSONReciever.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONReciever.swift; sourceTree = "<group>"; };
                F4FC3E931E44A5D600E41228 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
                F4FC3E951E46AC3000E41228 /* TSVSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSVSupport.swift; sourceTree = "<group>"; };
+               F4FF44C61F98DA6600039F21 /* BattleAPIsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BattleAPIsTest.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                        buildActionMask = 2147483647;
                        files = (
                                F4BDEB67187252F30069D0CE /* Cocoa.framework in Frameworks */,
+                               F4FF44C81F98DB1D00039F21 /* SwiftyJSON.framework in Frameworks */,
                                F4BDEB66187252F30069D0CE /* XCTest.framework in Frameworks */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                        isa = PBXGroup;
                        children = (
                                F4BDEB6B187252F30069D0CE /* Supporting Files */,
+                               F4FF44C61F98DA6600039F21 /* BattleAPIsTest.swift */,
                        );
                        path = KCDTests;
                        sourceTree = "<group>";
                                                LastSwiftMigration = 0900;
                                        };
                                        F4BDEB63187252F30069D0CE = {
+                                               LastSwiftMigration = 0900;
                                                TestTargetID = F4BDEB42187252F30069D0CE;
                                        };
                                        F4C5A2321C37F87500533FB6 = {
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               F4FF44C71F98DA6600039F21 /* BattleAPIsTest.swift in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        buildSettings = {
                                ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
                                BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/KCD.app/Contents/MacOS/KCD";
+                               CLANG_ENABLE_MODULES = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                FRAMEWORK_SEARCH_PATHS = (
                                        "$(DEVELOPER_FRAMEWORKS_DIR)",
                                        "$(inherited)",
+                                       "$(PROJECT_DIR)/Carthage/Build/Mac",
                                );
                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
                                GCC_PREFIX_HEADER = "KCD/KCD-Prefix.pch";
                                        "$(inherited)",
                                );
                                INFOPLIST_FILE = "KCDTests/KCDTests-Info.plist";
+                               LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
                                PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.${PRODUCT_NAME:rfc1034identifier}";
                                PRODUCT_NAME = "$(TARGET_NAME)";
+                               SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+                               SWIFT_VERSION = 3.0;
                                TEST_HOST = "$(BUNDLE_LOADER)";
                                WRAPPER_EXTENSION = xctest;
                        };
                        buildSettings = {
                                ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
                                BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/KCD.app/Contents/MacOS/KCD";
+                               CLANG_ENABLE_MODULES = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                FRAMEWORK_SEARCH_PATHS = (
                                        "$(DEVELOPER_FRAMEWORKS_DIR)",
                                        "$(inherited)",
+                                       "$(PROJECT_DIR)/Carthage/Build/Mac",
                                );
                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
                                GCC_PREFIX_HEADER = "KCD/KCD-Prefix.pch";
                                INFOPLIST_FILE = "KCDTests/KCDTests-Info.plist";
+                               LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
                                PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.${PRODUCT_NAME:rfc1034identifier}";
                                PRODUCT_NAME = "$(TARGET_NAME)";
+                               SWIFT_VERSION = 3.0;
                                TEST_HOST = "$(BUNDLE_LOADER)";
                                WRAPPER_EXTENSION = xctest;
                        };
diff --git a/KCDTests/BattleAPIsTest.swift b/KCDTests/BattleAPIsTest.swift
new file mode 100644 (file)
index 0000000..6242986
--- /dev/null
@@ -0,0 +1,163 @@
+//
+//  BattleAPIsTest.swift
+//  KCDTests
+//
+//  Created by Hori,Masaki on 2017/10/19.
+//  Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import XCTest
+
+@testable import KCD
+
+import SwiftyJSON
+
+class BattleAPIsTest: XCTestCase {
+
+    override func setUp() {
+        super.setUp()
+        // Put setup code here. This method is called before the invocation of each test method in the class.
+        
+    }
+    
+    override func tearDown() {
+        
+        do {
+            ResetSortie().reset()
+        }
+        
+        do {
+            let store = TemporaryDataStore.default
+            let battle = store.battle()
+            XCTAssertNil(battle)
+        }
+        
+        do {
+            let store = ServerDataStore.oneTimeEditor()
+            store.ships(byDeckId: 1).forEach {
+                $0.nowhp = $0.maxhp
+            }
+        }
+        super.tearDown()
+    }
+
+    func testNormalBattle() {
+        
+        // 艦隊を設定
+        do {
+            let store = ServerDataStore.oneTimeEditor()
+            guard let deck = store.deck(by: 1) else { return XCTFail("Can not get Deck.") }
+            (0...5).forEach { deck.setShip(id: $0 + 1, for: $0) }
+            
+            store.ships(byDeckId: 1).forEach {
+                $0.nowhp = $0.maxhp
+            }
+        }
+        
+        // 出撃艦隊を設定
+        do {
+            let rawValue: [String: Any] = [
+                "api_result": 1,
+                "api_data": [
+                    "api_no": 1
+                ]
+            ]
+            guard let json = JSON(rawValue: rawValue) else { return XCTFail("json is nil") }
+            XCTAssertNotNil(json["api_result"])
+            
+            let paramValue: [String: String] = [
+                "api_deck_id": "1",
+                "api_maparea_id": "1",
+                "api_mapinfo_no": "1"
+            ]
+            let param = Parameter(paramValue)
+            XCTAssertEqual(param["api_deck_id"].string, "1")
+            
+            let api = APIResponse(api: MapAPI.start.rawValue, parameter: param, json: json)
+            XCTAssertEqual(api.json, json)
+            XCTAssertEqual(api.parameter, param)
+            
+            let command = MapStartCommand(apiResponse: api)
+            
+            command.execute()
+        }
+        
+        // battleの生成確認
+        do {
+            let store = TemporaryDataStore.default
+            let battle = store.battle()
+            XCTAssertNotNil(battle)
+        }
+        
+        // 戦闘
+        do {
+            let rawValue: [String: Any] = [
+                "api_result": 1,
+                "api_data": [
+                    "api_kouku": [
+                        "api_stage3": [
+                            "api_fdam": [
+                                -1, 3, 0, 0, 0, 0, 0
+                            ]
+                        ]
+                    ],
+                    "api_opening_atack": [
+                        "api_fdam": [
+                            -1, 0, 3, 0, 0, 0, 0
+                        ]
+                    ],
+                    "api_hougeki1": [
+                        "api_df_list": [
+                            -1,
+                            [3, 3]
+                        ],
+                        "api_damage": [
+                            -1,
+                            [0, 1]
+                        ]
+                    ],
+                    "api_raigeki": [
+                        "api_fdam": [
+                            -1, 0, 0, 0, 1, 0, 0
+                        ]
+                    ]
+                ]
+            ]
+            guard let json = JSON(rawValue: rawValue) else { return XCTFail("json is nil") }
+            let param = Parameter(["Test": "Test"])
+            let api = APIResponse(api: BattleAPI.battle.rawValue, parameter: param, json: json)
+            
+            let command = BattleCommand(apiResponse: api)
+            command.execute()
+        }
+        
+        // 艦娘HP更新
+        do {
+            let rawValue: [String: Any] = [
+                "api_result": 1
+            ]
+            guard let json = JSON(rawValue: rawValue) else { return XCTFail("json is nil") }
+            let param = Parameter(["Test": "Test"])
+            let api = APIResponse(api: BattleAPI.battleResult.rawValue, parameter: param, json: json)
+
+            let command = BattleCommand(apiResponse: api)
+            command.execute()
+        }
+        
+        // HPチェック
+        do {
+            let store = ServerDataStore.oneTimeEditor()
+            let ships = store.ships(byDeckId: 1)
+            
+            XCTAssertEqual(ships.count, 6)
+            
+            XCTAssertEqual(ships[0].nowhp, 27)
+            XCTAssertEqual(ships[1].nowhp, 25)
+            XCTAssertEqual(ships[2].nowhp, 29)
+            XCTAssertEqual(ships[3].nowhp, 30)
+            XCTAssertEqual(ships[4].nowhp, 36)
+            XCTAssertEqual(ships[5].nowhp, 30)
+        }
+    }
+
+}