Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: update say exercise #903

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions exercises/practice/say/.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.

[5d22a120-ba0c-428c-bd25-8682235d83e8]
description = "zero"
Expand All @@ -17,12 +24,24 @@ description = "twenty"
[d78601eb-4a84-4bfa-bf0e-665aeb8abe94]
description = "twenty-two"

[f010d4ca-12c9-44e9-803a-27789841adb1]
description = "thirty"

[738ce12d-ee5c-4dfb-ad26-534753a98327]
description = "ninety-nine"

[e417d452-129e-4056-bd5b-6eb1df334dce]
description = "one hundred"

[d6924f30-80ba-4597-acf6-ea3f16269da8]
description = "one hundred twenty-three"

[2f061132-54bc-4fd4-b5df-0a3b778959b9]
description = "two hundred"

[feed6627-5387-4d38-9692-87c0dbc55c33]
description = "nine hundred ninety-nine"

[3d83da89-a372-46d3-b10d-de0c792432b3]
description = "one thousand"

Expand Down
106 changes: 55 additions & 51 deletions exercises/practice/say/say_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,97 @@
#include "test/catch.hpp"
#endif

TEST_CASE("zero")
{
REQUIRE("zero" == say::in_english(0ULL));
/*
An 'error' object is used as expected value to indicate that the
input value is out of the range described in the exercise.
*/

TEST_CASE("zero", "[5d22a120-ba0c-428c-bd25-8682235d83e8]") {
REQUIRE("zero" == say::in_english(0));
}

#if defined(EXERCISM_RUN_ALL_TESTS)
TEST_CASE("one")
{
REQUIRE("one" == say::in_english(1ULL));

TEST_CASE("one", "[9b5eed77-dbf6-439d-b920-3f7eb58928f6]") {
REQUIRE("one" == say::in_english(1));
}

TEST_CASE("fourteen", "[7c499be1-612e-4096-a5e1-43b2f719406d]") {
REQUIRE("fourteen" == say::in_english(14));
}

TEST_CASE("fourteen")
{
REQUIRE("fourteen" == say::in_english(14ULL));
TEST_CASE("twenty", "[f541dd8e-f070-4329-92b4-b7ce2fcf06b4]") {
REQUIRE("twenty" == say::in_english(20));
}

TEST_CASE("twenty")
{
REQUIRE("twenty" == say::in_english(20ULL));
TEST_CASE("twenty-two", "[d78601eb-4a84-4bfa-bf0e-665aeb8abe94]") {
REQUIRE("twenty-two" == say::in_english(22));
}

TEST_CASE("twenty_two")
{
REQUIRE("twenty-two" == say::in_english(22ULL));
TEST_CASE("thirty", "[f010d4ca-12c9-44e9-803a-27789841adb1]") {
REQUIRE("thirty" == say::in_english(30));
}

TEST_CASE("sixty_nine")
{
REQUIRE("sixty-nine" == say::in_english(69ULL));
TEST_CASE("ninety-nine", "[738ce12d-ee5c-4dfb-ad26-534753a98327]") {
REQUIRE("ninety-nine" == say::in_english(99));
}

TEST_CASE("one_hundred")
{
REQUIRE("one hundred" == say::in_english(100ULL));
TEST_CASE("one hundred", "[e417d452-129e-4056-bd5b-6eb1df334dce]") {
REQUIRE("one hundred" == say::in_english(100));
}

TEST_CASE("one_hundred_twenty_three")
{
REQUIRE("one hundred twenty-three" == say::in_english(123ULL));
TEST_CASE("one hundred twenty-three",
"[d6924f30-80ba-4597-acf6-ea3f16269da8]") {
REQUIRE("one hundred twenty-three" == say::in_english(123));
}

TEST_CASE("one_thousand")
{
REQUIRE("one thousand" == say::in_english(1000ULL));
TEST_CASE("two hundred", "[2f061132-54bc-4fd4-b5df-0a3b778959b9]") {
REQUIRE("two hundred" == say::in_english(200));
}

TEST_CASE("one_thousand_two_hundred_thirty_four")
{
REQUIRE("one thousand two hundred thirty-four" == say::in_english(1234ULL));
TEST_CASE("nine hundred ninety-nine",
"[feed6627-5387-4d38-9692-87c0dbc55c33]") {
REQUIRE("nine hundred ninety-nine" == say::in_english(999));
}

TEST_CASE("one_million")
{
REQUIRE("one million" == say::in_english(1000ULL*1000ULL));
TEST_CASE("one thousand", "[3d83da89-a372-46d3-b10d-de0c792432b3]") {
REQUIRE("one thousand" == say::in_english(1000));
}

TEST_CASE("one_million_two")
{
REQUIRE("one million two" == say::in_english(1000ULL*1000ULL + 2ULL));
TEST_CASE("one thousand two hundred thirty-four",
"[865af898-1d5b-495f-8ff0-2f06d3c73709]") {
REQUIRE("one thousand two hundred thirty-four" == say::in_english(1234));
}

TEST_CASE("one_million_two_thousand_three_hundred_forty_five")
{
REQUIRE("one million two thousand three hundred forty-five" == say::in_english(1002345ULL));
TEST_CASE("one million", "[b6a3f442-266e-47a3-835d-7f8a35f6cf7f]") {
REQUIRE("one million" == say::in_english(1000000));
}

TEST_CASE("one_billion")
{
REQUIRE("one billion" == say::in_english(1000ULL*1000ULL*1000ULL));
TEST_CASE("one million two thousand three hundred forty-five",
"[2cea9303-e77e-4212-b8ff-c39f1978fc70]") {
REQUIRE("one million two thousand three hundred forty-five" ==
say::in_english(1002345));
}

TEST_CASE("a_really_big_number")
{
TEST_CASE("one billion", "[3e240eeb-f564-4b80-9421-db123f66a38f]") {
REQUIRE("one billion" == say::in_english(1000000000));
}

TEST_CASE("a big number", "[9a43fed1-c875-4710-8286-5065d73b8a9e]") {
REQUIRE(
"nine hundred eighty-seven billion six hundred fifty-four million "
"three hundred twenty-one thousand one hundred twenty-three" ==
say::in_english(987654321123ULL));
say::in_english(987654321123));
}

TEST_CASE("raises_an_error_below_zero")
{
TEST_CASE("numbers below zero are out of range",
"[49a6a17b-084e-423e-994d-a87c0ecc05ef]") {
REQUIRE_THROWS_AS(say::in_english(-1), std::domain_error);
}

TEST_CASE("raises_an_error_for_one_trillion")
{
REQUIRE_THROWS_AS(say::in_english(1000ULL * 1000ULL * 1000ULL * 1000ULL),
std::domain_error);
TEST_CASE("numbers above 999,999,999,999 are out of range",
"[4d6492eb-5853-4d16-9d34-b0f61b261fd9]") {
REQUIRE_THROWS_AS(say::in_english(1000000000000), std::domain_error);
}

#endif