sharee.bike-App/TestShareeLib/Model/Bikes/BikeInfoNS/DriveNS/BatteryNS/TestBatteryMutable.cs
2023-08-31 12:31:38 +02:00

93 lines
1.8 KiB
C#

using NUnit.Framework;
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
namespace TestShareeLib.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
{
[TestFixture]
public class TestBatteryMutable
{
[Test]
public void TestCurrentChargeBars()
{
var battery = new BatteryMutable(new Battery.Builder {
MaxChargeBars = 5,
CurrentChargeBars = 1,
CurrentChargePercent = 20.0
}.Build());
battery.CurrentChargeBars = 4;
Assert.That(
battery.CurrentChargeBars,
Is.EqualTo(4));
Assert.That(
battery.CurrentChargePercent,
Is.EqualTo(80.0));
}
[Test]
public void TestCurrentChargeBarsNull()
{
var battery = new BatteryMutable(new Battery.Builder
{
MaxChargeBars = 5,
CurrentChargeBars = 1,
CurrentChargePercent = 20.0
}.Build());
battery.CurrentChargeBars = null;
Assert.That(
battery.CurrentChargeBars,
Is.Null);
Assert.That(
battery.CurrentChargePercent,
Is.EqualTo(double.NaN));
}
[Test]
public void TestCurrentChargeBarsInvalidStateZero()
{
var battery = new BatteryMutable(new Battery.Builder
{
MaxChargeBars = 0, // Could lead to division by zero if not handled correctly.
CurrentChargeBars = null,
CurrentChargePercent = 20.0
}.Build());
battery.CurrentChargeBars = 4;
Assert.That(
battery.CurrentChargeBars,
Is.Null);
Assert.That(
battery.CurrentChargePercent,
Is.EqualTo(20.0));
}
[Test]
public void TestCurrentChargeBarsInvalidStateNull()
{
var battery = new BatteryMutable(new Battery.Builder
{
MaxChargeBars = null,
CurrentChargeBars = null,
CurrentChargePercent = 20.0
}.Build());
battery.CurrentChargeBars = 4;
Assert.That(
battery.CurrentChargeBars,
Is.Null);
Assert.That(
battery.CurrentChargePercent,
Is.EqualTo(20.0));
}
}
}