Skip to content

Commit

Permalink
Fix robot-name tests (#403)
Browse files Browse the repository at this point in the history
* Fix robot-name tests

* Reduce iterations in robot-name
  • Loading branch information
timgott authored Sep 9, 2024
1 parent 78c1ed5 commit d19fedf
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions exercises/practice/robot-name/robot-name-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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

(define (check-proper-robot-name r)
(check-regexp-match proper-robot-name (name r)))
Expand All @@ -28,20 +28,21 @@
[name1 (name robby)]
[_ (reset! robby)]
[name2 (name robby)])
(and
(and (check-regexp-match proper-robot-name name1)
(check-regexp-match proper-robot-name name2))
(not (string=? name1 name2)))))
(check-regexp-match proper-robot-name name1)
(check-regexp-match proper-robot-name name2)
(check-not-equal? name1 name2)))

;; reset cache in order to generate all the names
(test-case
"Check that robots are created with unique names."
(begin
;; sufficient to cause collision (birthday paradox)
(let ([count 5000])
;; reset cache in order to generate all the names
(reset-name-cache!)
(= max-names
(let ([names (make-hash)])
(for ((_ (in-range (/ max-names 4))))
(hash-set! names (name (make-robot)) #t))
(hash-count names)))))))

(run-tests robot-name-suite))
(check-equal?
(let ([names (make-hash)])
(for ((_ (in-range count)))
(hash-set! names (name (make-robot)) #t))
(hash-count names))
count)))))

(run-tests robot-name-suite))

0 comments on commit d19fedf

Please sign in to comment.