Changeset 227


Ignore:
Timestamp:
03/16/10 11:32:28 (15 years ago)
Author:
lgiessmann
Message:

new-datamodel: added some unit-tests for equivalent-constructs --> OccurrenceC, NameC, VariantC; changed some "dangerous" code-sections in equivalent-construct

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

Legend:

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

    r226 r227  
    14461446;;; OccurrenceC
    14471447(defmethod equivalent-construct ((construct OccurrenceC)
    1448                                  &key (start-revision 0) (charvalue "")
     1448                                 &key (start-revision 0) (reifier nil)
     1449                                 (item-identifiers nil) (charvalue "")
    14491450                                 (themes nil) (instance-of nil)
    1450                                  (datatype *xml-string*))
     1451                                 (datatype ""))
    14511452  (declare (type (or null TopicC) instance-of) (string datatype)
    1452            (ignorable start-revision charvalue themes instance-of))
     1453           (ignorable start-revision charvalue themes instance-of
     1454                      reifier item-identifiers))
    14531455  (let ((equivalent-characteristic (call-next-method)))
    1454     (and equivalent-characteristic
    1455          (string= (datatype construct) datatype))))
     1456    (or (and equivalent-characteristic
     1457             (string= (datatype construct) datatype))
     1458        (equivalent-reifiable-construct construct reifier item-identifiers
     1459                                        :start-revision start-revision))))
    14561460
    14571461
    14581462;;; VariantC
    14591463(defmethod equivalent-construct ((construct VariantC)
    1460                                  &key (start-revision 0) (charvalue "")
    1461                                  (themes nil) (datatype *xml-string*))
    1462   (declare (string datatype) (ignorable start-revision charvalue themes))
     1464                                 &key (start-revision 0) (reifier nil)
     1465                                 (item-identifiers nil) (charvalue "")
     1466                                 (themes nil) (datatype ""))
     1467  (declare (string datatype) (ignorable start-revision charvalue themes
     1468                                        reifier item-identifiers))
    14631469  (let ((equivalent-characteristic (call-next-method)))
    1464     (and equivalent-characteristic
    1465          (string= (datatype construct) datatype))))
     1470    (or (and equivalent-characteristic
     1471             (string= (datatype construct) datatype))
     1472        (equivalent-reifiable-construct construct reifier item-identifiers
     1473                                        :start-revision start-revision))))
    14661474
    14671475
    14681476;;; NameC
    14691477(defmethod equivalent-construct ((construct NameC)
    1470                                  &key (start-revision 0) (charvalue "")
     1478                                 &key (start-revision 0) (reifier nil)
     1479                                 (item-identifiers nil) (charvalue "")
    14711480                                 (themes nil) (instance-of nil))
    14721481  (declare (type (or null TopicC) instance-of)
    1473            (ignorable start-revision charvalue instance-of themes))
     1482           (ignorable start-revision charvalue instance-of themes
     1483                      reifier item-identifiers))
    14741484  (call-next-method))
    14751485 
     
    17601770    (declare (integer start-revision) (list item-identifiers)
    17611771             (type (or null TopicC) reifier))
    1762     (or (eql reifier (reifier construct :revision start-revision))
    1763         (intersection (item-identifiers construct :revision start-revision)
    1764                       item-identifiers))))
     1772    (or (and (reifier construct :revision start-revision)
     1773             (eql reifier (reifier construct :revision start-revision)))
     1774        (and (item-identifiers construct :revision start-revision)
     1775             (intersection (item-identifiers construct :revision start-revision)
     1776                           item-identifiers)))))
    17651777
    17661778
  • TabularUnified branches/new-datamodel/src/unit_tests/datamodel_test.lisp

    r226 r227  
    1717  (:import-from :exceptions
    1818                duplicate-identifier-error)
     19  (:import-from :constants
     20                *xml-string*)
    1921  (:export :run-datamodel-tests
    2022           :datamodel-test
     
    4951           :test-delete-AssociationC
    5052           :test-delete-RoleC
    51            :test-equivalent-PointerC))
     53           :test-equivalent-PointerC
     54           :test-equivalent-OccurrenceC
     55           :test-equivalent-NameC
     56           :test-equivalent-VariantC))
    5257
    5358
     
    13571362
    13581363
     1364(test test-equivalent-OccurrenceC ()
     1365  "Tests the functions equivalent-construct depending on OccurrenceC."
     1366  (with-fixture with-empty-db (*db-dir*)
     1367    (let ((occ-1 (make-instance 'd:OccurrenceC :charvalue "occ-1"))
     1368          (type-1 (make-instance 'd:TopicC))
     1369          (type-2 (make-instance 'd:TopicC))
     1370          (scope-1 (make-instance 'd:TopicC))
     1371          (scope-2 (make-instance 'd:TopicC))
     1372          (scope-3 (make-instance 'd:TopicC))
     1373          (reifier-1 (make-instance 'd:TopicC))
     1374          (reifier-2 (make-instance 'd:TopicC))
     1375          (ii-1 (make-instance 'd:ItemIdentifierC :uri "ii-1"))
     1376          (ii-2 (make-instance 'd:ItemIdentifierC :uri "ii-2"))
     1377          (revision-0-5 50)
     1378          (version-1 100))
     1379      (setf *TM-REVISION* version-1)
     1380      (add-type occ-1 type-1)
     1381      (add-theme occ-1 scope-1)
     1382      (add-theme occ-1 scope-2)
     1383      (is-true (d::equivalent-construct
     1384                occ-1 :charvalue "occ-1" :datatype constants:*xml-string*
     1385                :instance-of type-1 :themes (list scope-2 scope-1)))
     1386      (is-false (d::equivalent-construct
     1387                 occ-1 :charvalue "occ-1" :datatype constants:*xml-string*
     1388                 :instance-of type-1 :themes (list scope-2 scope-1)
     1389                 :start-revision revision-0-5))
     1390      (is-false (d::equivalent-construct
     1391                 occ-1 :charvalue "occ-1" :datatype constants:*xml-string*
     1392                 :instance-of type-2 :themes (list scope-1 scope-2)))
     1393      (is-false (d::equivalent-construct
     1394                 occ-1 :charvalue "occ-1" :datatype constants:*xml-string*
     1395                 :instance-of type-1 :themes (list scope-3 scope-2)))
     1396      (is-false (d::equivalent-construct
     1397                 occ-1 :charvalue "occ-1"
     1398                 :instance-of type-1 :themes (list scope-1 scope-2)))
     1399      (is-false (d::equivalent-construct
     1400                 occ-1 :charvalue "occ-2" :datatype constants:*xml-string*
     1401                 :instance-of type-1 :themes (list scope-2 scope-1)))
     1402      (add-item-identifier occ-1 ii-1)
     1403      (is-true (d::equivalent-construct occ-1 :item-identifiers (list ii-1)))
     1404      (is-false (d::equivalent-construct occ-1 :item-identifiers (list ii-2)))
     1405      (add-reifier occ-1 reifier-1)
     1406      (is-true (d::equivalent-construct occ-1 :reifier reifier-1))
     1407      (is-false (d::equivalent-construct occ-1 :reifier reifier-2)))))
     1408
     1409
     1410(test test-equivalent-NameC ()
     1411  "Tests the functions equivalent-construct depending on NameC."
     1412  (with-fixture with-empty-db (*db-dir*)
     1413    (let ((nam-1 (make-instance 'd:NameC :charvalue "nam-1"))
     1414          (type-1 (make-instance 'd:TopicC))
     1415          (type-2 (make-instance 'd:TopicC))
     1416          (scope-1 (make-instance 'd:TopicC))
     1417          (scope-2 (make-instance 'd:TopicC))
     1418          (scope-3 (make-instance 'd:TopicC))
     1419          (reifier-1 (make-instance 'd:TopicC))
     1420          (reifier-2 (make-instance 'd:TopicC))
     1421          (ii-1 (make-instance 'd:ItemIdentifierC :uri "ii-1"))
     1422          (ii-2 (make-instance 'd:ItemIdentifierC :uri "ii-2"))
     1423          (revision-0-5 50)
     1424          (version-1 100))
     1425      (setf *TM-REVISION* version-1)
     1426      (add-type nam-1 type-1)
     1427      (add-theme nam-1 scope-1)
     1428      (add-theme nam-1 scope-2)
     1429      (is-true (d::equivalent-construct
     1430                nam-1 :charvalue "nam-1" :instance-of type-1
     1431                :themes (list scope-2 scope-1)))
     1432      (is-false (d::equivalent-construct
     1433                 nam-1 :charvalue "nam-1" :instance-of type-1
     1434                 :themes (list scope-2 scope-1)
     1435                 :start-revision revision-0-5))
     1436      (is-false (d::equivalent-construct
     1437                 nam-1 :charvalue "nam-1" :instance-of type-2
     1438                 :themes (list scope-1 scope-2)))
     1439      (is-false (d::equivalent-construct
     1440                 nam-1 :charvalue "nam-1" :instance-of type-1
     1441                 :themes (list scope-3 scope-2)))
     1442      (is-false (d::equivalent-construct
     1443                 nam-1 :charvalue "nam-2" :instance-of type-1
     1444                 :themes (list scope-2 scope-1)))
     1445      (add-item-identifier nam-1 ii-1)
     1446      (is-true (d::equivalent-construct nam-1 :item-identifiers (list ii-1)))
     1447      (is-false (d::equivalent-construct nam-1 :item-identifiers (list ii-2)))
     1448      (add-reifier nam-1 reifier-1)
     1449      (is-true (d::equivalent-construct nam-1 :reifier reifier-1))
     1450      (is-false (d::equivalent-construct nam-1 :reifier reifier-2)))))
     1451
     1452
     1453(test test-equivalent-VariantC ()
     1454  "Tests the functions equivalent-construct depending on VariantC."
     1455  (with-fixture with-empty-db (*db-dir*)
     1456    (let ((var-1 (make-instance 'd:OccurrenceC :charvalue "var-1"))
     1457          (scope-1 (make-instance 'd:TopicC))
     1458          (scope-2 (make-instance 'd:TopicC))
     1459          (scope-3 (make-instance 'd:TopicC))
     1460          (reifier-1 (make-instance 'd:TopicC))
     1461          (reifier-2 (make-instance 'd:TopicC))
     1462          (ii-1 (make-instance 'd:ItemIdentifierC :uri "ii-1"))
     1463          (ii-2 (make-instance 'd:ItemIdentifierC :uri "ii-2"))
     1464          (revision-0-5 50)
     1465          (version-1 100))
     1466      (setf *TM-REVISION* version-1)
     1467      (add-theme var-1 scope-1)
     1468      (add-theme var-1 scope-2)
     1469      (is-true (d::equivalent-construct
     1470                var-1 :charvalue "var-1" :datatype constants:*xml-string*
     1471                :themes (list scope-2 scope-1)))
     1472      (is-false (d::equivalent-construct
     1473                 var-1 :charvalue "var-1" :datatype constants:*xml-string*
     1474                 :themes (list scope-2 scope-1)
     1475                 :start-revision revision-0-5))
     1476      (is-false (d::equivalent-construct
     1477                 var-1 :charvalue "var-1" :datatype constants:*xml-string*
     1478                 :themes (list scope-3 scope-2)))
     1479      (is-false (d::equivalent-construct
     1480                 var-1 :charvalue "var-1"
     1481                 :themes (list scope-1 scope-2)))
     1482      (is-false (d::equivalent-construct
     1483                 var-1 :charvalue "var-2" :datatype constants:*xml-string*
     1484                 :themes (list scope-2 scope-1)))
     1485      (add-item-identifier var-1 ii-1)
     1486      (is-true (d::equivalent-construct var-1 :item-identifiers (list ii-1)))
     1487      (is-false (d::equivalent-construct var-1 :item-identifiers (list ii-2)))
     1488      (add-reifier var-1 reifier-1)
     1489      (is-true (d::equivalent-construct var-1 :reifier reifier-1))
     1490      (is-false (d::equivalent-construct var-1 :reifier reifier-2)))))
     1491
     1492
     1493
    13591494(defun run-datamodel-tests()
    13601495  "Runs all tests of this test-suite."
     
    13901525  (it.bese.fiveam:run! 'test-delete-RoleC)
    13911526  (it.bese.fiveam:run! 'test-equivalent-PointerC)
     1527  (it.bese.fiveam:run! 'test-equivalent-OccurrenceC)
     1528  (it.bese.fiveam:run! 'test-equivalent-NameC)
     1529  (it.bese.fiveam:run! 'test-equivalent-VariantC)
    13921530  )
Note: See TracChangeset for help on using the changeset viewer.