aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/deco_test.c
blob: b405970b20db9cfdcecfa65a18330a99c4ffcce9 (plain) (blame)
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
/* SPDX-License-Identifier: MIT-0 */

#include "minunit/minunit.h"

#include "src/deco.h"

MU_TEST(test_bar_to_msw)
{
    mu_assert_double_eq(10, bar_to_msw(1));
}

MU_TEST(test_msw_to_bar)
{
    mu_assert_double_eq(1, msw_to_bar(10));
}

MU_TEST(test_abs_gauge)
{
    mu_assert_double_eq(1, abs_depth(gauge_depth(1)));
}

MU_TEST(test_gas)
{
    double max_mod_err = 1E-3;

    gas_t foo = gas_new(21, 35, MOD_AUTO);
    gas_t bar = gas_new(21, 0, MOD_AUTO);
    gas_t baz = gas_new(21, 35, MOD_AUTO);
    gas_t qux = gas_new(21, 35, 99);

    mu_assert_int_eq(21, gas_o2(&foo));
    mu_assert_int_eq(35, gas_he(&foo));
    mu_assert_int_eq(44, gas_n2(&foo));

    mu_check(gas_equal(&foo, &foo));
    mu_check(!gas_equal(&foo, &bar));
    mu_check(gas_equal(&foo, &baz));
    mu_check(!gas_equal(&foo, &qux));

    mu_assert_double_near(abs_depth(msw_to_bar(51.6)), gas_mod(&foo), max_mod_err);
    mu_assert_double_near(abs_depth(msw_to_bar(30)), gas_mod(&bar), max_mod_err);
    mu_assert_double_near(99, gas_mod(&qux), max_mod_err);
}

void testsuite_deco_setup(void)
{
}

void testsuite_deco_teardown(void)
{
}

MU_TEST_SUITE(testsuite_deco)
{
    MU_SUITE_CONFIGURE(&testsuite_deco_setup, &testsuite_deco_teardown);

    MU_RUN_TEST(test_bar_to_msw);
    MU_RUN_TEST(test_msw_to_bar);
    MU_RUN_TEST(test_abs_gauge);
    MU_RUN_TEST(test_gas);
}