func TestMapRange(t *testing.T) {
	bx := NewTestDB()
	defer bx.Close()

	years, err := bx.New([]byte("years"))
	if err != nil {
		t.Error(err.Error())
	}

	// Setup items to insert in `years` bucket
	items := []struct {
		Key, Value []byte
	}{
		{[]byte("1970"), []byte("70")},
		{[]byte("1975"), []byte("75")},
		{[]byte("1980"), []byte("80")},
		{[]byte("1985"), []byte("85")},
		{[]byte("1990"), []byte("90")}, // min = 1990
		{[]byte("1995"), []byte("95")}, // min < 1995 < max
		{[]byte("2000"), []byte("00")}, // max = 2000
		{[]byte("2005"), []byte("05")},
		{[]byte("2010"), []byte("10")},
	}

	// Insert 'em.
	if err := years.Insert(items); err != nil {
		t.Error(err.Error())
	}

	// Time range to map over.
	min := []byte("1990")
	max := []byte("2000")

	// Expected items within time range: 1990 <= key <= 2000.
	expected := []struct {
		Key, Value []byte
	}{
		{[]byte("1990"), []byte("90")}, // min = 1990
		{[]byte("1995"), []byte("95")}, // min < 1995 < max
		{[]byte("2000"), []byte("00")}, // max = 2000
	}

	// Setup slice of items to collect results.
	type item struct {
		Key, Value []byte
	}
	results := []item{}

	// Anon func to map over matched keys.
	do := func(k, v []byte) error {
		results = append(results, item{k, v})
		return nil
	}

	if err := years.MapRange(do, min, max); err != nil {
		t.Error(err.Error())
	}

	for i, want := range expected {
		got := results[i]
		if !bytes.Equal(got.Key, want.Key) {
			t.Errorf("got %v, want %v", got.Key, want.Key)
		}
		if !bytes.Equal(got.Value, want.Value) {
			t.Errorf("got %v, want %v", got.Value, want.Value)
		}
	}
}
// Ensure we can apply functions to the k/v pairs
// of keys within a given range.
Ensure we can apply functions to the k/v pairs
of keys within a given range.
// Ensure we can apply functions to the k / v pairs // of keys within a given range .
func TestMapRange(t *testing.T) {
	bx := NewTestDB()
	defer bx.Close()
	years, err := bx.New([]byte("years"))
	if err != nil {
		t.Error(err.Error())
	}
	items := []struct {
		Key, Value []byte
	}{
		{[]byte("1970"), []byte("70")},
		{[]byte("1975"), []byte("75")},
		{[]byte("1980"), []byte("80")},
		{[]byte("1985"), []byte("85")},
		{[]byte("1990"), []byte("90")}, 
		{[]byte("1995"), []byte("95")}, 
		{[]byte("2000"), []byte("00")}, 
		{[]byte("2005"), []byte("05")},
		{[]byte("2010"), []byte("10")},
	}
	if err := years.Insert(items); err != nil {
		t.Error(err.Error())
	}
	min := []byte("1990")
	max := []byte("2000")
	expected := []struct {
		Key, Value []byte
	}{
		{[]byte("1990"), []byte("90")}, 
		{[]byte("1995"), []byte("95")}, 
		{[]byte("2000"), []byte("00")}, 
	}
	type item struct {
		Key, Value []byte
	}
	results := []item{}
	do := func(k, v []byte) error {
		results = append(results, item{k, v})
		return nil
	}
	if err := years.MapRange(do, min, max); err != nil {
		t.Error(err.Error())
	}
	for i, want := range expected {
		got := results[i]
		if !bytes.Equal(got.Key, want.Key) {
			t.Errorf("got %v, want %v", got.Key, want.Key)
		}
		if !bytes.Equal(got.Value, want.Value) {
			t.Errorf("got %v, want %v", got.Value, want.Value)
		}
	}
}
func TestMapRange ( t * testing . T ) { bx := NewTestDB ( ) defer bx . Close ( ) years , err := bx . New ( [ ] byte ( " " ) ) if err != nil { t . Error ( err . Error ( ) ) } items := [ ] struct { Key , Value [ ] byte } { { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , } if err := years . Insert ( items ) ; err != nil { t . Error ( err . Error ( ) ) } min := [ ] byte ( " " ) max := [ ] byte ( " " ) expected := [ ] struct { Key , Value [ ] byte } { { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , } type item struct { Key , Value [ ] byte } results := [ ] item { } do := func ( k , v [ ] byte ) error { results = append ( results , item { k , v } ) return nil } if err := years . MapRange ( do , min , max ) ; err != nil { t . Error ( err . Error ( ) ) } for i , want := range expected { got := results [ i ] if ! bytes . Equal ( got . Key , want . Key ) { t . Errorf ( " " , got . Key , want . Key ) } if ! bytes . Equal ( got . Value , want . Value ) { t . Errorf ( " " , got . Value , want . Value ) } } }
Ensure we can apply functions to the k/v pairs
of keys within a given range.
Ensure we can apply functions to the k / v pairs of keys within a given range .
// Setup items to insert in `years` bucket // min = 1990 // min < 1995 < max // max = 2000 // Insert 'em. // Time range to map over. // Expected items within time range: 1990 <= key <= 2000. // min = 1990 // min < 1995 < max // max = 2000 // Setup slice of items to collect results. // Anon func to map over matched keys.