|
| 1 | +#include "vendor/unity.h" |
| 2 | + |
| 3 | +#include <stddef.h> |
| 4 | +#include <stdbool.h> |
| 5 | + |
| 6 | +extern bool shared_birthday(const char **birthdates); |
| 7 | + |
| 8 | +// estimated probability of shared birthday |
| 9 | +extern double estimate(int group_size); |
| 10 | + |
| 11 | +void setUp(void) { |
| 12 | +} |
| 13 | + |
| 14 | +void tearDown(void) { |
| 15 | +} |
| 16 | + |
| 17 | +void test_one_birthdate(void) { |
| 18 | + const char *birthdates[] = {"2000-01-01", NULL}; |
| 19 | + TEST_ASSERT_FALSE(shared_birthday(birthdates)); |
| 20 | +} |
| 21 | + |
| 22 | +void test_two_birthdates_with_same_year_month_and_day(void) { |
| 23 | + TEST_IGNORE(); |
| 24 | + const char *birthdates[] = {"2000-01-01", "2000-01-01", NULL}; |
| 25 | + TEST_ASSERT_TRUE(shared_birthday(birthdates)); |
| 26 | +} |
| 27 | + |
| 28 | +void test_two_birthdates_with_same_year_and_month_but_different_day(void) { |
| 29 | + TEST_IGNORE(); |
| 30 | + const char *birthdates[] = {"2012-05-09", "2012-05-17", NULL}; |
| 31 | + TEST_ASSERT_FALSE(shared_birthday(birthdates)); |
| 32 | +} |
| 33 | + |
| 34 | +void test_two_birthdates_with_same_month_and_day_but_different_year(void) { |
| 35 | + TEST_IGNORE(); |
| 36 | + const char *birthdates[] = {"1999-10-23", "1988-10-23", NULL}; |
| 37 | + TEST_ASSERT_TRUE(shared_birthday(birthdates)); |
| 38 | +} |
| 39 | + |
| 40 | +void test_two_birthdates_with_same_year_but_different_month_and_day(void) { |
| 41 | + TEST_IGNORE(); |
| 42 | + const char *birthdates[] = {"2007-12-19", "2007-04-27", NULL}; |
| 43 | + TEST_ASSERT_FALSE(shared_birthday(birthdates)); |
| 44 | +} |
| 45 | + |
| 46 | +void test_two_birthdates_with_different_year_month_and_day(void) { |
| 47 | + TEST_IGNORE(); |
| 48 | + const char *birthdates[] = {"1997-08-04", "1963-11-23", NULL}; |
| 49 | + TEST_ASSERT_FALSE(shared_birthday(birthdates)); |
| 50 | +} |
| 51 | + |
| 52 | +void test_multiple_birthdates_without_shared_birthday(void) { |
| 53 | + TEST_IGNORE(); |
| 54 | + const char *birthdates[] = {"1966-07-29", "1977-02-12", "2001-12-25", "1980-11-10", NULL}; |
| 55 | + TEST_ASSERT_FALSE(shared_birthday(birthdates)); |
| 56 | +} |
| 57 | + |
| 58 | +void test_multiple_birthdates_with_one_shared_birthday(void) { |
| 59 | + TEST_IGNORE(); |
| 60 | + const char *birthdates[] = {"1966-07-29", "1977-02-12", "2001-07-29", "1980-11-10", NULL}; |
| 61 | + TEST_ASSERT_TRUE(shared_birthday(birthdates)); |
| 62 | +} |
| 63 | + |
| 64 | +void test_multiple_birthdates_with_more_than_one_shared_birthday(void) { |
| 65 | + TEST_IGNORE(); |
| 66 | + const char *birthdates[] = {"1966-07-29", "1977-02-12", "2001-12-25", "1980-07-29", "2019-02-12", NULL}; |
| 67 | + TEST_ASSERT_TRUE(shared_birthday(birthdates)); |
| 68 | +} |
| 69 | + |
| 70 | +void test_for_one_person(void) { |
| 71 | + TEST_IGNORE(); |
| 72 | + TEST_ASSERT_FLOAT_WITHIN(0.05, 0.0, estimate(1)); |
| 73 | +} |
| 74 | + |
| 75 | +void test_among_ten_people(void) { |
| 76 | + TEST_IGNORE(); |
| 77 | + TEST_ASSERT_FLOAT_WITHIN(0.05, 11.694818, estimate(10)); |
| 78 | +} |
| 79 | + |
| 80 | +void test_among_twentythree_people(void) { |
| 81 | + TEST_IGNORE(); |
| 82 | + TEST_ASSERT_FLOAT_WITHIN(0.05, 50.729723, estimate(23)); |
| 83 | +} |
| 84 | + |
| 85 | +void test_among_seventy_people(void) { |
| 86 | + TEST_IGNORE(); |
| 87 | + TEST_ASSERT_FLOAT_WITHIN(0.05, 99.915958, estimate(70)); |
| 88 | +} |
| 89 | + |
| 90 | +int main(void) { |
| 91 | + UNITY_BEGIN(); |
| 92 | + RUN_TEST(test_one_birthdate); |
| 93 | + RUN_TEST(test_two_birthdates_with_same_year_month_and_day); |
| 94 | + RUN_TEST(test_two_birthdates_with_same_year_and_month_but_different_day); |
| 95 | + RUN_TEST(test_two_birthdates_with_same_month_and_day_but_different_year); |
| 96 | + RUN_TEST(test_two_birthdates_with_same_year_but_different_month_and_day); |
| 97 | + RUN_TEST(test_two_birthdates_with_different_year_month_and_day); |
| 98 | + RUN_TEST(test_multiple_birthdates_without_shared_birthday); |
| 99 | + RUN_TEST(test_multiple_birthdates_with_one_shared_birthday); |
| 100 | + RUN_TEST(test_multiple_birthdates_with_more_than_one_shared_birthday); |
| 101 | + RUN_TEST(test_for_one_person); |
| 102 | + RUN_TEST(test_among_ten_people); |
| 103 | + RUN_TEST(test_among_twentythree_people); |
| 104 | + RUN_TEST(test_among_seventy_people); |
| 105 | + return UNITY_END(); |
| 106 | +} |
0 commit comments