Example #1
0
        public void TestMethodToUniversalString()
        {
            Time2 myTime = new Time2(11, 4, 5);

            //NUnit
            string expResult = "11:04:05";

            Assert.AreEqual(expResult, myTime.ToUniversalString());
        }
Example #2
0
    public static void Main(string[] args)
    {
        Time2 t1 = new Time2();           // 00:00:00
        Time2 t2 = new Time2(2);          // 02:00:00
        Time2 t3 = new Time2(21, 34);     // 21:34:00
        Time2 t4 = new Time2(12, 25, 42); // 12:25:42
        Time2 t5 = new Time2(t4);         // 12:25:42
        Time2 t6;                         // initialized later in the program

        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine("   {0}", t1.ToUniversalString()); // 00:00:00
        Console.WriteLine("   {0}\n", t1.ToString());        // 12:00:00 AM

        Console.WriteLine("t2: hour specified; minute and second defaulted");
        Console.WriteLine("   {0}", t2.ToUniversalString()); // 02:00:00
        Console.WriteLine("   {0}\n", t2.ToString());        // 2:00:00 AM

        Console.WriteLine("t3: hour and minute specified; second defaulted");
        Console.WriteLine("   {0}", t3.ToUniversalString()); // 21:34:00
        Console.WriteLine("   {0}\n", t3.ToString());        // 9:34:00 PM

        Console.WriteLine("t4: hour, minute and second specified");
        Console.WriteLine("   {0}", t4.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}\n", t4.ToString());        // 12:25:42 PM

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine("   {0}", t5.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}", t5.ToString());          // 12:25:42 PM

        // attempt to initialize t6 with invalid values
        try
        {
            t6 = new Time2(27, 74, 99); // invalid values
        } // end try
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        } // end catch

        Console.WriteLine("\nTecle qualquer tecla para finalizar...");
        Console.ReadKey();
    } // end Main
Example #3
0
    static void Main()
    {
        var t1 = new Time2();           // 00:00:00
        var t2 = new Time2(2);          // 02:00:00
        var t3 = new Time2(21, 34);     // 21:34:00
        var t4 = new Time2(12, 25, 42); // 12:25:42
        var t5 = new Time2(t4);         // 12:25:42

        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine($"   {t1.ToUniversalString()}"); // 00:00:00
        Console.WriteLine($"   {t1.ToString()}\n");        // 12:00:00 AM

        Console.WriteLine(
            "t2: hour specified; minute and second defaulted");
        Console.WriteLine($"   {t2.ToUniversalString()}"); // 02:00:00
        Console.WriteLine($"   {t2.ToString()}\n");        // 2:00:00 AM

        Console.WriteLine(
            "t3: hour and minute specified; second defaulted");
        Console.WriteLine($"   {t3.ToUniversalString()}"); // 21:34:00
        Console.WriteLine($"   {t3.ToString()}\n");        // 9:34:00 PM

        Console.WriteLine("t4: hour, minute and second specified");
        Console.WriteLine($"   {t4.ToUniversalString()}"); // 12:25:42
        Console.WriteLine($"   {t4.ToString()}\n");        // 12:25:42 PM

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine($"   {t5.ToUniversalString()}"); // 12:25:42
        Console.WriteLine($"   {t5.ToString()}");          // 12:25:42 PM

        // attempt to initialize t6 with invalid values
        try
        {
            var t6 = new Time2(27, 74, 99); // invalid values
        }
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        }
    }
    static void Main()
    {
        var t1 = new Time2();
        var t2 = new Time2(2);
        var t3 = new Time2(21, 34);
        var t4 = new Time2(12, 25, 42);
        var t5 = new Time2(t4);

        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine($"{t1.ToUniversalString()}");
        Console.WriteLine($"{t1.ToString()}\n");

        Console.WriteLine("t2: hour specified; minute and second defaulted");
        Console.WriteLine($"{t2.ToUniversalString()}");
        Console.WriteLine($"{t2.ToString()}\n");

        Console.WriteLine("t3: hour and minute specified; second defaulted");
        Console.WriteLine($"{t3.ToUniversalString()}");
        Console.WriteLine($"{t3.ToString()}\n");

        Console.WriteLine("t4: hour, minute and second defaulted");
        Console.WriteLine($"{t4.ToUniversalString()}");
        Console.WriteLine($"{t4.ToString()}\n");

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine($"{t5.ToUniversalString()}");
        Console.WriteLine($"{t5.ToString()}");


        try
        {
            var t6 = new Time2(27, 74, 99);
        }
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        }

        Console.ReadLine();
    }
    public static void Main()
    {
        Time2 t1 = new Time2();           // 00:00:00
        Time2 t2 = new Time2(2);          // 02:00:00
        Time2 t3 = new Time2(21, 34);     // 21:34:00
        Time2 t4 = new Time2(12, 25, 42); // 12:25:42
        Time2 t5 = new Time2(27, 74, 99); // 00:00:00
        Time2 t6 = new Time2(t4);         // 12:25:42

        Console.WriteLine("Constructed with :\n");

        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine("    {0}", t1.ToUniversalString());
        Console.WriteLine("    {0}\n", t1.ToString());

        Console.WriteLine("t2: hour specified");
        Console.WriteLine("    {0}", t2.ToUniversalString());
        Console.WriteLine("    {0}\n", t2.ToString());

        Console.WriteLine("t3: hour & minute specified");
        Console.WriteLine("    {0}", t3.ToUniversalString());
        Console.WriteLine("    {0}\n", t3.ToString());

        Console.WriteLine("t4: hour & minute & seconde specified");
        Console.WriteLine("    {0}", t4.ToUniversalString());
        Console.WriteLine("    {0}\n", t4.ToString());

        Console.WriteLine("t5: all invalid arguments");
        Console.WriteLine("    {0}", t5.ToUniversalString());
        Console.WriteLine("    {0}\n", t5.ToString());

        Console.WriteLine("t6: Time2 object t4 specified");
        Console.WriteLine("    {0}", t6.ToUniversalString());
        Console.WriteLine("    {0}\n", t6.ToString());

        Console.ReadLine();
    } // end Main
Example #6
0
    public static void Main( string[] args )
    {
        Time2 t1 = new Time2(); // 00:00:00
          Time2 t2 = new Time2( 2 ); // 02:00:00
          Time2 t3 = new Time2( 21, 34 ); // 21:34:00
          Time2 t4 = new Time2( 12, 25, 42 ); // 12:25:42
          Time2 t5 = new Time2( 27, 74, 99 ); // 00:00:00
          Time2 t6 = new Time2( t4 ); // 12:25:42

          Console.WriteLine( "Constructed with:\n" );
          Console.WriteLine( "t1: all arguments defaulted" );
          Console.WriteLine( "   {0}", t1.ToUniversalString() ); // 00:00:00
          Console.WriteLine( "   {0}\n", t1.ToString() ); // 12:00:00 AM

          Console.WriteLine(
         "t2: hour specified; minute and second defaulted" );
          Console.WriteLine( "   {0}", t2.ToUniversalString() ); // 02:00:00
          Console.WriteLine( "   {0}\n", t2.ToString() ); // 2:00:00 AM

          Console.WriteLine(
         "t3: hour and minute specified; second defaulted" );
          Console.WriteLine( "   {0}", t3.ToUniversalString() ); // 21:34:00
          Console.WriteLine( "   {0}\n", t3.ToString() ); // 9:34:00 PM

          Console.WriteLine( "t4: hour, minute and second specified" );
          Console.WriteLine( "   {0}", t4.ToUniversalString() ); // 12:25:42
          Console.WriteLine( "   {0}\n", t4.ToString() ); // 12:25:42 PM

          Console.WriteLine( "t5: all invalid values specified" );
          Console.WriteLine( "   {0}", t5.ToUniversalString() ); // 00:00:00
          Console.WriteLine( "   {0}\n", t5.ToString() ); // 12:00:00 AM

          Console.WriteLine( "t6: Time2 object t4 specified" );
          Console.WriteLine( "   {0}", t6.ToUniversalString() ); // 12:25:42
          Console.WriteLine( "   {0}", t6.ToString() ); // 12:25:42 PM
    }
Example #7
0
    public static void Main(string[] args)
    {
        Time2 t1 = new Time2();           // 00:00:00
        Time2 t2 = new Time2(2);          // 02:00:00
        Time2 t3 = new Time2(21, 34);     // 21:34:00
        Time2 t4 = new Time2(12, 25, 42); // 12:25:42
        Time2 t5 = new Time2(t4);         // 12:25:42
        Time2 t6;                         // initialized later in the program

        Time2 t44 = new Time2(12, 25, 42);
        Time2 t41 = t4;

        if (t4.Equals(t44))
        {
            Console.WriteLine("No way");
        }
        else
        {
            Console.WriteLine("t4 and t44 point to different objects");
        }

        if (t4.Equals(t41))
        {
            Console.WriteLine("t4 and t41 point to the same object");
        }


        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine("   {0}", t1.ToUniversalString()); // 00:00:00
        Console.WriteLine("   {0}\n", t1.ToString());        // 12:00:00 AM

        Console.WriteLine(
            "t2: hour specified; minute and second defaulted");
        Console.WriteLine("   {0}", t2.ToUniversalString()); // 02:00:00
        Console.WriteLine("   {0}\n", t2.ToString());        // 2:00:00 AM

        Console.WriteLine(
            "t3: hour and minute specified; second defaulted");
        Console.WriteLine("   {0}", t3.ToUniversalString()); // 21:34:00
        Console.WriteLine("   {0}\n", t3.ToString());        // 9:34:00 PM

        Console.WriteLine("t4: hour, minute and second specified");
        Console.WriteLine("   {0}", t4.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}\n", t4.ToString());        // 12:25:42 PM

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine("   {0}", t5.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}", t5.ToString());          // 12:25:42 PM

        // attempt to initialize t6 with invalid values
        try
        {
            t6 = new Time2(27, 74, 99); // invalid values
        } // end try
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        } // end catch
        Console.WriteLine("Push Enter to end the program");
        string s = Console.ReadLine();
    } // end Main
Example #8
0
        public static void Main(string[] args)
        {
            try
            {
                // Test Case - 1
                // Initializing constructor without parameters
                Time2 t1 = new Time2();
                Console.WriteLine("t1: all arguments defaulted");
                Console.WriteLine(" {0}", t1.ToUniversalString());
                Console.WriteLine(" {0}\n", t1.ToString());

                // Test Case - 2
                // Initializing constructor with one single parameter - hour
                Time2 t2 = new Time2(2);
                Console.WriteLine("Constructed with:\n");
                Console.WriteLine("t2: hour specified; minute and second defaulted");
                Console.WriteLine(" {0}", t2.ToUniversalString());
                Console.WriteLine(" {0}\n", t2.ToString());

                // Test Case - 3
                // Initializing constructor with two parameters - hour, minute
                Time2 t3 = new Time2(21, 34);
                Console.WriteLine("t3: hour and minute specified; second defaulted");
                Console.WriteLine(" {0}", t3.ToUniversalString());
                Console.WriteLine(" {0}\n", t3.ToString());

                // Test Case - 4
                // Initializing constructor with all parameters - hour, minute, second
                Time2 t4 = new Time2(12, 25, 42);
                Console.WriteLine("t4: hour, minute and second specified");
                Console.WriteLine(" {0}", t4.ToUniversalString());
                Console.WriteLine(" {0}\n", t4.ToString());


                // Test Case - 5
                // Initializing constructor with previous object
                Time2 t5 = new Time2(t4);
                Console.WriteLine("t5: Time2 object t4 specified");
                Console.WriteLine(" {0}", t5.ToUniversalString());
                Console.WriteLine(" {0}", t5.ToString());


                // Test Case - 6 (Negative Test Case)
                // Adding invalid values for hour, minute, second
                Time2 t6 = new Time2();
                Console.WriteLine("Running test case #6 - Adding invalid values for hour, minute, second");
                try
                {
                    t6.addtime(25, 120, 120);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                // Resetting the time object t1 to valid values
                t6.SetTime(4, 5, 6);


                // Test Case - 7 (Negative Test Case)
                // Invalid values
                Time2 t7;

                try
                {
                    t7 = new Time2(27, 45, 99);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("\nException while initializing t7:");
                    Console.WriteLine(ex.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }