Skip to content

Commit

Permalink
Fix robot-name tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timgott committed Sep 8, 2024
1 parent 78c1ed5 commit 276bfbf
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 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,20 @@
[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
(let ([count (/ max-names 4)])
(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 276bfbf

Please sign in to comment.