Sha256: 720721deed31534b079396522aec0963bd25b813496a163546c3ca4282cde5b7

Contents?: true

Size: 1.03 KB

Versions: 122

Compression:

Stored size: 1.03 KB

Contents

package robotname

import (
	"regexp"
	"testing"
)

var namePat = regexp.MustCompile(`^[A-Z]{2}\d{3}$`)

func New() *Robot { return new(Robot) }

func TestNameValid(t *testing.T) {
	n := New().Name()
	if !namePat.MatchString(n) {
		t.Errorf(`Invalid robot name %q, want form "AA###".`, n)
	}
}

func TestNameSticks(t *testing.T) {
	r := New()
	n1 := r.Name()
	n2 := r.Name()
	if n2 != n1 {
		t.Errorf(`Robot name changed.  Now %s, was %s.`, n2, n1)
	}
}

func TestSuccessiveRobotsHaveDifferentNames(t *testing.T) {
	n1 := New().Name()
	if New().Name() == n1 {
		t.Errorf(`Robots with same name.  Two %s's.`, n1)
	}
}

func TestResetName(t *testing.T) {
	r := New()
	n1 := r.Name()
	r.Reset()
	if r.Name() == n1 {
		t.Errorf(`Robot name not cleared on reset.  Still %s.`, n1)
	}
}

// Note if you go for bonus points, this benchmark likely won't be
// meaningful.  Bonus thought exercise, why won't it be meaningful?
func BenchmarkName(b *testing.B) {
	// Benchmark combined time to create robot and name.
	for i := 0; i < b.N; i++ {
		New().Name()
	}
}

Version data entries

122 entries across 122 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.179 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.178 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.177 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.176 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.175 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.174 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.173 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.172 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.171 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.170 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.169 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.167 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.166 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.165 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.164 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.163 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.162 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.161 tracks/go/exercises/robot-name/robot_name_test.go
trackler-2.2.1.160 tracks/go/exercises/robot-name/robot_name_test.go