PasteRack.org
Paste # 8314
2013-10-10 16:58:11

Forked from paste # 7551.

Fork as a new paste.

Paste viewed 46963 times.


Embed:

check-expect

  1. #lang htdp/bsl+
  2.  
  3. ; LON is one of:
  4. ;  empty
  5. ;  (cons Number LON)
  6. ; interpretation: a list of numbers
  7.  
  8. ; LON -> LON
  9. ; created a sorted version of one-lon
  10.  
  11. (check-expect (sort '(13 0 1 2 3 4 5 6 7 8 9 10 11 12 14 15))
  12.                     '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))
  13.  
  14. (define (sort one-lon)
  15.    (cond
  16.      [(empty? one-lon) '()]
  17.      [(cons? one-lon)
  18.       (ryan (first one-lon) (sort (rest one-lon)))]))
  19.  
  20. ; Number LON -> LON
  21. ; puts n into one-lon according to ascending order
  22. ; WHAT DO WE KNOW: one-lon is sorted in ascending order
  23. ; because ryan is called inside of sort with (sort (rest ...))
  24.  
  25. (check-expect (ryan 13 (list 11 12 14 15)) (list 11 12 13 14 15))
  26. (check-expect (ryan 13 empty) (list 13))
  27.  
  28. (define (ryan n one-lon)
  29.    (cond
  30.      [(empty? one-lon) (list n)]
  31.      [(cons? one-lon)
  32.       (if (<= (first one-lon) n)
  33.           (cons (first one-lon) (ryan n (rest one-lon)))
  34.           (cons n one-lon))]))
  35.  
  36. (ryan 13 empty)
  37. (check-expect (ryan 13 empty) (list 12))

=>

Ran 4 checks.

1 of the 4 checks failed.

Actual value (13) differs from (12), the expected value.

 At line (unknown) column (unknown)

'(13)