OSDN Git Service

補給状況の表示がおかしいのを直す
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 6 Oct 2019 11:36:03 +0000 (20:36 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 6 Oct 2019 11:36:03 +0000 (20:36 +0900)
KancolleSniffer.Test/ChargeStatusTest.cs [new file with mode: 0644]
KancolleSniffer.Test/KancolleSniffer.Test.csproj
KancolleSniffer.Test/SnifferTest.cs
KancolleSniffer/MainForm.cs
KancolleSniffer/Model/Fleet.cs

diff --git a/KancolleSniffer.Test/ChargeStatusTest.cs b/KancolleSniffer.Test/ChargeStatusTest.cs
new file mode 100644 (file)
index 0000000..b933289
--- /dev/null
@@ -0,0 +1,120 @@
+// Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//    http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using ExpressionToCodeLib;\r
+using KancolleSniffer.Model;\r
+using Microsoft.VisualStudio.TestTools.UnitTesting;\r
+// ReSharper disable CompareOfFloatsByEqualityOperator\r
+\r
+namespace KancolleSniffer.Test\r
+{\r
+    [TestClass]\r
+    public class ChargeStatusTest\r
+    {\r
+        private readonly Fleet _fleet = new Fleet(null, 6, null);\r
+\r
+        [TestMethod]\r
+        public void NoShips()\r
+        {\r
+            var stat = _fleet.ChargeStatus;\r
+            PAssert.That(() => stat.Fuel == 0 && stat.Bull == 0);\r
+            PAssert.That(() => stat.Empty);\r
+        }\r
+\r
+        [TestMethod]\r
+        public void FullFlagshipOnly()\r
+        {\r
+            var fs =_fleet.Ships[0];\r
+            fs.Fuel = 9;\r
+            fs.Spec.FuelMax = 9;\r
+            fs.Bull = 9;\r
+            fs.Spec.BullMax = 9;\r
+            var stat = _fleet.ChargeStatus;\r
+            PAssert.That(() => stat.Fuel == 0 && stat.FuelRatio == 1);\r
+            PAssert.That(() => stat.Bull == 0 && stat.BullRatio == 1);\r
+        }\r
+\r
+        [TestMethod]\r
+        public void FlagshipOnly()\r
+        {\r
+            var fs = _fleet.Ships[0];\r
+            fs.Fuel = 3;\r
+            fs.Spec.FuelMax = 9;\r
+            fs.Bull = 0;\r
+            fs.Spec.BullMax = 9;\r
+            var stat = _fleet.ChargeStatus;\r
+            PAssert.That(() => stat.Fuel == 2 && stat.FuelRatio == 3 / 9.0);\r
+            PAssert.That(() => stat.Bull == 4 && stat.BullRatio == 0.0);\r
+        }\r
+\r
+        [TestMethod]\r
+        public void FullFlagshipAndFullOther()\r
+        {\r
+            var fs = _fleet.Ships[0];\r
+            fs.Fuel = 9;\r
+            fs.Spec.FuelMax = 9;\r
+            fs.Bull = 9;\r
+            fs.Spec.BullMax = 9;\r
+            var other = _fleet.Ships[1];\r
+            other.Fuel = 9;\r
+            other.Spec.FuelMax = 9;\r
+            other.Bull = 9;\r
+            other.Spec.BullMax = 9;\r
+            var stat = _fleet.ChargeStatus;\r
+            PAssert.That(() => stat.Fuel == 5 && stat.FuelRatio == 1);\r
+            PAssert.That(() => stat.Bull == 5 && stat.BullRatio == 1);\r
+        }\r
+\r
+        [TestMethod]\r
+        public void FullFlagshipAndOther()\r
+        {\r
+            var fs = _fleet.Ships[0];\r
+            fs.Fuel = 9;\r
+            fs.Spec.FuelMax = 9;\r
+            fs.Bull = 9;\r
+            fs.Spec.BullMax = 9;\r
+            var other = _fleet.Ships[1];\r
+            other.Fuel = 7;\r
+            other.Spec.FuelMax = 9;\r
+            other.Bull = 3;\r
+            other.Spec.BullMax = 9;\r
+            var stat = _fleet.ChargeStatus;\r
+            PAssert.That(() => stat.Fuel == 6 && stat.FuelRatio == 7 / 9.0);\r
+            PAssert.That(() => stat.Bull == 7 && stat.BullRatio == 3 / 9.0);\r
+        }\r
+\r
+        [TestMethod]\r
+        public void FullFlagshipAndOthers()\r
+        {\r
+            var fs = _fleet.Ships[0];\r
+            fs.Fuel = 9;\r
+            fs.Spec.FuelMax = 9;\r
+            fs.Bull = 9;\r
+            fs.Spec.BullMax = 9;\r
+            var second = _fleet.Ships[1];\r
+            second.Fuel = 3;\r
+            second.Spec.FuelMax = 9;\r
+            second.Bull = 9;\r
+            second.Spec.BullMax = 9;\r
+            var third = _fleet.Ships[2];\r
+            third.Fuel = 7;\r
+            third.Spec.FuelMax = 9;\r
+            third.Bull = 0;\r
+            third.Spec.BullMax = 9;\r
+            var stat = _fleet.ChargeStatus;\r
+            PAssert.That(() => stat.Fuel == 7 && stat.FuelRatio == 3 / 9.0);\r
+            PAssert.That(() => stat.Bull == 9 && stat.BullRatio == 0.0);\r
+        }\r
+    }\r
+}
\ No newline at end of file
index 8ae94e4..c0231e2 100644 (file)
@@ -83,6 +83,7 @@
     <Compile Include="BattleLogProcessorTest.cs" />\r
     <Compile Include="BattleBriefTest.cs" />\r
     <Compile Include="BattleTest.cs" />\r
+    <Compile Include="ChargeStatusTest.cs" />\r
     <Compile Include="QuestCounterTest.cs" />\r
     <Compile Include="QuestPanelTest.cs" />\r
     <Compile Include="RepairShipCountTest.cs" />\r
index ddc6f0f..1c2e2e6 100644 (file)
@@ -657,7 +657,7 @@ namespace KancolleSniffer.Test
         {\r
             var sniffer = new Sniffer(true);\r
             SniffLogFile(sniffer, "twofleets_001");\r
-            PAssert.That(() => new[]{5, 5, 5, 5}.SequenceEqual(sniffer.Fleets.Select(f => f.ChargeStatus.Fuel)));\r
+            PAssert.That(() => new[]{5, 5, 0, 0}.SequenceEqual(sniffer.Fleets.Select(f => f.ChargeStatus.Fuel)));\r
         }\r
 \r
         /// <summary>\r
index 88b20bf..bd35c6e 100644 (file)
@@ -892,7 +892,7 @@ namespace KancolleSniffer
                 var stat = Sniffer.Fleets[i].ChargeStatus;\r
                 fuelSq[i].ImageIndex = stat.Fuel;\r
                 bullSq[i].ImageIndex = stat.Bull;\r
-                var text = $"燃{stat.FuelRatio * 100:f1}% 弾{stat.BullRatio * 100:f1}%";\r
+                var text = stat.Empty ? "" : $"燃{stat.FuelRatio * 100:f1}% 弾{stat.BullRatio * 100:f1}%";\r
                 _toolTip.SetToolTip(fuelSq[i], text);\r
                 _toolTip.SetToolTip(bullSq[i], text);\r
             }\r
index 736a9c1..fdf0213 100644 (file)
@@ -16,18 +16,19 @@ using System;
 using System.Collections.Generic;\r
 using System.Linq;\r
 using static System.Math;\r
+// ReSharper disable CompareOfFloatsByEqualityOperator\r
 \r
 namespace KancolleSniffer.Model\r
 {\r
     public class ChargeStatus\r
     {\r
+        public bool Empty => FuelRatio > 1.0;\r
+\r
         public double FuelRatio { get; set; }\r
-        public int Fuel => CalcChargeState(FuelRatio) + (Others ? 5 : 0);\r
+        public int Fuel { get; set; }\r
 \r
         public double BullRatio { get; set; }\r
-        public int Bull => CalcChargeState(BullRatio) + (Others ? 5 : 0);\r
-\r
-        public bool Others;\r
+        public int Bull { get; set; }\r
 \r
         public ChargeStatus()\r
         {\r
@@ -35,16 +36,35 @@ namespace KancolleSniffer.Model
 \r
         public ChargeStatus(ShipStatus status)\r
         {\r
-            FuelRatio = status.Spec.FuelMax == 0 ? 0 : (double)status.Fuel / status.Spec.FuelMax;\r
-            BullRatio = status.Spec.BullMax == 0 ? 0 : (double)status.Bull / status.Spec.BullMax;\r
+            if (status.Spec.FuelMax == 0)\r
+            {\r
+                FuelRatio = 2.0;\r
+                BullRatio = 2.0;\r
+                return;\r
+            }\r
+            FuelRatio = (double)status.Fuel / status.Spec.FuelMax;\r
+            BullRatio = (double)status.Bull / status.Spec.BullMax;\r
+        }\r
+\r
+        public void SetState()\r
+        {\r
+            Fuel = CalcChargeState(FuelRatio);\r
+            Bull = CalcChargeState(BullRatio);\r
         }\r
 \r
-        private int CalcChargeState(double ratio)\r
+        public void SetOthersState()\r
         {\r
-            // ReSharper disable CompareOfFloatsByEqualityOperator\r
-            if (ratio == 0.0 || ratio == 1.0)\r
+            SetState();\r
+            Fuel += 5;\r
+            Bull += 5;\r
+        }\r
+\r
+        private static int CalcChargeState(double ratio)\r
+        {\r
+            if (ratio > 1.0)\r
+                return 0;\r
+            if (ratio == 1.0)\r
                 return 0;\r
-            // ReSharper restore CompareOfFloatsByEqualityOperator\r
             if (ratio >= 7.0 / 9)\r
                 return 1;\r
             if (ratio >= 3.0 / 9)\r
@@ -165,8 +185,21 @@ namespace KancolleSniffer.Model
             {\r
                 var fs = new ChargeStatus(Ships[0]);\r
                 var others = (from ship in Ships.Skip(1) select new ChargeStatus(ship)).Aggregate(ChargeStatus.Min);\r
-                others.Others = true;\r
-                return fs.Fuel != 0 ? fs : others;\r
+                fs.SetState();\r
+                others.SetOthersState();\r
+                if (others.Empty)\r
+                    return fs;\r
+                if (fs.Fuel == 0)\r
+                {\r
+                    fs.Fuel = others.Fuel;\r
+                    fs.FuelRatio = others.FuelRatio;\r
+                }\r
+                if (fs.Bull == 0)\r
+                {\r
+                    fs.Bull = others.Bull;\r
+                    fs.BullRatio = others.BullRatio;\r
+                }\r
+                return fs;\r
             }\r
         }\r
 \r