1 | '--------------------------------------------------------------------
|
---|
2 | ' Test case of DateTime Class
|
---|
3 | '--------------------------------------------------------------------
|
---|
4 |
|
---|
5 | Namespace DateTimeTest
|
---|
6 |
|
---|
7 | Imports System
|
---|
8 |
|
---|
9 | Sub TestMain()
|
---|
10 |
|
---|
11 | UnitTest("DateTime.Now" + " " + DateTime.Now.ToString(), True)
|
---|
12 |
|
---|
13 | UnitTest("DateTime.IsLeapYear - 2000", DateTime.IsLeapYear(2000) = True)
|
---|
14 | UnitTest("DateTime.IsLeapYear - 2001", DateTime.IsLeapYear(2001) = False)
|
---|
15 | UnitTest("DateTime.IsLeapYear - 2004", DateTime.IsLeapYear(2004) = True)
|
---|
16 | UnitTest("DateTime.IsLeapYear - 2100", DateTime.IsLeapYear(2100) = False)
|
---|
17 |
|
---|
18 | Dim testDateTime = New DateTime(2008, 12, 31, 23, 59, 59, 999)
|
---|
19 | UnitTest("DateTime.Millisecond", testDateTime.Millisecond = 999)
|
---|
20 | UnitTest("DateTime.Second", testDateTime.Second = 59)
|
---|
21 | UnitTest("DateTime.Minute", testDateTime.Minute = 59)
|
---|
22 | UnitTest("DateTime.Hour", testDateTime.Hour = 23)
|
---|
23 | UnitTest("DateTime.Day", testDateTime.Day = 31)
|
---|
24 | UnitTest("DateTime.Month", testDateTime.Month = 12)
|
---|
25 | UnitTest("DateTime.Year", testDateTime.Year = 2008)
|
---|
26 | UnitTest("DateTime.DayOfWeek", testDateTime.DayOfWeek = 3)'DayOfWeek.Wednesday)
|
---|
27 | UnitTest("DateTime.Kind", testDateTime.Kind = DateTimeKind.Unspecified)
|
---|
28 | UnitTest("DateTime.DayOfYear", testDateTime.DayOfYear = 366)
|
---|
29 |
|
---|
30 | UnitTest("DateTime.Equals", testDateTime.Equals(testDateTime))
|
---|
31 | UnitTest("DateTime.Compare (Case1)", DateTime.Compare(New DateTime(2000, 1, 2), New DateTime(2000, 1, 2)) = 0)
|
---|
32 | UnitTest("DateTime.Compare (Case2)", DateTime.Compare(New DateTime(2000, 1, 2), New DateTime(2000, 1, 1)) > 0)
|
---|
33 | UnitTest("DateTime.Compare (Case3)", DateTime.Compare(New DateTime(2000, 1, 1), New DateTime(2000, 1, 2)) < 0)
|
---|
34 |
|
---|
35 | Dim testDate = testDateTime.Date
|
---|
36 | UnitTest("DateTime.Date", DateTime.Compare(testDate, New DateTime(2008, 12, 31)) = 0)
|
---|
37 | UnitTest("DateTime.Add", testDate.Add(TimeSpan.FromTicks(863999990000)) = testDateTime)
|
---|
38 | UnitTest("DateTime.AddTicks", testDate.AddTicks(863999990000) = testDateTime)
|
---|
39 | UnitTest("DateTime.AddMilliseconds", testDate.AddMilliseconds(86399999) = testDateTime)
|
---|
40 | UnitTest("DateTime.AddSeconds", testDate.AddSeconds(86399.999) = testDateTime)
|
---|
41 | UnitTest("DateTime.AddMinutes", DateTime.Compare(testDate.AddMinutes(1), New DateTime(2008, 12, 31, 0, 1, 0)) = 0)
|
---|
42 | UnitTest("DateTime.AddHours", DateTime.Compare(testDate.AddHours(1), New DateTime(2008, 12, 31, 1, 0, 0)) = 0)
|
---|
43 | UnitTest("DateTime.AddDays", DateTime.Compare(testDate.AddDays(1), New DateTime(2009, 1, 1)) = 0)
|
---|
44 | UnitTest("DateTime.AddYears", DateTime.Compare(testDate.AddYears(1), New DateTime(2009, 12, 31)) = 0)
|
---|
45 | End Sub
|
---|
46 |
|
---|
47 | End Namespace
|
---|
48 |
|
---|
49 | DateTimeTest.TestMain()
|
---|