Skip to content

Problems in pascals-triangle test #929

@toy

Description

@toy
  1. From description I expect the tests to check the triangle, I wouldn't expect that test 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 Update tests_pascals_triangle.c: Fix memory leaks #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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions