Skip to content

Commit b6b8d6d

Browse files
committed
Run pre-commit locally
1 parent 8686fa6 commit b6b8d6d

3 files changed

Lines changed: 121 additions & 119 deletions

File tree

‎exercises/practice/bottle-song/.meta/example.cpp‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@
22

33
namespace bottle_song {
44

5-
static const std::string wordsCap[] = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"};
6-
static const std::string wordsLower[] = {"no","one","two","three","four","five","six","seven","eight","nine","ten"};
5+
static const std::string wordsCap[] = {"Zero", "One", "Two", "Three",
6+
"Four", "Five", "Six", "Seven",
7+
"Eight", "Nine", "Ten"};
8+
static const std::string wordsLower[] = {"no", "one", "two", "three",
9+
"four", "five", "six", "seven",
10+
"eight", "nine", "ten"};
711

8-
std::vector<std::string> recite(int startBottles, int takeDown) {
9-
std::vector<std::string> verses;
10-
int end = startBottles - takeDown + 1;
11-
for (int bottles = startBottles; bottles >= end; --bottles) {
12-
int next = bottles - 1;
13-
verses.push_back(wordsCap[bottles] + " green bottle" + (bottles == 1 ? "" : "s") + " hanging on the wall,");
14-
verses.push_back(wordsCap[bottles] + " green bottle" + (bottles == 1 ? "" : "s") + " hanging on the wall,");
15-
verses.push_back("And if one green bottle should accidentally fall,");
16-
std::string nextWord = (next >= 0 && next <= 10) ? wordsLower[next] : std::to_string(next);
17-
verses.push_back("There'll be " + nextWord + " green bottle" + (next == 1 ? "" : "s") + " hanging on the wall.");
18-
if (bottles > end) {
19-
verses.push_back("");
20-
}
12+
std::vector<std::string> recite(int startBottles, int takeDown) {
13+
std::vector<std::string> verses;
14+
int end = startBottles - takeDown + 1;
15+
for (int bottles = startBottles; bottles >= end; --bottles) {
16+
int next = bottles - 1;
17+
verses.push_back(wordsCap[bottles] + " green bottle" +
18+
(bottles == 1 ? "" : "s") + " hanging on the wall,");
19+
verses.push_back(wordsCap[bottles] + " green bottle" +
20+
(bottles == 1 ? "" : "s") + " hanging on the wall,");
21+
verses.push_back("And if one green bottle should accidentally fall,");
22+
std::string nextWord =
23+
(next >= 0 && next <= 10) ? wordsLower[next] : std::to_string(next);
24+
verses.push_back("There'll be " + nextWord + " green bottle" +
25+
(next == 1 ? "" : "s") + " hanging on the wall.");
26+
if (bottles > end) {
27+
verses.push_back("");
2128
}
22-
return verses;
2329
}
30+
return verses;
31+
}
2432

25-
} // namespace bottle_song
33+
} // namespace bottle_song
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#pragma once
22

3-
#include <vector>
43
#include <string>
4+
#include <vector>
55

66
namespace bottle_song {
77

8-
std::vector<std::string> recite(int startBottles, int takeDown);
8+
std::vector<std::string> recite(int startBottles, int takeDown);
99

10-
} // namespace bottle_song
10+
} // namespace bottle_song

‎exercises/practice/bottle-song/bottle_song_test.cpp‎

Lines changed: 93 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -9,134 +9,128 @@ using namespace bottle_song;
99

1010
TEST_CASE("first_generic_verse", "[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03]") {
1111
auto verses = recite(10, 1);
12-
REQUIRE(verses == std::vector<std::string>{
13-
"Ten green bottles hanging on the wall,",
14-
"Ten green bottles hanging on the wall,",
15-
"And if one green bottle should accidentally fall,",
16-
"There'll be nine green bottles hanging on the wall."
17-
});
12+
REQUIRE(verses ==
13+
std::vector<std::string>{
14+
"Ten green bottles hanging on the wall,",
15+
"Ten green bottles hanging on the wall,",
16+
"And if one green bottle should accidentally fall,",
17+
"There'll be nine green bottles hanging on the wall."});
1818
}
1919

2020
#if defined(EXERCISM_RUN_ALL_TESTS)
2121

2222
TEST_CASE("last_generic_verse", "[0f0aded3-472a-4c64-b842-18d4f1f5f030]") {
2323
auto verses = recite(3, 1);
24-
REQUIRE(verses == std::vector<std::string>{
25-
"Three green bottles hanging on the wall,",
26-
"Three green bottles hanging on the wall,",
27-
"And if one green bottle should accidentally fall,",
28-
"There'll be two green bottles hanging on the wall."
29-
});
24+
REQUIRE(verses ==
25+
std::vector<std::string>{
26+
"Three green bottles hanging on the wall,",
27+
"Three green bottles hanging on the wall,",
28+
"And if one green bottle should accidentally fall,",
29+
"There'll be two green bottles hanging on the wall."});
3030
}
3131

3232
TEST_CASE("verse_with_2_bottles", "[f61f3c97-131f-459e-b40a-7428f3ed99d9]") {
3333
auto verses = recite(2, 1);
3434
REQUIRE(verses == std::vector<std::string>{
35-
"Two green bottles hanging on the wall,",
36-
"Two green bottles hanging on the wall,",
37-
"And if one green bottle should accidentally fall,",
38-
"There'll be one green bottle hanging on the wall."
39-
});
35+
"Two green bottles hanging on the wall,",
36+
"Two green bottles hanging on the wall,",
37+
"And if one green bottle should accidentally fall,",
38+
"There'll be one green bottle hanging on the wall."});
4039
}
4140

4241
TEST_CASE("verse_with_1_bottle", "[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0]") {
4342
auto verses = recite(1, 1);
4443
REQUIRE(verses == std::vector<std::string>{
45-
"One green bottle hanging on the wall,",
46-
"One green bottle hanging on the wall,",
47-
"And if one green bottle should accidentally fall,",
48-
"There'll be no green bottles hanging on the wall."
49-
});
44+
"One green bottle hanging on the wall,",
45+
"One green bottle hanging on the wall,",
46+
"And if one green bottle should accidentally fall,",
47+
"There'll be no green bottles hanging on the wall."});
5048
}
5149

5250
TEST_CASE("first_two_verses", "[a4a28170-83d6-4dc1-bd8b-319b6abb6a80]") {
5351
auto verses = recite(10, 2);
54-
REQUIRE(verses == std::vector<std::string>{
55-
"Ten green bottles hanging on the wall,",
56-
"Ten green bottles hanging on the wall,",
57-
"And if one green bottle should accidentally fall,",
58-
"There'll be nine green bottles hanging on the wall.",
59-
"",
60-
"Nine green bottles hanging on the wall,",
61-
"Nine green bottles hanging on the wall,",
62-
"And if one green bottle should accidentally fall,",
63-
"There'll be eight green bottles hanging on the wall."
64-
});
52+
REQUIRE(verses ==
53+
std::vector<std::string>{
54+
"Ten green bottles hanging on the wall,",
55+
"Ten green bottles hanging on the wall,",
56+
"And if one green bottle should accidentally fall,",
57+
"There'll be nine green bottles hanging on the wall.", "",
58+
"Nine green bottles hanging on the wall,",
59+
"Nine green bottles hanging on the wall,",
60+
"And if one green bottle should accidentally fall,",
61+
"There'll be eight green bottles hanging on the wall."});
6562
}
6663

6764
TEST_CASE("last_three_verses", "[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db]") {
6865
auto verses = recite(3, 3);
6966
REQUIRE(verses == std::vector<std::string>{
70-
"Three green bottles hanging on the wall,",
71-
"Three green bottles hanging on the wall,",
72-
"And if one green bottle should accidentally fall,",
73-
"There'll be two green bottles hanging on the wall.",
74-
"",
75-
"Two green bottles hanging on the wall,",
76-
"Two green bottles hanging on the wall,",
77-
"And if one green bottle should accidentally fall,",
78-
"There'll be one green bottle hanging on the wall.",
79-
"",
80-
"One green bottle hanging on the wall,",
81-
"One green bottle hanging on the wall,",
82-
"And if one green bottle should accidentally fall,",
83-
"There'll be no green bottles hanging on the wall."
84-
});
67+
"Three green bottles hanging on the wall,",
68+
"Three green bottles hanging on the wall,",
69+
"And if one green bottle should accidentally fall,",
70+
"There'll be two green bottles hanging on the wall.",
71+
"", "Two green bottles hanging on the wall,",
72+
"Two green bottles hanging on the wall,",
73+
"And if one green bottle should accidentally fall,",
74+
"There'll be one green bottle hanging on the wall.",
75+
"", "One green bottle hanging on the wall,",
76+
"One green bottle hanging on the wall,",
77+
"And if one green bottle should accidentally fall,",
78+
"There'll be no green bottles hanging on the wall."});
8579
}
8680

8781
TEST_CASE("all_verses", "[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28]") {
8882
auto verses = recite(10, 10);
89-
REQUIRE(verses == std::vector<std::string>{
90-
"Ten green bottles hanging on the wall,",
91-
"Ten green bottles hanging on the wall,",
92-
"And if one green bottle should accidentally fall,",
93-
"There'll be nine green bottles hanging on the wall.",
94-
"",
95-
"Nine green bottles hanging on the wall,",
96-
"Nine green bottles hanging on the wall,",
97-
"And if one green bottle should accidentally fall,",
98-
"There'll be eight green bottles hanging on the wall.",
99-
"",
100-
"Eight green bottles hanging on the wall,",
101-
"Eight green bottles hanging on the wall,",
102-
"And if one green bottle should accidentally fall,",
103-
"There'll be seven green bottles hanging on the wall.",
104-
"",
105-
"Seven green bottles hanging on the wall,",
106-
"Seven green bottles hanging on the wall,",
107-
"And if one green bottle should accidentally fall,",
108-
"There'll be six green bottles hanging on the wall.",
109-
"",
110-
"Six green bottles hanging on the wall,",
111-
"Six green bottles hanging on the wall,",
112-
"And if one green bottle should accidentally fall,",
113-
"There'll be five green bottles hanging on the wall.",
114-
"",
115-
"Five green bottles hanging on the wall,",
116-
"Five green bottles hanging on the wall,",
117-
"And if one green bottle should accidentally fall,",
118-
"There'll be four green bottles hanging on the wall.",
119-
"",
120-
"Four green bottles hanging on the wall,",
121-
"Four green bottles hanging on the wall,",
122-
"And if one green bottle should accidentally fall,",
123-
"There'll be three green bottles hanging on the wall.",
124-
"",
125-
"Three green bottles hanging on the wall,",
126-
"Three green bottles hanging on the wall,",
127-
"And if one green bottle should accidentally fall,",
128-
"There'll be two green bottles hanging on the wall.",
129-
"",
130-
"Two green bottles hanging on the wall,",
131-
"Two green bottles hanging on the wall,",
132-
"And if one green bottle should accidentally fall,",
133-
"There'll be one green bottle hanging on the wall.",
134-
"",
135-
"One green bottle hanging on the wall,",
136-
"One green bottle hanging on the wall,",
137-
"And if one green bottle should accidentally fall,",
138-
"There'll be no green bottles hanging on the wall."
139-
});
83+
REQUIRE(verses ==
84+
std::vector<std::string>{
85+
"Ten green bottles hanging on the wall,",
86+
"Ten green bottles hanging on the wall,",
87+
"And if one green bottle should accidentally fall,",
88+
"There'll be nine green bottles hanging on the wall.",
89+
"",
90+
"Nine green bottles hanging on the wall,",
91+
"Nine green bottles hanging on the wall,",
92+
"And if one green bottle should accidentally fall,",
93+
"There'll be eight green bottles hanging on the wall.",
94+
"",
95+
"Eight green bottles hanging on the wall,",
96+
"Eight green bottles hanging on the wall,",
97+
"And if one green bottle should accidentally fall,",
98+
"There'll be seven green bottles hanging on the wall.",
99+
"",
100+
"Seven green bottles hanging on the wall,",
101+
"Seven green bottles hanging on the wall,",
102+
"And if one green bottle should accidentally fall,",
103+
"There'll be six green bottles hanging on the wall.",
104+
"",
105+
"Six green bottles hanging on the wall,",
106+
"Six green bottles hanging on the wall,",
107+
"And if one green bottle should accidentally fall,",
108+
"There'll be five green bottles hanging on the wall.",
109+
"",
110+
"Five green bottles hanging on the wall,",
111+
"Five green bottles hanging on the wall,",
112+
"And if one green bottle should accidentally fall,",
113+
"There'll be four green bottles hanging on the wall.",
114+
"",
115+
"Four green bottles hanging on the wall,",
116+
"Four green bottles hanging on the wall,",
117+
"And if one green bottle should accidentally fall,",
118+
"There'll be three green bottles hanging on the wall.",
119+
"",
120+
"Three green bottles hanging on the wall,",
121+
"Three green bottles hanging on the wall,",
122+
"And if one green bottle should accidentally fall,",
123+
"There'll be two green bottles hanging on the wall.",
124+
"",
125+
"Two green bottles hanging on the wall,",
126+
"Two green bottles hanging on the wall,",
127+
"And if one green bottle should accidentally fall,",
128+
"There'll be one green bottle hanging on the wall.",
129+
"",
130+
"One green bottle hanging on the wall,",
131+
"One green bottle hanging on the wall,",
132+
"And if one green bottle should accidentally fall,",
133+
"There'll be no green bottles hanging on the wall."});
140134
}
141135

142136
#endif

0 commit comments

Comments
 (0)