OSDN Git Service

debug.logの競合状態を解消する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer.Test / ShipLabelTest.cs
1 // Copyright (C) 2016 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\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
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\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
14 \r
15 using System.Collections.Generic;\r
16 using System.Drawing;\r
17 using System.Windows.Forms;\r
18 using ExpressionToCodeLib;\r
19 using KancolleSniffer.Model;\r
20 using KancolleSniffer.View;\r
21 using Microsoft.VisualStudio.TestTools.UnitTesting;\r
22 \r
23 namespace KancolleSniffer.Test\r
24 {\r
25     [TestClass]\r
26     public class ShipLabelTest\r
27     {\r
28         /// <summary>\r
29         /// 明石タイマー表示中の艦娘の名前を縮める\r
30         /// </summary>\r
31         [TestMethod]\r
32         public void TruncateNameForAkashiTimer()\r
33         {\r
34             var dict = new Dictionary<string, string>\r
35             {\r
36                 {"夕立改二", "夕立改二"},\r
37                 {"千代田航改", "千代田航"},\r
38                 {"千代田航改二", "千代田航"},\r
39                 {"Bismarck改", "Bismarck"},\r
40                 {"Bismarck twei", "Bismarck"},\r
41                 {"Bismarck drei", "Bismarck"},\r
42                 {"Prinz Eugen", "Prinz Eug"},\r
43                 {"Prinz Eugen改", "Prinz Eug"},\r
44                 {"Graf Zeppelin", "Graf Zep"},\r
45                 {"Graf Zeppelin改", "Graf Zep"},\r
46                 {"Libeccio改", "Libeccio"},\r
47             };\r
48             TruncateNameSub(dict, ShipNameWidth.AkashiTimer);\r
49         }\r
50 \r
51         /// <summary>\r
52         /// 入渠中の艦娘名の名前を縮める\r
53         /// </summary>\r
54         [TestMethod]\r
55         public void TruncateNameForNDock()\r
56         {\r
57             var dict = new Dictionary<string, string>\r
58             {\r
59                 {"千歳航改二", "千歳航改二"},\r
60                 {"Graf Zeppelin", "Graf Zeppeli"},\r
61                 {"Graf Zeppelin改", "Graf Zeppeli"},\r
62                 {"千代田航改二", "千代田航改"}\r
63             };\r
64             TruncateNameSub(dict, ShipNameWidth.NDock);\r
65         }\r
66 \r
67         /// <summary>\r
68         /// 一覧ウィンドウの要修復一覧の艦娘の名前を縮める\r
69         /// </summary>\r
70         [TestMethod]\r
71         public void TruncateNameForRepairListFull()\r
72         {\r
73             var dict = new Dictionary<string, string>\r
74             {\r
75                 {"Graf Zeppelin", "Graf Zeppelin"},\r
76                 {"Graf Zeppelin改", "Graf Zeppelin"},\r
77                 {"千代田航改二", "千代田航改"}\r
78             };\r
79             TruncateNameSub(dict, ShipNameWidth.RepairListFull);\r
80         }\r
81 \r
82         /// <summary>\r
83         /// メインパネルの艦娘の名前を縮める\r
84         /// </summary>\r
85         [TestMethod]\r
86         public void TruncateNameForMainPanel()\r
87         {\r
88             var dict = new Dictionary<string, string>\r
89             {\r
90                 {"Commandant Teste", "Commandant Tes"}\r
91             };\r
92             TruncateNameSub(dict, ShipNameWidth.MainPanel);\r
93         }\r
94 \r
95         [TestMethod]\r
96         public void TruncateNameForShipList()\r
97         {\r
98             var dict = new Dictionary<string, string>\r
99             {\r
100                 {"Commandant Test", "Commandant T"},\r
101                 {"Graf Zeppelin改", "Graf Zeppelin"}\r
102             };\r
103             TruncateNameSub(dict, ShipNameWidth.ShipList);\r
104         }\r
105 \r
106         private void TruncateNameSub(Dictionary<string, string> dict, ShipNameWidth width)\r
107         {\r
108             var label = new ShipLabel {Parent = new Panel()};\r
109             ShipLabel.ScaleFactor = new SizeF(1,1);\r
110             foreach (var entry in dict)\r
111             {\r
112                 label.SetName(entry.Key, width);\r
113                 PAssert.That(() => label.Text == entry.Value, entry.Key);\r
114             }\r
115         }\r
116 \r
117         /// <summary>\r
118         /// prefixを加える\r
119         /// </summary>\r
120         [TestMethod]\r
121         public void SetName()\r
122         {\r
123             var label = new ShipLabel {Parent = new Panel()};\r
124             ShipLabel.ScaleFactor = new SizeF(1, 1);\r
125             label.SetName(new ShipStatus\r
126                 {\r
127                     Spec = new ShipSpec {Name = "綾波改二"},\r
128                     Escaped = true\r
129                 },\r
130                 ShipNameWidth.AkashiTimer);\r
131             PAssert.That(() => label.Text == "[避]綾波改二");\r
132             label.SetName(new ShipStatus\r
133                 {\r
134                     Spec = new ShipSpec {Name = "朝潮改二丁"},\r
135                     Escaped = true\r
136                 },\r
137                 ShipNameWidth.AkashiTimer);\r
138             PAssert.That(() => label.Text == "[避]朝潮改二");\r
139         }\r
140 \r
141         /// <summary>\r
142         /// %表示の小数部を切り捨てる\r
143         /// </summary>\r
144         [TestMethod]\r
145         public void RoundOffFractionOfPercent()\r
146         {\r
147             var label = new ShipLabel {Parent = new Panel()};\r
148             label.SetHp(104, 105);\r
149             label.ToggleHpPercent();\r
150             PAssert.That(() => label.Text == "99%");\r
151         }\r
152     }\r
153 }