Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 6.83 KB | None | 0 0
  1.  
  2. ;; (rect position dimension colour) makes a rectangle by getting
  3. ;; its position (top,left corner) and dimensions along with its colour
  4.  
  5. ;; rect: Coordinate Coordinate Str -> (list PrimTriangle PrimTriangle)
  6.  
  7. ;; Tests:
  8. (check-expect (rect (make-posn 0 0) (make-posn 20 30) "Red")
  9.               (list (make-prim-triangle
  10.                      (make-posn 0 0)
  11.                      (make-posn 20 0)
  12.                      (make-posn 20 30)
  13.                      "Red")
  14.                     (make-prim-triangle
  15.                      (make-posn 0 0)
  16.                      (make-posn 20 30)
  17.                      (make-posn 0 30)
  18.                      "Red")))
  19. (check-expect (rect (make-posn 50 20) (make-posn 10 20) "Red")
  20.               (list (make-prim-triangle
  21.                      (make-posn 50 20)
  22.                      (make-posn 60 20)
  23.                      (make-posn 60 40)
  24.                      "Red")
  25.                     (make-prim-triangle
  26.                      (make-posn 50 20)
  27.                      (make-posn 60 40)
  28.                      (make-posn 50 40)
  29.                      "Red")))
  30. (check-expect (rect (make-posn 0 0) (make-posn 0 0) "Red")
  31.               (list (make-prim-triangle
  32.                      (make-posn 0 0)
  33.                      (make-posn 0 0)
  34.                      (make-posn 0 0)
  35.                      "Red")
  36.                     (make-prim-triangle
  37.                      (make-posn 0 0)
  38.                      (make-posn 0 0)
  39.                      (make-posn 0 0)
  40.                      "Red")))
  41.  
  42. ;; (losID-in-list shapeID shape-list) returns the list in ShapeList
  43. ;; that contains the same name as the shapeID that is given in parameter
  44.  
  45. ;; losID-in-list: ShapeID ShapeList -> (list Shape)
  46.  
  47. ;; (get-picture-ids/acc picture shape-list losID) consumes a Picture
  48. ;; and a ShapeList, and produces a list of ShapeIDs that occur in the
  49. ;; Picture, with no duplicates
  50.  
  51. ;; get-picture-ids/acc: Picture ShapeList (listof ShapeID) -> (listof ShapeID)
  52.  
  53. ;; (get-picture-ids picture shape-list) is a wrapper function for
  54. ;; get-picture-ids/acc
  55.  
  56. ;; get-picture-ids: Picture ShapeList -> (listof ShapeID)
  57.  
  58. ;; (add-offsets offset1 offset2 loPE) adds up all the offsets
  59. ;; and returns the posn value for them
  60.  
  61. ;; add-offsets Coordinate Coordinate Coordinate -> Posn
  62.  
  63. ;; (picture->primitives/gen picture shape-list loPE) consumes a Picture and
  64. ;; a ShapeList, and produces a list of PrimElements that can be rendered in
  65. ;; the order that elements are drawn
  66.  
  67. ;; picture->primitive/gen: Picture ShapeList (list Nat Nat) ->
  68. ;;                                           (listof PrimElements)
  69.  
  70. ;; (picture->primitives picture shape-list) is a wrapper function for
  71. ;; picture->primitives/gen
  72.  
  73. ;; Example:
  74. (check-expect (picture->primitives '(((20 30) ice-cream)) summer-shapes)
  75.               (list
  76.                (make-prim-triangle
  77.                 (make-posn 20 70)
  78.                 (make-posn 40 70)
  79.                 (make-posn 30 120)
  80.                 "Burlywood")
  81.                (make-prim-circle (make-posn 30 65) 10 "LightBlue")
  82.                (make-prim-circle (make-posn 30 55) 10 "Pink")))
  83. ;; picture->primitives: Pictures ShapeList -> (listof PrimElements)
  84.  
  85. ;; (drawing->image whole-image) consumes a BundledDrawing and produces an Image
  86.  
  87. ;; drawing->image: BundledDrawing -> Image
  88.  
  89. Q3)============================================================================
  90.  
  91. ;; subtree-template: StringTree -> Any
  92. ;; stringtree-template: StringTree -> Any
  93.  
  94. ;; (lostringtree-insert name insert-path loST) consumes a name, a
  95. ;; insertion-path, and a listof StringTree. It is a mutually recursive function
  96. ;; and does something similar to stringtree-insert. Insertion-path indicates
  97. ;; the path to traverse in order to insert name within the stringtree
  98.  
  99. ;; lostringtree-insert: Str (listof Nat) (listof StringTree) -> StringTree
  100.  
  101. ;; (insert-name name insertion-path-num stringtree) inserts the name according
  102. ;; to insertion-path-num which is the index of where the name should be placed
  103. ;; in the stringtree
  104.  
  105. ;; insert-name: Str Nat (listof StringTree) -> StringTree
  106.  
  107. ;; (stringtree-insert name insertion-path stringtree) consumes a name, a
  108. ;; insertion-path, and a StringTree. Insertion-path indicates the path to
  109. ;; traverse in order to insert name within the stringtree
  110.  
  111. ;; Example:
  112. (check-expect (stringtree-insert "Daigo" (list 0) celebs)
  113.               '("Punk"
  114.                 (("Daigo"())
  115.                  ("Tokido" ())
  116.                  ("Marn" (("JWong" ()) ("Ricki" ()) ("KBrad" ())))
  117.                  ("Smug" (("Fuudo" ())
  118.                           ("Mena" (("Caba" ())
  119.                                    ("NuckleDu" ())))
  120.                           ("SnakeEyez" ()))))))
  121. (check-error (stringtree-insert "Daigo" empty celebs)
  122.              "root node cannot be replaced")
  123. ;; stringtree-insert: Str (listof Nat) StringTree -> StringTree
  124.  
  125. ;; Tests:
  126. (check-expect (stringtree-insert "Daigo" (list 2 1 1) celebs)
  127.               '("Punk"
  128.                 (("Tokido" ())
  129.                  ("Marn" (("JWong" ()) ("Ricki" ()) ("KBrad" ())))
  130.                  ("Smug" (("Fuudo" ())
  131.                           ("Mena" (("Caba" ())
  132.                                    ("Daigo"())
  133.                                    ("NuckleDu" ())))
  134.                           ("SnakeEyez" ()))))))
  135. (check-expect (stringtree-insert "Daigo" (list 2 1 1 0) celebs)
  136.               '("Punk"
  137.                 (("Tokido" ())
  138.                  ("Marn" (("JWong" ()) ("Ricki" ()) ("KBrad" ())))
  139.                  ("Smug" (("Fuudo" ())
  140.                           ("Mena" (("Caba" ())
  141.                                    ("NuckleDu" (("Daigo" ())))))
  142.                           ("SnakeEyez" ()))))))
  143. (check-error (stringtree-insert "Daigo" (list 2 5 1) celebs)
  144.              "first number in insert-path is too big")
  145. (check-error (stringtree-insert "Daigo" (list 2 5 ) celebs)
  146.              "insertion-path-num is longer than length of stringtree")
  147.  
  148.  
  149. Q4)===================================================================
  150. ;; (transpose table) produces a table with its columns and rows
  151. ;; switched.
  152. ;; Example:
  153. (check-expect (transpose mixed-table)
  154.               (list (list 3 3.2 '(1 2 3) "what")
  155.                     (list (make-posn 4 2) #\q 4 "is")
  156.                     (list "hello" #\r true "this")
  157.                     (list false "baby" false "even?")
  158.                     (list 4 -4.2 "quack" "Oy!")
  159.                     (list -3 -6 -9 "minus 12")))
  160. ;; transpose: Table -> Table
  161. ;; Tests:
  162. (check-expect (transpose (list (list 123 "afdsa" '(1 "F" 2 'ss))
  163.                                (list "fahg" '("AsdF" "Aasdf" "erg") 0000)
  164.                                (list "!@#3" 1222134 1)))
  165.               (list (list 123 "fahg" "!@#3")
  166.                     (list "afdsa" '("AsdF" "Aasdf" "erg") 1222134)
  167.                     (list '(1 "F" 2 'ss) 0000 1)))
  168. (check-expect (transpose empty) empty)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement