func BenchmarkMruNonceList(b *testing.B) {
	b.StopTimer()
	numNonces := 100000
	nonces := make([]uint64, 0, numNonces)
	for i := 0; i < numNonces; i++ {
		nonces = append(nonces, uint64(i))
	}
	b.StartTimer()
	limit := 20000
	mruNonceMap := newMruNonceMap(uint(limit))
	for i := 0; i < b.N; i++ {
		mruNonceMap.Add(nonces[i%numNonces])
	}
}
BenchmarkMruNonceList performs basic benchmarks on the most recently used
nonce handling.
package peer
import (
	"fmt"
	"testing"
)
func TestMruNonceMap(t *testing.T) {
	numNonces := 10
	nonces := make([]uint64, 0, numNonces)
	for i := 0; i < numNonces; i++ {
		nonces = append(nonces, uint64(i))
	}
	tests := []struct {
		name  string
		limit int
	}{
		{name: "limit 0", limit: 0},
		{name: "limit 1", limit: 1},
		{name: "limit 5", limit: 5},
		{name: "limit 7", limit: 7},
		{name: "limit one less than available", limit: numNonces - 1},
		{name: "limit all available", limit: numNonces},
	}
testLoop:
	for i, test := range tests {
		mruNonceMap := newMruNonceMap(uint(test.limit))
		for j := 0; j < numNonces; j++ {
			mruNonceMap.Add(nonces[j])
		}
		for j := numNonces - test.limit; j < numNonces; j++ {
			if !mruNonceMap.Exists(nonces[j]) {
				t.Errorf("Exists #%d (%s) entry %d does not "+
					"exist", i, test.name, nonces[j])
				continue testLoop
			}
		}
		for j := 0; j < numNonces-test.limit; j++ {
			if mruNonceMap.Exists(nonces[j]) {
				t.Errorf("Exists #%d (%s) entry %d exists", i,
					test.name, nonces[j])
				continue testLoop
			}
		}
		if test.limit > 1 {
			origLruIndex := numNonces - test.limit
			mruNonceMap.Add(nonces[origLruIndex])
			mruNonceMap.Add(uint64(numNonces) + 1)
			if !mruNonceMap.Exists(nonces[origLruIndex]) {
				t.Errorf("MRU #%d (%s) entry %d does not exist",
					i, test.name, nonces[origLruIndex])
				continue testLoop
			}
			newLruIndex := origLruIndex + 1
			if mruNonceMap.Exists(nonces[newLruIndex]) {
				t.Errorf("MRU #%d (%s) entry %d exists", i,
					test.name, nonces[newLruIndex])
				continue testLoop
			}
		}
		for j := 0; j < numNonces; j++ {
			mruNonceMap.Delete(nonces[j])
			if mruNonceMap.Exists(nonces[j]) {
				t.Errorf("Delete #%d (%s) entry %d exists", i,
					test.name, nonces[j])
				continue testLoop
			}
		}
	}
}
func TestMruNonceMapStringer(t *testing.T) {
	nonce1 := uint64(10)
	nonce2 := uint64(20)
	mruNonceMap := newMruNonceMap(uint(2))
	mruNonceMap.Add(nonce1)
	mruNonceMap.Add(nonce2)
	wantStr1 := fmt.Sprintf("<%d>[%d, %d]", 2, nonce1, nonce2)
	wantStr2 := fmt.Sprintf("<%d>[%d, %d]", 2, nonce2, nonce1)
	gotStr := mruNonceMap.String()
	if gotStr != wantStr1 && gotStr != wantStr2 {
		t.Fatalf("unexpected string representation - got %q, want %q "+
			"or %q", gotStr, wantStr1, wantStr2)
	}
}