Changeset 213 for branches/new-datamodel


Ignore:
Timestamp:
02/26/10 15:50:44 (15 years ago)
Author:
lgiessmann
Message:

new-datamodel: added some unit-tests for the base class TypableC; optimized the function add-type.

Location:
branches/new-datamodel/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/new-datamodel/src/model/datamodel.lisp

    r212 r213  
    9595
    9696
     97;;TODO: add-type/add-parent/add-<x>-identifier handle situation where
     98;;      new objects hve to be bound in an earlier revision than one
     99;;      where a object is already bound
    97100;;TODO: finalize add-reifier
    98101;;TODO: replace add-to-version-history in VersionedAssociationC with a pseudo
     
    171174
    172175(defpclass TypableC()
    173   ((instance-of :associate (TypeAssociationC type-topic)
     176  ((instance-of :associate (TypeAssociationC typable-construct)
    174177                :inherit t
    175178                :documentation "Contains all association-objects that contain
     
    15281531                (filter-slot-value-by-revision construct 'player
    15291532                                               :start-revision revision))))
     1533      ;;TODO: search a player-assoc for the passed construct that was set in an older version
    15301534      (cond ((and already-set-player
    15311535                  (eql (first already-set-player) player-topic))
     
    17641768           (map 'list #'type-topic
    17651769                (filter-slot-value-by-revision construct 'instance-of
    1766                                                :start-revision revision))))
    1767       (cond ((and already-set-type
    1768                   (eql (first already-set-type) type-topic))
     1770                                               :start-revision revision)))
     1771          (same-type-assoc
     1772           (loop for type-assoc in (slot-p construct 'instance-of)
     1773              when (eql (type-topic type-assoc) type-topic)
     1774              return type-assoc)))
     1775      (when (and already-set-type
     1776                 (not (eql type-topic already-set-type)))
     1777        (error "From add-type(): ~a can't be typed by ~a since it is typed by ~a"
     1778               construct type-topic already-set-type))
     1779      (cond (already-set-type
    17691780             (let ((type-assoc
    17701781                    (loop for type-assoc in (slot-p construct 'instance-of)
     
    17721783                       return type-assoc)))
    17731784               (add-to-version-history type-assoc :start-revision revision)))
    1774             ((not already-set-type)
     1785            (same-type-assoc
     1786             (add-to-version-history same-type-assoc :start-revision revision))
     1787            (t
    17751788             (let ((assoc
    17761789                    (make-instance 'TypeAssociationC
    17771790                                   :type-topic type-topic
    17781791                                   :typable-construct construct)))
    1779                (add-to-version-history assoc :start-revision revision)))
    1780             (t
    1781              (error "From add-type(): ~a can't be typed by ~a since it is already typed by the topic ~a"
    1782                     construct type-topic already-set-type)))
    1783       construct)))
     1792               (add-to-version-history assoc :start-revision revision)))))
     1793    construct))
    17841794
    17851795
  • TabularUnified branches/new-datamodel/src/unit_tests/datamodel_test.lisp

    r212 r213  
    3131           :test-OccurrenceC
    3232           :test-VariantC
    33            :test-NameC))
     33           :test-NameC
     34           :test-TypableC))
    3435
    3536
     
    690691      (add-parent name-2 top-1 :revision revision-8)
    691692      (is (eql top-1 (parent name-2))))))
     693
     694
     695(test test-TypableC ()
     696  "Tests various functions of the base class TypableC."
     697  (with-fixture with-empty-db (*db-dir*)
     698    (let ((name-1 (make-instance 'NameC))
     699          (name-2 (make-instance 'NameC))
     700          (top-1 (make-instance 'TopicC))
     701          (top-2 (make-instance 'TopicC))
     702          (revision-0-5 50)
     703          (revision-1 100)
     704          (revision-2 200)
     705          (revision-3 300))
     706      (setf *TM-REVISION* revision-1)
     707      (is-false (instance-of name-1))
     708      (add-type name-1 top-1)
     709      (is (eql top-1 (instance-of name-1)))
     710      (is-false (instance-of name-1 :revision revision-0-5))
     711      (is (eql top-1 (instance-of name-1 :revision revision-2)))
     712      (signals error (add-type name-1 top-2))
     713      (add-type name-2 top-1 :revision revision-2)
     714      (is (= (length (union (list name-1 name-2)
     715                            (used-as-type top-1))) 2))
     716      (is (= (length (union (list name-1)
     717                            (used-as-type top-1
     718                                          :revision revision-1))) 1))
     719      (delete-type name-1 top-1 :revision revision-3)
     720      (is-false (instance-of name-1))
     721      (is (= (length (union (list name-2)
     722                            (used-as-type top-1))) 1))
     723      (add-type name-1 top-1 :revision revision-3)
     724      (is (eql top-1 (instance-of name-1)))
     725      (is (= (length (union (list name-1 name-2)
     726                            (used-as-type top-1))) 2))
     727      (is (= (length (slot-value top-1 'd::used-as-type)) 2)))))
    692728     
    693729
     
    708744  (it.bese.fiveam:run! 'test-VariantC)
    709745  (it.bese.fiveam:run! 'test-NameC)
     746  (it.bese.fiveam:run! 'test-TypableC)
    710747)
Note: See TracChangeset for help on using the changeset viewer.