MCPcopy
hub / github.com/chai2010/advanced-go-programming-book / TestLoopAdd

Function TestLoopAdd

examples/ch3.x/loop/loop_test.go:12–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestLoopAdd(t *testing.T) {
13 t.Run("go", func(t *testing.T) {
14 if x := LoopAdd(100, 0, 1); x != 100 {
15 t.Fatalf("expect = %d, got = %d", 100, x)
16 }
17 if x := LoopAdd(100, 0, 2); x != 200 {
18 t.Fatalf("expect = %d, got = %d", 200, x)
19 }
20 if x := LoopAdd(100, 0, -1); x != -100 {
21 t.Fatalf("expect = %d, got = %d", -100, x)
22 }
23 if x := LoopAdd(100, 50, 1); x != 150 {
24 t.Fatalf("expect = %d, got = %d", 150, x)
25 }
26 })
27 t.Run("asm", func(t *testing.T) {
28 if x := AsmLoopAdd(100, 0, 1); x != 100 {
29 t.Fatalf("expect = %d, got = %d", 100, x)
30 }
31 if x := AsmLoopAdd(100, 0, 2); x != 200 {
32 t.Fatalf("expect = %d, got = %d", 200, x)
33 }
34 if x := AsmLoopAdd(100, 0, -1); x != -100 {
35 t.Fatalf("expect = %d, got = %d", -100, x)
36 }
37 if x := AsmLoopAdd(100, 50, 1); x != 150 {
38 t.Fatalf("expect = %d, got = %d", 150, x)
39 }
40 })
41}
42
43func BenchmarkLoopAdd(b *testing.B) {
44 b.Run("go", func(b *testing.B) {

Callers

nothing calls this directly

Calls 2

LoopAddFunction · 0.85
AsmLoopAddFunction · 0.85

Tested by

no test coverage detected