summaryrefslogtreecommitdiffstats
path: root/test/format.c
blob: 8033d1b7e0ab38e44b53abd4a849469ade598342 (plain)
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
92
93
94
95
96
97
98
99
#include "test_utils.h"
#include "common/common.h"

int main(void)
{
    void *ta_ctx = talloc_new(NULL);

    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, false, false, false), "123");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, false, false,  true), "123");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, false,  true, false), "123%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, false,  true,  true), "123%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, true,  false, false), "+123");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, true,  false,  true), "+123");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, true,   true, false), "+123%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 0, true,   true,  true), "+123%");

    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false, false), "-123");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false, false,  true), "-123");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false,  true, false), "-123%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, false,  true,  true), "-123%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true,  false, false), "-123");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true,  false,  true), "-123");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true,   true, false), "-123%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 0, true,   true,  true), "-123%");

    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, false, false, false), "123.46");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, false, false,  true), "123.46");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, false,  true, false), "123.46%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, false,  true,  true), "123.46%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, true,  false, false), "+123.46");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, true,  false,  true), "+123.46");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, true,   true, false), "+123.46%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 2, true,   true,  true), "+123.46%");

    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false, false), "-123.46");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false, false,  true), "-123.46");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false,  true, false), "-123.46%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, false,  true,  true), "-123.46%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true,  false, false), "-123.46");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true,  false,  true), "-123.46");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true,   true, false), "-123.46%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 2, true,   true,  true), "-123.46%");

    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, false, false, false), "123.456000");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, false, false,  true), "123.456");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, false,  true, false), "123.456000%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, false,  true,  true), "123.456%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, true,  false, false), "+123.456000");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, true,  false,  true), "+123.456");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, true,   true, false), "+123.456000%");
    assert_string_equal(mp_format_double(ta_ctx,  123.456, 6, true,   true,  true), "+123.456%");

    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false, false), "-123.456000");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false, false,  true), "-123.456");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false,  true, false), "-123.456000%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, false,  true,  true), "-123.456%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true,  false, false), "-123.456000");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true,  false,  true), "-123.456");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true,   true, false), "-123.456000%");
    assert_string_equal(mp_format_double(ta_ctx, -123.456, 6, true,   true,  true), "-123.456%");

    assert_string_equal(mp_format_double(ta_ctx,  123, 6, false, false, false), "123.000000");
    assert_string_equal(mp_format_double(ta_ctx,  123, 6, false, false,  true), "123");
    assert_string_equal(mp_format_double(ta_ctx,  123, 6, false,  true, false), "123.000000%");
    assert_string_equal(mp_format_double(ta_ctx,  123, 6, false,  true,  true), "123%");
    assert_string_equal(mp_format_double(ta_ctx,  123, 6, true,  false, false), "+123.000000");
    assert_string_equal(mp_format_double(ta_ctx,  123, 6, true,  false,  true), "+123");
    assert_string_equal(mp_format_double(ta_ctx,  123, 6, true,   true, false), "+123.000000%");
    assert_string_equal(mp_format_double(ta_ctx,  123, 6, true,   true,  true), "+123%");

    assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false, false), "-123.000000");
    assert_string_equal(mp_format_double(ta_ctx, -123, 6, false, false,  true), "-123");
    assert_string_equal(mp_format_double(ta_ctx, -123, 6, false,  true, false), "-123.000000%");
    assert_string_equal(mp_format_double(ta_ctx, -123, 6, false,  true,  true), "-123%");
    assert_string_equal(mp_format_double(ta_ctx, -123, 6, true,  false, false), "-123.000000");
    assert_string_equal(mp_format_double(ta_ctx, -123, 6, true,  false,  true), "-123");
    assert_string_equal(mp_format_double(ta_ctx, -123, 6, true,   true, false), "-123.000000%");
    assert_string_equal(mp_format_double(ta_ctx, -123, 6, true,   true,  true), "-123%");

    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, false, false, false), "inf");
    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, false, false,  true), "inf");
    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, false,  true, false), "inf%");
    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, false,  true,  true), "inf%");
    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, true,  false, false), "+inf");
    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, true,  false,  true), "+inf");
    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, true,   true, false), "+inf%");
    assert_string_equal(mp_format_double(ta_ctx,  INFINITY, 6, true,   true,  true), "+inf%");

    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false, false), "-inf");
    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false, false,  true), "-inf");
    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false,  true, false), "-inf%");
    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, false,  true,  true), "-inf%");
    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true,  false, false), "-inf");
    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true,  false,  true), "-inf");
    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true,   true, false), "-inf%");
    assert_string_equal(mp_format_double(ta_ctx, -INFINITY, 6, true,   true,  true), "-inf%");

    talloc_free(ta_ctx);
}