sharee.bike-App/SharedBusinessLogic.Tests/Model/Bikes/BikeInfoNS/DriveNS/BatteryNS/TestBatteryMutable.cs

94 lines
1.8 KiB
C#
Raw Normal View History

2023-08-31 12:31:38 +02:00
using NUnit.Framework;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
2023-08-31 12:31:38 +02:00
2024-04-09 12:53:23 +02:00
namespace SharedBusinessLogic.Tests.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
2023-08-31 12:31:38 +02:00
{
[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));
}
}
}