File: testorbench_test.go

package info (click to toggle)
golang-github-efficientgo-core 1.0.0~rc3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 580 kB
  • sloc: makefile: 68
file content (47 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) The EfficientGo Authors.
// Licensed under the Apache License 2.0.

package testutil

import "testing"

func TestTestOrBench(t *testing.T) {
	tb := NewTB(t)
	tb.Run("1", func(tb TB) { testorbenchComplexTest(tb) })
	tb.Run("2", func(tb TB) { testorbenchComplexTest(tb) })
}

func BenchmarkTestOrBench(b *testing.B) {
	tb := NewTB(b)
	tb.Run("1", func(tb TB) { testorbenchComplexTest(tb) })
	tb.Run("2", func(tb TB) { testorbenchComplexTest(tb) })
}

func testorbenchComplexTest(tb TB) {
	tb.Run("a", func(tb TB) {
		tb.Run("aa", func(tb TB) {
			tb.ResetTimer()
			for i := 0; i < tb.N(); i++ {
				if !tb.IsBenchmark() {
					if tb.N() != 1 {
						tb.FailNow()
					}
				}
			}
		})
	})
	tb.SetBytes(120220)
	tb.Run("b", func(tb TB) {
		tb.Run("bb", func(tb TB) {
			tb.ResetTimer()
			for i := 0; i < tb.N(); i++ {
				if !tb.IsBenchmark() {
					if tb.N() != 1 {
						tb.FailNow()
					}
				}
			}
		})
	})

}