-1
;; snoc : X [Listof Any] -> [Listof Any]
;; Adds the X to the end of the list
(define (snoc x l)
  (cond [(empty? l) (cons x empty)]
        [else (cons (first l)
                    (snoc x (rest l)))]))

如上所述,它只是在列表末尾添加一个 X。您将如何为此编写一个简单的检查期望函数?

4

1 回答 1

1

I'd test the obvious cases, for example:

  1. What happens if we add an element to an empty list?
  2. What happens if we add an element to a list with one element?
  3. What happens if we add an element to a list with two elements?

And so on. For example, the first test would look like this:

(check-expect (snoc 1 '()) '(1))
于 2013-03-20T04:40:33.937 回答