From a9ae4ebc6006271fc0e95626e0c95e6b9cc786de Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 28 Aug 2016 14:41:56 +0200 Subject: Solve robot --- go/robot-name/bonus_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 go/robot-name/bonus_test.go (limited to 'go/robot-name/bonus_test.go') diff --git a/go/robot-name/bonus_test.go b/go/robot-name/bonus_test.go new file mode 100644 index 0000000..17e7df9 --- /dev/null +++ b/go/robot-name/bonus_test.go @@ -0,0 +1,29 @@ +// +build bonus + +package robotname + +import "testing" + +func TestCollisions(t *testing.T) { + m := map[string]bool{} + // Test uniqueness for new robots. + // 10k should be plenty to catch names generated + // randomly without a uniqueness check. + for i := 0; i < 10000; i++ { + n := New().Name() + if m[n] { + t.Fatalf("Name %s reissued after %d robots.", n, i) + } + m[n] = true + } + // Test that names aren't recycled either. + r := New() + for i := 0; i < 10000; i++ { + r.Reset() + n := r.Name() + if m[n] { + t.Fatalf("Name %s reissued after Reset.", n) + } + m[n] = true + } +} -- cgit v1.2.3