]>
Commit | Line | Data |
---|---|---|
38d905bf RS |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic tests for the SHA1 array implementation' | |
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 |
aa218dff | 21 | } | test-tool sha1-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 | { |
1374003d | 28 | echoid append 88 44 aa 55 && |
29 | echoid append 88 44 aa 55 && | |
38d905bf | 30 | echo for_each_unique |
aa218dff | 31 | } | test-tool sha1-array >actual && |
38d905bf RS |
32 | test_cmp expect actual |
33 | ' | |
34 | ||
35 | test_expect_success 'lookup' ' | |
36 | { | |
1374003d | 37 | echoid append 88 44 aa 55 && |
38 | echoid lookup 55 | |
aa218dff | 39 | } | test-tool sha1-array >actual && |
38d905bf RS |
40 | n=$(cat actual) && |
41 | test "$n" -eq 1 | |
42 | ' | |
43 | ||
44 | test_expect_success 'lookup non-existing entry' ' | |
45 | { | |
1374003d | 46 | echoid append 88 44 aa 55 && |
47 | echoid lookup 33 | |
aa218dff | 48 | } | test-tool sha1-array >actual && |
38d905bf RS |
49 | n=$(cat actual) && |
50 | test "$n" -lt 0 | |
51 | ' | |
52 | ||
53 | test_expect_success 'lookup with duplicates' ' | |
54 | { | |
1374003d | 55 | echoid append 88 44 aa 55 && |
56 | echoid append 88 44 aa 55 && | |
57 | echoid 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 | ||
64 | test_expect_success 'lookup non-existing entry with duplicates' ' | |
65 | { | |
1374003d | 66 | echoid append 88 44 aa 55 && |
67 | echoid append 88 44 aa 55 && | |
68 | echoid lookup 66 | |
aa218dff | 69 | } | test-tool sha1-array >actual && |
38d905bf RS |
70 | n=$(cat actual) && |
71 | test "$n" -lt 0 | |
72 | ' | |
73 | ||
0eb0fb88 | 74 | test_expect_success 'lookup with almost duplicate values' ' |
1374003d | 75 | # n-1 5s |
76 | root=$(echoid "" 55) && | |
77 | root=${root%5} && | |
0eb0fb88 | 78 | { |
1374003d | 79 | id1="${root}5" && |
80 | id2="${root}f" && | |
81 | echo "append $id1" && | |
82 | echo "append $id2" && | |
83 | echoid lookup 55 | |
aa218dff | 84 | } | test-tool sha1-array >actual && |
0eb0fb88 RS |
85 | n=$(cat actual) && |
86 | test "$n" -eq 0 | |
87 | ' | |
88 | ||
89 | test_expect_success 'lookup with single duplicate value' ' | |
90 | { | |
1374003d | 91 | echoid append 55 55 && |
92 | echoid lookup 55 | |
aa218dff | 93 | } | test-tool sha1-array >actual && |
0eb0fb88 RS |
94 | n=$(cat actual) && |
95 | test "$n" -ge 0 && | |
96 | test "$n" -le 1 | |
97 | ' | |
98 | ||
38d905bf | 99 | test_done |