mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 18:46:30 +01:00
93 lines
1.8 KiB
C#
93 lines
1.8 KiB
C#
using NUnit.Framework;
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
|
|
|
|
namespace SharedBusinessLogic.Tests.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));
|
|
}
|
|
}
|
|
}
|