F42185111DF461A600256590 /* ScreenshotTouchBar.xib in Resources */ = {isa = PBXBuildFile; fileRef = F42185101DF461A600256590 /* ScreenshotTouchBar.xib */; };
F422D64C1FED474100183199 /* EnhancementListItemDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F422D64B1FED474100183199 /* EnhancementListItemDownloader.swift */; };
F422D64E1FEE14D500183199 /* ViewAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F422D64D1FEE14D500183199 /* ViewAnimation.swift */; };
+ F422D6521FEF584100183199 /* SakutekiTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F422D6511FEF584100183199 /* SakutekiTest.swift */; };
F42539E21EB4A7950083EB9D /* AirPlanInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42539E11EB4A7950083EB9D /* AirPlanInfoView.swift */; };
F42546921EF8002E00BE297E /* EquitType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42546911EF8002E00BE297E /* EquitType.swift */; };
F42546931EFBE0D300BE297E /* EquitType.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42546911EF8002E00BE297E /* EquitType.swift */; };
F42185101DF461A600256590 /* ScreenshotTouchBar.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ScreenshotTouchBar.xib; sourceTree = "<group>"; };
F422D64B1FED474100183199 /* EnhancementListItemDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnhancementListItemDownloader.swift; sourceTree = "<group>"; };
F422D64D1FEE14D500183199 /* ViewAnimation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewAnimation.swift; sourceTree = "<group>"; };
+ F422D6511FEF584100183199 /* SakutekiTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SakutekiTest.swift; sourceTree = "<group>"; };
F42539E11EB4A7950083EB9D /* AirPlanInfoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AirPlanInfoView.swift; sourceTree = "<group>"; };
F42546911EF8002E00BE297E /* EquitType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EquitType.swift; sourceTree = "<group>"; };
F429FAAD1F619927006299ED /* TPValueCalculator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TPValueCalculator.swift; sourceTree = "<group>"; };
F4CB371C1FCC5FCC0086999C /* CombinedBattleTest.swift */,
F4FF44CB1F9E41F600039F21 /* ShipStatusTest.swift */,
F4CB37281FD3C1A00086999C /* GuardEscapeTest.swift */,
+ F422D6511FEF584100183199 /* SakutekiTest.swift */,
);
path = KCDTests;
sourceTree = "<group>";
files = (
F4CB37291FD3C1A00086999C /* GuardEscapeTest.swift in Sources */,
F4CB371D1FCC5FCC0086999C /* CombinedBattleTest.swift in Sources */,
+ F422D6521FEF584100183199 /* SakutekiTest.swift in Sources */,
F4FF44C71F98DA6600039F21 /* NormalBattleTest.swift in Sources */,
F4FF44CC1F9E41F600039F21 /* ShipStatusTest.swift in Sources */,
);
--- /dev/null
+//
+// SakutekiTest.swift
+// KCDTests
+//
+// Created by Hori,Masaki on 2017/12/24.
+// Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import XCTest
+
+@testable import KCD
+
+class SakutekiTest: XCTestCase {
+
+ let store = ServerDataStore.oneTimeEditor()
+
+ override func setUp() {
+ super.setUp()
+
+ // 千歳航改二
+ // 天山一二型(村田隊), 流星(六○一空),彩雲(東カロリン空),零式艦戦53型(岩本隊)
+ // Bofors 40mm四連装機関砲
+ setupShip(id: 228, slotItems: [36_082, 28_114, 67_268, 17_930], exSlot: 51_387, saku0: 108)
+
+ // 熊野改二
+ // 紫雲, 零式水上偵察機11型乙, 強風改, 二式水戦改
+ // なし
+ setupShip(id: 4_184, slotItems: [65_505, 72_413, 70_952, 69_442], exSlot: 0, saku0: 110)
+
+ // 筑摩改二
+ // 二式水戦改, 32号対水上電探+8, FuMO25レーダー, 零式水上観測機+6
+ // なし
+ setupShip(id: 220, slotItems: [47_272, 26_065, 61_168, 13_621], exSlot: 0, saku0: 130)
+
+
+ let tempStore = TemporaryDataStore.oneTimeEditor()
+ tempStore.guardEscaped().forEach(tempStore.delete)
+
+ }
+
+ override func tearDown() {
+
+ let store = TemporaryDataStore.oneTimeEditor()
+ store.guardEscaped().forEach(store.delete)
+ super.tearDown()
+ }
+
+ func setupShip(id shipId: Int, slotItems: [Int], exSlot: Int, saku0: Int) {
+
+ guard let ship = store.ship(by: shipId) else {
+ XCTFail("Can not get ship, \(shipId)")
+ fatalError()
+ }
+ ship.onslot_0 = ship.master_ship.maxeq_0
+ ship.onslot_1 = ship.master_ship.maxeq_1
+ ship.onslot_2 = ship.master_ship.maxeq_2
+ ship.onslot_3 = ship.master_ship.maxeq_3
+ ship.onslot_4 = ship.master_ship.maxeq_4
+
+ setSlot(slotItems: slotItems, to: ship)
+
+ ship.slot_ex = exSlot
+ ship.extraItem = store.slotItem(by: ship.slot_ex)
+
+ ship.sakuteki_0 = saku0
+
+ }
+
+ func setSlot(slotItems: [Int], to ship: Ship) {
+
+ let newItems: [SlotItem] = slotItems
+ .filter { $0 != 0 && $0 != -1 }
+ .flatMap { store.slotItem(by: $0) }
+ ship.equippedItem = NSOrderedSet(array: newItems)
+
+ slotItems.enumerated().forEach { offset, element in
+ ship.setItem(element, to: offset)
+ }
+ }
+
+ // 小数点第2位以下切り捨て
+ func fitSakuteki(_ sakuteki: Double) -> Double {
+
+ return Double(Int(sakuteki * 10)) / 10
+ }
+
+ func testOneShip() {
+
+ // 千歳航改二
+ guard let ship = store.ship(by: 228) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+
+ XCTAssertEqual(SimpleCalculator().calculate([ship]), 108)
+
+ XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship])), -11.2)
+ XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship])), 127.9)
+ XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship])), 249.7)
+ }
+
+ func testOne2Ship() {
+
+ // 熊野改二
+ guard let ship = store.ship(by: 4_184) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+
+ XCTAssertEqual(SimpleCalculator().calculate([ship]), 110)
+
+ XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship])), -10.3)
+ XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship])), 133.6)
+ XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship])), 259.6)
+ }
+
+ func testTwoShips() {
+
+ // 千歳航改二
+ guard let ship1 = store.ship(by: 228) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+ // 熊野改二
+ guard let ship2 = store.ship(by: 4_184) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+
+ XCTAssertEqual(SimpleCalculator().calculate([ship1, ship2]), 218)
+
+ XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship1, ship2])), 14.4)
+ XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship1, ship2])), 297.6)
+ XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship1, ship2])), 545.4)
+ }
+
+ func testTreeShips() {
+
+ // 千歳航改二
+ guard let ship1 = store.ship(by: 228) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+ // 熊野改二
+ guard let ship2 = store.ship(by: 4_184) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+ // 筑摩改二
+ guard let ship3 = store.ship(by: 220) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+
+ XCTAssertEqual(SimpleCalculator().calculate([ship1, ship2, ship3]), 348)
+
+ XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship1, ship2, ship3])), 47.7)
+ XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship1, ship2, ship3])), 531.8)
+ XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship1, ship2, ship3])), 955.3)
+ }
+
+ func testEscapedShips() {
+
+ // 千歳航改二
+ guard let ship1 = store.ship(by: 228) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+ // 熊野改二
+ guard let ship2 = store.ship(by: 4_184) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+ // 筑摩改二
+ guard let ship3 = store.ship(by: 220) else {
+ XCTFail("Can not get ship")
+ fatalError()
+ }
+
+ // 熊野改二を退避
+ do {
+ let tempStore = TemporaryDataStore.oneTimeEditor()
+ let guardEscape = tempStore.createGuardEscaped()
+ guardEscape?.shipID = 4_184
+ guardEscape?.ensured = true
+ }
+
+ XCTAssertEqual(SimpleCalculator().calculate([ship1, ship2, ship3]), 238)
+
+ XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship1, ship2, ship3])), 22.0)
+ XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship1, ship2, ship3])), 362.1)
+ XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship1, ship2, ship3])), 659.6)
+ }
+}