1 // Copyright 2013 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.
15 var roundDownTests
= []struct {
29 func TestRoundDown10(t
*testing
.T
) {
30 for _
, tt
:= range roundDownTests
{
31 actual
:= testing
.RoundDown10(tt
.v
)
32 if tt
.expected
!= actual
{
33 t
.Errorf("roundDown10(%d): expected %d, actual %d", tt
.v
, tt
.expected
, actual
)
38 var roundUpTests
= []struct {
55 func TestRoundUp(t
*testing
.T
) {
56 for _
, tt
:= range roundUpTests
{
57 actual
:= testing
.RoundUp(tt
.v
)
58 if tt
.expected
!= actual
{
59 t
.Errorf("roundUp(%d): expected %d, actual %d", tt
.v
, tt
.expected
, actual
)
64 func TestRunParallel(t
*testing
.T
) {
65 testing
.Benchmark(func(b
*testing
.B
) {
69 b
.RunParallel(func(pb
*testing
.PB
) {
70 atomic
.AddUint32(&procs
, 1)
72 atomic
.AddUint64(&iters
, 1)
75 if want
:= uint32(3 * runtime
.GOMAXPROCS(0)); procs
!= want
{
76 t
.Errorf("got %v procs, want %v", procs
, want
)
78 if iters
!= uint64(b
.N
) {
79 t
.Errorf("got %v iters, want %v", iters
, b
.N
)
84 func TestRunParallelFail(t
*testing
.T
) {
85 testing
.Benchmark(func(b
*testing
.B
) {
86 b
.RunParallel(func(pb
*testing
.PB
) {
87 // The function must be able to log/abort
88 // w/o crashing/deadlocking the whole benchmark.
95 func ExampleB_RunParallel() {
96 // Parallel benchmark for text/template.Template.Execute on a single object.
97 testing
.Benchmark(func(b
*testing
.B
) {
98 templ
:= template
.Must(template
.New("test").Parse("Hello, {{.}}!"))
99 // RunParallel will create GOMAXPROCS goroutines
100 // and distribute work among them.
101 b
.RunParallel(func(pb
*testing
.PB
) {
102 // Each goroutine has its own bytes.Buffer.
105 // The loop body is executed b.N times total across all goroutines.
107 templ
.Execute(&buf
, "World")