From 7d63621cbe9eaef003097c5f93e90931733d5c72 Mon Sep 17 00:00:00 2001 From: Justin Lowery Date: Tue, 4 Jul 2017 00:20:32 -0400 Subject: [PATCH] Fix several test output messages: Fatal to Fatalf. Added comments to asc and desc package exported methods --- asc/numeric.go | 12 ++++++++++++ asc/numeric_test.go | 24 ++++++++++++------------ asc/time.go | 1 + desc/numeric.go | 12 ++++++++++++ desc/numeric_test.go | 24 ++++++++++++------------ desc/time.go | 1 + iter_test.go | 39 ++++++++++++++++++++++++--------------- sortedmap_bench_test.go | 6 ++++-- 8 files changed, 78 insertions(+), 41 deletions(-) diff --git a/asc/numeric.go b/asc/numeric.go index 61d25d0..13fc99b 100644 --- a/asc/numeric.go +++ b/asc/numeric.go @@ -1,49 +1,61 @@ package asc +// Uint8 is a less than comparison function for the Uint8 numeric type. func Uint8(i, j interface{}) bool { return i.(uint8) < j.(uint8) } +// Uint16 is a less than comparison function for the Uint16 numeric type. func Uint16(i, j interface{}) bool { return i.(uint16) < j.(uint16) } +// Uint32 is a less than comparison function for the Uint32 numeric type. func Uint32(i, j interface{}) bool { return i.(uint32) < j.(uint32) } +// Uint64 is a less than comparison function for the Uint64 numeric type. func Uint64(i, j interface{}) bool { return i.(uint64) < j.(uint64) } +// Int8 is a less than comparison function for the Int8 numeric type. func Int8(i, j interface{}) bool { return i.(int8) < j.(int8) } +// Int16 is a less than comparison function for the Int16 numeric type. func Int16(i, j interface{}) bool { return i.(int16) < j.(int16) } +// Int32 is a less than comparison function for the Int32 numeric type. func Int32(i, j interface{}) bool { return i.(int32) < j.(int32) } +// Int64 is a less than comparison function for the Int64 numeric type. func Int64(i, j interface{}) bool { return i.(int64) < j.(int64) } +// Float32 is a less than comparison function for the Float32 numeric type. func Float32(i, j interface{}) bool { return i.(float32) < j.(float32) } +// Float64 is a less than comparison function for the Float64 numeric type. func Float64(i, j interface{}) bool { return i.(float64) < j.(float64) } +// Uint is a less than comparison function for the Uint numeric type. func Uint(i, j interface{}) bool { return i.(uint) < j.(uint) } +// Int is a less than comparison function for the Int numeric type. func Int(i, j interface{}) bool { return i.(int) < j.(int) } diff --git a/asc/numeric_test.go b/asc/numeric_test.go index 7013ec3..6fe216b 100644 --- a/asc/numeric_test.go +++ b/asc/numeric_test.go @@ -4,72 +4,72 @@ import "testing" func TestUint8(t *testing.T) { if Uint8(uint8(1), uint8(0)) { - t.Fatal("asc.TestUint8 failed: %v", greaterThanErr) + t.Fatalf("asc.TestUint8 failed: %v\n", greaterThanErr) } } func TestUint16(t *testing.T) { if Uint16(uint16(1), uint16(0)) { - t.Fatal("asc.TestUint16 failed: %v", greaterThanErr) + t.Fatalf("asc.TestUint16 failed: %v\n", greaterThanErr) } } func TestUint32(t *testing.T) { if Uint32(uint32(1), uint32(0)) { - t.Fatal("asc.TestUint32 failed: %v", greaterThanErr) + t.Fatalf("asc.TestUint32 failed: %v\n", greaterThanErr) } } func TestUint64(t *testing.T) { if Uint64(uint64(1), uint64(0)) { - t.Fatal("asc.TestUint64 failed: %v", greaterThanErr) + t.Fatalf("asc.TestUint64 failed: %v\n", greaterThanErr) } } func TestInt8(t *testing.T) { if Int8(int8(1), int8(0)) { - t.Fatal("asc.TestInt8 failed: %v", greaterThanErr) + t.Fatalf("asc.TestInt8 failed: %v\n", greaterThanErr) } } func TestInt16(t *testing.T) { if Int16(int16(1), int16(0)) { - t.Fatal("asc.TestInt16 failed: %v", greaterThanErr) + t.Fatalf("asc.TestInt16 failed: %v\n", greaterThanErr) } } func TestInt32(t *testing.T) { if Int32(int32(1), int32(0)) { - t.Fatal("asc.TestInt32 failed: %v", greaterThanErr) + t.Fatalf("asc.TestInt32 failed: %v\n", greaterThanErr) } } func TestInt64(t *testing.T) { if Int64(int64(1), int64(0)) { - t.Fatal("asc.TestInt64 failed: %v", greaterThanErr) + t.Fatalf("asc.TestInt64 failed: %v\n", greaterThanErr) } } func TestFloat32(t *testing.T) { if Float32(float32(1), float32(0)) { - t.Fatal("asc.TestFloat32 failed: %v", greaterThanErr) + t.Fatalf("asc.TestFloat32 failed: %v\n", greaterThanErr) } } func TestFloat64(t *testing.T) { if Float64(float64(1), float64(0)) { - t.Fatal("asc.TestFloat64 failed: %v", greaterThanErr) + t.Fatalf("asc.TestFloat64 failed: %v\n", greaterThanErr) } } func TestUint(t *testing.T) { if Uint(uint(1), uint(0)) { - t.Fatal("asc.TestUint failed: %v", greaterThanErr) + t.Fatalf("asc.TestUint failed: %v\n", greaterThanErr) } } func TestInt(t *testing.T) { if Int(int(1), 0) { - t.Fatal("asc.TestInt failed: %v", greaterThanErr) + t.Fatalf("asc.TestInt failed: %v\n", greaterThanErr) } } diff --git a/asc/time.go b/asc/time.go index 20104c5..143889b 100644 --- a/asc/time.go +++ b/asc/time.go @@ -2,6 +2,7 @@ package asc import "time" +// Time is a less than comparison function for the time.Time type. func Time(i, j interface{}) bool { return i.(time.Time).Before(j.(time.Time)) } diff --git a/desc/numeric.go b/desc/numeric.go index 4429b42..85a2d3e 100644 --- a/desc/numeric.go +++ b/desc/numeric.go @@ -1,49 +1,61 @@ package desc +// Uint8 is a greater than comparison function for the Uint8 numeric type. func Uint8(i, j interface{}) bool { return i.(uint8) > j.(uint8) } +// Uint16 is a greater than comparison function for the Uint16 numeric type. func Uint16(i, j interface{}) bool { return i.(uint16) > j.(uint16) } +// Uint32 is a greater than comparison function for the Uint32 numeric type. func Uint32(i, j interface{}) bool { return i.(uint32) > j.(uint32) } +// Uint64 is a greater than comparison function for the Uint64 numeric type. func Uint64(i, j interface{}) bool { return i.(uint64) > j.(uint64) } +// Int8 is a greater than comparison function for the Int8 numeric type. func Int8(i, j interface{}) bool { return i.(int8) > j.(int8) } +// Int16 is a greater than comparison function for the Int16 numeric type. func Int16(i, j interface{}) bool { return i.(int16) > j.(int16) } +// Int32 is a greater than comparison function for the Int32 numeric type. func Int32(i, j interface{}) bool { return i.(int32) > j.(int32) } +// Int64 is a greater than comparison function for the Int64 numeric type. func Int64(i, j interface{}) bool { return i.(int64) > j.(int64) } +// Float32 is a greater than comparison function for the Float32 numeric type. func Float32(i, j interface{}) bool { return i.(float32) > j.(float32) } +// Float64 is a greater than comparison function for the Float64 numeric type. func Float64(i, j interface{}) bool { return i.(float64) > j.(float64) } +// Uint is a greater than comparison function for the Uint numeric type. func Uint(i, j interface{}) bool { return i.(uint) > j.(uint) } +// Int is a greater than comparison function for the Int numeric type. func Int(i, j interface{}) bool { return i.(int) > j.(int) } diff --git a/desc/numeric_test.go b/desc/numeric_test.go index cc085ae..032ff30 100644 --- a/desc/numeric_test.go +++ b/desc/numeric_test.go @@ -4,72 +4,72 @@ import "testing" func TestUint8(t *testing.T) { if Uint8(uint8(0), uint8(1)) { - t.Fatal("desc.TestUint8 failed: %v", greaterThanErr) + t.Fatalf("desc.TestUint8 failed: %v\n", greaterThanErr) } } func TestUint16(t *testing.T) { if Uint16(uint16(0), uint16(1)) { - t.Fatal("desc.TestUint16 failed: %v", greaterThanErr) + t.Fatalf("desc.TestUint16 failed: %v\n", greaterThanErr) } } func TestUint32(t *testing.T) { if Uint32(uint32(0), uint32(1)) { - t.Fatal("desc.TestUint32 failed: %v", greaterThanErr) + t.Fatalf("desc.TestUint32 failed: %v\n", greaterThanErr) } } func TestUint64(t *testing.T) { if Uint64(uint64(0), uint64(1)) { - t.Fatal("desc.TestUint64 failed: %v", greaterThanErr) + t.Fatalf("desc.TestUint64 failed: %v\n", greaterThanErr) } } func TestInt8(t *testing.T) { if Int8(int8(0), int8(1)) { - t.Fatal("desc.TestInt8 failed: %v", greaterThanErr) + t.Fatalf("desc.TestInt8 failed: %v\n", greaterThanErr) } } func TestInt16(t *testing.T) { if Int16(int16(0), int16(1)) { - t.Fatal("desc.TestInt16 failed: %v", greaterThanErr) + t.Fatalf("desc.TestInt16 failed: %v\n", greaterThanErr) } } func TestInt32(t *testing.T) { if Int32(int32(0), int32(1)) { - t.Fatal("desc.TestInt32 failed: %v", greaterThanErr) + t.Fatalf("desc.TestInt32 failed: %v\n", greaterThanErr) } } func TestInt64(t *testing.T) { if Int64(int64(0), int64(1)) { - t.Fatal("desc.TestInt64 failed: %v", greaterThanErr) + t.Fatalf("desc.TestInt64 failed: %v\n", greaterThanErr) } } func TestFloat32(t *testing.T) { if Float32(float32(0), float32(1)) { - t.Fatal("desc.TestFloat32 failed: %v", greaterThanErr) + t.Fatalf("desc.TestFloat32 failed: %v\n", greaterThanErr) } } func TestFloat64(t *testing.T) { if Float64(float64(0), float64(1)) { - t.Fatal("desc.TestFloat64 failed: %v", greaterThanErr) + t.Fatalf("desc.TestFloat64 failed: %v\n", greaterThanErr) } } func TestUint(t *testing.T) { if Uint(uint(0), uint(1)) { - t.Fatal("desc.TestUint failed: %v", greaterThanErr) + t.Fatalf("desc.TestUint failed: %v\n", greaterThanErr) } } func TestInt(t *testing.T) { if Int(int(0), 0) { - t.Fatal("desc.TestInt failed: %v", greaterThanErr) + t.Fatalf("desc.TestInt failed: %v\n", greaterThanErr) } } diff --git a/desc/time.go b/desc/time.go index a1a8310..bc6fadc 100644 --- a/desc/time.go +++ b/desc/time.go @@ -2,6 +2,7 @@ package desc import "time" +// Time is a greater than comparison function for the time.Time type. func Time(i, j interface{}) bool { return i.(time.Time).After(j.(time.Time)) } diff --git a/iter_test.go b/iter_test.go index f6502dd..5269624 100644 --- a/iter_test.go +++ b/iter_test.go @@ -39,7 +39,7 @@ func TestIterChTimeout(t *testing.T) { } } } else { - t.Fatal("TestIterChTimeout failed: %v", generalBoundsErr) + t.Fatalf("TestIterChTimeout failed: %v", generalBoundsErr) } params.LowerBound = time.Time{} @@ -54,7 +54,7 @@ func TestIterChTimeout(t *testing.T) { } } } else { - t.Fatal("TestIterChTimeout failed: %v", generalBoundsErr) + t.Fatalf("TestIterChTimeout failed: %v", generalBoundsErr) } params = IterChParams{ @@ -70,7 +70,7 @@ func TestIterChTimeout(t *testing.T) { } } } else { - t.Fatal("TestIterChTimeout failed: %v", generalBoundsErr) + t.Fatalf("TestIterChTimeout failed: %v", generalBoundsErr) } params.LowerBound = time.Time{} @@ -85,7 +85,7 @@ func TestIterChTimeout(t *testing.T) { } } } else { - t.Fatal("TestIterChTimeout failed: %v", generalBoundsErr) + t.Fatalf("TestIterChTimeout failed: %v", generalBoundsErr) } } @@ -104,7 +104,7 @@ func TestBoundedIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestBoundedIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestBoundedIterCh failed: %v", generalBoundsErr) } if ch, ok := sm.BoundedIterCh(reversed, time.Time{}, maxTime); ok { @@ -112,7 +112,7 @@ func TestBoundedIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestBoundedIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestBoundedIterCh failed: %v", generalBoundsErr) } if ch, ok := sm.BoundedIterCh(reversed, maxTime, time.Time{}); ok { @@ -120,7 +120,7 @@ func TestBoundedIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestBoundedIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestBoundedIterCh failed: %v", generalBoundsErr) } if ch, ok := sm.BoundedIterCh(reversed, earlierDate, time.Now()); ok { @@ -128,7 +128,7 @@ func TestBoundedIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestBoundedIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestBoundedIterCh failed: %v", generalBoundsErr) } if ch, ok := sm.BoundedIterCh(reversed, time.Now(), earlierDate); ok { @@ -136,7 +136,7 @@ func TestBoundedIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestBoundedIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestBoundedIterCh failed: %v", generalBoundsErr) } if ch, ok := sm.BoundedIterCh(reversed, time.Now(), laterDate); ok { @@ -144,11 +144,11 @@ func TestBoundedIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestBoundedIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestBoundedIterCh failed: %v", generalBoundsErr) } if _, ok := sm.BoundedIterCh(reversed, laterDate, laterDate); ok { - t.Fatal("TestBoundedIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestBoundedIterCh failed: %v", generalBoundsErr) } } @@ -178,7 +178,7 @@ func TestCustomIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestCustomIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestCustomIterCh failed: %v", generalBoundsErr) } params = IterChParams{ @@ -193,7 +193,7 @@ func TestCustomIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestCustomIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestCustomIterCh failed: %v", generalBoundsErr) } params = IterChParams{ @@ -208,7 +208,7 @@ func TestCustomIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestCustomIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestCustomIterCh failed: %v", generalBoundsErr) } reversed = false @@ -224,7 +224,7 @@ func TestCustomIterCh(t *testing.T) { t.Fatal(err) } } else { - t.Fatal("TestCustomIterCh failed: %v", generalBoundsErr) + t.Fatalf("TestCustomIterCh failed: %v", generalBoundsErr) } } @@ -370,4 +370,13 @@ func TestBoundedIterFunc(t *testing.T) { }); ok { t.Fatalf("TestBoundedIterFunc failed: %v", nilValErr) } + + if ok := sm.BoundedIterFunc(false, laterDate, laterDate, func(rec Record) bool { + if rec.Key == nil { + t.Fatalf("TestBoundedIterFunc failed: %v", nilValErr) + } + return false + }); ok { + t.Fatalf("TestBoundedIterFunc failed: %v", nilValErr) + } } diff --git a/sortedmap_bench_test.go b/sortedmap_bench_test.go index cef0b0e..cdeacc4 100644 --- a/sortedmap_bench_test.go +++ b/sortedmap_bench_test.go @@ -8,11 +8,13 @@ import ( func BenchmarkNew(b *testing.B) { var sm *SortedMap - if sm == nil { - } b.ResetTimer() for i := 0; i < b.N; i++ { sm = New(0, asc.Time) } + b.StopTimer() + + if sm == nil { + } }