added float support and cleaner code

This commit is contained in:
ston1th 2017-07-09 20:04:05 +02:00
commit 0ebcd6967b
5 changed files with 208 additions and 159 deletions

View file

@ -66,9 +66,14 @@ func TestNewQuery(t *testing.T) {
}
}
const (
filter1 = "String:*st* Bool:true"
filter2 = "Struct.Struct.Int:2 Struct.Struct.Int:3"
)
func TestFilter(t *testing.T) {
f1 := makefilter(data)
q1, err := NewQuery("String:*st* Bool:true", AND)
q1, err := NewQuery(filter1, AND)
if err != nil {
t.Error(err)
}
@ -84,7 +89,7 @@ func TestFilter(t *testing.T) {
}
f2 := makefilter(data)
q2, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", OR)
q2, err := NewQuery(filter2, OR)
if err != nil {
t.Error(err)
}
@ -100,7 +105,7 @@ func TestFilter(t *testing.T) {
}
f3 := makefilter(data)
q3, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", NOT)
q3, err := NewQuery(filter2, NOT)
if err != nil {
t.Error(err)
}
@ -114,7 +119,7 @@ func TestFilter(t *testing.T) {
}
func TestGenericFilter(t *testing.T) {
q1, err := NewQuery("String:*st* Bool:true", AND)
q1, err := NewQuery(filter1, AND)
if err != nil {
t.Error(err)
}
@ -133,7 +138,7 @@ func TestGenericFilter(t *testing.T) {
t.Error("f1[1] != data[1]")
}
q2, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", OR)
q2, err := NewQuery(filter2, OR)
if err != nil {
t.Error(err)
}
@ -152,7 +157,7 @@ func TestGenericFilter(t *testing.T) {
t.Error("f2[1] != data[2]")
}
q3, err := NewQuery("Struct.Struct.Int:2 Struct.Struct.Int:3", NOT)
q3, err := NewQuery(filter2, NOT)
if err != nil {
t.Error(err)
}
@ -169,9 +174,36 @@ func TestGenericFilter(t *testing.T) {
}
}
const (
simple = "Bool:true"
comp = "String:*st* Bool:false Struct.Struct.Int:1"
compOr = "Int:47 Bool:false Struct.String:s1*"
)
func BenchmarkNewQuerySimple(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
NewQuery(simple, OR)
}
}
func BenchmarkNewQueryComplex(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
NewQuery(comp, AND)
}
}
func BenchmarkNewQueryComplexOr(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
NewQuery(compOr, OR)
}
}
func BenchmarkFilterSimple(b *testing.B) {
b.ReportAllocs()
q, err := NewQuery("Bool:true", OR)
q, err := NewQuery(simple, OR)
if err != nil {
b.Error(err)
}
@ -183,7 +215,7 @@ func BenchmarkFilterSimple(b *testing.B) {
func BenchmarkFilterComplex(b *testing.B) {
b.ReportAllocs()
q, err := NewQuery("String:*st* Bool:false Struct.Struct.Int:1", AND)
q, err := NewQuery(comp, AND)
if err != nil {
b.Error(err)
}
@ -195,7 +227,7 @@ func BenchmarkFilterComplex(b *testing.B) {
func BenchmarkFilterComplexOr(b *testing.B) {
b.ReportAllocs()
q, err := NewQuery("Int:47 Bool:false Struct.String:s1*", OR)
q, err := NewQuery(compOr, OR)
if err != nil {
b.Error(err)
}
@ -207,7 +239,7 @@ func BenchmarkFilterComplexOr(b *testing.B) {
func BenchmarkGenericFilterSimple(b *testing.B) {
b.ReportAllocs()
q, err := NewQuery("Bool:true", OR)
q, err := NewQuery(simple, OR)
if err != nil {
b.Error(err)
}
@ -218,7 +250,7 @@ func BenchmarkGenericFilterSimple(b *testing.B) {
func BenchmarkGenericFilterComplex(b *testing.B) {
b.ReportAllocs()
q, err := NewQuery("String:*st* Bool:false Struct.Struct.Int:1", AND)
q, err := NewQuery(comp, AND)
if err != nil {
b.Error(err)
}
@ -229,7 +261,7 @@ func BenchmarkGenericFilterComplex(b *testing.B) {
func BenchmarkGenericFilterComplexOr(b *testing.B) {
b.ReportAllocs()
q, err := NewQuery("Int:47 Bool:false Struct.String:s1*", OR)
q, err := NewQuery(compOr, OR)
if err != nil {
b.Error(err)
}