--- /dev/null
+// 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
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
\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
{\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