summaryrefslogtreecommitdiff
path: root/go/robot-name/bonus_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-28 14:41:56 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-28 14:41:56 +0200
commita9ae4ebc6006271fc0e95626e0c95e6b9cc786de (patch)
treeda95be2382b384b52dd0157c1b6126e9b57b3d4f /go/robot-name/bonus_test.go
parentfef4ced569da1bdbc167d0786ab0a188973de3c5 (diff)
Solve robot
Diffstat (limited to 'go/robot-name/bonus_test.go')
-rw-r--r--go/robot-name/bonus_test.go29
1 files changed, 29 insertions, 0 deletions
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
+ }
+}