func TestFalsePositiveRate(t *testing.T) {
	f := NewDefaultStableBloomFilter(1000, 0.01)
	fps := round(f.FalsePositiveRate(), 0.5, 2)
	if fps > 0.01 {
		t.Errorf("Expected fps less than or equal to 0.01, got %f", fps)
	}
	bf := NewUnstableBloomFilter(1000, 0.1)
	if fps := bf.FalsePositiveRate(); fps != 1 {
		t.Errorf("Expected fps 1, got %f", fps)
	}
}
Ensures that FalsePositiveRate returns the upper bound on false positives
for stable filters.
package boom
import (
	"math"
	"strconv"
	"testing"
)
func TestNewUnstableBloomFilter(t *testing.T) {
	f := NewUnstableBloomFilter(100, 0.1)
	k := OptimalK(0.1)
	if f.k != k {
		t.Errorf("Expected %f, got %d", k, f.k)
	}
	if f.m != 100 {
		t.Errorf("Expected 100, got %d", f.m)
	}
	if f.P() != 0 {
		t.Errorf("Expected 0, got %d", f.p)
	}
	if f.max != 1 {
		t.Errorf("Expected 1, got %d", f.max)
	}
}
func TestCells(t *testing.T) {
	f := NewStableBloomFilter(100, 1, 0.1)
	if cells := f.Cells(); cells != 100 {
		t.Errorf("Expected 100, got %d", cells)
	}
}
func TestK(t *testing.T) {
	f := NewStableBloomFilter(100, 1, 0.01)
	if k := f.K(); k != 3 {
		t.Errorf("Expected 3, got %d", k)
	}
}
func TestTestAndAdd(t *testing.T) {
	f := NewDefaultStableBloomFilter(10000, 0.01)
	if f.Test([]byte(`a`)) {
		t.Error("`a` should not be a member")
	}
	if f.Add([]byte(`a`)) != f {
		t.Error("Returned StableBloomFilter should be the same instance")
	}
	if !f.Test([]byte(`a`)) {
		t.Error("`a` should be a member")
	}
	if !f.TestAndAdd([]byte(`a`)) {
		t.Error("`a` should be a member")
	}
	if f.TestAndAdd([]byte(`b`)) {
		t.Error("`b` should not be a member")
	}
	if !f.Test([]byte(`a`)) {
		t.Error("`a` should be a member")
	}
	if !f.Test([]byte(`b`)) {
		t.Error("`b` should be a member")
	}
	if f.Test([]byte(`c`)) {
		t.Error("`c` should not be a member")
	}
	for i := 0; i < 1000000; i++ {
		f.TestAndAdd([]byte(strconv.Itoa(i)))
	}
	if f.Test([]byte(`a`)) {
		t.Error("`a` should not be a member")
	}
}
func TestStablePoint(t *testing.T) {
	f := NewStableBloomFilter(1000, 1, 0.1)
	for i := 0; i < 1000000; i++ {
		f.Add([]byte(strconv.Itoa(i)))
	}
	zeros := 0
	for i := uint(0); i < f.m; i++ {
		if f.cells.Get(i) == 0 {
			zeros++
		}
	}
	actual := round(float64(zeros)/float64(f.m), 0.5, 1)
	expected := round(f.StablePoint(), 0.5, 1)
	if actual != expected {
		t.Errorf("Expected stable point %f, got %f", expected, actual)
	}
	bf := NewUnstableBloomFilter(1000, 0.1)
	if stablePoint := bf.StablePoint(); stablePoint != 0 {
		t.Errorf("Expected stable point 0, got %f", stablePoint)
	}
}