Merge branch 'ps/ci-fix-detection-of-ubuntu-20' into maint-2.45
[alt-git.git] / t / t0064-oid-array.sh
blob88c89e8f48ac1082892734c5bdb0e73a796f74f0
1 #!/bin/sh
3 test_description='basic tests for the oid array implementation'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 echoid () {
9 prefix="${1:+$1 }"
10 shift
11 while test $# -gt 0
13 echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g"
14 shift
15 done
18 test_expect_success 'ordered enumeration' '
19 echoid "" 44 55 88 aa >expect &&
21 echoid append 88 44 aa 55 &&
22 echo for_each_unique
23 } | test-tool oid-array >actual &&
24 test_cmp expect actual
27 test_expect_success 'ordered enumeration with duplicate suppression' '
28 echoid "" 44 55 88 aa >expect &&
30 echoid append 88 44 aa 55 &&
31 echoid append 88 44 aa 55 &&
32 echoid append 88 44 aa 55 &&
33 echo for_each_unique
34 } | test-tool oid-array >actual &&
35 test_cmp expect actual
38 test_expect_success 'lookup' '
40 echoid append 88 44 aa 55 &&
41 echoid lookup 55
42 } | test-tool oid-array >actual &&
43 n=$(cat actual) &&
44 test "$n" -eq 1
47 test_expect_success 'lookup non-existing entry' '
49 echoid append 88 44 aa 55 &&
50 echoid lookup 33
51 } | test-tool oid-array >actual &&
52 n=$(cat actual) &&
53 test "$n" -lt 0
56 test_expect_success 'lookup with duplicates' '
58 echoid append 88 44 aa 55 &&
59 echoid append 88 44 aa 55 &&
60 echoid append 88 44 aa 55 &&
61 echoid lookup 55
62 } | test-tool oid-array >actual &&
63 n=$(cat actual) &&
64 test "$n" -ge 3 &&
65 test "$n" -le 5
68 test_expect_success 'lookup non-existing entry with duplicates' '
70 echoid append 88 44 aa 55 &&
71 echoid append 88 44 aa 55 &&
72 echoid append 88 44 aa 55 &&
73 echoid lookup 66
74 } | test-tool oid-array >actual &&
75 n=$(cat actual) &&
76 test "$n" -lt 0
79 test_expect_success 'lookup with almost duplicate values' '
80 # n-1 5s
81 root=$(echoid "" 55) &&
82 root=${root%5} &&
84 id1="${root}5" &&
85 id2="${root}f" &&
86 echo "append $id1" &&
87 echo "append $id2" &&
88 echoid lookup 55
89 } | test-tool oid-array >actual &&
90 n=$(cat actual) &&
91 test "$n" -eq 0
94 test_expect_success 'lookup with single duplicate value' '
96 echoid append 55 55 &&
97 echoid lookup 55
98 } | test-tool oid-array >actual &&
99 n=$(cat actual) &&
100 test "$n" -ge 0 &&
101 test "$n" -le 1
104 test_done