Hello, and here is my code
using System;
class RemoteControlCar
{
private int distance = 0;
private int battery = 100;
public static RemoteControlCar Buy()
{
return new RemoteControlCar();
}
public string DistanceDisplay()
{
return "Driven " + distance + " meters";
}
public string BatteryDisplay()
{
if (distance == 2000)
{
return "Battery empty";
}
else
{
return "Battery at "+battery+"%";
}
}
public void Drive()
{
if(battery > 0)
{
distance = + 20;
battery = - 1;
}
}
}
when it run
var car = new RemoteControlCar();
for (var i = 0; i < 17; i++)
{
car.Drive();
}
it reports
Assert.Equal() Failure: Strings differ
↓ (pos 7)
Expected: “Driven 340 meters”
Actual: “Driven 20 meters”
↑ (pos 7)
it’s seems like my code failure to update the value of distance.