1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

int _test_merge_sort_large_array() {
    mu_start();
    //────────────────────
    // for this test, could even randomly generate the array
    int input_array[]     = { 1, 6, 3, 78, 3, 1, 4 };
    int expected_array[]  = { 1, 1, 3, 3, 4, 6, 78 };
    int size = sizeof(input_array) / sizeof(*input_array);

    merge_sort_array(merge_sort_array, size);

    for (int i = 0; i < size; i++) {
        // could print the failing index, because its hard to tell
        // with mu_checks in a loop which failed
        if (input_array[i] != expected_array[i]) {
            printf("Failed at index %d\n", i);
        }
        mu_check(input_array[i] == expected_array[i]);
    }
    // alternatively, just print out the arrays

    //────────────────────
    mu_end();
}

int _test_compare_array_sort_merge_vs_tree() {
    mu_start();
    //────────────────────
    // for this test, could even randomly generate the array
    int merge_sort_array[] = { 1, 6, 3, 78, 3, 1, 4 };
    int tree_sort_array[]  = { 1, 6, 3, 78, 3, 1, 4 };
    int size = sizeof(merge_sort_array) / sizeof(*merge_sort_array);

    // this is only a useful test if at least one of them are valid
    merge_sort_array(merge_sort_array, size);
    tree_sort_array(tree_sort_array, size);

    for (int i = 0; i < size; i++) {
        // could print the failing index, because its hard to tell
        // with mu_checks in a loop which failed
        if (merge_sort_array[i] != tree_sort_array[i]) {
            printf("Failed at index %d\n", i);
        }
        mu_check(merge_sort_array[i] == tree_sort_array[i]);
    }
    // alternatively, just print out the arrays

    //────────────────────
    mu_end();
}

int main(int argc, char* argv[]) {
    
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2024 Alexander J. Quinn & David Burnett         This content is protected and may not be shared, uploaded, or distributed.