Ad
  • Default User Avatar

    C:

    • expected and actual are flipped
    • input should be displayed
    • booleans should be used instead of chars
    • input should be const qualified
    • array notation should be used

    fork fixing all (author gone)

  • Default User Avatar

    I think that expected and actual lists were not matched in the test case in the c language. they might be good to swap each other.

  • Custom User Avatar
  • Custom User Avatar

    C++ version generates warnings.

  • Default User Avatar

    hello there! Can you explain to me how did you come out with that pattern ? (i mean the one stored in the array solver).

  • Custom User Avatar

    Right. I was not defensive enough when I was writing my solution ;-)

  • Custom User Avatar

    Do you really think this is an issue?
    void solve(const char* input, char* result) just tells you where to store your result.
    It's not unusual for output parameters to be uninitialized, e.g. int int1; if (scanf("%d", &int1) == 1) // ...

  • Custom User Avatar

    Added it myself.

  • Custom User Avatar

    C version: the memory content inside result is not reset during the random tests, which means we have to reset them ourselves.

  • Custom User Avatar

    I just fixed the issues but I have an additional suggestion for the C version.
    The current error messages are not that helpful: "The expression test_if_equal(result1, expected_result1) is false."
    Why not this:

    #define do_test(n) solve(input##n, result##n);\
        cr_assert(test_if_equal(result##n, expected_result##n), \
            "expected: {%d, %d, %d, %d, %d, %d, %d, %d, %d}\n" \
            "actual:   {%d, %d, %d, %d, %d, %d, %d, %d, %d}", \
            expected_result##n[0], expected_result##n[1], expected_result##n[2], \
            expected_result##n[3], expected_result##n[4], expected_result##n[5], \
            expected_result##n[6], expected_result##n[7], expected_result##n[8], \
            result##n[0], result##n[1], result##n[2], \
            result##n[3], result##n[4], result##n[5], \
            result##n[6], result##n[7], result##n[8])
    

    or put some of that into its own function and put it into the "Preloaded" section:

    void solve (char* input, char* result);
    char test_if_equal(char* input1, char* input2);
    void test_solve(char* input, char *expected) {
        char actual[9];
        solve(input, actual);
        cr_assert(test_if_equal(actual, expected),
            "expected: {%d, %d, %d, %d, %d, %d, %d, %d, %d}\n"
            "actual:   {%d, %d, %d, %d, %d, %d, %d, %d, %d}",
            actual[0], actual[1], actual[2],
            actual[3], actual[4], actual[5],
            actual[6], actual[7], actual[8],
            expected[0], expected[1], expected[2],
            expected[3], expected[4], expected[5],
            expected[6], expected[7], expected[8]);
    }
    

    In the sample and final tests do_test can then be reduced to #define do_test(n) test_solve(input##n, expected_result##n).

  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar
    using namespace std;
    
    typedef std::bitset<9> state;
    

    I don't think you really need that using namespace std; on the top ;-)

  • Custom User Avatar

    C

    error: called object type 'int' is not a function or function pointer
        do_test(1);
        ^~~~~~~~~~
    /home/codewarrior/fixture.c:27:25: note: expanded from macro 'do_test'
    #define do_test(n) solve(input##n, result##n);\
                       ~~~~~^
    

    Sample tests missing

    • #include <criterion/criterion.h>
    • definition of test_if_equal
  • Loading more items...