MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/likely/test/run-debug.c:29–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29int main(void)
30{
31 char *bad;
32
33 plan_tests(14);
34
35 /* Correct guesses. */
36 one_seems_likely(1);
37 ok1(likely_stats(0, 90) == NULL);
38 one_seems_unlikely(2);
39 ok1(likely_stats(0, 90) == NULL);
40
41 /* Incorrect guesses. */
42 one_seems_likely(0);
43 one_seems_likely(2);
44 /* Hasn't been hit 4 times, so this fails */
45 ok1(!likely_stats(4, 90));
46 bad = likely_stats(3, 90);
47 ok(strends(bad, "run-debug.c:9:likely(val == 1) correct 33% (1/3)"),
48 "likely_stats returned %s", bad);
49 free(bad);
50
51 /* Nothing else above 90% */
52 ok1(!likely_stats(0, 90));
53
54 /* This should get everything. */
55 bad = likely_stats(0, 100);
56 ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 100% (1/1)"),
57 "likely_stats returned %s", bad);
58 free(bad);
59
60 /* Nothing left (table is actually cleared) */
61 ok1(!likely_stats(0, 100));
62
63 /* Make sure unlikely works */
64 one_seems_unlikely(0);
65 one_seems_unlikely(2);
66 one_seems_unlikely(1);
67
68 bad = likely_stats(0, 90);
69 ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 66% (2/3)"),
70 "likely_stats returned %s", bad);
71 free(bad);
72 ok1(!likely_stats(0, 100));
73
74 likely_one_unlikely_two(1, 1);
75 likely_one_unlikely_two(1, 1);
76 likely_one_unlikely_two(1, 1);
77 ok1(!likely_stats(0, 90));
78 likely_one_unlikely_two(1, 2);
79
80 bad = likely_stats(0, 90);
81 ok(strends(bad, "run-debug.c:24:unlikely(val2 == 2) correct 75% (3/4)"),
82 "likely_stats returned %s", bad);
83 free(bad);
84 bad = likely_stats(0, 100);
85 ok(strends(bad, "run-debug.c:24:likely(val1 == 1) correct 100% (4/4)"),
86 "likely_stats returned %s", bad);

Callers

nothing calls this directly

Calls 6

likely_statsFunction · 0.85
strendsFunction · 0.85
likely_one_unlikely_twoFunction · 0.85
likely_stats_resetFunction · 0.85
one_seems_likelyFunction · 0.70
one_seems_unlikelyFunction · 0.70

Tested by

no test coverage detected