René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='basic tests for the SHA1 array implementation' |
| 4 | . ./test-lib.sh |
| 5 | |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 6 | echoid () { |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 7 | prefix="${1:+$1 }" |
| 8 | shift |
| 9 | while test $# -gt 0 |
| 10 | do |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 11 | echo "$prefix$ZERO_OID" | sed -e "s/00/$1/g" |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 12 | shift |
| 13 | done |
| 14 | } |
| 15 | |
| 16 | test_expect_success 'ordered enumeration' ' |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 17 | echoid "" 44 55 88 aa >expect && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 18 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 19 | echoid append 88 44 aa 55 && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 20 | echo for_each_unique |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 21 | } | test-tool oid-array >actual && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 22 | test_cmp expect actual |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'ordered enumeration with duplicate suppression' ' |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 26 | echoid "" 44 55 88 aa >expect && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 27 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 28 | echoid append 88 44 aa 55 && |
| 29 | echoid append 88 44 aa 55 && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 30 | echo for_each_unique |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 31 | } | test-tool oid-array >actual && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 32 | test_cmp expect actual |
| 33 | ' |
| 34 | |
| 35 | test_expect_success 'lookup' ' |
| 36 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 37 | echoid append 88 44 aa 55 && |
| 38 | echoid lookup 55 |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 39 | } | test-tool oid-array >actual && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 40 | n=$(cat actual) && |
| 41 | test "$n" -eq 1 |
| 42 | ' |
| 43 | |
| 44 | test_expect_success 'lookup non-existing entry' ' |
| 45 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 46 | echoid append 88 44 aa 55 && |
| 47 | echoid lookup 33 |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 48 | } | test-tool oid-array >actual && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 49 | n=$(cat actual) && |
| 50 | test "$n" -lt 0 |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'lookup with duplicates' ' |
| 54 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 55 | echoid append 88 44 aa 55 && |
| 56 | echoid append 88 44 aa 55 && |
| 57 | echoid lookup 55 |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 58 | } | test-tool oid-array >actual && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 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 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 66 | echoid append 88 44 aa 55 && |
| 67 | echoid append 88 44 aa 55 && |
| 68 | echoid lookup 66 |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 69 | } | test-tool oid-array >actual && |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 70 | n=$(cat actual) && |
| 71 | test "$n" -lt 0 |
| 72 | ' |
| 73 | |
René Scharfe | 0eb0fb8 | 2014-10-01 17:02:37 +0200 | [diff] [blame] | 74 | test_expect_success 'lookup with almost duplicate values' ' |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 75 | # n-1 5s |
| 76 | root=$(echoid "" 55) && |
| 77 | root=${root%5} && |
René Scharfe | 0eb0fb8 | 2014-10-01 17:02:37 +0200 | [diff] [blame] | 78 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 79 | id1="${root}5" && |
| 80 | id2="${root}f" && |
| 81 | echo "append $id1" && |
| 82 | echo "append $id2" && |
| 83 | echoid lookup 55 |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 84 | } | test-tool oid-array >actual && |
René Scharfe | 0eb0fb8 | 2014-10-01 17:02:37 +0200 | [diff] [blame] | 85 | n=$(cat actual) && |
| 86 | test "$n" -eq 0 |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'lookup with single duplicate value' ' |
| 90 | { |
brian m. carlson | 1374003 | 2018-09-13 05:17:36 +0000 | [diff] [blame] | 91 | echoid append 55 55 && |
| 92 | echoid lookup 55 |
Jeff King | ed4b804 | 2020-03-30 10:04:03 -0400 | [diff] [blame^] | 93 | } | test-tool oid-array >actual && |
René Scharfe | 0eb0fb8 | 2014-10-01 17:02:37 +0200 | [diff] [blame] | 94 | n=$(cat actual) && |
| 95 | test "$n" -ge 0 && |
| 96 | test "$n" -le 1 |
| 97 | ' |
| 98 | |
René Scharfe | 38d905b | 2014-10-01 17:00:33 +0200 | [diff] [blame] | 99 | test_done |