Skip to content

Commit a227d99

Browse files
BNAndrasvaeng
authored andcommitted
Sync and sort roman-numeral tests (#914)
[no important files changed]
1 parent 1ea690e commit a227d99

File tree

6 files changed

+72
-169
lines changed

6 files changed

+72
-169
lines changed
Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,23 @@
11
#include "roman_numerals.h"
22

3-
namespace
4-
{
3+
namespace {
54

6-
struct digit_values
7-
{
5+
struct digit_values {
86
char numeral;
97
int value;
108
};
119

12-
const digit_values roman_numerals[] =
13-
{
14-
{ 'M', 1000 },
15-
{ 'D', 500 },
16-
{ 'C', 100 },
17-
{ 'L', 50 },
18-
{ 'X', 10 },
19-
{ 'V', 5 },
20-
{ 'I', 1 }
21-
};
10+
const digit_values roman_numerals[] = {{'M', 1000}, {'D', 500}, {'C', 100},
11+
{'L', 50}, {'X', 10}, {'V', 5},
12+
{'I', 1}};
2213

23-
class converter
24-
{
25-
public:
26-
converter(int n)
27-
: n_(n)
28-
{}
14+
class converter {
15+
public:
16+
converter(int n) : n_(n) {}
2917

3018
std::string convert();
3119

32-
private:
20+
private:
3321
void thousands();
3422
void hundreds();
3523
void tens();
@@ -42,37 +30,23 @@ class converter
4230
std::string result_;
4331
};
4432

45-
std::string converter::convert()
46-
{
33+
std::string converter::convert() {
4734
thousands();
4835
hundreds();
4936
tens();
5037
ones();
5138
return result_;
5239
}
5340

54-
void converter::thousands()
55-
{
56-
place(0);
57-
}
41+
void converter::thousands() { place(0); }
5842

59-
void converter::hundreds()
60-
{
61-
place(2);
62-
}
43+
void converter::hundreds() { place(2); }
6344

64-
void converter::tens()
65-
{
66-
place(4);
67-
}
45+
void converter::tens() { place(4); }
6846

69-
void converter::ones()
70-
{
71-
result_ += std::string(n_, 'I');
72-
}
47+
void converter::ones() { result_ += std::string(n_, 'I'); }
7348

74-
void converter::place(int place)
75-
{
49+
void converter::place(int place) {
7650
const int tenth_place = place + 2;
7751
place_numeral(place);
7852
place_numeral_penultimate(place, tenth_place);
@@ -81,27 +55,23 @@ void converter::place(int place)
8155
place_numeral_penultimate(half_place, tenth_place);
8256
}
8357

84-
void converter::place_numeral(int place)
85-
{
58+
void converter::place_numeral(int place) {
8659
while (n_ >= roman_numerals[place].value) {
8760
result_ += roman_numerals[place].numeral;
8861
n_ -= roman_numerals[place].value;
8962
}
9063
}
9164

92-
void converter::place_numeral_penultimate(int place, int penultimate_place)
93-
{
94-
const int amount = roman_numerals[place].value - roman_numerals[penultimate_place].value;
65+
void converter::place_numeral_penultimate(int place, int penultimate_place) {
66+
const int amount =
67+
roman_numerals[place].value - roman_numerals[penultimate_place].value;
9568
if (n_ >= amount) {
9669
result_ += roman_numerals[penultimate_place].numeral;
9770
result_ += roman_numerals[place].numeral;
9871
n_ -= amount;
9972
}
10073
}
10174

102-
}
75+
} // namespace
10376

104-
std::string roman_numerals::convert(int n)
105-
{
106-
return converter(n).convert();
107-
}
77+
std::string roman_numerals::convert(int n) { return converter(n).convert(); }

exercises/practice/roman-numerals/.meta/example.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
#include <string>
55

6-
namespace roman_numerals
7-
{
6+
namespace roman_numerals {
87

98
std::string convert(int n);
109

exercises/practice/roman-numerals/.meta/tests.toml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ description = "6 is VI"
3030
[ff3fb08c-4917-4aab-9f4e-d663491d083d]
3131
description = "9 is IX"
3232

33+
[6d1d82d5-bf3e-48af-9139-87d7165ed509]
34+
description = "16 is XVI"
35+
3336
[2bda64ca-7d28-4c56-b08d-16ce65716cf6]
3437
description = "27 is XXVII"
3538

@@ -42,6 +45,9 @@ description = "49 is XLIX"
4245
[d5b283d4-455d-4e68-aacf-add6c4b51915]
4346
description = "59 is LIX"
4447

48+
[4465ffd5-34dc-44f3-ada5-56f5007b6dad]
49+
description = "66 is LXVI"
50+
4551
[46b46e5b-24da-4180-bfe2-2ef30b39d0d0]
4652
description = "93 is XCIII"
4753

@@ -51,38 +57,35 @@ description = "141 is CXLI"
5157
[267f0207-3c55-459a-b81d-67cec7a46ed9]
5258
description = "163 is CLXIII"
5359

60+
[902ad132-0b4d-40e3-8597-ba5ed611dd8d]
61+
description = "166 is CLXVI"
62+
5463
[cdb06885-4485-4d71-8bfb-c9d0f496b404]
5564
description = "402 is CDII"
5665

5766
[6b71841d-13b2-46b4-ba97-dec28133ea80]
5867
description = "575 is DLXXV"
5968

69+
[dacb84b9-ea1c-4a61-acbb-ce6b36674906]
70+
description = "666 is DCLXVI"
71+
6072
[432de891-7fd6-4748-a7f6-156082eeca2f]
6173
description = "911 is CMXI"
6274

6375
[e6de6d24-f668-41c0-88d7-889c0254d173]
6476
description = "1024 is MXXIV"
6577

66-
[bb550038-d4eb-4be2-a9ce-f21961ac3bc6]
67-
description = "3000 is MMM"
68-
69-
[6d1d82d5-bf3e-48af-9139-87d7165ed509]
70-
description = "16 is XVI"
71-
72-
[4465ffd5-34dc-44f3-ada5-56f5007b6dad]
73-
description = "66 is LXVI"
74-
75-
[902ad132-0b4d-40e3-8597-ba5ed611dd8d]
76-
description = "166 is CLXVI"
77-
78-
[dacb84b9-ea1c-4a61-acbb-ce6b36674906]
79-
description = "666 is DCLXVI"
80-
8178
[efbe1d6a-9f98-4eb5-82bc-72753e3ac328]
8279
description = "1666 is MDCLXVI"
8380

81+
[bb550038-d4eb-4be2-a9ce-f21961ac3bc6]
82+
description = "3000 is MMM"
83+
8484
[3bc4b41c-c2e6-49d9-9142-420691504336]
8585
description = "3001 is MMMI"
8686

87+
[2f89cad7-73f6-4d1b-857b-0ef531f68b7e]
88+
description = "3888 is MMMDCCCLXXXVIII"
89+
8790
[4e18e96b-5fbb-43df-a91b-9cb511fe0856]
8891
description = "3999 is MMMCMXCIX"
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#include "roman_numerals.h"
22

3-
namespace roman_numerals {
4-
5-
} // namespace roman_numerals
3+
namespace roman_numerals {} // namespace roman_numerals
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#if !defined(ROMAN_NUMERALS_H)
22
#define ROMAN_NUMERALS_H
33

4-
namespace roman_numerals {
4+
namespace roman_numerals {} // namespace roman_numerals
55

6-
} // namespace roman_numerals
7-
8-
#endif // ROMAN_NUMERALS_H
6+
#endif // ROMAN_NUMERALS_H

exercises/practice/roman-numerals/roman_numerals_test.cpp

Lines changed: 29 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,109 +5,44 @@
55
#include "test/catch.hpp"
66
#endif
77

8-
TEST_CASE("1_is_i")
9-
{
10-
REQUIRE("I" == roman_numerals::convert(1));
11-
}
8+
TEST_CASE("1_is_i") { REQUIRE("I" == roman_numerals::convert(1)); }
129
#if defined(EXERCISM_RUN_ALL_TESTS)
13-
TEST_CASE("2_is_ii")
14-
{
15-
REQUIRE("II" == roman_numerals::convert(2));
16-
}
17-
TEST_CASE("3_is_iii")
18-
{
19-
REQUIRE("III" == roman_numerals::convert(3));
20-
}
21-
TEST_CASE("4_is_iv")
22-
{
23-
REQUIRE("IV" == roman_numerals::convert(4));
24-
}
25-
TEST_CASE("5_is_v")
26-
{
27-
REQUIRE("V" == roman_numerals::convert(5));
28-
}
29-
TEST_CASE("6_is_vi")
30-
{
31-
REQUIRE("VI" == roman_numerals::convert(6));
32-
}
33-
TEST_CASE("9_is_ix")
34-
{
35-
REQUIRE("IX" == roman_numerals::convert(9));
36-
}
37-
TEST_CASE("27_is_xxvii")
38-
{
39-
REQUIRE("XXVII" == roman_numerals::convert(27));
40-
}
41-
TEST_CASE("48_is_xlviii")
42-
{
43-
REQUIRE("XLVIII" == roman_numerals::convert(48));
44-
}
45-
TEST_CASE("49_is_xlix")
46-
{
47-
REQUIRE("XLIX" == roman_numerals::convert(49));
48-
}
49-
TEST_CASE("59_is_lix")
50-
{
51-
REQUIRE("LIX" == roman_numerals::convert(59));
52-
}
53-
TEST_CASE("93_is_xciii")
54-
{
55-
REQUIRE("XCIII" == roman_numerals::convert(93));
56-
}
57-
TEST_CASE("141_is_cxli")
58-
{
59-
REQUIRE("CXLI" == roman_numerals::convert(141));
60-
}
61-
TEST_CASE("163_is_clxiii")
62-
{
10+
TEST_CASE("2_is_ii") { REQUIRE("II" == roman_numerals::convert(2)); }
11+
TEST_CASE("3_is_iii") { REQUIRE("III" == roman_numerals::convert(3)); }
12+
TEST_CASE("4_is_iv") { REQUIRE("IV" == roman_numerals::convert(4)); }
13+
TEST_CASE("5_is_v") { REQUIRE("V" == roman_numerals::convert(5)); }
14+
TEST_CASE("6_is_vi") { REQUIRE("VI" == roman_numerals::convert(6)); }
15+
TEST_CASE("9_is_ix") { REQUIRE("IX" == roman_numerals::convert(9)); }
16+
TEST_CASE("16_is_xvi") { REQUIRE("XVI" == roman_numerals::convert(16)); }
17+
TEST_CASE("27_is_xxvii") { REQUIRE("XXVII" == roman_numerals::convert(27)); }
18+
TEST_CASE("48_is_xlviii") { REQUIRE("XLVIII" == roman_numerals::convert(48)); }
19+
TEST_CASE("49_is_xlix") { REQUIRE("XLIX" == roman_numerals::convert(49)); }
20+
TEST_CASE("59_is_lix") { REQUIRE("LIX" == roman_numerals::convert(59)); }
21+
TEST_CASE("66_is_lxvi") { REQUIRE("LXVI" == roman_numerals::convert(66)); }
22+
TEST_CASE("93_is_xciii") { REQUIRE("XCIII" == roman_numerals::convert(93)); }
23+
TEST_CASE("141_is_cxli") { REQUIRE("CXLI" == roman_numerals::convert(141)); }
24+
TEST_CASE("163_is_clxiii") {
6325
REQUIRE("CLXIII" == roman_numerals::convert(163));
6426
}
65-
TEST_CASE("402_is_cdii")
66-
{
67-
REQUIRE("CDII" == roman_numerals::convert(402));
68-
}
69-
TEST_CASE("575_is_dlxxv")
70-
{
71-
REQUIRE("DLXXV" == roman_numerals::convert(575));
72-
}
73-
TEST_CASE("911_is_cmxi")
74-
{
75-
REQUIRE("CMXI" == roman_numerals::convert(911));
27+
TEST_CASE("166_is_clxvi") { REQUIRE("CLXVI" == roman_numerals::convert(166)); }
28+
TEST_CASE("402_is_cdii") { REQUIRE("CDII" == roman_numerals::convert(402)); }
29+
TEST_CASE("575_is_dlxxv") { REQUIRE("DLXXV" == roman_numerals::convert(575)); }
30+
TEST_CASE("666_is_dclxvi") {
31+
REQUIRE("DCLXVI" == roman_numerals::convert(666));
7632
}
77-
TEST_CASE("1024_is_mxxiv")
78-
{
33+
TEST_CASE("911_is_cmxi") { REQUIRE("CMXI" == roman_numerals::convert(911)); }
34+
TEST_CASE("1024_is_mxxiv") {
7935
REQUIRE("MXXIV" == roman_numerals::convert(1024));
8036
}
81-
TEST_CASE("3000_is_mmm")
82-
{
83-
REQUIRE("MMM" == roman_numerals::convert(3000));
84-
}
85-
TEST_CASE("16_is_xvi")
86-
{
87-
REQUIRE("XVI" == roman_numerals::convert(16));
88-
}
89-
TEST_CASE("66_is_lxvi")
90-
{
91-
REQUIRE("LXVI" == roman_numerals::convert(66));
92-
}
93-
TEST_CASE("166_is_clxvi")
94-
{
95-
REQUIRE("CLXVI" == roman_numerals::convert(166));
96-
}
97-
TEST_CASE("666_is_dclxvi")
98-
{
99-
REQUIRE("DCLXVI" == roman_numerals::convert(666));
100-
}
101-
TEST_CASE("1666_is_mdclxvi")
102-
{
37+
TEST_CASE("1666_is_mdclxvi") {
10338
REQUIRE("MDCLXVI" == roman_numerals::convert(1666));
10439
}
105-
TEST_CASE("3001_is_mmmi")
106-
{
107-
REQUIRE("MMMI" == roman_numerals::convert(3001));
40+
TEST_CASE("3000_is_mmm") { REQUIRE("MMM" == roman_numerals::convert(3000)); }
41+
TEST_CASE("3001_is_mmmi") { REQUIRE("MMMI" == roman_numerals::convert(3001)); }
42+
TEST_CASE("3888_is_mmmdccclxxxviii") {
43+
REQUIRE("MMMDCCCLXXXVIII" == roman_numerals::convert(3888));
10844
}
109-
TEST_CASE("3999_is_mmmcmxcix")
110-
{
45+
TEST_CASE("3999_is_mmmcmxcix") {
11146
REQUIRE("MMMCMXCIX" == roman_numerals::convert(3999));
11247
}
11348
#endif

0 commit comments

Comments
 (0)