summaryrefslogtreecommitdiff
path: root/go/robot-name/bonus_test.go
blob: 17e7df9b6a507c7d836fc2b0e2d2a5ad1f43681d (plain)
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
// +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
	}
}