Skip to content

Commit 01ba11b

Browse files
Updating tests for palindrome-products (#1031)
* Updating tests for palindrome-products * Updating example.c to fix memmroy leak * Fixed test --------- Co-authored-by: Ryan Hartlage <[email protected]>
1 parent d3b0e9e commit 01ba11b

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

Diff for: exercises/practice/palindrome-products/.meta/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"bcc32",
77
"Gamecock",
88
"h-3-0",
9+
"jagdish-15",
910
"patricksjackson",
1011
"QLaille",
1112
"vlzware",

Diff for: exercises/practice/palindrome-products/.meta/example.c

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ product_t *get_palindrome_product(int from, int to)
9494
err = addfactors(&result->factors_lg, i, k);
9595
}
9696
if (err) {
97+
free_ll(result->factors_lg);
98+
free_ll(result->factors_sm);
9799
free(result);
98100
return NULL;
99101
}

Diff for: exercises/practice/palindrome-products/.meta/tests.toml

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
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
[5cff78fe-cf02-459d-85c2-ce584679f887]
6-
description = "finds the smallest palindrome from single digit factors"
13+
description = "find the smallest palindrome from single digit factors"
714

815
[0853f82c-5fc4-44ae-be38-fadb2cced92d]
9-
description = "finds the largest palindrome from single digit factors"
16+
description = "find the largest palindrome from single digit factors"
1017

1118
[66c3b496-bdec-4103-9129-3fcb5a9063e1]
1219
description = "find the smallest palindrome from double digit factors"
@@ -15,13 +22,13 @@ description = "find the smallest palindrome from double digit factors"
1522
description = "find the largest palindrome from double digit factors"
1623

1724
[cecb5a35-46d1-4666-9719-fa2c3af7499d]
18-
description = "find smallest palindrome from triple digit factors"
25+
description = "find the smallest palindrome from triple digit factors"
1926

2027
[edab43e1-c35f-4ea3-8c55-2f31dddd92e5]
2128
description = "find the largest palindrome from triple digit factors"
2229

2330
[4f802b5a-9d74-4026-a70f-b53ff9234e4e]
24-
description = "find smallest palindrome from four digit factors"
31+
description = "find the smallest palindrome from four digit factors"
2532

2633
[787525e0-a5f9-40f3-8cb2-23b52cf5d0be]
2734
description = "find the largest palindrome from four digit factors"
@@ -37,3 +44,6 @@ description = "error result for smallest if min is more than max"
3744

3845
[eeeb5bff-3f47-4b1e-892f-05829277bd74]
3946
description = "error result for largest if min is more than max"
47+
48+
[16481711-26c4-42e0-9180-e2e4e8b29c23]
49+
description = "smallest product does not use the smallest factor"

Diff for: exercises/practice/palindrome-products/test_palindrome_products.c

+15
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ static void test_error_result_for_largest_if_min_is_more_than_max(void)
227227
free_product(product);
228228
}
229229

230+
static void test_smallest_product_not_using_smallest_factor(void)
231+
{
232+
TEST_IGNORE(); // delete this line to run test
233+
product_t *product = get_palindrome_product(3215, 4000);
234+
TEST_ASSERT_NOT_NULL(product);
235+
TEST_ASSERT_EQUAL_INT(10988901, product->smallest);
236+
237+
factor_t expected_lg[] = { { 3297, 3333, NULL } };
238+
check_factors(product->factors_sm, 1, expected_lg);
239+
240+
free_product(product);
241+
}
242+
230243
int main(void)
231244
{
232245
UNITY_BEGIN();
@@ -249,5 +262,7 @@ int main(void)
249262
RUN_TEST(test_error_result_for_smallest_if_min_is_more_than_max);
250263
RUN_TEST(test_error_result_for_largest_if_min_is_more_than_max);
251264

265+
RUN_TEST(test_smallest_product_not_using_smallest_factor);
266+
252267
return UNITY_END();
253268
}

0 commit comments

Comments
 (0)