Skip to content

Commit bac9cd0

Browse files
authored
tests: update luhn exercise (#818)
1 parent 0a8455f commit bac9cd0

File tree

2 files changed

+72
-117
lines changed

2 files changed

+72
-117
lines changed

exercises/practice/luhn/.meta/tests.toml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[792a7082-feb7-48c7-b88b-bbfec160865e]
613
description = "single digit strings can not be valid"
@@ -26,6 +33,9 @@ description = "invalid credit card"
2633
[20e67fad-2121-43ed-99a8-14b5b856adb9]
2734
description = "invalid long number with an even remainder"
2835

36+
[7e7c9fc1-d994-457c-811e-d390d52fba5e]
37+
description = "invalid long number with a remainder divisible by 5"
38+
2939
[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]
3040
description = "valid number with an even number of digits"
3141

@@ -50,8 +60,17 @@ description = "more than a single zero is valid"
5060
[ab56fa80-5de8-4735-8a4a-14dae588663e]
5161
description = "input digit 9 is correctly converted to output digit 9"
5262

63+
[b9887ee8-8337-46c5-bc45-3bcab51bc36f]
64+
description = "very long input is valid"
65+
66+
[8a7c0e24-85ea-4154-9cf1-c2db90eabc08]
67+
description = "valid luhn with an odd number of digits and non zero first digit"
68+
5369
[39a06a5a-5bad-4e0f-b215-b042d46209b1]
5470
description = "using ascii value for non-doubled non-digit isn't allowed"
5571

5672
[f94cf191-a62f-4868-bc72-7253114aa157]
5773
description = "using ascii value for doubled non-digit isn't allowed"
74+
75+
[8b72ad26-c8be-49a2-b99c-bcc3bf631b33]
76+
description = "non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed"

exercises/practice/luhn/luhn_test.cpp

Lines changed: 50 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -5,159 +5,95 @@
55
#include "test/catch.hpp"
66
#endif
77

8-
//Luhn exercise test case data version 1.6.0
98

10-
TEST_CASE("single_digit_strings_can_not_be_valid")
11-
{
12-
const bool actual = luhn::valid("1");
13-
14-
const bool expected {false};
15-
16-
REQUIRE(expected == actual);
9+
TEST_CASE("single digit strings can not be valid", "[792a7082-feb7-48c7-b88b-bbfec160865e]") {
10+
REQUIRE(false == luhn::valid("1"));
1711
}
1812

1913
#if defined(EXERCISM_RUN_ALL_TESTS)
20-
TEST_CASE("a_single_zero_is_invalid")
21-
{
22-
const bool actual = luhn::valid("0");
23-
24-
const bool expected {false};
2514

26-
REQUIRE(expected == actual);
15+
TEST_CASE("a single zero is invalid", "[698a7924-64d4-4d89-8daa-32e1aadc271e]") {
16+
REQUIRE(false == luhn::valid("0"));
2717
}
2818

29-
TEST_CASE("a_simple_valid_SIN_that_remains_valid_if_reversed")
30-
{
31-
const bool actual = luhn::valid("059");
32-
33-
const bool expected {true};
34-
35-
REQUIRE(expected == actual);
19+
TEST_CASE("a simple valid SIN that remains valid if reversed", "[73c2f62b-9b10-4c9f-9a04-83cee7367965]") {
20+
REQUIRE(true == luhn::valid("059"));
3621
}
3722

38-
TEST_CASE("a_simple_valid_SIN_that_becomes_invalid_if_reversed")
39-
{
40-
const bool actual = luhn::valid("59");
41-
42-
const bool expected {true};
43-
44-
REQUIRE(expected == actual);
23+
TEST_CASE("a simple valid SIN that becomes invalid if reversed", "[9369092e-b095-439f-948d-498bd076be11]") {
24+
REQUIRE(true == luhn::valid("59"));
4525
}
4626

47-
TEST_CASE("a_valid_Canadian_SIN")
48-
{
49-
const bool actual = luhn::valid("055 444 285");
50-
51-
const bool expected {true};
52-
53-
REQUIRE(expected == actual);
27+
TEST_CASE("a valid Canadian SIN", "[8f9f2350-1faf-4008-ba84-85cbb93ffeca]") {
28+
REQUIRE(true == luhn::valid("055 444 285"));
5429
}
5530

56-
TEST_CASE("invalid_Canadian_SIN")
57-
{
58-
const bool actual = luhn::valid("055 444 286");
59-
60-
const bool expected {false};
61-
62-
REQUIRE(expected == actual);
31+
TEST_CASE("invalid Canadian SIN", "[1cdcf269-6560-44fc-91f6-5819a7548737]") {
32+
REQUIRE(false == luhn::valid("055 444 286"));
6333
}
6434

65-
TEST_CASE("invalid_credit_card")
66-
{
67-
const bool actual = luhn::valid("8273 1232 7352 0569");
68-
69-
const bool expected {false};
70-
71-
REQUIRE(expected == actual);
35+
TEST_CASE("invalid credit card", "[656c48c1-34e8-4e60-9a5a-aad8a367810a]") {
36+
REQUIRE(false == luhn::valid("8273 1232 7352 0569"));
7237
}
7338

74-
TEST_CASE("valid_number_with_an_even_number_of_digits")
75-
{
76-
const bool actual = luhn::valid("095 245 88");
77-
78-
const bool expected {true};
79-
80-
REQUIRE(expected == actual);
39+
TEST_CASE("invalid long number with an even remainder", "[20e67fad-2121-43ed-99a8-14b5b856adb9]") {
40+
REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9012"));
8141
}
8242

83-
TEST_CASE("valid_number_with_an_odd_number_of_spaces")
84-
{
85-
const bool actual = luhn::valid("234 567 891 234");
86-
87-
const bool expected {true};
88-
89-
REQUIRE(expected == actual);
43+
TEST_CASE("invalid long number with a remainder divisible by 5", "[7e7c9fc1-d994-457c-811e-d390d52fba5e]") {
44+
REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9013"));
9045
}
9146

92-
TEST_CASE("valid_strings_with_a_non_digit_added_at_the_end_become_invalid")
93-
{
94-
const bool actual = luhn::valid("059a");
95-
96-
const bool expected {false};
97-
98-
REQUIRE(expected == actual);
47+
TEST_CASE("valid number with an even number of digits", "[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]") {
48+
REQUIRE(true == luhn::valid("095 245 88"));
9949
}
10050

101-
TEST_CASE("valid_strings_with_punctuation_included_become_invalid")
102-
{
103-
const bool actual = luhn::valid("055-444-285");
104-
105-
const bool expected {false};
106-
107-
REQUIRE(expected == actual);
51+
TEST_CASE("valid number with an odd number of spaces", "[ef081c06-a41f-4761-8492-385e13c8202d]") {
52+
REQUIRE(true == luhn::valid("234 567 891 234"));
10853
}
10954

110-
TEST_CASE("valid_strings_with_symbols_included_become_invalid")
111-
{
112-
const bool actual = luhn::valid("055£ 444$ 285");
113-
114-
const bool expected {false};
115-
116-
REQUIRE(expected == actual);
55+
TEST_CASE("valid strings with a non-digit added at the end become invalid", "[bef66f64-6100-4cbb-8f94-4c9713c5e5b2]") {
56+
REQUIRE(false == luhn::valid("059a"));
11757
}
11858

119-
TEST_CASE("single_zero_with_spaces_invalid")
120-
{
121-
const bool actual = luhn::valid(" 0");
122-
123-
const bool expected {false};
124-
125-
REQUIRE(expected == actual);
59+
TEST_CASE("valid strings with punctuation included become invalid", "[2177e225-9ce7-40f6-b55d-fa420e62938e]") {
60+
REQUIRE(false == luhn::valid("055-444-285"));
12661
}
12762

128-
TEST_CASE("more_than_a_single_zero_is_valid")
129-
{
130-
const bool actual = luhn::valid("0000 0");
131-
132-
const bool expected {true};
133-
134-
REQUIRE(expected == actual);
63+
TEST_CASE("valid strings with symbols included become invalid", "[ebf04f27-9698-45e1-9afe-7e0851d0fe8d]") {
64+
REQUIRE(false == luhn::valid("055# 444$ 285"));
13565
}
13666

137-
TEST_CASE("input_digit_9_is_correctly_converted_to_output_digit_9")
138-
{
139-
const bool actual = luhn::valid("091");
140-
141-
const bool expected {true};
67+
TEST_CASE("single zero with space is invalid", "[08195c5e-ce7f-422c-a5eb-3e45fece68ba]") {
68+
REQUIRE(false == luhn::valid(" 0"));
69+
}
14270

143-
REQUIRE(expected == actual);
71+
TEST_CASE("more than a single zero is valid", "[12e63a3c-f866-4a79-8c14-b359fc386091]") {
72+
REQUIRE(true == luhn::valid("0000 0"));
14473
}
14574

146-
TEST_CASE("using_ascii_value_for_non_doubled_non_digit_is_not_allowed")
147-
{
148-
const bool actual = luhn::valid("055b 444 285");
75+
TEST_CASE("input digit 9 is correctly converted to output digit 9", "[ab56fa80-5de8-4735-8a4a-14dae588663e]") {
76+
REQUIRE(true == luhn::valid("091"));
77+
}
14978

150-
const bool expected {false};
79+
TEST_CASE("very long input is valid", "[b9887ee8-8337-46c5-bc45-3bcab51bc36f]") {
80+
REQUIRE(true == luhn::valid("9999999999 9999999999 9999999999 9999999999"));
81+
}
15182

152-
REQUIRE(expected == actual);
83+
TEST_CASE("valid luhn with an odd number of digits and non zero first digit", "[8a7c0e24-85ea-4154-9cf1-c2db90eabc08]") {
84+
REQUIRE(true == luhn::valid("109"));
15385
}
15486

155-
TEST_CASE("strings_with_non_digits_is_invalid")
156-
{
157-
const bool actual = luhn::valid(":9");
87+
TEST_CASE("using ascii value for non-doubled non-digit isn't allowed", "[39a06a5a-5bad-4e0f-b215-b042d46209b1]") {
88+
REQUIRE(false == luhn::valid("055b 444 285"));
89+
}
15890

159-
const bool expected {false};
91+
TEST_CASE("using ascii value for doubled non-digit isn't allowed", "[f94cf191-a62f-4868-bc72-7253114aa157]") {
92+
REQUIRE(false == luhn::valid(":9"));
93+
}
16094

161-
REQUIRE(expected == actual);
95+
TEST_CASE("non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed", "[8b72ad26-c8be-49a2-b99c-bcc3bf631b33]") {
96+
REQUIRE(false == luhn::valid("59%59"));
16297
}
98+
16399
#endif

0 commit comments

Comments
 (0)