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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "math_functions.h"
// miniunit is a file you will write as part of HW06
#include "miniunit.h"
#include <string.h>

int _test_power_cubed() {
    mu_start();
    //────────────────────
    mu_check(power(5, 3) == 125);
    //────────────────────
    mu_end();
}


int _test_is_even_with_even() {
    mu_start();
    //────────────────────
    mu_check(is_even(8));
    //────────────────────
    mu_end();
}

int _test_is_odd_with_even() {
    mu_start();
    //────────────────────
    mu_check(!is_odd(8));
    //────────────────────
    mu_end();
}

int _test_is_odd_with_odd() {
    mu_start();
    //────────────────────
    mu_check(is_odd(7));
    //────────────────────
    mu_end();
}


int _test_compare_strings() {
    mu_start();
    //────────────────────
    const char* expected = "Monday";
    const char* actual = get_day_name(2);
    //mu_check(strcmp(expected, actual) == 0);
    mu_check_strings_equal(expected, actual);
    //────────────────────
    mu_end();
}

int _test_mu_passing() {
    return 0;
}

int _test_mu_failing() {
    return 12;
}

int main(int argc, char* argv[]) {
    // diff testing - ideal for things that already
    // print to stdout
    //printf("5^3 == %d\n", power(5, 3));

    // assert testing - better than diff
    // downside is it stops running when a test fails
    //assert(is_even(8));
    //assert(power(5, 3) == 125);
    
    mu_run(_test_power_cubed);
    mu_run(_test_is_even_with_even);
    mu_run(_test_is_odd_with_even);
    mu_run(_test_is_odd_with_odd);
    mu_run(_test_compare_strings);
    mu_run(_test_mu_passing);
    mu_run(_test_mu_failing);

    // misleading indentation
    // this gives a compiler error with our gcc flags,
    // but not the default gcc flags
    int num = 5;
    if (num == 4)
        printf("Num is 4\n");
        printf("Num is really 4\n");

    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.