1 // Copyright (C) 2017 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
16 using ExpressionToCodeLib;
\r
17 using KancolleSniffer.Model;
\r
18 using KancolleSniffer.Util;
\r
19 using Microsoft.VisualStudio.TestTools.UnitTesting;
\r
21 namespace KancolleSniffer.Test
\r
24 public class BattleTest
\r
26 private ItemInfo _itemInfo;
\r
27 private ShipInfo _shipInfo;
\r
28 private BattleInfo _battleInfo;
\r
30 private string[] ReadAllLines(string log)
\r
32 using (var logfile = SnifferTest.OpenLogFile(log))
\r
33 return logfile.ReadToEnd().Split(new [] {"\r\n"}, StringSplitOptions.None);
\r
37 public void Initialize()
\r
39 _itemInfo = new ItemInfo(new ItemMaster(), new ItemInventry());
\r
40 _shipInfo = new ShipInfo(new ShipMaster(), new ShipInventry(), _itemInfo);
\r
41 _battleInfo = new BattleInfo(_shipInfo, _itemInfo);
\r
48 public void CauseRepairGoddessByDoubleAttack()
\r
50 var logs = ReadAllLines("damecon_001");
\r
51 var items = JsonParser.Parse("[[[],[],[],[],[43]]]");
\r
52 dynamic battle = JsonParser.Parse(logs[2]);
\r
53 _shipInfo.InjectShips(battle, items);
\r
54 _battleInfo.InspectBattle(logs[0], logs[1], battle);
\r
55 dynamic result = JsonParser.Parse(logs[5]);
\r
56 _battleInfo.InspectBattleResult(result);
\r
57 PAssert.That(() => _shipInfo.Fleets[2].Ships[4].NowHp == 31);
\r
64 public void AttackedByBattleShipInMidnight()
\r
66 var logs = ReadAllLines("midnight_002");
\r
67 var battle = JsonParser.Parse(logs[3]);
\r
68 _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
\r
69 _battleInfo.InspectBattle(logs[1], logs[2], battle);
\r
70 _battleInfo.InspectBattleResult(JsonParser.Parse(logs[6]));
\r
71 PAssert.That(() => _shipInfo.Fleets[0].Ships[3].NowHp == 12);
\r
74 private dynamic Data(string json) => ((dynamic)JsonParser.Parse(json)).api_data;
\r
80 public void NpcFriendFleetAttack()
\r
82 var logs = ReadAllLines("friendfleet_001");
\r
83 var battle = Data(logs[3]);
\r
84 _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
\r
85 _battleInfo.InspectBattle(logs[1], logs[2], battle);
\r
86 _battleInfo.InspectBattle(logs[4], logs[5], Data(logs[6]));
\r
87 _battleInfo.InspectBattleResult(Data(logs[9]));
\r
88 PAssert.That(() => !_battleInfo.DisplayedResultRank.IsError);
\r
95 public void LdAirbattleHaveSunkenShip()
\r
97 var logs = ReadAllLines("ld_airbattle_001");
\r
98 var battle = Data(logs[3]);
\r
99 _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
\r
100 _battleInfo.InspectBattle(logs[1], logs[2], battle);
\r
101 _battleInfo.InspectBattleResult(Data(logs[6]));
\r
102 PAssert.That(() => !_battleInfo.DisplayedResultRank.IsError);
\r
106 /// 空襲戦で女神が発動して復活する
\r
109 public void LdAirbattleHaveRevivedShip()
\r
111 var logs = ReadAllLines("ld_airbattle_002");
\r
112 var battle = Data(logs[3]);
\r
113 _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
\r
114 _battleInfo.InspectBattle(logs[1], logs[2], battle);
\r
115 _battleInfo.InspectBattleResult(Data(logs[6]));
\r
116 PAssert.That(() => !_battleInfo.DisplayedResultRank.IsError);
\r
120 /// 機動対敵連合の雷撃戦でダメコンが発動する
\r
123 public void TreiggerDameconInCombinedBattle()
\r
125 var logs = ReadAllLines("damecon_002");
\r
126 var battle = Data(logs[3]);
\r
127 _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
\r
128 _battleInfo.InspectBattle(logs[1], logs[2], battle);
\r
129 _battleInfo.InspectBattle(logs[4], logs[5], Data(logs[6]));
\r
130 _battleInfo.InspectBattleResult(Data(logs[9]));
\r
131 PAssert.That(() => !_battleInfo.DisplayedResultRank.IsError);
\r