exercism / exercism/c

Problems in pascals-triangle test

Open
#929 12 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
383
Forks
215
PR merge metrics
No merged PRs in 30d

Description

1. From description I expect the tests to check the triangle, I wouldn't expect that [test](https://github.com/exercism/c/blob/9182dd5ea2aa9d00dd5a89b23a139ed09bc7f768/exercises/practice/pascals-triangle/test_pascals_triangle.c#L36) wants all rows of numbers to be of same length and to end with zeroes. This prevents several solutions that I imagined while solving:
* to reserve exactly the needed space for every row (for me it failed for ten rows test)
* even hackier solution that takes into account that rows always start and end with 1, so creating an array containing `{1, 1, 2, 1, 3, 3, 1, 4, 6, 4, 1}` and an array of pointers at right positions should be the right solution.
2. Is there really a need to free in `tearDown`? Leaked memory should be freed anyway after all tests finish (or am I missing something?), but having expectation about used structure in `tearDown` may cause a segmentation fault instead of a list of failing tests in case `free` is called on wrong pointer. I went with reserving space for all rows in one `malloc` to save on calls and reduce memory usage and had problems understanding that for me the case with 0 rows was failing and causing `free` to cause segmentation fault. It was introduced in #755 and probably better to ping @bobahop
3. Why does zero rows expect `{ { 0 } }` in result, shouldn't it be expecting 0 rows, or even be ok with `NULL`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.