t0064: make duplicate tests more robust
[git] / t / t0064-oid-array.sh
1 #!/bin/sh
2
3 test_description='basic tests for the oid array implementation'
4 . ./test-lib.sh
5
6 echoid () {
7         prefix="${1:+$1 }"
8         shift
9         while test $# -gt 0
10         do
11                 echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g"
12                 shift
13         done
14 }
15
16 test_expect_success 'ordered enumeration' '
17         echoid "" 44 55 88 aa >expect &&
18         {
19                 echoid append 88 44 aa 55 &&
20                 echo for_each_unique
21         } | test-tool oid-array >actual &&
22         test_cmp expect actual
23 '
24
25 test_expect_success 'ordered enumeration with duplicate suppression' '
26         echoid "" 44 55 88 aa >expect &&
27         {
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
34 '
35
36 test_expect_success 'lookup' '
37         {
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
43 '
44
45 test_expect_success 'lookup non-existing entry' '
46         {
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
52 '
53
54 test_expect_success 'lookup with duplicates' '
55         {
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
64 '
65
66 test_expect_success 'lookup non-existing entry with duplicates' '
67         {
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
75 '
76
77 test_expect_success 'lookup with almost duplicate values' '
78         # n-1 5s
79         root=$(echoid "" 55) &&
80         root=${root%5} &&
81         {
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
90 '
91
92 test_expect_success 'lookup with single duplicate value' '
93         {
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
100 '
101
102 test_done