Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(59)

Side by Side Diff: 2014/testing/test2/string_test.go

Issue 108170043: code review 108170043: "Testing Techniques" talk (Closed)
Patch Set: diff -r c636a8a8316f https://code.google.com/p/go.talks Created 9 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 package string_test
2
3 import (
4 "fmt"
5 "strings"
6 "testing"
7 )
8
9 func TestIndex(t *testing.T) {
10 var tests = []struct {
Sameer at Google 2014/06/25 14:07:16 It's common to inline tests in the loop: for _, te
11 s string
12 sep string
13 out int
Sameer at Google 2014/06/25 14:07:16 call this want, like the previous slide?
14 }{
15 {"", "", 0},
Sameer at Google 2014/06/25 14:07:16 Include {"chicken", "ken", 4} to show that this is
16 {"", "a", -1},
17 {"fo", "foo", -1},
18 {"foo", "foo", 0},
19 {"oofofoofooo", "f", 2},
20 // etc
21 }
22 for _, test := range tests {
23 actual := strings.Index(test.s, test.sep)
24 if actual != test.out {
25 t.Errorf("Index(%q,%q) = %v; want %v", test.s, test.sep, actual, test.out)
Sameer at Google 2014/06/25 14:07:15 do you want a space between %q,%q to mirror the co
26 }
27 }
28 }
29
30 func BenchmarkIndex(b *testing.B) {
31 const s = "some_text=some☺value"
32 for i := 0; i < b.N; i++ {
33 strings.Index(s, "v")
34 }
35 }
36
37 func ExampleIndex() {
38 fmt.Println(strings.Index("chicken", "ken"))
39 fmt.Println(strings.Index("chicken", "dmr"))
40 // Output:
41 // 4
42 // -1
43 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b