Skip to content

Commit d19fedf

Browse files
authored
Fix robot-name tests (#403)
* Fix robot-name tests * Reduce iterations in robot-name
1 parent 78c1ed5 commit d19fedf

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

exercises/practice/robot-name/robot-name-test.rkt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
(define max-names (* 26 26 10 10 10))
1111

12-
(define proper-robot-name #px"\\p{Lu}{2}\\p{Nd}{3}")
12+
(define proper-robot-name #px"^\\p{Lu}{2}\\p{Nd}{3}$")
1313

1414
(define (check-proper-robot-name r)
1515
(check-regexp-match proper-robot-name (name r)))
@@ -28,20 +28,21 @@
2828
[name1 (name robby)]
2929
[_ (reset! robby)]
3030
[name2 (name robby)])
31-
(and
32-
(and (check-regexp-match proper-robot-name name1)
33-
(check-regexp-match proper-robot-name name2))
34-
(not (string=? name1 name2)))))
31+
(check-regexp-match proper-robot-name name1)
32+
(check-regexp-match proper-robot-name name2)
33+
(check-not-equal? name1 name2)))
3534

36-
;; reset cache in order to generate all the names
3735
(test-case
3836
"Check that robots are created with unique names."
39-
(begin
37+
;; sufficient to cause collision (birthday paradox)
38+
(let ([count 5000])
39+
;; reset cache in order to generate all the names
4040
(reset-name-cache!)
41-
(= max-names
42-
(let ([names (make-hash)])
43-
(for ((_ (in-range (/ max-names 4))))
44-
(hash-set! names (name (make-robot)) #t))
45-
(hash-count names)))))))
46-
47-
(run-tests robot-name-suite))
41+
(check-equal?
42+
(let ([names (make-hash)])
43+
(for ((_ (in-range count)))
44+
(hash-set! names (name (make-robot)) #t))
45+
(hash-count names))
46+
count)))))
47+
48+
(run-tests robot-name-suite))

0 commit comments

Comments
 (0)