Skip to content

Instantly share code, notes, and snippets.

@supki
Created February 21, 2013 18:25
Show Gist options
  • Select an option

  • Save supki/5006901 to your computer and use it in GitHub Desktop.

Select an option

Save supki/5006901 to your computer and use it in GitHub Desktop.
proglang week 5 tests
#lang racket
(require "hw4.rkt")
;; Tests Start Here
; These definitions will work only after you do some of the problems
; so you need to comment them out until you are ready.
; Add more tests as appropriate, of course.
; 1
(print (equal? (sequence 3 11 2) '(3 5 7 9 11)))
(print (equal? (sequence 3 8 3) '(3 6)))
(print (equal? (sequence 3 2 1) '()))
(newline)
; 2
(print (equal? (string-append-map '() "suffix") '()))
(print (equal? (string-append-map '("eblo" "sobachka") "suffix")
'("eblosuffix" "sobachkasuffix")))
(newline)
; 3
(print (equal? (list-nth-mod '(1 2 3 4 5) 14) 5))
(print (equal? (list-nth-mod '(1 2 3) 14) 3))
(print (equal? (list-nth-mod '(1 2 3 4 5 6 7) 25) 5))
(newline)
; 4
(define ones (λ () (cons 1 ones)))
(define onetwos
(letrec ([ones (λ () (cons 1 twos))]
[twos (λ () (cons 2 ones))])
ones))
(print (equal? (stream-for-n-steps ones 5) '(1 1 1 1 1)))
(print (equal? (stream-for-n-steps onetwos 5) '(1 2 1 2 1)))
(newline)
; 5
(print (equal? (stream-for-n-steps funny-number-stream 10)
'(1 2 3 4 -5 6 7 8 9 -10)))
(newline)
; 6
(print (equal? (stream-for-n-steps dan-then-dog 5)
'("dan.jpg" "dog.jpg" "dan.jpg" "dog.jpg" "dan.jpg")))
(newline)
; 7
(print (equal? (stream-for-n-steps (stream-add-zero ones) 3)
'((0 . 1) (0 . 1) (0 . 1))))
(print (equal? (stream-for-n-steps (stream-add-zero onetwos) 3)
'((0 . 1) (0 . 2) (0 . 1))))
(newline)
; 8
(print (equal? (stream-for-n-steps (cycle-lists '(1 2 3) '("a" "b")) 8)
'((1 . "a") (2 . "b") (3 . "a") (1 . "b") (2 . "a") (3 . "b") (1 . "a") (2 . "b"))))
(newline)
; 9
(print (equal? (vector-assoc 5 (list->vector '((2 . 8) (5 . 7))))
'(5 . 7)))
(print (equal? (vector-assoc 5 (list->vector '((2 . 8) (5 . 3) (5 . 7))))
'(5 . 3)))
(print (equal? (vector-assoc 5 (list->vector '((2 . 8))))
#f))
(newline)
; 10
(print (equal? ((cached-assoc '((2 . 8) (5 . 7)) 3) 5)
'(5 . 7)))
(print (equal? ((cached-assoc '((2 . 8) (5 . 3) (5 . 7)) 1) 5)
'(5 . 3)))
(print (equal? ((cached-assoc '((2 . 8)) 3) 5)
#f))
(newline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment