From a39e82719bd55d4059e9393b806033c9d7c0c49b Mon Sep 17 00:00:00 2001 From: Arjen Baart Date: Sun, 11 Aug 2019 09:25:47 +0200 Subject: [PATCH] Added tests for today() and date attributes. --- TODO | 4 +++- test/Makefile.am | 8 +++++-- test/date_attributes.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++ test/date_check_today.cpp | 27 ++++++++++++++++++++++ test/date_today | 7 ++++++ 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 test/date_attributes.cpp create mode 100644 test/date_check_today.cpp create mode 100755 test/date_today diff --git a/TODO b/TODO index c08422f..7ac6bdc 100644 --- a/TODO +++ b/TODO @@ -8,6 +8,8 @@ Things to do: - date: test parser for invalid dates and syntax errors - date: Parser for stream input +- date: Weekday and week number -- Include classes: time, complex, integer +- Include classes: UTC, complex, integer +- UTC: Convert to and from time_t, struct tm diff --git a/test/Makefile.am b/test/Makefile.am index b8642c1..c3f99c7 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,9 +1,9 @@ -TESTS = $(check_PROGRAMS) check_output +TESTS = $(check_PROGRAMS) date_today check_output AM_CPPFLAGS = -I../src LDADD = ../src/.libs/libACL.la check_PROGRAMS = string_assign string_basics string_compare string_cat string_substring string_regex \ - date_assign date_parse date_compare date_arithmetic + date_assign date_parse date_compare date_arithmetic date_attributes date_check_today string_assign_SOURCES = string_assign.cpp string_basics_SOURCES = string_basics.cpp @@ -16,4 +16,8 @@ date_assign_SOURCES = date_assign.cpp date_parse_SOURCES = date_parse.cpp date_compare_SOURCES = date_compare.cpp date_arithmetic_SOURCES = date_arithmetic.cpp +date_attributes_SOURCES = date_attributes.cpp +date_check_today_SOURCES = date_check_today.cpp + +date_today : date_check_today diff --git a/test/date_attributes.cpp b/test/date_attributes.cpp new file mode 100644 index 0000000..44204d4 --- /dev/null +++ b/test/date_attributes.cpp @@ -0,0 +1,57 @@ +/******************************************************* + * Unit test for the date class + * + * test date attribute functions + ****************************************************** + * + */ + +#include "date.h" +#include + +int main() +{ + date d0(9, 6, 2019); + + std::cout << d0 << " Day = " << d0.Day() << "\n"; + assert(d0.Day() == 9); + + std::cout << d0 << " Month = " << d0.Month() << "\n"; + assert(d0.Month() == 6); + + std::cout << d0 << " Monthname = " << d0.MonthName() << "\n"; + assert(d0.MonthName() == "Jun"); + + std::cout << d0 << " Year = " << d0.Year() << "\n"; + assert(d0.Year() == 2019); + + std::cout << d0 << " Leap = " << d0.Leap() << "\n"; + assert(d0.Leap() == 0); + + date d1(9, 6, 2020); + std::cout << d1 << " Leap = " << d1.Leap() << "\n"; + assert(d1.Leap() == 1); + + date d2(9, 6, 2000); + std::cout << d2 << " Leap = " << d2.Leap() << "\n"; + assert(d2.Leap() == 1); + + date d3(9, 6, 2100); + std::cout << d3 << " Leap = " << d3.Leap() << "\n"; + assert(d3.Leap() == 0); + + date d4(1, 1, 2019); + std::cout << d4.MonthName() << " " << d4.Year() << " has " << d4.DaysInMonth() << " days.\n"; + assert(d4.DaysInMonth() == 31); + + date d5(1, 2, 2019); + std::cout << d5.MonthName() << " " << d5.Year() << " has " << d5.DaysInMonth() << " days.\n"; + assert(d5.DaysInMonth() == 28); + + date d6(1, 2, 2020); + std::cout << d6.MonthName() << " " << d6.Year() << " has " << d6.DaysInMonth() << " days.\n"; + assert(d6.DaysInMonth() == 29); + + return 0; +} + diff --git a/test/date_check_today.cpp b/test/date_check_today.cpp new file mode 100644 index 0000000..5d0d9e0 --- /dev/null +++ b/test/date_check_today.cpp @@ -0,0 +1,27 @@ +/******************************************************* + * Unit test for the date class + * + * test contrustor and assignment of Sting objects + ****************************************************** + * + */ + +#include "date.h" +#include + +int main(int argc, char *argv[]) +{ + date d0; + + if (argc == 2) + { + String system_date(argv[1]); + date d1(system_date); + + d0 = today(); + assert(d0 == d1); + } + + return 0; +} + diff --git a/test/date_today b/test/date_today new file mode 100755 index 0000000..3640ea4 --- /dev/null +++ b/test/date_today @@ -0,0 +1,7 @@ +#!/bin/bash + +STATUS=0 + +TODAY=`date` +./date_check_today "$TODAY" +exit $? -- 2.11.0