Skip to content

Commit

Permalink
tests: update luhn exercise (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeng authored Feb 26, 2024
1 parent 0a8455f commit bac9cd0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 117 deletions.
25 changes: 22 additions & 3 deletions exercises/practice/luhn/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

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

[7e7c9fc1-d994-457c-811e-d390d52fba5e]
description = "invalid long number with a remainder divisible by 5"

[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]
description = "valid number with an even number of digits"

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

[b9887ee8-8337-46c5-bc45-3bcab51bc36f]
description = "very long input is valid"

[8a7c0e24-85ea-4154-9cf1-c2db90eabc08]
description = "valid luhn with an odd number of digits and non zero first digit"

[39a06a5a-5bad-4e0f-b215-b042d46209b1]
description = "using ascii value for non-doubled non-digit isn't allowed"

[f94cf191-a62f-4868-bc72-7253114aa157]
description = "using ascii value for doubled non-digit isn't allowed"

[8b72ad26-c8be-49a2-b99c-bcc3bf631b33]
description = "non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed"
164 changes: 50 additions & 114 deletions exercises/practice/luhn/luhn_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,159 +5,95 @@
#include "test/catch.hpp"
#endif

//Luhn exercise test case data version 1.6.0

TEST_CASE("single_digit_strings_can_not_be_valid")
{
const bool actual = luhn::valid("1");

const bool expected {false};

REQUIRE(expected == actual);
TEST_CASE("single digit strings can not be valid", "[792a7082-feb7-48c7-b88b-bbfec160865e]") {
REQUIRE(false == luhn::valid("1"));
}

#if defined(EXERCISM_RUN_ALL_TESTS)
TEST_CASE("a_single_zero_is_invalid")
{
const bool actual = luhn::valid("0");

const bool expected {false};

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

TEST_CASE("a_simple_valid_SIN_that_remains_valid_if_reversed")
{
const bool actual = luhn::valid("059");

const bool expected {true};

REQUIRE(expected == actual);
TEST_CASE("a simple valid SIN that remains valid if reversed", "[73c2f62b-9b10-4c9f-9a04-83cee7367965]") {
REQUIRE(true == luhn::valid("059"));
}

TEST_CASE("a_simple_valid_SIN_that_becomes_invalid_if_reversed")
{
const bool actual = luhn::valid("59");

const bool expected {true};

REQUIRE(expected == actual);
TEST_CASE("a simple valid SIN that becomes invalid if reversed", "[9369092e-b095-439f-948d-498bd076be11]") {
REQUIRE(true == luhn::valid("59"));
}

TEST_CASE("a_valid_Canadian_SIN")
{
const bool actual = luhn::valid("055 444 285");

const bool expected {true};

REQUIRE(expected == actual);
TEST_CASE("a valid Canadian SIN", "[8f9f2350-1faf-4008-ba84-85cbb93ffeca]") {
REQUIRE(true == luhn::valid("055 444 285"));
}

TEST_CASE("invalid_Canadian_SIN")
{
const bool actual = luhn::valid("055 444 286");

const bool expected {false};

REQUIRE(expected == actual);
TEST_CASE("invalid Canadian SIN", "[1cdcf269-6560-44fc-91f6-5819a7548737]") {
REQUIRE(false == luhn::valid("055 444 286"));
}

TEST_CASE("invalid_credit_card")
{
const bool actual = luhn::valid("8273 1232 7352 0569");

const bool expected {false};

REQUIRE(expected == actual);
TEST_CASE("invalid credit card", "[656c48c1-34e8-4e60-9a5a-aad8a367810a]") {
REQUIRE(false == luhn::valid("8273 1232 7352 0569"));
}

TEST_CASE("valid_number_with_an_even_number_of_digits")
{
const bool actual = luhn::valid("095 245 88");

const bool expected {true};

REQUIRE(expected == actual);
TEST_CASE("invalid long number with an even remainder", "[20e67fad-2121-43ed-99a8-14b5b856adb9]") {
REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9012"));
}

TEST_CASE("valid_number_with_an_odd_number_of_spaces")
{
const bool actual = luhn::valid("234 567 891 234");

const bool expected {true};

REQUIRE(expected == actual);
TEST_CASE("invalid long number with a remainder divisible by 5", "[7e7c9fc1-d994-457c-811e-d390d52fba5e]") {
REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9013"));
}

TEST_CASE("valid_strings_with_a_non_digit_added_at_the_end_become_invalid")
{
const bool actual = luhn::valid("059a");

const bool expected {false};

REQUIRE(expected == actual);
TEST_CASE("valid number with an even number of digits", "[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]") {
REQUIRE(true == luhn::valid("095 245 88"));
}

TEST_CASE("valid_strings_with_punctuation_included_become_invalid")
{
const bool actual = luhn::valid("055-444-285");

const bool expected {false};

REQUIRE(expected == actual);
TEST_CASE("valid number with an odd number of spaces", "[ef081c06-a41f-4761-8492-385e13c8202d]") {
REQUIRE(true == luhn::valid("234 567 891 234"));
}

TEST_CASE("valid_strings_with_symbols_included_become_invalid")
{
const bool actual = luhn::valid("055£ 444$ 285");

const bool expected {false};

REQUIRE(expected == actual);
TEST_CASE("valid strings with a non-digit added at the end become invalid", "[bef66f64-6100-4cbb-8f94-4c9713c5e5b2]") {
REQUIRE(false == luhn::valid("059a"));
}

TEST_CASE("single_zero_with_spaces_invalid")
{
const bool actual = luhn::valid(" 0");

const bool expected {false};

REQUIRE(expected == actual);
TEST_CASE("valid strings with punctuation included become invalid", "[2177e225-9ce7-40f6-b55d-fa420e62938e]") {
REQUIRE(false == luhn::valid("055-444-285"));
}

TEST_CASE("more_than_a_single_zero_is_valid")
{
const bool actual = luhn::valid("0000 0");

const bool expected {true};

REQUIRE(expected == actual);
TEST_CASE("valid strings with symbols included become invalid", "[ebf04f27-9698-45e1-9afe-7e0851d0fe8d]") {
REQUIRE(false == luhn::valid("055# 444$ 285"));
}

TEST_CASE("input_digit_9_is_correctly_converted_to_output_digit_9")
{
const bool actual = luhn::valid("091");

const bool expected {true};
TEST_CASE("single zero with space is invalid", "[08195c5e-ce7f-422c-a5eb-3e45fece68ba]") {
REQUIRE(false == luhn::valid(" 0"));
}

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

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

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

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

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

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

REQUIRE(expected == actual);
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]") {
REQUIRE(false == luhn::valid("59%59"));
}

#endif

0 comments on commit bac9cd0

Please sign in to comment.