1// Copyright 2014 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package testing_test
6
7import "testing"
8
9var global any
10
11var allocsPerRunTests = []struct {
12	name   string
13	fn     func()
14	allocs float64
15}{
16	{"alloc *byte", func() { global = new(*byte) }, 1},
17	{"alloc complex128", func() { global = new(complex128) }, 1},
18	{"alloc float64", func() { global = new(float64) }, 1},
19	{"alloc int32", func() { global = new(int32) }, 1},
20	{"alloc byte", func() { global = new(byte) }, 1},
21}
22
23func TestAllocsPerRun(t *testing.T) {
24	for _, tt := range allocsPerRunTests {
25		if allocs := testing.AllocsPerRun(100, tt.fn); allocs != tt.allocs {
26			t.Errorf("AllocsPerRun(100, %s) = %v, want %v", tt.name, allocs, tt.allocs)
27		}
28	}
29}
30