5 // Created by Hori,Masaki on 2017/12/24.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
13 class SakutekiTest: XCTestCase {
15 let store = ServerDataStore.oneTimeEditor()
17 override func setUp() {
21 // 天山一二型(村田隊), 流星(六○一空),彩雲(東カロリン空),零式艦戦53型(岩本隊)
23 setupShip(id: 228, slotItems: [36_082, 28_114, 67_268, 17_930], exSlot: 51_387, saku0: 108)
26 // 紫雲, 零式水上偵察機11型乙, 強風改, 二式水戦改
28 setupShip(id: 4_184, slotItems: [65_505, 72_413, 70_952, 69_442], exSlot: 0, saku0: 110)
31 // 二式水戦改, 32号対水上電探+8, FuMO25レーダー, 零式水上観測機+6
33 setupShip(id: 220, slotItems: [47_272, 26_065, 61_168, 13_621], exSlot: 0, saku0: 130)
36 let tempStore = TemporaryDataStore.oneTimeEditor()
37 tempStore.guardEscaped().forEach(tempStore.delete)
41 override func tearDown() {
43 let store = TemporaryDataStore.oneTimeEditor()
44 store.guardEscaped().forEach(store.delete)
48 func setupShip(id shipId: Int, slotItems: [Int], exSlot: Int, saku0: Int) {
50 guard let ship = store.ship(by: shipId) else {
51 XCTFail("Can not get ship, \(shipId)")
54 ship.onslot_0 = ship.master_ship.maxeq_0
55 ship.onslot_1 = ship.master_ship.maxeq_1
56 ship.onslot_2 = ship.master_ship.maxeq_2
57 ship.onslot_3 = ship.master_ship.maxeq_3
58 ship.onslot_4 = ship.master_ship.maxeq_4
60 setSlot(slotItems: slotItems, to: ship)
63 ship.extraItem = store.slotItem(by: ship.slot_ex)
65 ship.sakuteki_0 = saku0
69 func setSlot(slotItems: [Int], to ship: Ship) {
71 let newItems: [SlotItem] = slotItems
72 .filter { $0 != 0 && $0 != -1 }
73 .flatMap { store.slotItem(by: $0) }
74 ship.equippedItem = NSOrderedSet(array: newItems)
76 slotItems.enumerated().forEach { offset, element in
77 ship.setItem(element, to: offset)
82 func fitSakuteki(_ sakuteki: Double) -> Double {
84 return Double(Int(sakuteki * 10)) / 10
90 guard let ship = store.ship(by: 228) else {
91 XCTFail("Can not get ship")
95 XCTAssertEqual(SimpleCalculator().calculate([ship]), 108)
97 XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship])), -11.2)
98 XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship])), 127.9)
99 XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship])), 249.7)
102 func testOne2Ship() {
105 guard let ship = store.ship(by: 4_184) else {
106 XCTFail("Can not get ship")
110 XCTAssertEqual(SimpleCalculator().calculate([ship]), 110)
112 XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship])), -10.3)
113 XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship])), 133.6)
114 XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship])), 259.6)
117 func testTwoShips() {
120 guard let ship1 = store.ship(by: 228) else {
121 XCTFail("Can not get ship")
125 guard let ship2 = store.ship(by: 4_184) else {
126 XCTFail("Can not get ship")
130 XCTAssertEqual(SimpleCalculator().calculate([ship1, ship2]), 218)
132 XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship1, ship2])), 14.4)
133 XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship1, ship2])), 297.6)
134 XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship1, ship2])), 545.4)
137 func testTreeShips() {
140 guard let ship1 = store.ship(by: 228) else {
141 XCTFail("Can not get ship")
145 guard let ship2 = store.ship(by: 4_184) else {
146 XCTFail("Can not get ship")
150 guard let ship3 = store.ship(by: 220) else {
151 XCTFail("Can not get ship")
155 XCTAssertEqual(SimpleCalculator().calculate([ship1, ship2, ship3]), 348)
157 XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship1, ship2, ship3])), 47.7)
158 XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship1, ship2, ship3])), 531.8)
159 XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship1, ship2, ship3])), 955.3)
162 func testEscapedShips() {
165 guard let ship1 = store.ship(by: 228) else {
166 XCTFail("Can not get ship")
170 guard let ship2 = store.ship(by: 4_184) else {
171 XCTFail("Can not get ship")
175 guard let ship3 = store.ship(by: 220) else {
176 XCTFail("Can not get ship")
182 let tempStore = TemporaryDataStore.oneTimeEditor()
183 let guardEscape = tempStore.createGuardEscaped()
184 guardEscape?.shipID = 4_184
185 guardEscape?.ensured = true
188 XCTAssertEqual(SimpleCalculator().calculate([ship1, ship2, ship3]), 238)
190 XCTAssertEqual(fitSakuteki(Formula33(1).calculate([ship1, ship2, ship3])), 22.0)
191 XCTAssertEqual(fitSakuteki(Formula33(3).calculate([ship1, ship2, ship3])), 362.1)
192 XCTAssertEqual(fitSakuteki(Formula33(4).calculate([ship1, ship2, ship3])), 659.6)