private static void Main(string[] args) { AlarmClock ac; // Test 1 ViewTestHeader("Test 1.\nTest av standardkonstruktorn."); ac = new AlarmClock(); Console.WriteLine(ac.ToString()); // Test 2 ViewTestHeader("Test 2.\nTest av konstruktorn med två parametrar, (9, 42)."); ac = new AlarmClock(9, 42); Console.WriteLine(ac.ToString()); // Test 3 ViewTestHeader("Test 3.\nTest av konstruktorn med fyra parametrar, (13, 24, 7, 35)."); ac = new AlarmClock(13, 24, 7, 35); Console.WriteLine(ac.ToString()); // Test 4 ViewTestHeader("Test 4.\nTest av konstruktorn med minst två parametrar av typen string, (\"7:07\", \"7:10\", \"7:15\", \"7:30\")."); ac = new AlarmClock("7:07", "7:10", "7:15", "7:30"); Console.WriteLine(ac.ToString()); // Test 5 ViewTestHeader("Test 5.\nStäller befintligt AlarmClock-objekt till 23:58 och låter den gå 13 minuter."); ac.Time = "23:58"; Run(ac, 13); // Test 6 ViewTestHeader("Test 6.\nStäller befintligt AlarmClock-objekt till tiden 6:12 och alarmtiden till 6:15 och låter den gå 6 minuter."); ac.Time = "6:12"; ac.AlarmTimes = new String[] { "6:15" }; Run(ac, 6); // Test 7 ViewTestHeader("Test 7.\nTestar egenskaperna så att ett undantag kastas då tid och alarmtid tilldelas felaktiga värden."); try { ac.Time = "24:89"; } catch (Exception e) { ViewErrorMessage(e.Message); } try { ac.AlarmTimes = new String[] { "7:69" }; } catch (Exception e) { ViewErrorMessage(e.Message); } // Test 8 ViewTestHeader("Test 8.\nTestar konstruktorer så att ett undantag kastas då tid och alarmtid tilldelas felaktiga värden."); try { ac = new AlarmClock("32:03", "27:00"); } catch (Exception e) { ViewErrorMessage(e.Message); } }
/// <summary> /// Runs the clock the specified minutes and prints the result /// </summary> /// <param name="ac">The clock to run</param> /// <param name="minutes">The amount of minutes to run</param> private static void Run(AlarmClock ac, int minutes) { Console.BackgroundColor = ConsoleColor.DarkRed; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557 "); Console.WriteLine(" \u2551 Väckarklockan URLED (TM) \u2551 "); Console.Write(" \u2551 "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Modellnr.: 1DV402S2L2C"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" \u2551 "); Console.WriteLine(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D "); Console.ResetColor(); for (int i = 0; i < minutes; i++) { if (ac.TickTock()) { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.WriteLine(" \u266B {0} BEEP! BEEP! BEEP! BEEP!", ac.ToString()); Console.ResetColor(); } else { Console.WriteLine(" {0}", ac.ToString()); } } }
/// <summary> /// The core of the test program /// </summary> /// <param name="args">Command-line Arguments</param> static void Main(string[] args) { //Test 1 ViewTestHeader("Test 1.\nTest av standardkonstuktorn."); AlarmClock test = new AlarmClock(); Console.WriteLine(test.ToString()); //Test2 ViewTestHeader("Test 2.\nTest av konstruktorn med två parametrar, (9, 42)."); test = new AlarmClock(9, 42); Console.WriteLine(test.ToString()); //Test3 ViewTestHeader("Test 3.\nTest av konstruktorn med fyra parametrar, (13, 24, 7, 35)."); test = new AlarmClock(13, 24, 7, 35); Console.WriteLine(test.ToString()); //Test4 ViewTestHeader("Test 4.\nTest av konstruktorn med minst två parametrar av typen string. (\"7:07\", \"7:10\", \"7:15\", \"7:30\")."); test = new AlarmClock("7:07", new[] { "7:10", "7:15", "7:30" }); Console.WriteLine(test.ToString()); //Test5 ViewTestHeader("Test 5.\nStäller befintligt AlarmClock-objekt till 23:58 och låter den gå 13 minuter."); test.Time = "23:58"; Run(test, 13); //Test6 ViewTestHeader("Test 6.\nStäller befintligt AlarmClock-objekt till tiden 6:12 och alarmtiden till 6:15 och låter den gå 6 minuter"); test.Time = "6:12"; test.AlarmTimes = new[] { "6:15" }; Run(test, 6); //Test7 ViewTestHeader("Test 7.\nTestar egenskaperna så att undantag kastas då tid och alarmtid tilldelas felaktiga värden."); try { test.Time = "24:89"; } catch (FormatException ex) { ViewErrorMessage(string.Format("Strängen '{0}' kan inte tolkas som en tid på formatet HH:mm", ex.Message)); } try { test.AlarmTimes = new[] { "7:69" }; } catch (FormatException ex) { ViewErrorMessage(string.Format("Strängen '{0}' kan inte tolkas som en tid på formatet HH:mm", ex.Message)); } //Test8 ViewTestHeader("Test 8.\nTestar konstruktorer så att undantag kastas då tid och alarmtid tilldelas felaktiga värden."); try { test = new AlarmClock(32, 03, 0, 0); } catch (ArgumentException ex) { ViewErrorMessage(string.Format("Strängen '{0}' kan inte tolkas som en tid på formatet HH", ex.Message)); } try { test = new AlarmClock(0, 0, 27, 00); } catch (ArgumentException ex) { ViewErrorMessage(string.Format("Strängen '{0}' kan inte tolkas som en tid på formatet HH", ex.Message)); } //Test9 ViewTestHeader("Test 9 (extra).\nTestar ifall flera alarmtider kan aktiveras under en och samma körning"); test = new AlarmClock("7:07", new[] { "7:09", "7:11", "7:14" }); Run(test, 8); }