Git fork
1#!/bin/sh
2
3test_description='Testing the various Bloom filter computations in bloom.c'
4
5. ./test-lib.sh
6
7test_expect_success 'compute unseeded murmur3 hash for empty string' '
8 cat >expect <<-\EOF &&
9 Murmur3 Hash with seed=0:0x00000000
10 EOF
11 test-tool bloom get_murmur3 "" >actual &&
12 test_cmp expect actual
13'
14
15test_expect_success 'compute unseeded murmur3 hash for test string 1' '
16 cat >expect <<-\EOF &&
17 Murmur3 Hash with seed=0:0x627b0c2c
18 EOF
19 test-tool bloom get_murmur3 "Hello world!" >actual &&
20 test_cmp expect actual
21'
22
23test_expect_success 'compute unseeded murmur3 hash for test string 2' '
24 cat >expect <<-\EOF &&
25 Murmur3 Hash with seed=0:0x2e4ff723
26 EOF
27 test-tool bloom get_murmur3 "The quick brown fox jumps over the lazy dog" >actual &&
28 test_cmp expect actual
29'
30
31test_expect_success 'compute unseeded murmur3 hash for test string 3' '
32 cat >expect <<-\EOF &&
33 Murmur3 Hash with seed=0:0xa183ccfd
34 EOF
35 test-tool bloom get_murmur3_seven_highbit >actual &&
36 test_cmp expect actual
37'
38
39test_expect_success 'compute bloom key for empty string' '
40 cat >expect <<-\EOF &&
41 Hashes:0x5615800c|0x5b966560|0x61174ab4|0x66983008|0x6c19155c|0x7199fab0|0x771ae004|
42 Filter_Length:2
43 Filter_Data:11|11|
44 EOF
45 test-tool bloom generate_filter "" >actual &&
46 test_cmp expect actual
47'
48
49test_expect_success 'compute bloom key for whitespace' '
50 cat >expect <<-\EOF &&
51 Hashes:0xf178874c|0x5f3d6eb6|0xcd025620|0x3ac73d8a|0xa88c24f4|0x16510c5e|0x8415f3c8|
52 Filter_Length:2
53 Filter_Data:51|55|
54 EOF
55 test-tool bloom generate_filter " " >actual &&
56 test_cmp expect actual
57'
58
59test_expect_success 'compute bloom key for test string 1' '
60 cat >expect <<-\EOF &&
61 Hashes:0xb270de9b|0x1bb6f26e|0x84fd0641|0xee431a14|0x57892de7|0xc0cf41ba|0x2a15558d|
62 Filter_Length:2
63 Filter_Data:92|6c|
64 EOF
65 test-tool bloom generate_filter "Hello world!" >actual &&
66 test_cmp expect actual
67'
68
69test_expect_success 'compute bloom key for test string 2' '
70 cat >expect <<-\EOF &&
71 Hashes:0x20ab385b|0xf5237fe2|0xc99bc769|0x9e140ef0|0x728c5677|0x47049dfe|0x1b7ce585|
72 Filter_Length:2
73 Filter_Data:a5|4a|
74 EOF
75 test-tool bloom generate_filter "file.txt" >actual &&
76 test_cmp expect actual
77'
78
79test_expect_success 'get bloom filters for commit with no changes' '
80 git init &&
81 git commit --allow-empty -m "c0" &&
82 cat >expect <<-\EOF &&
83 Filter_Length:1
84 Filter_Data:00|
85 EOF
86 test-tool bloom get_filter_for_commit "$(git rev-parse HEAD)" >actual &&
87 test_cmp expect actual
88'
89
90test_expect_success 'get bloom filter for commit with 10 changes' '
91 rm actual &&
92 rm expect &&
93 mkdir smallDir &&
94 for i in $(test_seq 0 9)
95 do
96 echo $i >smallDir/$i || return 1
97 done &&
98 git add smallDir &&
99 git commit -m "commit with 10 changes" &&
100 cat >expect <<-\EOF &&
101 Filter_Length:14
102 Filter_Data:02|b3|c4|a0|34|e7|fe|eb|cb|47|fe|a0|e8|72|
103 EOF
104 test-tool bloom get_filter_for_commit "$(git rev-parse HEAD)" >actual &&
105 test_cmp expect actual
106'
107
108test_expect_success EXPENSIVE 'get bloom filter for commit with 513 changes' '
109 rm actual &&
110 rm expect &&
111 mkdir bigDir &&
112 for i in $(test_seq 0 511)
113 do
114 echo $i >bigDir/$i || return 1
115 done &&
116 git add bigDir &&
117 git commit -m "commit with 513 changes" &&
118 cat >expect <<-\EOF &&
119 Filter_Length:1
120 Filter_Data:ff|
121 EOF
122 test-tool bloom get_filter_for_commit "$(git rev-parse HEAD)" >actual &&
123 test_cmp expect actual
124'
125
126test_done