From: Kazuhiro Fujieda Date: Sun, 6 Oct 2019 11:36:03 +0000 (+0900) Subject: 補給状況の表示がおかしいのを直す X-Git-Tag: v11.27~2 X-Git-Url: http://git.osdn.net/view?p=kancollesniffer%2FKancolleSniffer.git;a=commitdiff_plain;h=51f996fb135acc32e55af255076e2d7528f12c36 補給状況の表示がおかしいのを直す --- diff --git a/KancolleSniffer.Test/ChargeStatusTest.cs b/KancolleSniffer.Test/ChargeStatusTest.cs new file mode 100644 index 0000000..b933289 --- /dev/null +++ b/KancolleSniffer.Test/ChargeStatusTest.cs @@ -0,0 +1,120 @@ +// Copyright (C) 2019 Kazuhiro Fujieda +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ExpressionToCodeLib; +using KancolleSniffer.Model; +using Microsoft.VisualStudio.TestTools.UnitTesting; +// ReSharper disable CompareOfFloatsByEqualityOperator + +namespace KancolleSniffer.Test +{ + [TestClass] + public class ChargeStatusTest + { + private readonly Fleet _fleet = new Fleet(null, 6, null); + + [TestMethod] + public void NoShips() + { + var stat = _fleet.ChargeStatus; + PAssert.That(() => stat.Fuel == 0 && stat.Bull == 0); + PAssert.That(() => stat.Empty); + } + + [TestMethod] + public void FullFlagshipOnly() + { + var fs =_fleet.Ships[0]; + fs.Fuel = 9; + fs.Spec.FuelMax = 9; + fs.Bull = 9; + fs.Spec.BullMax = 9; + var stat = _fleet.ChargeStatus; + PAssert.That(() => stat.Fuel == 0 && stat.FuelRatio == 1); + PAssert.That(() => stat.Bull == 0 && stat.BullRatio == 1); + } + + [TestMethod] + public void FlagshipOnly() + { + var fs = _fleet.Ships[0]; + fs.Fuel = 3; + fs.Spec.FuelMax = 9; + fs.Bull = 0; + fs.Spec.BullMax = 9; + var stat = _fleet.ChargeStatus; + PAssert.That(() => stat.Fuel == 2 && stat.FuelRatio == 3 / 9.0); + PAssert.That(() => stat.Bull == 4 && stat.BullRatio == 0.0); + } + + [TestMethod] + public void FullFlagshipAndFullOther() + { + var fs = _fleet.Ships[0]; + fs.Fuel = 9; + fs.Spec.FuelMax = 9; + fs.Bull = 9; + fs.Spec.BullMax = 9; + var other = _fleet.Ships[1]; + other.Fuel = 9; + other.Spec.FuelMax = 9; + other.Bull = 9; + other.Spec.BullMax = 9; + var stat = _fleet.ChargeStatus; + PAssert.That(() => stat.Fuel == 5 && stat.FuelRatio == 1); + PAssert.That(() => stat.Bull == 5 && stat.BullRatio == 1); + } + + [TestMethod] + public void FullFlagshipAndOther() + { + var fs = _fleet.Ships[0]; + fs.Fuel = 9; + fs.Spec.FuelMax = 9; + fs.Bull = 9; + fs.Spec.BullMax = 9; + var other = _fleet.Ships[1]; + other.Fuel = 7; + other.Spec.FuelMax = 9; + other.Bull = 3; + other.Spec.BullMax = 9; + var stat = _fleet.ChargeStatus; + PAssert.That(() => stat.Fuel == 6 && stat.FuelRatio == 7 / 9.0); + PAssert.That(() => stat.Bull == 7 && stat.BullRatio == 3 / 9.0); + } + + [TestMethod] + public void FullFlagshipAndOthers() + { + var fs = _fleet.Ships[0]; + fs.Fuel = 9; + fs.Spec.FuelMax = 9; + fs.Bull = 9; + fs.Spec.BullMax = 9; + var second = _fleet.Ships[1]; + second.Fuel = 3; + second.Spec.FuelMax = 9; + second.Bull = 9; + second.Spec.BullMax = 9; + var third = _fleet.Ships[2]; + third.Fuel = 7; + third.Spec.FuelMax = 9; + third.Bull = 0; + third.Spec.BullMax = 9; + var stat = _fleet.ChargeStatus; + PAssert.That(() => stat.Fuel == 7 && stat.FuelRatio == 3 / 9.0); + PAssert.That(() => stat.Bull == 9 && stat.BullRatio == 0.0); + } + } +} \ No newline at end of file diff --git a/KancolleSniffer.Test/KancolleSniffer.Test.csproj b/KancolleSniffer.Test/KancolleSniffer.Test.csproj index 8ae94e4..c0231e2 100644 --- a/KancolleSniffer.Test/KancolleSniffer.Test.csproj +++ b/KancolleSniffer.Test/KancolleSniffer.Test.csproj @@ -83,6 +83,7 @@ + diff --git a/KancolleSniffer.Test/SnifferTest.cs b/KancolleSniffer.Test/SnifferTest.cs index ddc6f0f..1c2e2e6 100644 --- a/KancolleSniffer.Test/SnifferTest.cs +++ b/KancolleSniffer.Test/SnifferTest.cs @@ -657,7 +657,7 @@ namespace KancolleSniffer.Test { var sniffer = new Sniffer(true); SniffLogFile(sniffer, "twofleets_001"); - PAssert.That(() => new[]{5, 5, 5, 5}.SequenceEqual(sniffer.Fleets.Select(f => f.ChargeStatus.Fuel))); + PAssert.That(() => new[]{5, 5, 0, 0}.SequenceEqual(sniffer.Fleets.Select(f => f.ChargeStatus.Fuel))); } /// diff --git a/KancolleSniffer/MainForm.cs b/KancolleSniffer/MainForm.cs index 88b20bf..bd35c6e 100644 --- a/KancolleSniffer/MainForm.cs +++ b/KancolleSniffer/MainForm.cs @@ -892,7 +892,7 @@ namespace KancolleSniffer var stat = Sniffer.Fleets[i].ChargeStatus; fuelSq[i].ImageIndex = stat.Fuel; bullSq[i].ImageIndex = stat.Bull; - var text = $"燃{stat.FuelRatio * 100:f1}% å¼¾{stat.BullRatio * 100:f1}%"; + var text = stat.Empty ? "" : $"燃{stat.FuelRatio * 100:f1}% å¼¾{stat.BullRatio * 100:f1}%"; _toolTip.SetToolTip(fuelSq[i], text); _toolTip.SetToolTip(bullSq[i], text); } diff --git a/KancolleSniffer/Model/Fleet.cs b/KancolleSniffer/Model/Fleet.cs index 736a9c1..fdf0213 100644 --- a/KancolleSniffer/Model/Fleet.cs +++ b/KancolleSniffer/Model/Fleet.cs @@ -16,18 +16,19 @@ using System; using System.Collections.Generic; using System.Linq; using static System.Math; +// ReSharper disable CompareOfFloatsByEqualityOperator namespace KancolleSniffer.Model { public class ChargeStatus { + public bool Empty => FuelRatio > 1.0; + public double FuelRatio { get; set; } - public int Fuel => CalcChargeState(FuelRatio) + (Others ? 5 : 0); + public int Fuel { get; set; } public double BullRatio { get; set; } - public int Bull => CalcChargeState(BullRatio) + (Others ? 5 : 0); - - public bool Others; + public int Bull { get; set; } public ChargeStatus() { @@ -35,16 +36,35 @@ namespace KancolleSniffer.Model public ChargeStatus(ShipStatus status) { - FuelRatio = status.Spec.FuelMax == 0 ? 0 : (double)status.Fuel / status.Spec.FuelMax; - BullRatio = status.Spec.BullMax == 0 ? 0 : (double)status.Bull / status.Spec.BullMax; + if (status.Spec.FuelMax == 0) + { + FuelRatio = 2.0; + BullRatio = 2.0; + return; + } + FuelRatio = (double)status.Fuel / status.Spec.FuelMax; + BullRatio = (double)status.Bull / status.Spec.BullMax; + } + + public void SetState() + { + Fuel = CalcChargeState(FuelRatio); + Bull = CalcChargeState(BullRatio); } - private int CalcChargeState(double ratio) + public void SetOthersState() { - // ReSharper disable CompareOfFloatsByEqualityOperator - if (ratio == 0.0 || ratio == 1.0) + SetState(); + Fuel += 5; + Bull += 5; + } + + private static int CalcChargeState(double ratio) + { + if (ratio > 1.0) + return 0; + if (ratio == 1.0) return 0; - // ReSharper restore CompareOfFloatsByEqualityOperator if (ratio >= 7.0 / 9) return 1; if (ratio >= 3.0 / 9) @@ -165,8 +185,21 @@ namespace KancolleSniffer.Model { var fs = new ChargeStatus(Ships[0]); var others = (from ship in Ships.Skip(1) select new ChargeStatus(ship)).Aggregate(ChargeStatus.Min); - others.Others = true; - return fs.Fuel != 0 ? fs : others; + fs.SetState(); + others.SetOthersState(); + if (others.Empty) + return fs; + if (fs.Fuel == 0) + { + fs.Fuel = others.Fuel; + fs.FuelRatio = others.FuelRatio; + } + if (fs.Bull == 0) + { + fs.Bull = others.Bull; + fs.BullRatio = others.BullRatio; + } + return fs; } }