OSDN Git Service

第二艦隊単独出撃でのテストを追加
authormasakih <masakih@users.sourceforge.jp>
Sun, 22 Oct 2017 13:37:21 +0000 (22:37 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 22 Oct 2017 13:37:21 +0000 (22:37 +0900)
KCD.xcodeproj/project.pbxproj
KCDTests/SecondFleetBattleTest.swift [new file with mode: 0644]

index 161acca..c07cf0c 100644 (file)
                F4FC3E961E46AC3000E41228 /* TSVSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FC3E951E46AC3000E41228 /* TSVSupport.swift */; };
                F4FF44C71F98DA6600039F21 /* NormalBattleAPIsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF44C61F98DA6600039F21 /* NormalBattleAPIsTest.swift */; };
                F4FF44C81F98DB1D00039F21 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4EFBCA21E7D439A00DE4A58 /* SwiftyJSON.framework */; };
+               F4FF44CA1F9CB39000039F21 /* SecondFleetBattleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF44C91F9CB39000039F21 /* SecondFleetBattleTest.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                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 /* NormalBattleAPIsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NormalBattleAPIsTest.swift; sourceTree = "<group>"; };
+               F4FF44C91F9CB39000039F21 /* SecondFleetBattleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondFleetBattleTest.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                        children = (
                                F4BDEB6B187252F30069D0CE /* Supporting Files */,
                                F4FF44C61F98DA6600039F21 /* NormalBattleAPIsTest.swift */,
+                               F4FF44C91F9CB39000039F21 /* SecondFleetBattleTest.swift */,
                        );
                        path = KCDTests;
                        sourceTree = "<group>";
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               F4FF44CA1F9CB39000039F21 /* SecondFleetBattleTest.swift in Sources */,
                                F4FF44C71F98DA6600039F21 /* NormalBattleAPIsTest.swift in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
diff --git a/KCDTests/SecondFleetBattleTest.swift b/KCDTests/SecondFleetBattleTest.swift
new file mode 100644 (file)
index 0000000..be4d6bc
--- /dev/null
@@ -0,0 +1,289 @@
+//
+//  SecondFleetBattleTest.swift
+//  KCDTests
+//
+//  Created by Hori,Masaki on 2017/10/22.
+//  Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import XCTest
+
+@testable import KCD
+
+import SwiftyJSON
+
+class SecondFleetBattleTest: XCTestCase {
+    
+    var savedShips: [Ship] = []
+    var shipsHp: [Int] = []
+    var shipEquipments: [NSOrderedSet] = []
+    var shipExSlot: [Int] = []
+    
+    let deckId = 2
+    
+    override func setUp() {
+        
+        super.setUp()
+        
+        savedShips = []
+        shipsHp = []
+        shipEquipments = []
+        shipExSlot = []
+        
+        // 艦隊を設定
+        do {
+            let store = ServerDataStore.oneTimeEditor()
+            
+            guard let secondFleet = store.deck(by: 2) else { return XCTFail("Can not get Deck.") }
+            (0...5).forEach { secondFleet.setShip(id: $0 + 10, for: $0) }
+            
+            guard let deck = store.deck(by: deckId) else { return XCTFail("Can not get Deck.") }
+            (0...5).forEach { deck.setShip(id: $0 + 1, for: $0) }
+            
+            store.ships(byDeckId: deckId).forEach {
+                $0.nowhp = $0.maxhp
+                
+                savedShips += [$0]
+                shipsHp += [$0.nowhp]
+                shipEquipments += [$0.equippedItem]
+                shipExSlot += [$0.slot_ex]
+            }
+        }
+        
+        // 出撃艦隊を設定
+        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": "\(deckId)",
+                "api_maparea_id": "1",
+                "api_mapinfo_no": "1"
+            ]
+            let param = Parameter(paramValue)
+            XCTAssertEqual(param["api_deck_id"].string, "\(deckId)")
+            
+            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)
+            XCTAssertEqual(battle?.deckId, deckId)
+        }
+    }
+    
+    override func tearDown() {
+        
+        do {
+            ResetSortie().reset()
+        }
+        
+        do {
+            let store = TemporaryDataStore.default
+            let battle = store.battle()
+            XCTAssertNil(battle)
+        }
+        
+        do {
+            let store = ServerDataStore.oneTimeEditor()
+            
+            let ships = store.ships(byDeckId: deckId)
+            
+            zip(ships, shipsHp).forEach { $0.nowhp = $1 }
+            zip(ships, shipEquipments).forEach { $0.equippedItem = $1 }
+            zip(ships, shipExSlot).forEach { $0.slot_ex = $1 }
+            
+            guard let deck = store.deck(by: deckId) else { return XCTFail("Can not get Deck.") }
+            savedShips.enumerated().forEach { deck.setShip(id: $0.element.id, for: $0.offset) }
+        }
+        super.tearDown()
+    }
+    
+    func testNormalBattle() {
+        
+        // 戦闘(昼戦)
+        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()
+        }
+        
+        // 戦闘(夜戦)
+        do {
+            let rawValue: [String: Any] = [
+                "api_result": 1,
+                "api_data": [
+                    "api_hougeki": [
+                        "api_df_list": [
+                            -1,
+                            [5]
+                        ],
+                        "api_damage": [
+                            -1,
+                            [5]
+                        ]
+                    ]
+                ]
+            ]
+            guard let json = JSON(rawValue: rawValue) else { return XCTFail("json is nil") }
+            let param = Parameter(["Test": "Test"])
+            let api = APIResponse(api: BattleAPI.midnightBattle.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: deckId)
+            
+            XCTAssertEqual(ships.count, 6)
+            
+            XCTAssertEqual(ships[0].nowhp, shipsHp[0] - 3)
+            XCTAssertEqual(ships[1].nowhp, shipsHp[1] - 3)
+            XCTAssertEqual(ships[2].nowhp, shipsHp[2] - 1)
+            XCTAssertEqual(ships[3].nowhp, shipsHp[3] - 1)
+            XCTAssertEqual(ships[4].nowhp, shipsHp[4] - 5)
+            XCTAssertEqual(ships[5].nowhp, shipsHp[5])
+        }
+    }
+    
+    func testDamageControl() {
+        
+        // ダメコンを設定
+        do {
+            let store = ServerDataStore.oneTimeEditor()
+            
+            store.ship(by: 5).flatMap {
+                $0.nowhp = $0.maxhp
+                $0.slot_ex = 63765  // 女神
+            }
+            store.ship(by: 6).flatMap {
+                $0.nowhp = $0.maxhp
+                // ダメコン
+                $0.equippedItem = store.slotItem(by: 72418).map { NSOrderedSet(array: [$0]) } ?? []
+            }
+        }
+        
+        // 戦闘(夜戦)
+        do {
+            let rawValue: [String: Any] = [
+                "api_result": 1,
+                "api_data": [
+                    "api_hougeki": [
+                        "api_df_list": [
+                            -1,
+                            [4],
+                            [5],
+                            [6]
+                        ],
+                        "api_damage": [
+                            -1,
+                            [50],
+                            [50],
+                            [50]
+                        ]
+                    ]
+                ]
+            ]
+            guard let json = JSON(rawValue: rawValue) else { return XCTFail("json is nil") }
+            let param = Parameter(["Test": "Test"])
+            let api = APIResponse(api: BattleAPI.midnightBattle.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: deckId)
+            
+            XCTAssertEqual(ships.count, 6)
+            
+            XCTAssertEqual(ships[0].nowhp, shipsHp[0])
+            XCTAssertEqual(ships[1].nowhp, shipsHp[1])
+            XCTAssertEqual(ships[2].nowhp, shipsHp[2])
+            XCTAssertEqual(ships[3].nowhp, 0)
+            XCTAssertEqual(ships[4].nowhp, shipsHp[4])
+            XCTAssertEqual(ships[5].nowhp, Int(Double(shipsHp[5]) * 0.2))
+        }
+    }
+}