public void testGetVesselInfo(string name, int year, int passengers) { Speed sp = new Speed(50); Ferry aFerry = new Ferry(name, year, sp, passengers); var info = string.Format("Type of vessel: Ferry, name: {0}, year built: {1}, maximum speed: {2}|{3}, number of passengers: {4}", name, year, sp.ToString("KN"), sp.ToString("MS"), passengers); Assert.Equal(info, aFerry.GetVesselInfo()); }
static void Main(string[] args) { List <Vessel> vesselList = new List <Vessel>(); // Different speeds for the types Speed sp = new Speed(10); Speed sp2 = new Speed(20.03); Speed sp3 = new Speed(30.82); // created 5 of each vesseltype Ferry fer1 = new Ferry("Lickety Split", 2005, sp, 300); Ferry fer2 = new Ferry("Greased Lightning", 2012, sp, 250); Ferry fer3 = new Ferry("Flying Lady", 2003, sp, 400); Ferry fer4 = new Ferry("Blew By Ya", 2009, sp, 600); Ferry fer5 = new Ferry("Breaking Waves", 2018, sp, 100); Tugboat tug1 = new Tugboat("Loon-A-Sea", 1999, sp2, 70.01); Tugboat tug2 = new Tugboat("Sleeping With Oars", 2000, sp2, 60.23); Tugboat tug3 = new Tugboat("What's up Dock", 2019, sp2, 30.11); Tugboat tug4 = new Tugboat("Your Place Oar Mine", 2004, sp2, 80.10); Tugboat tug5 = new Tugboat("Silver Bullet", 2005, sp2, 75.50); Submarine sub1 = new Submarine("Terminator", 2019, sp3, 170.32); Submarine sub2 = new Submarine("Summer Wind", 2016, sp3, 200.12); Submarine sub3 = new Submarine("Ocean Breeze", 2002, sp3, 160.32); Submarine sub4 = new Submarine("Called in Sick", 2000, sp3, 182.42); Submarine sub5 = new Submarine("Sail Away", 2013, sp3, 190.80); // Added all to an list of vessels vesselList.Add(fer1); vesselList.Add(fer2); vesselList.Add(fer3); vesselList.Add(fer4); vesselList.Add(fer5); vesselList.Add(tug1); vesselList.Add(tug2); vesselList.Add(tug3); vesselList.Add(tug4); vesselList.Add(tug5); vesselList.Add(sub1); vesselList.Add(sub2); vesselList.Add(sub3); vesselList.Add(sub4); vesselList.Add(sub5); Console.WriteLine("Number of Vessels " + Vessel.getNumOfVessels() + "\n"); Console.WriteLine("The ToString method"); foreach (var vessel in vesselList) { Console.WriteLine(vessel.ToString()); } Console.WriteLine("\nThe GetVesselInfo() method"); foreach (var vessel in vesselList) { Console.WriteLine(vessel.GetVesselInfo()); } Console.WriteLine("\nPrinting some speed values in m/s and knots"); Console.WriteLine("Tug3 speed in knots: " + tug3.GetSpeed().ToString()); Console.WriteLine("Tug3 speed in m/s: " + tug3.GetSpeed().ToString("MS")); }
public void testPassengersField() { int passengers = 200; int passengers2 = 300; Speed sp = new Speed(50); Ferry aFerry = new Ferry("Fer", 2000, sp, passengers); Assert.Equal(passengers, aFerry.passengers); // Since it is not a private variable, we can change it aFerry.passengers = passengers2; Assert.Equal(passengers2, aFerry.passengers); }