@@ -4,47 +4,47 @@ load bats-extra
44@test " shared birthday -> one birthdate" {
55 # [[ $BATS_RUN_SKIPPED == "true" ]] || skip
66 birthdates=(" 2000-01-01" )
7- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
7+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
88 assert_success
99 assert_output " false"
1010}
1111
1212@test " shared birthday -> two birthdates with same year, month, and day" {
1313 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
1414 birthdates=(" 2000-01-01" " 2000-01-01" )
15- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
15+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
1616 assert_success
1717 assert_output " true"
1818}
1919
2020@test " shared birthday -> two birthdates with same year and month, but different day" {
2121 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
2222 birthdates=(" 2012-05-09" " 2012-05-17" )
23- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
23+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
2424 assert_success
2525 assert_output " false"
2626}
2727
2828@test " shared birthday -> two birthdates with same month and day, but different year" {
2929 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
3030 birthdates=(" 1999-10-23" " 1988-10-23" )
31- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
31+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
3232 assert_success
3333 assert_output " true"
3434}
3535
3636@test " shared birthday -> two birthdates with same year, but different month and day" {
3737 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
3838 birthdates=(" 2007-12-19" " 2007-04-27" )
39- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
39+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
4040 assert_success
4141 assert_output " false"
4242}
4343
4444@test " shared birthday -> two birthdates with different year, month, and day" {
4545 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
4646 birthdates=(" 1997-08-04" " 1963-11-23" )
47- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
47+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
4848 assert_success
4949 assert_output " false"
5050}
@@ -57,7 +57,7 @@ load bats-extra
5757 " 2001-12-25"
5858 " 1980-11-10"
5959 )
60- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
60+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
6161 assert_success
6262 assert_output " false"
6363}
@@ -70,7 +70,7 @@ load bats-extra
7070 " 2001-07-29"
7171 " 1980-11-10"
7272 )
73- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
73+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
7474 assert_success
7575 assert_output " true"
7676}
@@ -84,95 +84,95 @@ load bats-extra
8484 " 1980-07-29"
8585 " 2019-02-12"
8686 )
87- run bash baffling_birthdays.sh sharedBirthday " ${birthdates[@]} "
87+ run bash baffling_birthdays.sh shared_birthday " ${birthdates[@]} "
8888 assert_success
8989 assert_output " true"
9090}
9191
9292@test " random birthdates -> generate requested number of birthdates" {
9393 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
94- generate=$( shuf -n 1 -i 100-1000 )
95- run bash baffling_birthdays.sh randomBirthdates $generate
94+ generate=500
95+ run bash baffling_birthdays.sh random_birthdates " $generate "
9696 assert_success
97- read -ra output_dates <<< " $output"
98- assert_equal ${ # output_dates[@]} $generate
97+ num_output_dates= $( wc -w <<< " $output" )
98+ assert_equal " $num_output_dates " " $generate "
9999}
100100
101101@test " random birthdates -> years are not leap years" {
102102 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
103- generate=$( shuf -n 1 -i 100-1000 )
103+ generate=500
104104 seen_leap=0
105- run bash baffling_birthdays.sh randomBirthdates $generate
105+ run bash baffling_birthdays.sh random_birthdates " $generate "
106106 assert_success
107107 read -ra output_dates <<< " $output"
108108 for date in " ${output_dates[@]} " ; do
109109 year=${date: 0: 4}
110110 if (( year % 400 == 0 || (year % 4 == 0 && year % 100 != 0 ) )) ; then
111- (( ++ seen_leap ))
111+ (( ++ seen_leap ))
112112 fi
113113 done
114- assert_equal $ seen_leap 0
114+ assert_equal " ${ seen_leap} " 0
115115}
116116
117117@test " random birthdates -> months are random" {
118118 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
119119 declare -A seen_month
120- generate=$( shuf -n 1 -i 100-1000 )
121- run bash baffling_birthdays.sh randomBirthdates $generate
120+ generate=500
121+ run bash baffling_birthdays.sh random_birthdates " $generate "
122122 assert_success
123123 read -ra output_dates <<< " $output"
124124 for date in " ${output_dates[@]} " ; do
125125 month=${date: 5: 2}
126126
127127 seen_month[$month ]=true
128128 done
129- assert_equal ${# seen_month[@]} 12
129+ assert_equal " ${# seen_month[@]} " 12
130130}
131131
132132@test " random birthdates -> days are random" {
133133 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
134134 declare -A seen_day
135- generate=$( shuf -n 1 -i 100-1000 )
136- run bash baffling_birthdays.sh randomBirthdates $generate
135+ generate=500
136+ run bash baffling_birthdays.sh random_birthdates " $generate "
137137 assert_success
138138 read -ra output_dates <<< " $output"
139139 for date in " ${output_dates[@]} " ; do
140140 day=${date: 8}
141141
142142 seen_day[$day ]=true
143143 done
144- assert_equal ${# seen_day[@]} 31
144+ assert_equal " ${# seen_day[@]} " 31
145145}
146146
147147# "The expected probability values should be compared using some tolerance to allow for small deviations."
148148@test " estimated probability of at least one shared birthday -> for one person" {
149149 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
150- # expect="0.0" # this is the exercice ref.
151- run bash baffling_birthdays.sh estimatedProbabilityOfSharedBirthday 1
150+ # The expected probability is 0.0
151+ run bash baffling_birthdays.sh estimated_probability_of_share_birthday 1
152152 assert_success
153- [[ " $output " =~ ^(0 \. ) ]]
153+ assert_equal " $output " 0
154154}
155155
156156@test " estimated probability of at least one shared birthday -> among ten people" {
157157 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
158- # expect="11.694818" # this is the exercice ref.
159- run bash baffling_birthdays.sh estimatedProbabilityOfSharedBirthday 10
158+ # The expected probability is 11.694818
159+ run bash baffling_birthdays.sh estimated_probability_of_share_birthday 10
160160 assert_success
161- [[ " $ output" =~ ^(10 \. | 11 \. | 12 \. | 13 \. | 14 \. ) ]]
161+ (( output >= 10 && output <= 13 ))
162162}
163163
164164@test " estimated probability of at least one shared birthday -> among twenty-three people" {
165165 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
166- # expect="50.729723" # this is the exercice ref.
167- run bash baffling_birthdays.sh estimatedProbabilityOfSharedBirthday 23
166+ # The expected probability is 50.729723
167+ run bash baffling_birthdays.sh estimated_probability_of_share_birthday 23
168168 assert_success
169- [[ " $ output" =~ ^(48 \. | 49 \. | 50 \. | 51 \. | 52 \. | 53 \. ) ]]
169+ (( output >= 48 && output <= 53 ))
170170}
171171
172172@test " estimated probability of at least one shared birthday -> among seventy people" {
173173 [[ $BATS_RUN_SKIPPED == " true" ]] || skip
174- # expect="99.915958" # this is the exercice ref.
175- run bash baffling_birthdays.sh estimatedProbabilityOfSharedBirthday 70
174+ # The expected probability is 99.915958
175+ run bash baffling_birthdays.sh estimated_probability_of_share_birthday 70
176176 assert_success
177- [[ " $ output" =~ ^(98 \. | 99 \. | 100\. ) ]]
177+ (( output >= 98 && output <= 100 ))
178178}
0 commit comments