Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; (rect position dimension colour) makes a rectangle by getting
- ;; its position (top,left corner) and dimensions along with its colour
- ;; rect: Coordinate Coordinate Str -> (list PrimTriangle PrimTriangle)
- ;; Tests:
- (check-expect (rect (make-posn 0 0) (make-posn 20 30) "Red")
- (list (make-prim-triangle
- (make-posn 0 0)
- (make-posn 20 0)
- (make-posn 20 30)
- "Red")
- (make-prim-triangle
- (make-posn 0 0)
- (make-posn 20 30)
- (make-posn 0 30)
- "Red")))
- (check-expect (rect (make-posn 50 20) (make-posn 10 20) "Red")
- (list (make-prim-triangle
- (make-posn 50 20)
- (make-posn 60 20)
- (make-posn 60 40)
- "Red")
- (make-prim-triangle
- (make-posn 50 20)
- (make-posn 60 40)
- (make-posn 50 40)
- "Red")))
- (check-expect (rect (make-posn 0 0) (make-posn 0 0) "Red")
- (list (make-prim-triangle
- (make-posn 0 0)
- (make-posn 0 0)
- (make-posn 0 0)
- "Red")
- (make-prim-triangle
- (make-posn 0 0)
- (make-posn 0 0)
- (make-posn 0 0)
- "Red")))
- ;; (losID-in-list shapeID shape-list) returns the list in ShapeList
- ;; that contains the same name as the shapeID that is given in parameter
- ;; losID-in-list: ShapeID ShapeList -> (list Shape)
- ;; (get-picture-ids/acc picture shape-list losID) consumes a Picture
- ;; and a ShapeList, and produces a list of ShapeIDs that occur in the
- ;; Picture, with no duplicates
- ;; get-picture-ids/acc: Picture ShapeList (listof ShapeID) -> (listof ShapeID)
- ;; (get-picture-ids picture shape-list) is a wrapper function for
- ;; get-picture-ids/acc
- ;; get-picture-ids: Picture ShapeList -> (listof ShapeID)
- ;; (add-offsets offset1 offset2 loPE) adds up all the offsets
- ;; and returns the posn value for them
- ;; add-offsets Coordinate Coordinate Coordinate -> Posn
- ;; (picture->primitives/gen picture shape-list loPE) consumes a Picture and
- ;; a ShapeList, and produces a list of PrimElements that can be rendered in
- ;; the order that elements are drawn
- ;; picture->primitive/gen: Picture ShapeList (list Nat Nat) ->
- ;; (listof PrimElements)
- ;; (picture->primitives picture shape-list) is a wrapper function for
- ;; picture->primitives/gen
- ;; Example:
- (check-expect (picture->primitives '(((20 30) ice-cream)) summer-shapes)
- (list
- (make-prim-triangle
- (make-posn 20 70)
- (make-posn 40 70)
- (make-posn 30 120)
- "Burlywood")
- (make-prim-circle (make-posn 30 65) 10 "LightBlue")
- (make-prim-circle (make-posn 30 55) 10 "Pink")))
- ;; picture->primitives: Pictures ShapeList -> (listof PrimElements)
- ;; (drawing->image whole-image) consumes a BundledDrawing and produces an Image
- ;; drawing->image: BundledDrawing -> Image
- Q3)============================================================================
- ;; subtree-template: StringTree -> Any
- ;; stringtree-template: StringTree -> Any
- ;; (lostringtree-insert name insert-path loST) consumes a name, a
- ;; insertion-path, and a listof StringTree. It is a mutually recursive function
- ;; and does something similar to stringtree-insert. Insertion-path indicates
- ;; the path to traverse in order to insert name within the stringtree
- ;; lostringtree-insert: Str (listof Nat) (listof StringTree) -> StringTree
- ;; (insert-name name insertion-path-num stringtree) inserts the name according
- ;; to insertion-path-num which is the index of where the name should be placed
- ;; in the stringtree
- ;; insert-name: Str Nat (listof StringTree) -> StringTree
- ;; (stringtree-insert name insertion-path stringtree) consumes a name, a
- ;; insertion-path, and a StringTree. Insertion-path indicates the path to
- ;; traverse in order to insert name within the stringtree
- ;; Example:
- (check-expect (stringtree-insert "Daigo" (list 0) celebs)
- '("Punk"
- (("Daigo"())
- ("Tokido" ())
- ("Marn" (("JWong" ()) ("Ricki" ()) ("KBrad" ())))
- ("Smug" (("Fuudo" ())
- ("Mena" (("Caba" ())
- ("NuckleDu" ())))
- ("SnakeEyez" ()))))))
- (check-error (stringtree-insert "Daigo" empty celebs)
- "root node cannot be replaced")
- ;; stringtree-insert: Str (listof Nat) StringTree -> StringTree
- ;; Tests:
- (check-expect (stringtree-insert "Daigo" (list 2 1 1) celebs)
- '("Punk"
- (("Tokido" ())
- ("Marn" (("JWong" ()) ("Ricki" ()) ("KBrad" ())))
- ("Smug" (("Fuudo" ())
- ("Mena" (("Caba" ())
- ("Daigo"())
- ("NuckleDu" ())))
- ("SnakeEyez" ()))))))
- (check-expect (stringtree-insert "Daigo" (list 2 1 1 0) celebs)
- '("Punk"
- (("Tokido" ())
- ("Marn" (("JWong" ()) ("Ricki" ()) ("KBrad" ())))
- ("Smug" (("Fuudo" ())
- ("Mena" (("Caba" ())
- ("NuckleDu" (("Daigo" ())))))
- ("SnakeEyez" ()))))))
- (check-error (stringtree-insert "Daigo" (list 2 5 1) celebs)
- "first number in insert-path is too big")
- (check-error (stringtree-insert "Daigo" (list 2 5 ) celebs)
- "insertion-path-num is longer than length of stringtree")
- Q4)===================================================================
- ;; (transpose table) produces a table with its columns and rows
- ;; switched.
- ;; Example:
- (check-expect (transpose mixed-table)
- (list (list 3 3.2 '(1 2 3) "what")
- (list (make-posn 4 2) #\q 4 "is")
- (list "hello" #\r true "this")
- (list false "baby" false "even?")
- (list 4 -4.2 "quack" "Oy!")
- (list -3 -6 -9 "minus 12")))
- ;; transpose: Table -> Table
- ;; Tests:
- (check-expect (transpose (list (list 123 "afdsa" '(1 "F" 2 'ss))
- (list "fahg" '("AsdF" "Aasdf" "erg") 0000)
- (list "!@#3" 1222134 1)))
- (list (list 123 "fahg" "!@#3")
- (list "afdsa" '("AsdF" "Aasdf" "erg") 1222134)
- (list '(1 "F" 2 'ss) 0000 1)))
- (check-expect (transpose empty) empty)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement