Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
bbloom
Commits
6c7292d0
Unverified
Commit
6c7292d0
authored
Jul 11, 2017
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add collision testing test
parent
0bd8cd29
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
collision_test.go
collision_test.go
+44
-0
No files found.
collision_test.go
0 → 100644
View file @
6c7292d0
package
bbloom
import
(
"math/rand"
"testing"
"time"
)
func
TestCollisionRate
(
t
*
testing
.
T
)
{
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
N
:=
1
<<
20
M
:=
N
*
12
K
:=
2
bl
,
err
:=
New
(
float64
(
M
),
float64
(
K
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
buf
[
64
]
byte
for
i
:=
0
;
i
<
N
;
i
++
{
_
,
err
:=
rand
.
Read
(
buf
[
:
])
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
bl
.
Add
(
buf
[
:
])
}
Ntest
:=
int
(
1e6
)
falsePositive
:=
0
for
i
:=
0
;
i
<
Ntest
;
i
++
{
_
,
err
:=
rand
.
Read
(
buf
[
:
])
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
bl
.
Has
(
buf
[
:
])
{
falsePositive
++
}
}
t
.
Logf
(
"false positive ratio: %f"
,
float64
(
falsePositive
)
/
float64
(
Ntest
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment