11#include " baffling_birthdays.h"
2+
3+ #include < boost/date_time/gregorian/gregorian.hpp>
24#ifdef EXERCISM_TEST_SUITE
35#include < catch2/catch.hpp>
46#else
57#include " test/catch.hpp"
68#endif
79
10+ using namespace baffling_birthdays ;
11+ using boost::gregorian::date;
12+
813TEST_CASE (" one_birthdate" , " [716dcc2b-8fe4-4fc9-8c48-cbe70d8e6b67]" ) {
9- std::vector<std::string> birthdates{ " 2000-01-01 " };
10- REQUIRE_FALSE (baffling_birthdays:: shared_birthday (birthdates ));
14+ std::vector<date> dates{ date ( 2000 , 1 , 1 ) };
15+ REQUIRE_FALSE (shared_birthday (dates ));
1116}
1217
1318#if defined(EXERCISM_RUN_ALL_TESTS)
1419
1520TEST_CASE (" two_birthdates_with_same_year_month_and_day" ,
16- " [f7b3eb26-bcfc-4a1e -a2de-af07afc33f45]" ) {
17- std::vector<std::string> birthdates{ " 2000-01-01 " , " 2000-01-01 " };
18- REQUIRE (baffling_birthdays:: shared_birthday (birthdates ));
21+ " [f7b3eb26-bcfc-4e1e -a2de-af07afc33f45]" ) {
22+ std::vector<date> dates{ date ( 2000 , 1 , 1 ), date ( 2000 , 1 , 1 ) };
23+ REQUIRE (shared_birthday (dates ));
1924}
2025
2126TEST_CASE (" two_birthdates_with_same_year_and_month_but_different_day" ,
2227 " [7193409a-6e16-4bcb-b4cc-9ffe55f79b25]" ) {
23- std::vector<std::string> birthdates{ " 2012-05-09 " , " 2012-05-17 " };
24- REQUIRE_FALSE (baffling_birthdays:: shared_birthday (birthdates ));
28+ std::vector<date> dates{ date ( 2012 , 5 , 9 ), date ( 2012 , 5 , 17 ) };
29+ REQUIRE_FALSE (shared_birthday (dates ));
2530}
2631
2732TEST_CASE (" two_birthdates_with_same_month_and_day_but_different_year" ,
2833 " [d04db648-121b-4b72-93e8-d7d2dced4495]" ) {
29- std::vector<std::string> birthdates{ " 1999-10-23 " , " 1988-10-23 " };
30- REQUIRE (baffling_birthdays:: shared_birthday (birthdates ));
34+ std::vector<date> dates{ date ( 1999 , 10 , 23 ), date ( 1988 , 10 , 23 ) };
35+ REQUIRE (shared_birthday (dates ));
3136}
3237
3338TEST_CASE (" two_birthdates_with_same_year_but_different_month_and_day" ,
3439 " [3c8bd0f0-14c6-4d4c-975a-4c636bfdc233]" ) {
35- std::vector<std::string> birthdates{ " 2007-12-19 " , " 2007-04-27 " };
36- REQUIRE_FALSE (baffling_birthdays:: shared_birthday (birthdates ));
40+ std::vector<date> dates{ date ( 2007 , 12 , 19 ), date ( 2007 , 4 , 27 ) };
41+ REQUIRE_FALSE (shared_birthday (dates ));
3742}
3843
3944TEST_CASE (" two_birthdates_with_different_year_month_and_day" ,
4045 " [df5daba6-0879-4480-883c-e855c99cdaa3]" ) {
41- std::vector<std::string> birthdates{ " 1997-08-04 " , " 1963-11-23 " };
42- REQUIRE_FALSE (baffling_birthdays:: shared_birthday (birthdates ));
46+ std::vector<date> dates{ date ( 1997 , 8 , 4 ), date ( 1963 , 11 , 23 ) };
47+ REQUIRE_FALSE (shared_birthday (dates ));
4348}
4449
4550TEST_CASE (" multiple_birthdates_without_shared_birthday" ,
4651 " [0c17b220-cbb9-4bd7-872f-373044c7b406]" ) {
47- std::vector<std::string> birthdates{ " 1966-07-29 " , " 1977-02-12 " ,
48- " 2001-12-25 " , " 1980-11-10 " };
49- REQUIRE_FALSE (baffling_birthdays:: shared_birthday (birthdates ));
52+ std::vector<date> dates{ date ( 1966 , 7 , 29 ), date ( 1977 , 2 , 12 ) ,
53+ date ( 2001 , 12 , 25 ), date ( 1980 , 11 , 10 ) };
54+ REQUIRE_FALSE (shared_birthday (dates ));
5055}
5156
5257TEST_CASE (" multiple_birthdates_with_one_shared_birthday" ,
5358 " [966d6b0b-5c0a-4b8c-bc2d-64939ada49f8]" ) {
54- std::vector<std::string> birthdates{ " 1966-07-29 " , " 1977-02-12 " ,
55- " 2001-07-29 " , " 1980-11-10 " };
56- REQUIRE (baffling_birthdays:: shared_birthday (birthdates ));
59+ std::vector<date> dates{ date ( 1966 , 7 , 29 ), date ( 1977 , 2 , 12 ) ,
60+ date ( 2001 , 7 , 29 ), date ( 1980 , 11 , 10 ) };
61+ REQUIRE (shared_birthday (dates ));
5762}
5863
5964TEST_CASE (" multiple_birthdates_with_more_than_one_shared_birthday" ,
6065 " [b7937d28-403b-4500-acce-4d9fe3a9620d]" ) {
61- std::vector<std::string> birthdates{
62- " 1966-07-29" , " 1977-02-12" , " 2001-12-25" , " 1980-07-29" , " 2019-02-12" };
63- REQUIRE (baffling_birthdays::shared_birthday (birthdates));
66+ std::vector<date> dates{date (1966 , 7 , 29 ), date (1977 , 2 , 12 ),
67+ date (2001 , 12 , 25 ), date (1980 , 7 , 29 ),
68+ date (2019 , 2 , 12 )};
69+ REQUIRE (shared_birthday (dates));
6470}
6571
6672TEST_CASE (" generate_requested_number_of_birthdates" ,
6773 " [70b38cea-d234-4697-b146-7d130cd4ee12]" ) {
6874 const std::size_t group_size = 10 ;
69- auto dates = baffling_birthdays:: random_birthdates (group_size);
70- REQUIRE (dates .size () == group_size);
75+ auto d_dates = random_birthdates (group_size);
76+ REQUIRE (d_dates .size () == group_size);
7177}
7278
7379TEST_CASE (" years_are_not_leap_years" ,
7480 " [d9d5b7d3-5fea-4752-b9c1-3fcd176d1b03]" ) {
7581 const std::size_t group_size = 1000 ;
76- auto dates = baffling_birthdays:: random_birthdates (group_size);
77- for (auto const & date : dates ) {
78- REQUIRE (!(date. substr ( 5 , 2 ) == " 02 " && date. substr ( 8 , 2 ) == " 29 " ));
82+ auto d_dates = random_birthdates (group_size);
83+ for (auto const & d : d_dates ) {
84+ REQUIRE (!(d. month (). as_number () == 2 && d. day ( ) == 29 ));
7985 }
8086}
8187
8288TEST_CASE (" months_are_random" , " [d1074327-f68c-4c8a-b0ff-e3730d0f0521]" ) {
8389 const std::size_t group_size = 1000 ;
84- auto d1 = baffling_birthdays:: random_birthdates (group_size);
85- auto d2 = baffling_birthdays:: random_birthdates (group_size);
90+ auto d1 = random_birthdates (group_size);
91+ auto d2 = random_birthdates (group_size);
8692 REQUIRE (d1 != d2);
8793}
8894
8995TEST_CASE (" days_are_random" , " [7df706b3-c3f5-471d-9563-23a4d0577940]" ) {
9096 const std::size_t group_size = 1000 ;
91- auto d1 = baffling_birthdays:: random_birthdates (group_size);
92- auto d2 = baffling_birthdays:: random_birthdates (group_size);
97+ auto d1 = random_birthdates (group_size);
98+ auto d2 = random_birthdates (group_size);
9399 REQUIRE (d1 != d2);
94100}
95101
96102TEST_CASE (" for_one_person" , " [89a462a4-4265-4912-9506-fb027913f221]" ) {
97- REQUIRE (baffling_birthdays::estimated_probability_of_shared_birthday (1 ) ==
98- Approx (0.0 ));
103+ REQUIRE (estimated_probability_of_shared_birthday (1 ) == Approx (0.0 ));
99104}
100105
101106TEST_CASE (" among_ten_people" , " [ec31c787-0ebb-4548-970c-5dcb4eadfb5f]" ) {
102- REQUIRE (baffling_birthdays:: estimated_probability_of_shared_birthday (10 ) ==
107+ REQUIRE (estimated_probability_of_shared_birthday (10 ) ==
103108 Approx (11.694818 ).epsilon (0.01 ));
104109}
105110
106111TEST_CASE (" among_twenty-three_people" ,
107112 " [b548afac-a451-46a3-9bb0-cb1f60c48e2f]" ) {
108- REQUIRE (baffling_birthdays:: estimated_probability_of_shared_birthday (23 ) ==
113+ REQUIRE (estimated_probability_of_shared_birthday (23 ) ==
109114 Approx (50.729723 ).epsilon (0.01 ));
110115}
111116
112117TEST_CASE (" among_seventy_people" , " [e43e6b9d-d77b-4f6c-a960-0fc0129a0bc5]" ) {
113- REQUIRE (baffling_birthdays:: estimated_probability_of_shared_birthday (70 ) ==
118+ REQUIRE (estimated_probability_of_shared_birthday (70 ) ==
114119 Approx (99.915958 ).epsilon (0.01 ));
115120}
116121
117- #endif
122+ #endif
0 commit comments