Exemple #1
0
        public Boolean IsBetween(MyTime start, MyTime end)
        {
            int m1 = end.GetSecondsFromMidnight() - GetSecondsFromMidnight();
            int m2 = GetSecondsFromMidnight() - start.GetSecondsFromMidnight();

            return(m1 >= 0 && m2 >= 0);
        }
Exemple #2
0
        static void TimeSecConstructorTest()
        {
            MyTime actual   = new MyTime(25 * 60 * 60 + 120 + 1);
            MyTime expected = new MyTime(1, 2, 1);

            Assertions.AssertEquals(expected, actual, "TimeSecConstructorTest");
        }
Exemple #3
0
        public static String WhatLesson(MyTime t)
        {
            if (t.IsBetween(MyTime.from(8, 0, 0), MyTime.from(9, 20, 0)))
            {
                return("This is 1 Lecture");
            }

            if (t.IsBetween(MyTime.from(9, 40, 0), MyTime.from(11, 0, 0)))
            {
                return("This is 2 Lecture");
            }

            if (t.IsBetween(MyTime.from(11, 20, 0), MyTime.from(12, 40, 0)))
            {
                return("This is 3 Lecture");
            }

            if (t.IsBetween(MyTime.from(13, 0, 0), MyTime.from(14, 20, 0)))
            {
                return("This is 4 Lecture");
            }

            if (t.IsBetween(MyTime.from(14, 40, 0), MyTime.from(16, 0, 0)))
            {
                return("This is 5 Lecture");
            }

            return("There is chill time");
        }
Exemple #4
0
        static void TimeSinceMidnightTest()
        {
            MyTime actual   = MyTime.TimeSinceMidnight(1234);
            MyTime expected = new MyTime(0, 20, 34);

            Assertions.AssertEquals(expected, actual, "TimeSinceMidnightTest");
        }
Exemple #5
0
        static void WhatLessonTest()
        {
            MyTime t1       = new MyTime(8, 10, 12);
            String actual   = MyTime.WhatLesson(t1);
            String expected = "This is 1 Lecture";

            Assertions.AssertEquals(expected, actual, "WhatLessonTest");
        }
Exemple #6
0
        static void AddSecondsTest()
        {
            MyTime t        = new MyTime(23, 59, 59);
            MyTime actual   = t.AddSeconds(2);
            MyTime expected = new MyTime(0, 0, 1);

            Assertions.AssertEquals(expected, actual, "AddSecondsTest");
        }
Exemple #7
0
        static void TimeFromMidnightTest()
        {
            MyTime t        = new MyTime(1, 2, 3);
            int    expected = 1 * 60 * 60 + 2 * 60 + 3;
            int    actual   = t.TimeSinceMidnight();

            Assertions.AssertEquals(expected, actual, "TimeFromMidnightTest");
        }
Exemple #8
0
        static void ToStringTest()
        {
            MyTime t        = new MyTime(1, 2, 3);
            String expected = "1:02:03";
            String actual   = t.ToString();

            Assertions.AssertEquals(expected, actual, "ToStringTest");
        }
Exemple #9
0
        static void MinusTimeTest()
        {
            MyTime t1       = new MyTime(120);
            MyTime t2       = new MyTime(123);
            MyTime actual   = t1 - t2;
            MyTime expected = new MyTime(0, 0, 3);

            Assertions.AssertEquals(expected, actual, "MinusTimeTest");
        }
Exemple #10
0
 public static void AssertEquals(MyTime expected, MyTime actual, String testName)
 {
     if (expected.Equals(actual))
     {
         Console.WriteLine(testName + " PASSED");
     }
     else
     {
         Console.WriteLine(testName + " FAILED");
     }
 }
Exemple #11
0
        public override bool Equals(object obj)
        {
            if (obj != null)
            {
                if (obj == this)
                {
                    return(true);
                }

                MyTime t = (MyTime)obj;
                if (t.hour == hour && t.minute == minute && t.second == second)
                {
                    return(true);
                }
            }

            return(false);
        }