-
Notifications
You must be signed in to change notification settings - Fork 0
/
050.rkt
40 lines (34 loc) · 1.25 KB
/
050.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#lang htdp/bsl
; Exercise 50.
; ------------
;
; ; TrafficLight -> TrafficLight
; ; yields the next state given current state s
; (check-expect (traffic-light-next "red") "green")
; (define (traffic-light-next s)
; (cond
; [(string=? "red" s) "green"]
; [(string=? "green" s) "yellow"]
; [(string=? "yellow" s) "red"]))
;
; If you copy and paste the above function definition into the definitions area
; of DrRacket and click RUN, DrRacket highlights two of the three cond lines.
; This coloring tells you that your test cases do not cover the full
; conditional. Add enough tests to make DrRacket happy.
; ------------------------------------------------------------------------------
; A TrafficLight is one of the following Strings:
; – "red"
; – "green"
; – "yellow"
; interpretation the three strings represent the three
; possible states that a traffic light may assume
; TrafficLight -> TrafficLight
; yields the next state given current state s
(check-expect (traffic-light-next "red") "green")
(check-expect (traffic-light-next "green") "yellow")
(check-expect (traffic-light-next "yellow") "red")
(define (traffic-light-next s)
(cond
[(string=? "red" s) "green"]
[(string=? "green" s) "yellow"]
[(string=? "yellow" s) "red"]))