home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume10 / comobj.lisp / part04 / regress.l < prev   
Encoding:
Text File  |  1987-07-30  |  17.1 KB  |  538 lines

  1.  
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         regress.l
  5. ; RCS:          $Revision: 1.1 $
  6. ; SCCS:         %A% %G% %U%
  7. ; Description:  Regression Tests for COOL.
  8. ; Author:       James Kempf, HP/DCC
  9. ; Created:      24-Feb-87
  10. ; Modified:     25-Feb-87 08:45:24 (James Kempf)
  11. ; Language:     Lisp
  12. ; Package:      TEST
  13. ;
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. ;
  16. ; Copyright (c) 1987 Hewlett-Packard Corporation. All rights reserved.
  17. ;
  18. ; Use and copying of this software and preparation of derivative works based
  19. ; upon this software are permitted.  Any distribution of this software or
  20. ; derivative works must comply with all applicable United States export
  21. ; control laws.
  22. ; This software is made available AS IS, and Hewlett-Packard Corporation makes
  23. ; no warranty about the software, its performance or its conformity to any
  24. ; specification.
  25. ;
  26. ; Suggestions, comments and requests for improvement may be mailed to
  27. ; aiws@hplabs.HP.COM
  28.  
  29.  
  30. (provide "co-regress")
  31.  
  32. (in-package 'test)
  33.  
  34. (require "co")
  35.  
  36. (require "co-test")
  37.  
  38. (use-package 'co)
  39.  
  40.  
  41.  
  42. ;;Need the test macro from PCL
  43.  
  44. (import
  45.   '(
  46.     pcl:do-test
  47.   )
  48. )
  49.  
  50. ;;This is needed to be sure the Lisp functions are
  51. ;;  correctly redefined
  52.  
  53. (import-specialized-functions)
  54.  
  55. (do-test ("define-type" :return-value T)
  56.      (
  57.        (define-type car 
  58.          (:var name :gettable)
  59.          (:var top-speed :settable)
  60.          (:var turbo-p :initable)
  61.          :all-initable
  62.        )
  63.        car
  64.      )
  65.      ( (instancep 'car) NIL)
  66.      ( (typep 'car 'instance) NIL)
  67. )
  68.  
  69. (do-test "make-instance"
  70.       (instancep (setq c (make-instance 'car :name 'porsche)))
  71.       (=> c :typep 'car)
  72. )
  73.  
  74. (do-test ("make-instance error cases" :should-error T)
  75.       (make-instance NIL)
  76.       (make-instance (gensym))
  77.       (make-instance 'not-a-type)
  78.       (make-instance 'float)
  79.       (make-instance 'car :not-initkw 314159)
  80. )
  81.  
  82. (do-test ("make-instance syntax" :should-error T)
  83.       (make-instance)
  84.       (make-instance '(a b))
  85.       (make-instance 'car :boink)
  86.       (make-instance 'car :name)
  87.       (make-instance 'car 'truck 'van)
  88. )
  89.  
  90.  
  91.  
  92. (do-test ("the right methods there?" :return-value T)
  93.     ((supports-operation-p c :name)            T)
  94.     ((supports-operation-p c :set-name)        NIL)
  95.     ((supports-operation-p c :set-top-speed)   T)
  96.     ((supports-operation-p c :top-speed)       T)
  97.     ((supports-operation-p c :turbo-p)         NIL)
  98.     ((supports-operation-p c :set-turbo-p)     NIL)
  99.     ((supports-operation-p c :not-a-method)    NIL)
  100.     ((supports-operation-p c 'describe)        NIL)
  101.     ((supports-operation-p c 'init)            NIL)
  102.     ((supports-operation-p c 'channelprin)     NIL)
  103.     ((supports-operation-p c 'init)            NIL)
  104.     ((supports-operation-p c :describe)        T)
  105.     ((supports-operation-p c :print)           T)
  106.     ((supports-operation-p c :initialize)      T)
  107.     ((supports-operation-p c :initialize-variables)  T)
  108.     ((supports-operation-p c :init)            T)
  109.     ((supports-operation-p c :eql)             T)
  110.     ((supports-operation-p c :equal)           T)
  111.     ((supports-operation-p c :equalp)          T)
  112.     ((supports-operation-p c :typep)           T)
  113.     ((supports-operation-p c :copy)            T)
  114.     ((supports-operation-p c :copy-state)      T)
  115.     ((supports-operation-p c :copy-instance)   T)
  116. )
  117.  
  118.  
  119. (do-test ("typep" :return-value T)
  120.     ((typep c 'car)                           T)
  121.     ((typep c 'instance)                      T)
  122.     ((typep c t)                              T)
  123.     ((typep c 'integer)                       NIL)
  124.     ((typep '(frog) 'car)                     NIL)
  125.     ((type-of c)                              car)
  126. )
  127.  
  128. (do-test ("rename-type" :return-value T)
  129.     ((rename-type 'car 'auto)                 auto)
  130.     ((typep c 'car)                           NIL)
  131.     ((typep c 'auto)                          T)
  132.     ((type-of c)                              auto)
  133.     ((undefine-type 'car)                     NIL)
  134.     ((typep c 'auto)                          T)
  135.     ((typep c 'auto)                          T)
  136. )
  137.  
  138. (do-test ("rename-type error cases" :should-error T)
  139.     (rename-type 'float 'pneuname)
  140.     (rename-type 'auto 'auto)
  141.     (rename-type 'car 'auto)
  142. )
  143.  
  144. (do-test ("define-method error case" :should-error T)
  145.     (eval '(define-method (car :flat) ()))
  146. )
  147.  
  148. (do-test ("now that type car is renamed" :return-value T)
  149.     ((=> c :name)                        porsche)
  150.     ((=> c :set-top-speed 157)           157)
  151.     ((=> c :top-speed)                   157)
  152.     ((define-method (auto :sportscar-p) () (> top-speed 130))    (auto :sportscar-p))
  153.     ((=> c :sportscar-p)                 T)
  154. )
  155.  
  156.  
  157. (do-test ("define a new type car" :return-value T)
  158.     ((define-type car (:var railroad) (:var type) :all-settable)  car)
  159. )
  160.  
  161. (do-test ("now that we have a new type car" :return-value T)
  162.     ((=> c :name)  porsche) 
  163.     ((=> c :set-top-speed 157)  157) 
  164.     ((=> c :top-speed)  157)
  165.     ((define-method (auto :sportscar-p) () (> top-speed 130))    (auto :sportscar-p))
  166.     ((=> c :sportscar-p)                 T)
  167.     ((undefine-type 'car)                T)
  168. )
  169.  
  170.  
  171. (do-test ("type for rename-type and undefine-type" :return-value T)
  172.     ((define-type other)  other)
  173. )
  174.  
  175. (do-test ("rename-type syntax" :should-error T)
  176.     (rename-type 'auto NIL)
  177.     (rename-type 'other 'auto)
  178.     (rename-type NIL 'auto)
  179.     (rename-type '(a) 'other)
  180.     (rename-type 'other '(a b))
  181.     (rename-type)
  182.     (rename-type 'auto)
  183. )
  184.        
  185.  
  186. (do-test ("undefine-type" :return-value T)
  187.    ((undefine-type 'auto)                    T)
  188.    ((null (type-of c))                        NIL)
  189.    ((eq (type-of c) T)                        NIL)
  190.    ((member (type-of c) '(auto car))          NIL)
  191.    ((symbolp (type-of c))                     T)
  192.    ((undefine-type 'auto)                     NIL)
  193.    ((undefine-type 'other)                    T)
  194.    ((undefine-type 'float)                    NIL)
  195. )
  196.  
  197.  
  198. (do-test ("let's use those undefined types" :should-error T)
  199.    (make-instance 'auto)
  200.    (eval '(define-method (auto :burp) () T))
  201.    (=> c :name)
  202. )
  203.  
  204. (do-test ("send? to object with undefined type" :return-value T)
  205.  
  206.    ((send? c :name)  NIL)
  207.  
  208. )
  209.  
  210.  
  211. (do-test ("undefine-type syntax" :should-error T)
  212.    (undefine-type '(a big dog))
  213. )
  214.  
  215. (do-test ("define-type syntax" :should-error T)
  216.     (eval '(define-type)) 
  217.     (eval '(define-type (a list)))
  218.     (eval '(define-type actress ann-margret))
  219.     (eval '(define-type actress (ann-margret)))
  220.     (eval '(define-type actress (:var))) 
  221.     (eval '(define-type actress (:var :var))) 
  222.     (eval '(define-type actress (:var :a-keyword))) 
  223.     (eval '(define-type actress (:var twin) (:var not-twin) (:var twin))) 
  224.     (eval '(define-type actress (:var ann-margret ()))) 
  225.     (eval '(define-type actress (:var ann-margret dyan-cannon))) 
  226.     (eval '(define-type actress (:var ann-margret (:not-option lips))))
  227.     (eval '(define-type actress (:var ann-margret (:init))))
  228.     (eval '(define-type actress (:var ann-margret (:init 'one 'two))))
  229.     (eval '(define-type actress (:var ann-margret :not-an-option)))
  230.     (eval '(define-type actress (:var ann-margret (:gettable))))
  231. )
  232.     
  233. (do-test ("various define-types that should work" :return-value T)
  234.     ((undefine-type 'actress) NIL)
  235.     ((undefine-type 'self) NIL)
  236. )
  237.  
  238. (do-test ("define an actress" :return-value T)
  239.     ((define-type actress (:var actress))  actress)
  240. )
  241.     
  242. (do-test ("check self" :return-value T)
  243.     ((eval '(define-type self (:var me :settable (:init 'hit))))  self)
  244.     ((let ((self (make-instance 'self))) (=> self :me))  hit)
  245.  
  246. )
  247.  
  248. (do-test "get rid of self"
  249.     (undefine-type 'self)
  250. )
  251.  
  252. (do-test ("initial funny business setup" :return-value T)
  253.     ((define-type oedipus-rex)    oedipus-rex)
  254.     ((define-type laius (:inherit-from oedipus-rex))  laius)
  255.     ((define-type jocasta (:inherit-from laius))  jocasta)
  256. )
  257.  
  258. (do-test ("check for inheritence funny business" :should-error T)
  259.     (eval '(define-type oedipus-rex (:inherit-from oedipus-rex)))
  260.     (eval '(define-type oedipus-rex (:inherit-from laius)))
  261.     (eval '(define-type oedipus-rex (:inherit-from jocasta)))
  262. )
  263.  
  264. (do-test ("clean up after funny business check" :return-value T)    
  265.     ((undefine-type 'jocasta) T)
  266.     ((undefine-type 'laius) T)
  267.     ((undefine-type 'oedipus-rex) T)
  268. )
  269.      
  270. (do-test ("get rid of it" :return-value T)
  271.       ((undefine-type 'animal) NIL)
  272. )
  273.  
  274. (do-test ("general animal test" :return-value T)
  275.     ((list (makunbound 'name)
  276.        (makunbound 'num-legs)
  277.        (makunbound 'color)
  278.        (makunbound 'lives-where))  (name num-legs color lives-where))
  279.     ((define-type animal 
  280.          (:var name :gettable)
  281.              (:var num-legs :gettable)
  282.          (:var color (:init 'brown))
  283.          (:var lives-where (:init 'on-ground) :settable)
  284.          :all-initable
  285.          )  animal)
  286.     ((instancep (setq an-animal (make-instance 'animal :name 'horse :num-legs 4)))   T)
  287.     ((type-of an-animal)                 animal)
  288.     ((typep an-animal 'animal)           T)
  289.     ((supports-operation-p an-animal :name)               T)
  290.     ((supports-operation-p an-animal :set-name)           NIL)
  291.     ((supports-operation-p an-animal :num-legs)           T)
  292.     ((supports-operation-p an-animal :set-num-legs)       NIL)
  293.     ((supports-operation-p an-animal :color)              NIL)
  294.     ((supports-operation-p an-animal :set-color)          NIL)
  295.     ((supports-operation-p an-animal :lives-where)        T)
  296.     ((supports-operation-p an-animal :set-lives-where)    T)
  297.     ((=> an-animal :num-legs)            4)
  298.     ((=> an-animal :name)                horse)
  299.     ((=> an-animal :lives-where)         on-ground)
  300.     ((=> an-animal :set-lives-where 'ocean)  ocean)
  301.     ((=> an-animal :lives-where)         ocean)
  302. )
  303.  
  304. (do-test ("=> error case to animal" :should-error T)
  305.     (setq no-animal (make-instance 'animal :rocky 'bullwinkle))
  306.     name
  307.     (=> an-animal :set-name 'new-name)
  308.     name                              
  309.     num-legs                          
  310.     (=> an-animal :set-num-legs)      
  311.     (=> an-animal :set-num-legs 8)    
  312.     (=> an-animal :color)             
  313.     color                             
  314.     (=> an-animal :set-color 'red)    
  315.     lives-where                       
  316.     (=> an-animal :not-a-method)      
  317.     (=> an-animal :set-lives-where)   
  318. )
  319.  
  320.  
  321. (do-test ("=> syntax error check" :should-error T)
  322.     (eval '(=>))           
  323.     (eval '(=> an-animal)) 
  324.     (=> animal :lives-where)
  325.     (=> an-animal NIL)      
  326.     (=> NIL :lives-where)   
  327.     (=> an-animal :lives-where 'extra-parm)
  328. )
  329.  
  330.  
  331.  
  332. (do-test ("supports-operation-p syntax" :should-error T)
  333.     (supports-operation-p animal :lives-where) 
  334. )
  335.  
  336. (do-test ("supports-operation-p syntax" :return-value T)
  337.     ((supports-operation-p an-animal NIL)            NIL)
  338.     ((supports-operation-p NIL :lives-where)         NIL)
  339. )        
  340.  
  341.  
  342. (do-test ("instancep syntax" :return-value T)
  343.     ((instancep 'float)                     NIL)
  344.     ((instancep an-animal)                  T)
  345. )
  346.  
  347.  
  348.  
  349. (do-test ("send? to animal"  :return-value T)
  350.     ((send? an-animal :name)                horse)
  351.     ((send? an-animal :set-name 'new-name)  NIL)
  352.     ((send? an-animal :num-legs)            4)
  353.     ((send? an-animal :set-num-legs)        NIL)
  354.     ((send? an-animal :set-num-legs 8)      NIL)
  355.     ((send? an-animal :color)               NIL)
  356.     ((send? an-animal :set-color 'red)      NIL)
  357.     ((send? an-animal :lives-where)         ocean)
  358.     ((send? an-animal :not-a-method)        NIL)
  359.     ((send? an-animal :set-lives-where 'mars)  mars)
  360.     ((send? an-animal :lives-where)         mars)
  361.     ((send? an-animal NIL)            NIL)
  362.     ((send? NIL :lives-where)         NIL)
  363. )
  364.  
  365.  
  366. (do-test ("send? syntax and error case" :should-error T)
  367.     (send? an-animal :set-lives-where)
  368.     (eval '(send?)) 
  369.     (eval '(send? an-animal))
  370.     (send? animal :lives-where) 
  371.     (send? an-animal :lives-where 'extra-parm) 
  372. )
  373.  
  374.  
  375.  
  376. (do-test ("define-method in general" :return-value T)
  377.     ((define-method (animal :num-legs) ()
  378.         num-legs)            (animal :num-legs))
  379.     ((define-method (animal :num-legs) ()
  380.         num-legs)            (animal :num-legs))
  381.     ((define-method (animal :set-num-legs) (new-num-legs)
  382.         (setq num-legs new-num-legs))
  383.                                      (animal :set-num-legs))
  384.     ((=> an-animal :num-legs)  4)
  385.     ((=> an-animal :num-legs)  4)
  386.     ((=> an-animal :set-num-legs 2)  2)
  387.     ((=> an-animal :num-legs)  2)
  388.     ((define-method (animal :doc) () "doctari" "veterinarian")  (animal :doc))
  389.     ((define-method (animal :quote-two) 'train (list quote train))  (animal :quote-two))
  390. )
  391.  
  392.  
  393. (do-test ("define-method syntax" :should-error T)
  394.     (eval '(define-method (float :nines) () ))
  395.     (=> an-animal :set-num-legs)
  396.     (=> an-animal :set-num-legs 1 'and 'a 2)
  397.     (eval '(define-method))
  398.     (eval '(define-method 'frog))
  399.     (eval '(define-method (corn mash)))
  400.     (eval '(define-method (animal mash) bleach))
  401. )
  402.  
  403.  
  404. (do-test ("undefine-method" :return-value T)
  405.     ((=> (make-instance 'animal) :doc)  "veterinarian")
  406.     ((undefine-method 'animal 'not-a-method)  NIL)
  407.     ((undefine-method 'animal '(a))  NIL)
  408.     ((undefine-method 'animal :quote-two)  T)
  409.     ((undefine-method 'animal :quote-two)  NIL)
  410.     ((=> an-animal :doc)  "veterinarian")
  411.     ((undefine-method 'animal :doc)  T)
  412. )
  413.  
  414. (do-test ("undefine-method error cases" :should-error T)
  415.     (=> an-animal :doc)
  416.     (undefine-method '(a) :quote-two)
  417.     (eval '(undefine-method))
  418.     (undefine-method 'not-a-type :quote-two)
  419.     (undefine-method 'integer :quote-two)
  420. )
  421.  
  422.        
  423. (do-test ("undefine bird" :return-value T)
  424.       ((undefine-type 'bird)                   NIL)
  425. )
  426.  
  427. (do-test ("define bird type" :return-value T)
  428.     ((define-type bird 
  429.          (:inherit-from animal 
  430.                 :init-keywords 
  431.                 (:methods :name :num-legs :set-num-legs 
  432.                       :lives-where :set-lives-where
  433.                       )
  434.                 )
  435.          (:var aquatic-p (:init NIL))
  436.          :all-initable
  437.          :all-settable
  438.          )                           bird)
  439. )
  440.  
  441.  
  442. (do-test ("make bird instances" :return-value T)
  443.     ((instancep (setf ibis
  444.     (make-instance 'bird :name 'ibis :num-legs 2 :aquatic-p T)))   T)
  445.     ((=> ibis :name)                      ibis)
  446.     ((=> ibis :num-legs)                  2)
  447.     ((=> ibis :aquatic-p)                 T)
  448.     ((=> ibis :lives-where)               on-ground)
  449. )
  450.  
  451.  
  452. (do-test ("make-instance error cases" :should-error T)
  453.     (make-instance 'bird :num-legs)
  454.     (make-instance 'bird :not-init-keyword 89) 
  455.     (=> ibis :color)               
  456. )
  457.  
  458.  
  459. (do-test ("undefine horse" :return-value T)
  460.     ((undefine-type 'horse)                   NIL)
  461. )
  462.  
  463. (do-test ("define horse type" :return-value T)
  464.  
  465.     ((define-type horse
  466.          (:inherit-from animal 
  467.                 :init-keywords 
  468.                 (:methods :except :num-legs :set-num-legs
  469.                       )
  470.                 )
  471.          (:var races-won (:init NIL) :settable)
  472.          )                           horse)
  473. )
  474.  
  475.  
  476. (do-test ("make horse instances" :return-value T)
  477.     ((instancep (setf wildfire
  478.     (make-instance 'horse :name 'wildfire)))   T)
  479.     ((=> wildfire :name)                      wildfire)
  480.     ((=> wildfire :lives-where)               on-ground)
  481. )
  482.  
  483. (do-test ("make horse instance error cases" :should-error T)
  484.     (=> wildfire :num-legs) 
  485.     (=> wildfire :color)    
  486.     (=> wildfire :aquatic-p)
  487.     (make-instance 'horse :not-init-keyword 89) 
  488.     (make-instance 'horse :name) 
  489. )
  490.  
  491.  
  492. (do-test ("call method on horse" :return-value T)
  493.     ((define-method (horse horses-name) () (call-method (animal :name))) 
  494.                                               (horse horses-name))
  495.     ((=> wildfire 'horses-name)               wildfire)
  496.     ((define-method (horse :num-legs) () (call-method (animal :num-legs))) 
  497.                                               (horse :num-legs))
  498.     ((define-method (horse :set-num-legs) (new-num-legs) (call-method (animal :set-num-legs) new-num-legs))
  499.                                               (horse :set-num-legs))
  500.     ((=> wildfire :set-num-legs 6)            6)
  501.     ((=> wildfire :num-legs)                  6)
  502. )
  503.  
  504.  
  505. (do-test ("apply method on horse" :return-value T)
  506.     ((define-method (horse horses-name) () (apply-method (animal :name) ())) 
  507.                                           (horse horses-name))
  508.     ((=> wildfire 'horses-name)                wildfire)
  509.     ((define-method (horse :num-legs) () (apply-method (animal :num-legs) ())) 
  510.                                           (horse :num-legs))
  511.  
  512.     ((define-method (horse :set-num-legs) (new-num-legs) (apply-method (animal :set-num-legs) (list new-num-legs)))
  513.                                           (horse :set-num-legs))
  514.     ((=> wildfire :set-num-legs 6)          6)
  515.     ((=> wildfire :num-legs)                     6)
  516. )           
  517.  
  518. (do-test ("call-method syntax error cases" :should-error T)
  519.     (eval '(call-method (wildfire :name))) 
  520.     (eval '(apply-method (horse :name)))   
  521.     (eval '(apply-method (horse :name) 'not-a-list)) 
  522.     (eval '(define-method (horse horses-name) () (apply-method (horse)) )) 
  523.     (eval '(define-method (horse horses-name) () (apply-method (horse :name)) )) 
  524.     (eval '(define-method (horse horses-name) () (apply-method (horse :name) 'not-a-list) ))  
  525.     (eval '(define-method (horse horses-name) () (apply-method (horse :name 'should-not-be-here)) )) 
  526. )
  527.  
  528. (do-test ("undefine-method part II" :return-value T)
  529.     ((undefine-method 'horse 'unknown-method)  NIL)
  530.     ((undefine-method 'horse 'horses-name)  T)
  531.     ((undefine-method 'horse 'horses-name)  NIL)
  532. )
  533.  
  534. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  535.  
  536.  
  537.