]>
Commit | Line | Data |
---|---|---|
38d905bf RS |
1 | #!/bin/sh |
2 | ||
d9ca6f8d | 3 | test_description='basic tests for the oid array implementation' |
6ad66ab4 ÆAB |
4 | |
5 | TEST_PASSES_SANITIZE_LEAK=true | |
38d905bf RS |
6 | . ./test-lib.sh |
7 | ||
1374003d | 8 | echoid () { |
38d905bf RS |
9 | prefix="${1:+$1 }" |
10 | shift | |
11 | while test $# -gt 0 | |
12 | do | |
1374003d | 13 | echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g" |
38d905bf RS |
14 | shift |
15 | done | |
16 | } | |
17 | ||
18 | test_expect_success 'ordered enumeration' ' | |
1374003d | 19 | echoid "" 44 55 88 aa >expect && |
38d905bf | 20 | { |
1374003d | 21 | echoid append 88 44 aa 55 && |
38d905bf | 22 | echo for_each_unique |
ed4b804e | 23 | } | test-tool oid-array >actual && |
38d905bf RS |
24 | test_cmp expect actual |
25 | ' | |
26 | ||
27 | test_expect_success 'ordered enumeration with duplicate suppression' ' | |
1374003d | 28 | echoid "" 44 55 88 aa >expect && |
38d905bf | 29 | { |
3ea922fc | 30 | echoid append 88 44 aa 55 && |
1374003d | 31 | echoid append 88 44 aa 55 && |
32 | echoid append 88 44 aa 55 && | |
38d905bf | 33 | echo for_each_unique |
ed4b804e | 34 | } | test-tool oid-array >actual && |
38d905bf RS |
35 | test_cmp expect actual |
36 | ' | |
37 | ||
38 | test_expect_success 'lookup' ' | |
39 | { | |
1374003d | 40 | echoid append 88 44 aa 55 && |
41 | echoid lookup 55 | |
ed4b804e | 42 | } | test-tool oid-array >actual && |
38d905bf RS |
43 | n=$(cat actual) && |
44 | test "$n" -eq 1 | |
45 | ' | |
46 | ||
47 | test_expect_success 'lookup non-existing entry' ' | |
48 | { | |
1374003d | 49 | echoid append 88 44 aa 55 && |
50 | echoid lookup 33 | |
ed4b804e | 51 | } | test-tool oid-array >actual && |
38d905bf RS |
52 | n=$(cat actual) && |
53 | test "$n" -lt 0 | |
54 | ' | |
55 | ||
56 | test_expect_success 'lookup with duplicates' ' | |
57 | { | |
3ea922fc | 58 | echoid append 88 44 aa 55 && |
1374003d | 59 | echoid append 88 44 aa 55 && |
60 | echoid append 88 44 aa 55 && | |
61 | echoid lookup 55 | |
ed4b804e | 62 | } | test-tool oid-array >actual && |
38d905bf | 63 | n=$(cat actual) && |
3ea922fc JK |
64 | test "$n" -ge 3 && |
65 | test "$n" -le 5 | |
38d905bf RS |
66 | ' |
67 | ||
68 | test_expect_success 'lookup non-existing entry with duplicates' ' | |
69 | { | |
3ea922fc | 70 | echoid append 88 44 aa 55 && |
1374003d | 71 | echoid append 88 44 aa 55 && |
72 | echoid append 88 44 aa 55 && | |
73 | echoid lookup 66 | |
ed4b804e | 74 | } | test-tool oid-array >actual && |
38d905bf RS |
75 | n=$(cat actual) && |
76 | test "$n" -lt 0 | |
77 | ' | |
78 | ||
0eb0fb88 | 79 | test_expect_success 'lookup with almost duplicate values' ' |
1374003d | 80 | # n-1 5s |
81 | root=$(echoid "" 55) && | |
82 | root=${root%5} && | |
0eb0fb88 | 83 | { |
1374003d | 84 | id1="${root}5" && |
85 | id2="${root}f" && | |
86 | echo "append $id1" && | |
87 | echo "append $id2" && | |
88 | echoid lookup 55 | |
ed4b804e | 89 | } | test-tool oid-array >actual && |
0eb0fb88 RS |
90 | n=$(cat actual) && |
91 | test "$n" -eq 0 | |
92 | ' | |
93 | ||
94 | test_expect_success 'lookup with single duplicate value' ' | |
95 | { | |
1374003d | 96 | echoid append 55 55 && |
97 | echoid lookup 55 | |
ed4b804e | 98 | } | test-tool oid-array >actual && |
0eb0fb88 RS |
99 | n=$(cat actual) && |
100 | test "$n" -ge 0 && | |
101 | test "$n" -le 1 | |
102 | ' | |
103 | ||
38d905bf | 104 | test_done |