5 // Created by Hori,Masaki on 2018/03/04.
6 // Copyright © 2018年 Hori,Masaki. All rights reserved.
27 // 大発動艇(八十九式中戦車&陸戦隊) 8
34 class TPTest: XCTestCase {
36 let store = ServerDataStore.oneTimeEditor()
38 override func setUp() {
45 setupShip(id: 14, slotItems: [74_719, 11_825, 58_197], exSlot: -1, saku0: 0)
50 setupShip(id: 26, slotItems: [], exSlot: -1, saku0: 0)
55 setupShip(id: 62, slotItems: [60_172, 51_323, 9_742], exSlot: -1, saku0: 0)
60 setupShip(id: 475, slotItems: [], exSlot: -1, saku0: 0)
65 setupShip(id: 1_716, slotItems: [], exSlot: -1, saku0: 0)
68 // 特大発, 特大発戦車, 特二式内火艇, ドラム缶
70 setupShip(id: 15_562, slotItems: [62_546, 70_464, 50_943, 75_011], exSlot: -1, saku0: 0)
75 setupShip(id: 24_844, slotItems: [], exSlot: -1, saku0: 0)
80 setupShip(id: 36_488, slotItems: [], exSlot: 70_318, saku0: 0)
85 setupShip(id: 5_545, slotItems: [], exSlot: -1, saku0: 0)
90 setupShip(id: 50_132, slotItems: [], exSlot: -1, saku0: 0)
95 setupShip(id: 88, slotItems: [80_171], exSlot: -1, saku0: 0)
100 setupShip(id: 35_997, slotItems: [], exSlot: 37_933, saku0: 0)
105 setupShip(id: 3_386, slotItems: [], exSlot: -1, saku0: 0)
110 setupShip(id: 5_500, slotItems: [], exSlot: -1, saku0: 0)
115 setupShip(id: 602, slotItems: [], exSlot: -1, saku0: 0)
120 setupShip(id: 24_875, slotItems: [], exSlot: -1, saku0: 0)
125 setupShip(id: 36_069, slotItems: [], exSlot: -1, saku0: 0)
130 setupShip(id: 29_953, slotItems: [], exSlot: -1, saku0: 0)
135 setupShip(id: 6_036, slotItems: [], exSlot: -1, saku0: 0)
140 setupShip(id: 21_208, slotItems: [], exSlot: -1, saku0: 0)
145 setupShip(id: 29_268, slotItems: [], exSlot: -1, saku0: 0)
150 setupShip(id: 48_510, slotItems: [], exSlot: -1, saku0: 0)
153 let tempStore = TemporaryDataStore.oneTimeEditor()
154 tempStore.guardEscaped().forEach(tempStore.delete)
157 override func tearDown() {
159 let store = TemporaryDataStore.oneTimeEditor()
160 store.guardEscaped().forEach(store.delete)
165 func setupShip(id shipId: Int, slotItems: [Int], exSlot: Int, saku0: Int) {
167 guard let ship = store.ship(by: shipId) else {
169 XCTFail("Can not get ship, \(shipId)")
173 ship.onslot_0 = ship.master_ship.maxeq_0
174 ship.onslot_1 = ship.master_ship.maxeq_1
175 ship.onslot_2 = ship.master_ship.maxeq_2
176 ship.onslot_3 = ship.master_ship.maxeq_3
177 ship.onslot_4 = ship.master_ship.maxeq_4
179 setSlot(slotItems: slotItems, to: ship)
181 ship.slot_ex = exSlot
182 ship.extraItem = store.slotItem(by: ship.slot_ex)
184 ship.sakuteki_0 = saku0
188 func setSlot(slotItems: [Int], to ship: Ship) {
190 let newItems: [SlotItem] = slotItems
191 .filter { $0 != 0 && $0 != -1 }
192 .flatMap { store.slotItem(by: $0) }
193 ship.equippedItem = NSOrderedSet(array: newItems)
195 slotItems.enumerated().forEach { offset, element in
197 ship.setItem(element, to: offset)
201 func checkShip(_ shipId: Int, sTp: Int, bTp: Double, file: StaticString = #file, line: UInt = #line) {
203 guard let ship1 = store.ship(by: shipId) else {
205 XCTFail("Can not get ship")
209 ship1.nowhp = ship1.maxhp
210 let tp = ShipTPValueCalculator(ship1).value
211 XCTAssertEqual(tp, sTp, file: file, line: line)
212 XCTAssertLessThan(abs(Double(tp) * 0.7 - bTp), 0.00000001, file: file, line: line)
215 ship1.nowhp = Int(Double(ship1.nowhp) * 0.2)
216 XCTAssertEqual(ShipTPValueCalculator(ship1).value, 0, "Taiha", file: file, line: line)
222 checkShip(14, sTp: 26, bTp: 18.2)
225 checkShip(26, sTp: 5, bTp: 3.5)
228 checkShip(62, sTp: 40, bTp: 28)
231 checkShip(475, sTp: 2, bTp: 1.4)
234 checkShip(15_562, sTp: 49, bTp: 34.3)
237 checkShip(24_844, sTp: 6, bTp: 4.2)
240 checkShip(36_488, sTp: 1, bTp: 0.7)
243 checkShip(5_545, sTp: 4, bTp: 2.8)
246 checkShip(50_132, sTp: 9, bTp: 6.3)
249 checkShip(88, sTp: 1, bTp: 0.7)
252 checkShip(35_997, sTp: 1, bTp: 0.7)
255 checkShip(3_386, sTp: 0, bTp: 0)
258 checkShip(5_500, sTp: 0, bTp: 0)
261 checkShip(602, sTp: 7, bTp: 4.9)
264 checkShip(24_875, sTp: 0, bTp: 0)
267 checkShip(36_069, sTp: 1, bTp: 0.7)
270 checkShip(29_953, sTp: 7, bTp: 4.9)
273 checkShip(6_036, sTp: 12, bTp: 8.4)
276 checkShip(21_208, sTp: 15, bTp: 10.5)
279 checkShip(29_268, sTp: 0, bTp: 0)
282 checkShip(48_510, sTp: 0, bTp: 0)