Git 2.33.3
[alt-git.git] / t / t0064-oid-array.sh
blob2e5438ccdacdeb31d60d3ffab22dcbc8151134fd
1 #!/bin/sh
3 test_description='basic tests for the oid array implementation'
4 . ./test-lib.sh
6 echoid () {
7 prefix="${1:+$1 }"
8 shift
9 while test $# -gt 0
11 echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g"
12 shift
13 done
16 test_expect_success 'ordered enumeration' '
17 echoid "" 44 55 88 aa >expect &&
19 echoid append 88 44 aa 55 &&
20 echo for_each_unique
21 } | test-tool oid-array >actual &&
22 test_cmp expect actual
25 test_expect_success 'ordered enumeration with duplicate suppression' '
26 echoid "" 44 55 88 aa >expect &&
28 echoid append 88 44 aa 55 &&
29 echoid append 88 44 aa 55 &&
30 echoid append 88 44 aa 55 &&
31 echo for_each_unique
32 } | test-tool oid-array >actual &&
33 test_cmp expect actual
36 test_expect_success 'lookup' '
38 echoid append 88 44 aa 55 &&
39 echoid lookup 55
40 } | test-tool oid-array >actual &&
41 n=$(cat actual) &&
42 test "$n" -eq 1
45 test_expect_success 'lookup non-existing entry' '
47 echoid append 88 44 aa 55 &&
48 echoid lookup 33
49 } | test-tool oid-array >actual &&
50 n=$(cat actual) &&
51 test "$n" -lt 0
54 test_expect_success 'lookup with duplicates' '
56 echoid append 88 44 aa 55 &&
57 echoid append 88 44 aa 55 &&
58 echoid append 88 44 aa 55 &&
59 echoid lookup 55
60 } | test-tool oid-array >actual &&
61 n=$(cat actual) &&
62 test "$n" -ge 3 &&
63 test "$n" -le 5
66 test_expect_success 'lookup non-existing entry with duplicates' '
68 echoid append 88 44 aa 55 &&
69 echoid append 88 44 aa 55 &&
70 echoid append 88 44 aa 55 &&
71 echoid lookup 66
72 } | test-tool oid-array >actual &&
73 n=$(cat actual) &&
74 test "$n" -lt 0
77 test_expect_success 'lookup with almost duplicate values' '
78 # n-1 5s
79 root=$(echoid "" 55) &&
80 root=${root%5} &&
82 id1="${root}5" &&
83 id2="${root}f" &&
84 echo "append $id1" &&
85 echo "append $id2" &&
86 echoid lookup 55
87 } | test-tool oid-array >actual &&
88 n=$(cat actual) &&
89 test "$n" -eq 0
92 test_expect_success 'lookup with single duplicate value' '
94 echoid append 55 55 &&
95 echoid lookup 55
96 } | test-tool oid-array >actual &&
97 n=$(cat actual) &&
98 test "$n" -ge 0 &&
99 test "$n" -le 1
102 test_done