From b86892ac2b7abb8e92280c7f4d260b98848ed9e3 Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Thu, 9 Jan 2025 22:11:31 +0530 Subject: [PATCH 1/2] Updating tests for palindrome-products --- .../palindrome-products/.meta/config.json | 1 + .../palindrome-products/.meta/tests.toml | 24 +++++++++++++------ .../test_palindrome_products.c | 15 ++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/exercises/practice/palindrome-products/.meta/config.json b/exercises/practice/palindrome-products/.meta/config.json index 961b98edf..5cd421f0a 100644 --- a/exercises/practice/palindrome-products/.meta/config.json +++ b/exercises/practice/palindrome-products/.meta/config.json @@ -6,6 +6,7 @@ "bcc32", "Gamecock", "h-3-0", + "jagdish-15", "patricksjackson", "QLaille", "vlzware", diff --git a/exercises/practice/palindrome-products/.meta/tests.toml b/exercises/practice/palindrome-products/.meta/tests.toml index b34cb0d47..a3bc41750 100644 --- a/exercises/practice/palindrome-products/.meta/tests.toml +++ b/exercises/practice/palindrome-products/.meta/tests.toml @@ -1,12 +1,19 @@ -# 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. [5cff78fe-cf02-459d-85c2-ce584679f887] -description = "finds the smallest palindrome from single digit factors" +description = "find the smallest palindrome from single digit factors" [0853f82c-5fc4-44ae-be38-fadb2cced92d] -description = "finds the largest palindrome from single digit factors" +description = "find the largest palindrome from single digit factors" [66c3b496-bdec-4103-9129-3fcb5a9063e1] description = "find the smallest palindrome from double digit factors" @@ -15,13 +22,13 @@ description = "find the smallest palindrome from double digit factors" description = "find the largest palindrome from double digit factors" [cecb5a35-46d1-4666-9719-fa2c3af7499d] -description = "find smallest palindrome from triple digit factors" +description = "find the smallest palindrome from triple digit factors" [edab43e1-c35f-4ea3-8c55-2f31dddd92e5] description = "find the largest palindrome from triple digit factors" [4f802b5a-9d74-4026-a70f-b53ff9234e4e] -description = "find smallest palindrome from four digit factors" +description = "find the smallest palindrome from four digit factors" [787525e0-a5f9-40f3-8cb2-23b52cf5d0be] description = "find the largest palindrome from four digit factors" @@ -37,3 +44,6 @@ description = "error result for smallest if min is more than max" [eeeb5bff-3f47-4b1e-892f-05829277bd74] description = "error result for largest if min is more than max" + +[16481711-26c4-42e0-9180-e2e4e8b29c23] +description = "smallest product does not use the smallest factor" diff --git a/exercises/practice/palindrome-products/test_palindrome_products.c b/exercises/practice/palindrome-products/test_palindrome_products.c index 1305d2b83..e8e3eded6 100644 --- a/exercises/practice/palindrome-products/test_palindrome_products.c +++ b/exercises/practice/palindrome-products/test_palindrome_products.c @@ -227,6 +227,19 @@ static void test_error_result_for_largest_if_min_is_more_than_max(void) free_product(product); } +static void test_smallest_product_not_using_smallest_factor(void) +{ + TEST_IGNORE(); // delete this line to run test + product_t *product = get_palindrome_product(3215, 4000); + TEST_ASSERT_NOT_NULL(product); + TEST_ASSERT_EQUAL_INT(10988901, product->smallest); + + factor_t expected_lg[] = { { 3297, 3333, NULL } }; + check_factors(product->factors_lg, 1, expected_lg); + + free_product(product); +} + int main(void) { UNITY_BEGIN(); @@ -249,5 +262,7 @@ int main(void) RUN_TEST(test_error_result_for_smallest_if_min_is_more_than_max); RUN_TEST(test_error_result_for_largest_if_min_is_more_than_max); + RUN_TEST(test_smallest_product_not_using_smallest_factor); + return UNITY_END(); } From 3bb143935a623bb0bc0d63882d9c706ce18f611d Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Thu, 9 Jan 2025 22:47:49 +0530 Subject: [PATCH 2/2] Updating example.c to fix memmroy leak --- exercises/practice/palindrome-products/.meta/example.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercises/practice/palindrome-products/.meta/example.c b/exercises/practice/palindrome-products/.meta/example.c index 289bd71da..04687c4a8 100644 --- a/exercises/practice/palindrome-products/.meta/example.c +++ b/exercises/practice/palindrome-products/.meta/example.c @@ -94,6 +94,8 @@ product_t *get_palindrome_product(int from, int to) err = addfactors(&result->factors_lg, i, k); } if (err) { + free_ll(result->factors_lg); + free_ll(result->factors_sm); free(result); return NULL; }