public void Enumerator() { // Arrange int capacity = 10; var vehicles = new TestVehicle[] { new TestVehicle(), new TestVehicle(), new TestVehicle(), new TestVehicle(), }; var garage = new Garage <TestVehicle>(capacity); foreach (var item in vehicles) { garage.Add(item); } // Act var result = garage.ToList(); // Assert // Using result.Count instead of vehicles.Length, // to make sure we don't iterate over any null items for (int i = 0; i < result.Count; i++) { Assert.AreSame(vehicles[i], result[i]); } Assert.AreEqual(vehicles.Length, result.Count); }
public void Add_When_Not_Full() { // Arrange int capacity = 4; var garage = new Garage <TestVehicle>(capacity); var vehicles = new TestVehicle[] { new TestVehicle(), new TestVehicle(), new TestVehicle(), new TestVehicle(), }; // Act foreach (var item in vehicles) { garage.Add(item); } // Assert int i = 0; foreach (var item in garage) { Assert.AreSame(vehicles[i++], item); } Assert.AreEqual(vehicles.Length, garage.Count); Assert.AreEqual(vehicles.Length, i); }
public void Remove_Empty_Fail() { // Arrange var garage = new Garage <TestVehicle>(4); var car = new TestVehicle(); // Act bool success = garage.Remove(car); // Assert Assert.IsFalse(success); Assert.AreEqual(0, garage.Count); Assert.AreEqual(0, garage.Count()); // Just to make sure the iterator agrees }
public void Remove_At_Back_Success() { // Arrange var garage = new Garage <TestVehicle>(4); var car = new TestVehicle(); garage.Add(new TestVehicle()); garage.Add(new TestVehicle()); garage.Add(car); // Act bool success = garage.Remove(car); // Assert Assert.IsTrue(success); foreach (var item in garage) { Assert.AreNotSame(car, item); } Assert.AreEqual(2, garage.Count); Assert.AreEqual(2, garage.Count()); // Just to make sure the iterator agrees }