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