Sha256: 03a51c2c950b8587528dd7ea541853dcbbd3a221306cec04b678f4f0e322400f

Contents?: true

Size: 1.88 KB

Versions: 81

Compression:

Stored size: 1.88 KB

Contents

#include "vendor/unity.h"
#include "../src/gigasecond.h"

// Constructs a time_t type from the given date settings
time_t construct_date(int year, int month, int day, int hour, int min, int sec)
{
   struct tm date;
   date.tm_year = year - 1900;
   date.tm_mon = month - 1;
   date.tm_mday = day;
   date.tm_hour = hour;
   date.tm_min = min;
   date.tm_sec = sec;
   date.tm_isdst = 0;
   return mktime(&date);
}

void test_date(void)
{
   time_t expected = construct_date(2043, 1, 1, 1, 46, 40);
   time_t actual = gigasecond_after(construct_date(2011, 4, 25, 0, 0, 0));
   TEST_ASSERT(expected == actual);
}

void test_another_date(void)
{
   time_t expected = construct_date(2009, 2, 19, 1, 46, 40);
   time_t actual = gigasecond_after(construct_date(1977, 6, 13, 0, 0, 0));
   TEST_ASSERT(expected == actual);
}

void test_third_date(void)
{
   time_t expected = construct_date(1991, 3, 27, 1, 46, 40);
   time_t actual = gigasecond_after(construct_date(1959, 7, 19, 0, 0, 0));
   TEST_ASSERT(expected == actual);
}

void test_date_and_time(void)
{
   time_t expected = construct_date(2046, 10, 2, 23, 46, 40);
   time_t actual = gigasecond_after(construct_date(2015, 1, 24, 22, 0, 0));
   TEST_ASSERT(expected == actual);
}

void test_date_and_time_with_day_rollover(void)
{
   time_t expected = construct_date(2046, 10, 3, 1, 46, 39);
   time_t actual = gigasecond_after(construct_date(2015, 1, 24, 23, 59, 59));
   TEST_ASSERT(expected == actual);
}

/*
void test_your_birthday(void)
{
   time_t birthday = construct_date(1989, 1, 1, 1, 1, 1);
   time_t gigday = gigasecond_after(birthday);
   printf(ctime(&gigday));
}
*/

int main(void)
{
   UnityBegin("test/test_gigasecond.c");

   RUN_TEST(test_date);
   RUN_TEST(test_another_date);
   RUN_TEST(test_third_date);
   RUN_TEST(test_date_and_time);
   RUN_TEST(test_date_and_time_with_day_rollover);
   //RUN_TEST(test_your_birthday);

   UnityEnd();
   return 0;
}

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
trackler-2.0.6.25 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.24 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.23 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.22 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.21 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.20 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.19 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.18 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.17 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.16 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.15 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.14 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.13 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.12 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.11 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.10 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.9 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.8 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.7 tracks/c/exercises/gigasecond/test/test_gigasecond.c
trackler-2.0.6.6 tracks/c/exercises/gigasecond/test/test_gigasecond.c