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

t: port reftable/tree_test.c to the unit testing framework #1740

Closed
wants to merge 5 commits into from

Commits on Aug 3, 2024

  1. reftable: remove unnecessary curly braces in reftable/tree.c

    According to Documentation/CodingGuidelines, single-line control-flow
    statements must omit curly braces (except for some special cases).
    Make reftable/tree.c adhere to this guideline.
    
    Mentored-by: Patrick Steinhardt <[email protected]>
    Mentored-by: Christian Couder <[email protected]>
    Signed-off-by: Chandra Pratap <[email protected]>
    Chandra Pratap committed Aug 3, 2024
    Configuration menu
    Copy the full SHA
    d738bf5 View commit details
    Browse the repository at this point in the history
  2. t: move reftable/tree_test.c to the unit testing framework

    reftable/tree_test.c exercises the functions defined in
    reftable/tree.{c, h}. Migrate reftable/tree_test.c to the unit
    testing framework. Migration involves refactoring the tests to use
    the unit testing framework instead of reftable's test framework and
    renaming the tests to align with unit-tests' standards.
    
    Also add a comment to help understand the test routine.
    
    Note that this commit mostly moves the test from reftable/ to
    t/unit-tests/ and most of the refactoring is performed by the
    trailing commits.
    
    Mentored-by: Patrick Steinhardt <[email protected]>
    Mentored-by: Christian Couder <[email protected]>
    Signed-off-by: Chandra Pratap <[email protected]>
    Chandra Pratap committed Aug 3, 2024
    Configuration menu
    Copy the full SHA
    f090ace View commit details
    Browse the repository at this point in the history
  3. t-reftable-tree: split test_tree() into two sub-test functions

    In the current testing setup, tests for both tree_search() and
    infix_walk() defined by reftable/tree.{c, h} are performed by
    a single test function, test_tree(). Split tree_test() into
    test_tree_search() and test_infix_walk() responsible for
    independently testing tree_search() and infix_walk() respectively.
    This improves the overall readability of the test file as well as
    simplifies debugging.
    
    Note that the last parameter in the tree_search() functiom is
    'int insert' which when set, inserts the key if it is not found
    in the tree. Otherwise, the function returns NULL for such cases.
    
    While at it, use 'func' to pass function pointers and not '&func'.
    
    Mentored-by: Patrick Steinhardt <[email protected]>
    Mentored-by: Christian Couder <[email protected]>
    Signed-off-by: Chandra Pratap <[email protected]>
    Chandra Pratap committed Aug 3, 2024
    Configuration menu
    Copy the full SHA
    22256e7 View commit details
    Browse the repository at this point in the history
  4. t-reftable-tree: add test for non-existent key

    In the current testing setup for tree_search(), the case for
    non-existent key is not exercised. Improve this by adding a
    test-case for the same.
    
    Mentored-by: Patrick Steinhardt <[email protected]>
    Mentored-by: Christian Couder <[email protected]>
    Signed-off-by: Chandra Pratap <[email protected]>
    Chandra Pratap committed Aug 3, 2024
    Configuration menu
    Copy the full SHA
    0d04daa View commit details
    Browse the repository at this point in the history
  5. t-reftable-tree: improve the test for infix_walk()

    In the current testing setup for infix_walk(), the following
    properties of an infix traversal of a tree remain untested:
    - every node of the tree must be visited
    - every node must be visited exactly once
    In fact, only the property 'traversal in increasing order' is tested.
    Modify test_infix_walk() to check for all the properties above.
    
    This can be achieved by storing the nodes' keys linearly, in a nullified
    buffer, as we visit them and then checking the input keys against this
    buffer in increasing order. By checking that the element just after
    the last input key is 'NULL' in the output buffer, we ensure that
    every node is traversed exactly once.
    
    Mentored-by: Patrick Steinhardt <[email protected]>
    Mentored-by: Christian Couder <[email protected]>
    Signed-off-by: Chandra Pratap <[email protected]>
    Chandra Pratap committed Aug 3, 2024
    Configuration menu
    Copy the full SHA
    80d4aa2 View commit details
    Browse the repository at this point in the history