[Git][NTPsec/ntpsec][working] 8 commits: Added test for ntpcal_days_in_years.

Ian Bruene gitlab at mg.gitlab.com
Sat Jun 30 21:31:12 UTC 2018


Ian Bruene pushed to branch working at NTPsec / ntpsec


Commits:
c0a6ee36 by Ian Bruene at 2018-06-29T23:47:01Z
Added test for ntpcal_days_in_years.

- - - - -
80fe704e by Ian Bruene at 2018-06-30T00:09:43Z
Added test for ntpcal_edate_to_eradays.

- - - - -
dcd3c46b by Ian Bruene at 2018-06-30T00:17:50Z
Added test for ntpcal_etime_to_seconds.

- - - - -
638a2331 by Ian Bruene at 2018-06-30T15:15:23Z
Added test for ntpcal_tm_to_rd.

- - - - -
cd688b7c by Ian Bruene at 2018-06-30T15:29:13Z
Added tests for ntpcal_date_to_daysec and ntpcal_tm_to_daysec.

- - - - -
6f982e53 by Ian Bruene at 2018-06-30T15:36:02Z
Added test for ntpcal_date_to_time.

- - - - -
14be487b by Ian Bruene at 2018-06-30T20:33:45Z
Added tests for ntpcal_ntp64_to_date, ntpcal_ntp_to_date.

- - - - -
2e0da1b9 by Ian Bruene at 2018-06-30T21:30:19Z
Added test for ntpcal_periodic_event.

- - - - -


1 changed file:

- tests/libntp/ntp_calendar.c


Changes:

=====================================
tests/libntp/ntp_calendar.c
=====================================
--- a/tests/libntp/ntp_calendar.c
+++ b/tests/libntp/ntp_calendar.c
@@ -128,6 +128,17 @@ TEST(calendar, parse_to_unixtime) {
 }
 #endif
 
+TEST(calendar, PeriodicExtend1) {
+  // Test positive cycle, pivot > value
+  TEST_ASSERT_EQUAL(1001, ntpcal_periodic_extend(1000, 5, 2));
+  // Test positive cycle, pivot < value
+  TEST_ASSERT_EQUAL(6, ntpcal_periodic_extend(5, 1000, 2));
+  // Test negative cycle, pivot > value
+  TEST_ASSERT_EQUAL(999, ntpcal_periodic_extend(1000, 5, -2));
+  // Test negative cycle, pivot < value
+  TEST_ASSERT_EQUAL(4, ntpcal_periodic_extend(5, 1000, -2));
+}
+
 // test the NTP to 64-bit Unix scale time conversion
 TEST(calendar, NtpToTime1) {
     TEST_ASSERT_EQUAL(2085978538, ntpcal_ntp_to_time(42, 23));
@@ -272,6 +283,49 @@ TEST(calendar, TimeToDate1) {
 	TEST_ASSERT_EQUAL(1, jd.weekday);
 }
 
+TEST(calendar, DayJoin1) {
+	TEST_ASSERT_EQUAL(4323600, ntpcal_dayjoin(50, 3600));
+}
+
+TEST(calendar, DaysInYears1) {
+    // Test positive less than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(109572, ntpcal_days_in_years(300));
+	// Test positive one gregorian cycle of years
+	TEST_ASSERT_EQUAL(146097, ntpcal_days_in_years(400));
+	// Test positive greater than one gregorian cycle of years
+	TEST_ASSERT_EQUAL(182621, ntpcal_days_in_years(500));
+    // Test negative less than one gregorian cycle of years
+    TEST_ASSERT_EQUAL(-109573, ntpcal_days_in_years(-300));
+	// Test negative one gregorian cycle of years
+	TEST_ASSERT_EQUAL(-146097, ntpcal_days_in_years(-400));
+	// Test negative greater than one gregorian cycle of years
+	TEST_ASSERT_EQUAL(-182622, ntpcal_days_in_years(-500));
+}
+
+TEST(calendar, EdateToEradays1) {
+    // Test positive, no months
+    TEST_ASSERT_EQUAL(1827, ntpcal_edate_to_eradays(5, 0, 1));
+    // Test positive, with months
+    TEST_ASSERT_EQUAL(1917, ntpcal_edate_to_eradays(5, 3, 1));
+    // Test negative, no months
+    TEST_ASSERT_EQUAL(-1828, ntpcal_edate_to_eradays(-5, 0, -1));
+    // Test negative, with months
+    TEST_ASSERT_EQUAL(-1920, ntpcal_edate_to_eradays(-5, -3, -1));
+}
+
+TEST(calendar, EtimeToSeconds1) {
+    TEST_ASSERT_EQUAL(18181, ntpcal_etime_to_seconds(5, 3, 1));
+}
+
+TEST(calendar, TmToRd1) {
+    struct tm utm;
+
+	utm.tm_year = 10;
+	utm.tm_mon = 5;
+	utm.tm_mday = 1;
+    TEST_ASSERT_EQUAL(697399, ntpcal_tm_to_rd(&utm));
+}
+
 // check last day of february for first 10000 years
 TEST(calendar, LeapYears1) {
 	struct calendar dateIn, dateOut;
@@ -334,6 +388,60 @@ TEST(calendar, RoundTripDate) {
 	}
 }
 
+TEST(calendar, DateToDaysec1) {
+    struct calendar jd;
+
+	jd.hour = 18;
+	jd.minute = 45;
+	jd.second = 15;
+	TEST_ASSERT_EQUAL(67515, ntpcal_date_to_daysec(&jd));
+}
+
+TEST(calendar, TmToDaysec1) {
+    struct tm utm;
+
+	utm.tm_hour = 18;
+	utm.tm_min = 45;
+	utm.tm_sec = 15;
+	TEST_ASSERT_EQUAL(67515, ntpcal_tm_to_daysec(&utm));
+}
+
+TEST(calendar, DateToTime1) {
+    struct calendar jd;
+
+	jd.year = 1;
+	jd.month = 2;
+	jd.monthday = 4;
+	jd.hour = 8;
+	jd.minute = 16;
+	jd.second = 32;
+	TEST_ASSERT_EQUAL(-62132629408, ntpcal_date_to_time(&jd));
+}
+
+TEST(calendar, Ntp64ToDate1) {
+    struct calendar jd;
+
+	TEST_ASSERT_EQUAL(0, ntpcal_ntp64_to_date(&jd, 10000000));
+	TEST_ASSERT_EQUAL(1900, jd.year);
+	TEST_ASSERT_EQUAL(4, jd.month);
+	TEST_ASSERT_EQUAL(26, jd.monthday);
+	TEST_ASSERT_EQUAL(17, jd.hour);
+	TEST_ASSERT_EQUAL(46, jd.minute);
+	TEST_ASSERT_EQUAL(40, jd.second);
+}
+
+TEST(calendar, NtpToDate1) {
+    struct calendar jd;
+
+	TEST_ASSERT_EQUAL(1, ntpcal_ntp_to_date(&jd, 86400, 1000000));
+	TEST_ASSERT_EQUAL(2036, jd.year);
+	TEST_ASSERT_EQUAL(2, jd.month);
+	TEST_ASSERT_EQUAL(8, jd.monthday);
+	TEST_ASSERT_EQUAL(6, jd.hour);
+	TEST_ASSERT_EQUAL(28, jd.minute);
+	TEST_ASSERT_EQUAL(16, jd.second);
+}
+
 
 TEST_GROUP_RUNNER(calendar) {
 	RUN_TEST_CASE(calendar, is_leapyear);
@@ -342,6 +450,7 @@ TEST_GROUP_RUNNER(calendar) {
 #ifdef CLOCK_GENERIC
 	RUN_TEST_CASE(calendar, parse_to_unixtime);
 #endif
+	RUN_TEST_CASE(calendar, PeriodicExtend1);
 	RUN_TEST_CASE(calendar, NtpToTime1);
 	RUN_TEST_CASE(calendar, NtpToNtp1);
 	RUN_TEST_CASE(calendar, DaySplitMerge);
@@ -351,7 +460,17 @@ TEST_GROUP_RUNNER(calendar) {
 	RUN_TEST_CASE(calendar, SplitYearDays2);
 	RUN_TEST_CASE(calendar, RataDie1);
 	RUN_TEST_CASE(calendar, TimeToDate1);
+	RUN_TEST_CASE(calendar, DayJoin1);
+	RUN_TEST_CASE(calendar, DaysInYears1);
+	RUN_TEST_CASE(calendar, EdateToEradays1);
+	RUN_TEST_CASE(calendar, EtimeToSeconds1);
+	RUN_TEST_CASE(calendar, TmToRd1);
 	RUN_TEST_CASE(calendar, LeapYears1);
 	RUN_TEST_CASE(calendar, LeapYears2);
 	RUN_TEST_CASE(calendar, RoundTripDate);
+	RUN_TEST_CASE(calendar, DateToDaysec1);
+	RUN_TEST_CASE(calendar, TmToDaysec1);
+	RUN_TEST_CASE(calendar, DateToTime1);
+	RUN_TEST_CASE(calendar, Ntp64ToDate1);
+	RUN_TEST_CASE(calendar, NtpToDate1);
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/295fcad5a905f01bc88e1013f3b117738e6c9c1a...2e0da1b900fcb6fcfde3b02d06065a53d6ba901d

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/295fcad5a905f01bc88e1013f3b117738e6c9c1a...2e0da1b900fcb6fcfde3b02d06065a53d6ba901d
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180630/1a005e0a/attachment.html>


More information about the vc mailing list