示例#1
0
        public static void Main()
        {
            var gsms = new List<GSM>
            {
                new GSM("Galaxy 6", "Samsung", 800.00m, new Battery(BatteryType.LiIon, "model", 500, 100), new Display(5.3)),
                new GSM("6", "IPhone", 1200.00m, new Battery(BatteryType.LiIon, "model", 800, 400), new Display()),
                new GSM("Model", "LG", 400.00m, new Battery(BatteryType.NiCd, "model", 300, 100), new Display(4.5)),
                new GSM("Lumia 930", "Nokia", 500.00m, new Battery(BatteryType.NiMH, "model 3", 400, 200), new Display()),
                new GSM("Neshto si", "Sony", 450.00m, new Battery(BatteryType.NiCd, "model", 343, 140), new Display(4.8)),
                new GSM("Galaxy 4", "Samsung", 550.00m, new Battery(BatteryType.LiIon, "model", 400, 150), new Display())
            };

            foreach (var gsm in gsms)
            {
                Console.WriteLine(gsm);
            }

            Console.WriteLine(GSM.iPhone4s);

            var testCallsGsm = new GSM();
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(234), "+359888787878"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(434), "+35988865161"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(2234), "+359887846163"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(624), "+359885525056"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(12352), "+359884651625"));

            Console.WriteLine("Before removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));

            var longestcall = testCallsGsm.CallHistory.OrderByDescending(x => x.Length).FirstOrDefault();
            testCallsGsm.CallHistory.Remove(longestcall);
            Console.WriteLine("After removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
            testCallsGsm.ClearHistory();
            Console.WriteLine("After removing all the calls from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
        }
        public static void GSMCallHistoryTestMethod()
        {
            Console.WriteLine("\n------------------------------------");
            Console.WriteLine("        Call History Test!");
            Console.WriteLine("------------------------------------\n");

            GSM phone = new GSM("Galaxy S 3", "Samsung");

            phone.AddCall(new Call(DateTime.Parse("6/12/2009 07:23:00 AM"), "0888123456") { Duration = 31 });
            phone.AddCall(new Call(DateTime.Parse("10/11/2010 10:44:00 AM"), "0888678910") { Duration = 360 });
            phone.AddCall(new Call(DateTime.Parse("7/05/2012 06:56:00 PM"), "0888111213") { Duration = 600 });

            PrintCalls(phone);

            //Get longest call.
            var maxCall =
                (from call in phone.CallHistory
                 orderby call.Duration descending
                 select call).First();

            //Delete longest call.
            phone.DeleteCall(phone.CallHistory.IndexOf(maxCall));

            PrintCalls(phone);

            //Clear all calls.
            phone.ClearHistory();

            PrintCalls(phone);
        }
示例#3
0
        public static void TestCallHistory()
        {
            GSM motorola = new GSM("nexus", "Motorola", 500, "comapny phone", new Battery(BatteryType.NiCd), new Display(5, 2000));
            GSM newBrand = new GSM("SSD", "MegaHyper");

            motorola.AddCall(new Call("12/03/2015", "05:34", "0889888888", 100));
            motorola.AddCall(new Call("02.02.2012", "12:34", "0999999999", 140));
            motorola.AddCall(new Call("12.30.2012", "00:34", "0999999999", 12));
            ShowCalls(motorola.calls);
            Console.WriteLine("The Total Price is {0}", motorola.CalculateTotalPrice());
            motorola.FindAndRemoveLongestCall();
            Console.WriteLine("Longest call now removed");
            Console.WriteLine("The Total Price is {0:F2}", motorola.CalculateTotalPrice());
            motorola.ClearHistory();
            Console.WriteLine("Call history deleted");
        }
示例#4
0
        static void Main()
        {
            //create a test instance & add 3 calls
            var gsmTest = new GSM("nokia", "test model");

            gsmTest.AddCall(new Call(new DateTime(2015, 12, 31, 10, 00, 00), "0888123456", 61));
            gsmTest.AddCall(new Call(new DateTime(2016, 12, 31, 10, 15, 00), "0888666555", 333));
            gsmTest.AddCall(new Call(new DateTime(2017, 01, 01, 00, 00, 01), "0888123456", 60));


            //test call price calculations
            Console.WriteLine("Test call price calculation method\r\n==========================================");
            Console.WriteLine("Total Calls Count: {0}", gsmTest.CallHistory.Count);
            Console.WriteLine("Total Price: {0: 0.00}", gsmTest.CallPrice(0.37M));
            Console.WriteLine();

            //print initial state of the instance
            Console.WriteLine("Initial state of the gsmTest object\r\n==========================================\r\n{0}", gsmTest);

            //delete the longest call
            int indexLongestCall = -1;
            int maxSeconds       = 0;

            foreach (var call in gsmTest.CallHistory)
            {
                if (call.Duration > maxSeconds)
                {
                    maxSeconds = (int)call.Duration;
                    indexLongestCall++;
                }
            }
            gsmTest.DeleteCall(indexLongestCall);

            //print price without longest call
            Console.WriteLine("\r\nPrice calculation without the longest call\r\n==========================================");
            Console.WriteLine("Total Calls Count: {0}", gsmTest.CallHistory.Count);
            Console.WriteLine("Total Price: {0: 0.00}\r\n", gsmTest.CallPrice(0.37M));
            Console.WriteLine("gsmTest object without the longest call\r\n==========================================\r\n{0}", gsmTest);

            //print the final state of the instance

            //clear the history
            gsmTest.ClearHistory();

            Console.WriteLine("gsmTest object with cleared history\r\n==========================================\r\n{0}", gsmTest);
        }
        public void Test()
        {
            divaice.addCall(new Call(new DateTime(2015, 05, 27), new DateTime(2015, 07, 27, 13, 22, 12), "+359 445 874 254", 520));
            divaice.addCall(new Call(new DateTime(2015, 05, 27), new DateTime(2015, 06, 02, 12, 00, 40), "+359 105 574 794", 50));
            divaice.addCall(new Call(new DateTime(2015, 05, 27), new DateTime(2015, 05, 13, 20, 23, 09), "+359 845 774 851", 1520));
            divaice.addCall(new Call(new DateTime(2015, 05, 27), new DateTime(2015, 04, 12, 21, 16, 10), "+359 888 872 699", 5230));
            divaice.addCall(new Call(new DateTime(2015, 05, 27), new DateTime(2015, 03, 01, 01, 55, 00), "+359 111 111 125", 10));

            foreach (var call in divaice.CallHistory)
            {
                Console.WriteLine(call.ToString());
            }

            Console.WriteLine("The price of the calls is: " + divaice.TotalPrice(0.37M));
            int finalMax = 0;
            int index    = 0;
            int max      = divaice.CallHistory[0].Duration;

            for (int i = 0; i < divaice.CallHistory.Count; i++)
            {
                if (max < divaice.CallHistory[i].Duration)
                {
                    max = divaice.CallHistory[i].Duration;
                    if (max > finalMax)
                    {
                        finalMax = max;
                        index    = i;
                    }
                }
            }
            divaice.CallHistory.RemoveAt(index);
            Console.WriteLine("The price of the calls is: " + divaice.TotalPrice(0.37M));
            divaice.ClearHistory();
            Console.WriteLine("History: ");
            foreach (var call in divaice.CallHistory)
            {
                Console.WriteLine(call);
            }
        }
示例#6
0
        public static void Main()
        {
            var gsms = new List <GSM>
            {
                new GSM("Galaxy 6", "Samsung", 800.00m, new Battery(BatteryType.LiIon, "model", 500, 100), new Display(5.3)),
                new GSM("6", "IPhone", 1200.00m, new Battery(BatteryType.LiIon, "model", 800, 400), new Display()),
                new GSM("Model", "LG", 400.00m, new Battery(BatteryType.NiCd, "model", 300, 100), new Display(4.5)),
                new GSM("Lumia 930", "Nokia", 500.00m, new Battery(BatteryType.NiMH, "model 3", 400, 200), new Display()),
                new GSM("Neshto si", "Sony", 450.00m, new Battery(BatteryType.NiCd, "model", 343, 140), new Display(4.8)),
                new GSM("Galaxy 4", "Samsung", 550.00m, new Battery(BatteryType.LiIon, "model", 400, 150), new Display())
            };

            foreach (var gsm in gsms)
            {
                Console.WriteLine(gsm);
            }

            Console.WriteLine(GSM.iPhone4s);

            var testCallsGsm = new GSM();

            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(234), "+359888787878"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(434), "+35988865161"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(2234), "+359887846163"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(624), "+359885525056"));
            testCallsGsm.AddCall(new Call(DateTime.Now, DateTime.Now.AddSeconds(12352), "+359884651625"));

            Console.WriteLine("Before removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));

            var longestcall = testCallsGsm.CallHistory.OrderByDescending(x => x.Length).FirstOrDefault();

            testCallsGsm.CallHistory.Remove(longestcall);
            Console.WriteLine("After removing the longest call from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
            testCallsGsm.ClearHistory();
            Console.WriteLine("After removing all the calls from call history the price is - {0:F2}", testCallsGsm.CalculatePrice(0.37));
        }
示例#7
0
        static void Main(string[] args)
        {
            GSM justInstance = new GSM();

            //Testing full parameter ctor
            Console.WriteLine(new string('-', 80));
            GSM Nokia = new GSM("E52", "Nokia", 200.0m, "Ivan", new Battery("2000 mAh", 12.3, 4.5, BatteryType.NiMH), new Display(2.6, 16000000));
            Console.WriteLine("\nTesting full parameter ctor");
            Console.WriteLine(Nokia.ToString());

            //Testing full param ctor with default Battery and Display
            Console.WriteLine(new string('-', 80));
            GSM Nokia1 = new GSM("E52", "Nokia", 200.0m, "Ivan", new Battery(), new Display());
            Console.WriteLine("\nTesting full param ctor with default Battery and Display");
            Console.WriteLine(Nokia1.ToString());

            //Testing partial param ctor
            Console.WriteLine(new string('-', 80));
            GSM Nokia2 = new GSM("E52", "Nokia");
            Console.WriteLine("\nTesting partial param ctor");
            Console.WriteLine(Nokia2.ToString());

            ///////////////////////////TASK 7 tests//////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 7 TEST START HERE !");
            GSM[] gsmList = new GSM[5];
            for (int i = 0; i < 5; i++)
            {
                gsmList[i] = Nokia;
            }
            foreach (GSM gsm in gsmList)
            {
                Console.WriteLine(gsm.ToString() + "\n");
            }

            Console.WriteLine("\nPrinting static field iPhone4s");
            Console.WriteLine(justInstance.IPhone4s);

            ///////////////////////////TASK 10 tests////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 10 TEST START HERE !");
            GSM vladosPhone = new GSM("S35", "Siemens", 79.99m, "Vlado", new Battery("750mAh", 72, 6, BatteryType.LiIon), new Display(1.5, 64), null);
            vladosPhone.AddCalltoHistory(new Call("+359888555777",3600));
            vladosPhone.AddCalltoHistory(new Call("0000",0));
            vladosPhone.AddCalltoHistory(new Call("+359888000000",15));
            vladosPhone.AddCalltoHistory(new Call("0888555777",10));
            vladosPhone.AddCalltoHistory(new Call("028685512",20));
            vladosPhone.AddCalltoHistory(new Call("0359887551552",60));
            vladosPhone.PrintCallLog();
            vladosPhone.DeleteCallFromHistory(new Call("+359888555777"));
            vladosPhone.DeleteCallFromHistory(new Call("0000"));
            vladosPhone.DeleteCallFromHistory(new Call("+359888000000"));
            Console.WriteLine("Testing callHistory delete function:");
            vladosPhone.PrintCallLog();
            Console.WriteLine("Testing callHistory clear function:");
            vladosPhone.ClearHistory();
            vladosPhone.PrintCallLog();

            ///////////////////////////TASK 11 tests////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 11 TEST START HERE !");
            vladosPhone.AddCalltoHistory(new Call("+359888555777", 3600));
            vladosPhone.AddCalltoHistory(new Call("+359888000000", 15));
            vladosPhone.AddCalltoHistory(new Call("0359887551552", 60));
            vladosPhone.CalculatePrice();

            ///////////////////////////TASK 12 tests////////////////////////////
            Console.WriteLine(new string('-', 80));
            Console.WriteLine("\nTASK 12 TEST START HERE !");
            /*  Write a class GSMCallHistoryTest to test the call history functionality of the GSM class.
                Create an instance of the GSM class.
                Add few calls.
                Display the information about the calls.
                Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history.
                Remove the longest call from the history and calculate the total price again.
                Finally clear the call history and print it.
            */
            //Create an instance of the GSM class.
            GSM instance = new GSM();
            // Add few calls.
            instance.AddCalltoHistory(new Call("+359888555777", 3600));
            instance.AddCalltoHistory(new Call("+359888123321", 300));
            instance.AddCalltoHistory(new Call("0359888333222", 80));
            instance.AddCalltoHistory(new Call("028683939", 50));
            instance.AddCalltoHistory(new Call("+123000128937912837", 0));
            // Display the information about the calls.
            instance.PrintCallLog();
            //Assuming that the price per minute is 0.37 calculate and print the total price of the calls in the history.
            instance.CalculatePrice();
            //Remove the longest call from the history and calculate the total price again.
            instance.DeleteCallFromHistory(new Call("+359888555777"));
            instance.CalculatePrice();
            // Finally clear the call history and print it.
            instance.ClearHistory();
            instance.PrintCallLog();
        }