t/helper: merge test-sha1-array into test-tool
[git/git.git] / t / t0064-sha1-array.sh
CommitLineData
38d905bf
RS
1#!/bin/sh
2
3test_description='basic tests for the SHA1 array implementation'
4. ./test-lib.sh
5
6echo20 () {
7 prefix="${1:+$1 }"
8 shift
9 while test $# -gt 0
10 do
11 echo "$prefix$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1"
12 shift
13 done
14}
15
16test_expect_success 'ordered enumeration' '
17 echo20 "" 44 55 88 aa >expect &&
18 {
19 echo20 append 88 44 aa 55 &&
20 echo for_each_unique
aa218dff 21 } | test-tool sha1-array >actual &&
38d905bf
RS
22 test_cmp expect actual
23'
24
25test_expect_success 'ordered enumeration with duplicate suppression' '
26 echo20 "" 44 55 88 aa >expect &&
27 {
28 echo20 append 88 44 aa 55 &&
29 echo20 append 88 44 aa 55 &&
30 echo for_each_unique
aa218dff 31 } | test-tool sha1-array >actual &&
38d905bf
RS
32 test_cmp expect actual
33'
34
35test_expect_success 'lookup' '
36 {
37 echo20 append 88 44 aa 55 &&
38 echo20 lookup 55
aa218dff 39 } | test-tool sha1-array >actual &&
38d905bf
RS
40 n=$(cat actual) &&
41 test "$n" -eq 1
42'
43
44test_expect_success 'lookup non-existing entry' '
45 {
46 echo20 append 88 44 aa 55 &&
47 echo20 lookup 33
aa218dff 48 } | test-tool sha1-array >actual &&
38d905bf
RS
49 n=$(cat actual) &&
50 test "$n" -lt 0
51'
52
53test_expect_success 'lookup with duplicates' '
54 {
55 echo20 append 88 44 aa 55 &&
56 echo20 append 88 44 aa 55 &&
57 echo20 lookup 55
aa218dff 58 } | test-tool sha1-array >actual &&
38d905bf
RS
59 n=$(cat actual) &&
60 test "$n" -ge 2 &&
61 test "$n" -le 3
62'
63
64test_expect_success 'lookup non-existing entry with duplicates' '
65 {
66 echo20 append 88 44 aa 55 &&
67 echo20 append 88 44 aa 55 &&
68 echo20 lookup 66
aa218dff 69 } | test-tool sha1-array >actual &&
38d905bf
RS
70 n=$(cat actual) &&
71 test "$n" -lt 0
72'
73
0eb0fb88
RS
74test_expect_success 'lookup with almost duplicate values' '
75 {
76 echo "append 5555555555555555555555555555555555555555" &&
77 echo "append 555555555555555555555555555555555555555f" &&
78 echo20 lookup 55
aa218dff 79 } | test-tool sha1-array >actual &&
0eb0fb88
RS
80 n=$(cat actual) &&
81 test "$n" -eq 0
82'
83
84test_expect_success 'lookup with single duplicate value' '
85 {
86 echo20 append 55 55 &&
87 echo20 lookup 55
aa218dff 88 } | test-tool sha1-array >actual &&
0eb0fb88
RS
89 n=$(cat actual) &&
90 test "$n" -ge 0 &&
91 test "$n" -le 1
92'
93
38d905bf 94test_done