public static string TestGSMs(int count,string iphoneInfo="Unknown") { StringBuilder sb = new StringBuilder(); GSM[] GSMs = new GSM[count]; for (int i = 0; i < GSMs.Length; i++) { GSM newGSM = new GSM((Models)rnd.Next(0, 8), "SomeManufacturer", rnd.Next(1000, 5000), new GSM.Battery(BatteryTypes.NiMH, rnd.Next(20, 2000), rnd.Next(10, 1000)), new GSM.Display(rnd.Next(200, 500), rnd.Next(200, 500), (Colors)rnd.Next(0, 9))); GSMs[i] = newGSM; sb.AppendLine(GSMs[i].ToString()); sb.AppendLine(); } GSM.Iphone4s = iphoneInfo; sb.AppendLine(GSM.Iphone4s); return sb.ToString(); }
public static void doTests() { GSM newGSm = new GSM(Models.Iphone, "Dunno"); Console.WriteLine("Phone Created"); Console.WriteLine("Please wait while generating calls..."); int rndCallsAmount = rnd.Next(2,10); for (int i = 0; i < rndCallsAmount ; i++) { string number = (rnd.Next(500000, 700000)).ToString(); Call newCall = new Call(number); int rndThreadSleep = rnd.Next(1000,6000); Thread.Sleep(rndThreadSleep); newCall.HangUp(); newGSm.callHistory.Add(newCall); } Console.WriteLine("Calls generated"); Console.WriteLine("Writing info"); foreach (var call in newGSm.callHistory) { Console.WriteLine(call); } Console.WriteLine(); Console.WriteLine("Calculating price for 0.37 per minute"); string price = newGSm.CalculatePrice(0.37); Console.WriteLine("Price is {0}",price); Console.WriteLine("Findign and removing the longest call"); double longestCall = 0; int index = 0; for (int i = 0; i < newGSm.callHistory.Count; i++) { if (double.Parse(newGSm.callHistory[i].duration) > longestCall) { longestCall = double.Parse(newGSm.callHistory[i].duration); index = i; } } newGSm.callHistory.RemoveAt(index); Console.WriteLine("Recalculating price"); price = newGSm.CalculatePrice(0.37); Console.WriteLine("Price is {0}", price); newGSm.callHistory.Clear(); Console.WriteLine("History Cleared"); }