File tree Expand file tree Collapse file tree 1 file changed +15
-14
lines changed
exercises/practice/robot-name Expand file tree Collapse file tree 1 file changed +15
-14
lines changed Original file line number Diff line number Diff line change 9
9
10
10
(define max-names (* 26 26 10 10 10 ))
11
11
12
- (define proper-robot-name #px"\\p{Lu}{2}\\p{Nd}{3} " )
12
+ (define proper-robot-name #px"^ \\p{Lu}{2}\\p{Nd}{3}$ " )
13
13
14
14
(define (check-proper-robot-name r)
15
15
(check-regexp-match proper-robot-name (name r)))
28
28
[name1 (name robby)]
29
29
[_ (reset! robby)]
30
30
[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)))
35
34
36
- ;; reset cache in order to generate all the names
37
35
(test-case
38
36
"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
40
40
(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))
You can’t perform that action at this time.
0 commit comments