|
1 | | - import org.junit.jupiter.api.Disabled; |
2 | | - import org.junit.jupiter.api.DisplayName; |
3 | | - import org.junit.jupiter.api.Test; |
| 1 | +import org.junit.jupiter.api.Disabled; |
| 2 | +import org.junit.jupiter.api.DisplayName; |
| 3 | +import org.junit.jupiter.api.Test; |
4 | 4 |
|
5 | | - import static org.assertj.core.api.Assertions.assertThat; |
6 | | - import static org.assertj.core.data.Offset.offset; |
| 5 | +import static org.assertj.core.api.Assertions.assertThat; |
| 6 | +import static org.assertj.core.data.Offset.offset; |
7 | 7 |
|
8 | | - import java.time.LocalDate; |
9 | | - import java.util.HashSet; |
10 | | - import java.util.List; |
11 | | - import java.util.Set; |
| 8 | +import java.time.LocalDate; |
| 9 | +import java.util.HashSet; |
| 10 | +import java.util.List; |
| 11 | +import java.util.Set; |
12 | 12 |
|
13 | | - public class BafflingBirthdaysTest { |
14 | | - private BafflingBirthdays birthdays = new BafflingBirthdays(); |
| 13 | +public class BafflingBirthdaysTest { |
| 14 | + private BafflingBirthdays birthdays = new BafflingBirthdays(); |
15 | 15 |
|
16 | | - @Test |
17 | | - @DisplayName("one birthdate") |
18 | | - public void oneBirthdateTest() { |
19 | | - assertThat(birthdays.sharedBirthday(List.of("2000-01-01"))).isFalse(); |
20 | | - } |
| 16 | + @Test |
| 17 | + @DisplayName("one birthdate") |
| 18 | + public void oneBirthdateTest() { |
| 19 | + assertThat(birthdays.sharedBirthday(List.of("2000-01-01"))).isFalse(); |
| 20 | + } |
21 | 21 |
|
22 | | - @Disabled("Remove to run test") |
23 | | - @Test |
24 | | - @DisplayName("two birthdates with same year, month, and day") |
25 | | - public void twoBirthdatesWithSameYearMonthAndDayTest() { |
26 | | - assertThat(birthdays.sharedBirthday(List.of("2000-01-01", "2000-01-01"))).isTrue(); |
27 | | - } |
| 22 | + @Disabled("Remove to run test") |
| 23 | + @Test |
| 24 | + @DisplayName("two birthdates with same year, month, and day") |
| 25 | + public void twoBirthdatesWithSameYearMonthAndDayTest() { |
| 26 | + assertThat(birthdays.sharedBirthday(List.of("2000-01-01", "2000-01-01"))).isTrue(); |
| 27 | + } |
28 | 28 |
|
29 | | - @Disabled("Remove to run test") |
30 | | - @Test |
31 | | - @DisplayName("two birthdates with same year and month, but different day") |
32 | | - public void twoBirthdatesWithSameYearAndMonthButDifferentDayTest() { |
33 | | - assertThat(birthdays.sharedBirthday(List.of("2012-05-09", "2012-05-17"))).isFalse(); |
34 | | - } |
| 29 | + @Disabled("Remove to run test") |
| 30 | + @Test |
| 31 | + @DisplayName("two birthdates with same year and month, but different day") |
| 32 | + public void twoBirthdatesWithSameYearAndMonthButDifferentDayTest() { |
| 33 | + assertThat(birthdays.sharedBirthday(List.of("2012-05-09", "2012-05-17"))).isFalse(); |
| 34 | + } |
35 | 35 |
|
36 | | - @Disabled("Remove to run test") |
37 | | - @Test |
38 | | - @DisplayName("two birthdates with same month and day, but different year") |
39 | | - public void twoBirthdatesWithSameMonthAndDayButDifferentYearTest() { |
40 | | - assertThat(birthdays.sharedBirthday(List.of("1999-10-23", "1988-10-23"))).isTrue(); |
41 | | - } |
| 36 | + @Disabled("Remove to run test") |
| 37 | + @Test |
| 38 | + @DisplayName("two birthdates with same month and day, but different year") |
| 39 | + public void twoBirthdatesWithSameMonthAndDayButDifferentYearTest() { |
| 40 | + assertThat(birthdays.sharedBirthday(List.of("1999-10-23", "1988-10-23"))).isTrue(); |
| 41 | + } |
42 | 42 |
|
43 | | - @Disabled("Remove to run test") |
44 | | - @Test |
45 | | - @DisplayName("two birthdates with same year, but different month and day") |
46 | | - public void twoBirthdatesWithSameYearButDifferentMonthAndDayTest() { |
47 | | - assertThat(birthdays.sharedBirthday(List.of("2007-12-19", "2007-04-27"))).isFalse(); |
48 | | - } |
| 43 | + @Disabled("Remove to run test") |
| 44 | + @Test |
| 45 | + @DisplayName("two birthdates with same year, but different month and day") |
| 46 | + public void twoBirthdatesWithSameYearButDifferentMonthAndDayTest() { |
| 47 | + assertThat(birthdays.sharedBirthday(List.of("2007-12-19", "2007-04-27"))).isFalse(); |
| 48 | + } |
49 | 49 |
|
50 | | - @Disabled("Remove to run test") |
51 | | - @Test |
52 | | - @DisplayName("two birthdates with different year, month, and day") |
53 | | - public void twoBirthdatesWithDifferentYearMonthAndDayTest() { |
54 | | - assertThat(birthdays.sharedBirthday(List.of("1997-08-04", "1963-11-23"))).isFalse(); |
55 | | - } |
| 50 | + @Disabled("Remove to run test") |
| 51 | + @Test |
| 52 | + @DisplayName("two birthdates with different year, month, and day") |
| 53 | + public void twoBirthdatesWithDifferentYearMonthAndDayTest() { |
| 54 | + assertThat(birthdays.sharedBirthday(List.of("1997-08-04", "1963-11-23"))).isFalse(); |
| 55 | + } |
56 | 56 |
|
57 | | - @Disabled("Remove to run test") |
58 | | - @Test |
59 | | - @DisplayName("multiple birthdates without shared birthday") |
60 | | - public void multipleBirthdatesWithoutSharedBirthdayTest() { |
61 | | - assertThat(birthdays.sharedBirthday(List.of("1966-07-29", "1977-02-12", "2001-12-25", "1980-11-10"))).isFalse(); |
62 | | - } |
| 57 | + @Disabled("Remove to run test") |
| 58 | + @Test |
| 59 | + @DisplayName("multiple birthdates without shared birthday") |
| 60 | + public void multipleBirthdatesWithoutSharedBirthdayTest() { |
| 61 | + assertThat(birthdays.sharedBirthday(List.of("1966-07-29", "1977-02-12", "2001-12-25", "1980-11-10"))).isFalse(); |
| 62 | + } |
63 | 63 |
|
64 | | - @Disabled("Remove to run test") |
65 | | - @Test |
66 | | - @DisplayName("multiple birthdates with one shared birthday") |
67 | | - public void multipleBirthdatesWithOneSharedBirthdayTest() { |
68 | | - assertThat(birthdays.sharedBirthday(List.of("1966-07-29", "1977-02-12", "2001-07-29", "1980-11-10"))).isTrue(); |
69 | | - } |
| 64 | + @Disabled("Remove to run test") |
| 65 | + @Test |
| 66 | + @DisplayName("multiple birthdates with one shared birthday") |
| 67 | + public void multipleBirthdatesWithOneSharedBirthdayTest() { |
| 68 | + assertThat(birthdays.sharedBirthday(List.of("1966-07-29", "1977-02-12", "2001-07-29", "1980-11-10"))).isTrue(); |
| 69 | + } |
70 | 70 |
|
71 | | - @Disabled("Remove to run test") |
72 | | - @Test |
73 | | - @DisplayName("multiple birthdates with more than one shared birthday") |
74 | | - public void multipleBirthdatesWithMoreThanOneSharedBirthdayTest() { |
75 | | - assertThat(birthdays.sharedBirthday(List.of( |
76 | | - "1966-07-29", |
77 | | - "1977-02-12", |
78 | | - "2001-12-25", |
79 | | - "1980-07-29", |
80 | | - "2019-02-12" |
81 | | - ))).isTrue(); |
82 | | - } |
| 71 | + @Disabled("Remove to run test") |
| 72 | + @Test |
| 73 | + @DisplayName("multiple birthdates with more than one shared birthday") |
| 74 | + public void multipleBirthdatesWithMoreThanOneSharedBirthdayTest() { |
| 75 | + assertThat(birthdays.sharedBirthday(List.of( |
| 76 | + "1966-07-29", |
| 77 | + "1977-02-12", |
| 78 | + "2001-12-25", |
| 79 | + "1980-07-29", |
| 80 | + "2019-02-12" |
| 81 | + ))).isTrue(); |
| 82 | + } |
83 | 83 |
|
84 | | - @Disabled("Remove to run test") |
85 | | - @Test |
86 | | - @DisplayName("generate requested number of birthdates") |
87 | | - public void generateRequestedNumberOfBirthdatesTest() { |
88 | | - int groupSize = 50; |
89 | | - assertThat(birthdays.randomBirthdates(groupSize).size()).isEqualTo(groupSize); |
90 | | - } |
| 84 | + @Disabled("Remove to run test") |
| 85 | + @Test |
| 86 | + @DisplayName("generate requested number of birthdates") |
| 87 | + public void generateRequestedNumberOfBirthdatesTest() { |
| 88 | + int groupSize = 50; |
| 89 | + assertThat(birthdays.randomBirthdates(groupSize).size()).isEqualTo(groupSize); |
| 90 | + } |
91 | 91 |
|
92 | | - @Disabled("Remove to run test") |
93 | | - @Test |
94 | | - @DisplayName("years are not leap years") |
95 | | - public void yearsAreNotLeapYearsTest() { |
96 | | - for (String birthdate : birthdays.randomBirthdates(100)) { |
97 | | - LocalDate date = LocalDate.parse(birthdate); |
98 | | - assertThat(date.isLeapYear()).isFalse(); |
99 | | - assertThat(date.getMonthValue() == 2 && date.getDayOfMonth() == 29).isFalse(); |
100 | | - } |
| 92 | + @Disabled("Remove to run test") |
| 93 | + @Test |
| 94 | + @DisplayName("years are not leap years") |
| 95 | + public void yearsAreNotLeapYearsTest() { |
| 96 | + for (String birthdate : birthdays.randomBirthdates(100)) { |
| 97 | + LocalDate date = LocalDate.parse(birthdate); |
| 98 | + assertThat(date.isLeapYear()).isFalse(); |
| 99 | + assertThat(date.getMonthValue() == 2 && date.getDayOfMonth() == 29).isFalse(); |
101 | 100 | } |
| 101 | + } |
102 | 102 |
|
103 | | - @Disabled("Remove to run test") |
104 | | - @Test |
105 | | - @DisplayName("months are random") |
106 | | - public void monthsAreRandomTest() { |
107 | | - Set<Integer> months = new HashSet<>(); |
108 | | - for (String birthdate : birthdays.randomBirthdates(500)) { |
109 | | - LocalDate date = LocalDate.parse(birthdate); |
110 | | - months.add(date.getMonthValue()); |
111 | | - if (months.size() >= 7) { |
112 | | - break; |
113 | | - } |
| 103 | + @Disabled("Remove to run test") |
| 104 | + @Test |
| 105 | + @DisplayName("months are random") |
| 106 | + public void monthsAreRandomTest() { |
| 107 | + Set<Integer> months = new HashSet<>(); |
| 108 | + for (String birthdate : birthdays.randomBirthdates(500)) { |
| 109 | + LocalDate date = LocalDate.parse(birthdate); |
| 110 | + months.add(date.getMonthValue()); |
| 111 | + if (months.size() >= 7) { |
| 112 | + break; |
114 | 113 | } |
115 | | - assertThat(months).hasSizeGreaterThanOrEqualTo(7); |
116 | 114 | } |
| 115 | + assertThat(months).hasSizeGreaterThanOrEqualTo(7); |
| 116 | + } |
117 | 117 |
|
118 | | - @Disabled("Remove to run test") |
119 | | - @Test |
120 | | - @DisplayName("days are random") |
121 | | - public void daysAreRandomTest() { |
122 | | - Set<Integer> days = new HashSet<>(); |
123 | | - for (String birthdate : birthdays.randomBirthdates(500)) { |
124 | | - LocalDate date = LocalDate.parse(birthdate); |
125 | | - days.add(date.getDayOfMonth()); |
126 | | - if (days.size() >= 11) { |
127 | | - break; |
128 | | - } |
| 118 | + @Disabled("Remove to run test") |
| 119 | + @Test |
| 120 | + @DisplayName("days are random") |
| 121 | + public void daysAreRandomTest() { |
| 122 | + Set<Integer> days = new HashSet<>(); |
| 123 | + for (String birthdate : birthdays.randomBirthdates(500)) { |
| 124 | + LocalDate date = LocalDate.parse(birthdate); |
| 125 | + days.add(date.getDayOfMonth()); |
| 126 | + if (days.size() >= 11) { |
| 127 | + break; |
129 | 128 | } |
130 | | - assertThat(days).hasSizeGreaterThanOrEqualTo(11); |
131 | 129 | } |
| 130 | + assertThat(days).hasSizeGreaterThanOrEqualTo(11); |
| 131 | + } |
132 | 132 |
|
133 | | - @Disabled("Remove to run test") |
134 | | - @Test |
135 | | - @DisplayName("estimated probability of at least one shared birthday case for one person") |
136 | | - public void estimatedProbabilityOfAtLeastOneSharedBirthdayForOnePersonTest() { |
137 | | - assertThat(birthdays.estimatedProbabilityOfSharedBirthday(1)).isEqualTo(0.0); |
138 | | - } |
| 133 | + @Disabled("Remove to run test") |
| 134 | + @Test |
| 135 | + @DisplayName("estimated probability of at least one shared birthday case for one person") |
| 136 | + public void estimatedProbabilityOfAtLeastOneSharedBirthdayForOnePersonTest() { |
| 137 | + assertThat(birthdays.estimatedProbabilityOfSharedBirthday(1)).isEqualTo(0.0); |
| 138 | + } |
139 | 139 |
|
140 | | - @Disabled("Remove to run test") |
141 | | - @Test |
142 | | - @DisplayName("estimated probability of at least one shared birthday case among ten people") |
143 | | - public void estimatedProbabilityOfAtLeastOneSharedBirthdayAmongTenPeopleTest() { |
144 | | - assertThat(birthdays.estimatedProbabilityOfSharedBirthday(10)).isCloseTo(11.694818, offset(1.0)); |
145 | | - } |
| 140 | + @Disabled("Remove to run test") |
| 141 | + @Test |
| 142 | + @DisplayName("estimated probability of at least one shared birthday case among ten people") |
| 143 | + public void estimatedProbabilityOfAtLeastOneSharedBirthdayAmongTenPeopleTest() { |
| 144 | + assertThat(birthdays.estimatedProbabilityOfSharedBirthday(10)).isCloseTo(11.694818, offset(1.0)); |
| 145 | + } |
146 | 146 |
|
147 | | - @Disabled("Remove to run test") |
148 | | - @Test |
149 | | - @DisplayName("estimated probability of at least one shared birthday case among twenty-three people") |
150 | | - public void estimatedProbabilityOfAtLeastOneSharedBirthdayAmongTwentyThreePeopleTest() { |
151 | | - assertThat(birthdays.estimatedProbabilityOfSharedBirthday(23)).isCloseTo(50.729723, offset(1.0)); |
152 | | - } |
| 147 | + @Disabled("Remove to run test") |
| 148 | + @Test |
| 149 | + @DisplayName("estimated probability of at least one shared birthday case among twenty-three people") |
| 150 | + public void estimatedProbabilityOfAtLeastOneSharedBirthdayAmongTwentyThreePeopleTest() { |
| 151 | + assertThat(birthdays.estimatedProbabilityOfSharedBirthday(23)).isCloseTo(50.729723, offset(1.0)); |
| 152 | + } |
153 | 153 |
|
154 | | - @Disabled("Remove to run test") |
155 | | - @Test |
156 | | - @DisplayName("estimated probability of at least one shared birthday case among seventy people") |
157 | | - public void estimatedProbabilityOfAtLeastOneSharedBirthdayAmongSeventyPeopleTest() { |
158 | | - assertThat(birthdays.estimatedProbabilityOfSharedBirthday(70)).isCloseTo(99.915958, offset(1.0)); |
159 | | - } |
| 154 | + @Disabled("Remove to run test") |
| 155 | + @Test |
| 156 | + @DisplayName("estimated probability of at least one shared birthday case among seventy people") |
| 157 | + public void estimatedProbabilityOfAtLeastOneSharedBirthdayAmongSeventyPeopleTest() { |
| 158 | + assertThat(birthdays.estimatedProbabilityOfSharedBirthday(70)).isCloseTo(99.915958, offset(1.0)); |
160 | 159 | } |
| 160 | +} |
0 commit comments