Skip to content

Commit

Permalink
Update tests + correct valueset values
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinqian00 committed Jun 23, 2023
1 parent 9ffdf31 commit 2d9eb43
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,11 @@
:inlineSchema "{\"type\":\"boolean\"}"}})

(def valuegen-valuesets
{:verbs #{{:id "http://foo.org/verb"
:type "Verb"}}
{:verbs #{{"id""http://foo.org/verb"}}
:verb-ids #{"http://foo.org/verb"}
:activities #{{:id "http://foo.org/activity"
:type "Activity"
:definition {:type "http://foo.org/activity-type"}}}
:activities #{{"id" "http://foo.org/activity"
"objectType" "Activity"
"definition" {"type" "http://foo.org/activity-type"}}}
:activity-ids #{"http://foo.org/activity"}
:activity-types #{"http://foo.org/activity-type"}})

Expand Down Expand Up @@ -547,98 +546,94 @@
:presence :included
:path ["verb"]
:spec ::xs/verb
:valueset #{{:id "http://foo.org/verb" :type "Verb"}}
:all #{{:id "http://foo.org/verb" :type "Verb"}}}
:valueset #{{"id" "http://foo.org/verb"}}}
(parse-rule-valuegen
{:location "$.verb"
:presence "included"})))
(is (= {:location [[["verb"] ["id"]]]
:presence :included
:path ["verb" "id"]
:spec :verb/id
:valueset #{"http://foo.org/verb"}
:all #{"http://foo.org/verb"}}
:valueset #{"http://foo.org/verb"}}
(parse-rule-valuegen
{:location "$.verb.id"
:presence "included"})))
(is (= {:location [[["object"]]]
:presence :included
:path ["object"]
:spec ::xs/activity
:valueset #{{:id "http://foo.org/activity"
:type "Activity"
:definition {:type "http://foo.org/activity-type"}}}
:all #{{:id "http://foo.org/activity"
:type "Activity"
:definition {:type "http://foo.org/activity-type"}}}}
:valueset #{{"id" "http://foo.org/activity"
"objectType" "Activity"
"definition" {"type" "http://foo.org/activity-type"}}}}
(parse-rule-valuegen
{:location "$.object"
:presence "included"})))
(is (= {:location [[["object"] ["id"]]]
:presence :included
:path ["object" "id"]
:spec :activity/id
:valueset #{"http://foo.org/activity"}
:all #{"http://foo.org/activity"}}
:valueset #{"http://foo.org/activity"}}
(parse-rule-valuegen
{:location "$.object.id"
:presence "included"})))
(is (= {:location [[["object"] ["definition"] ["type"]]]
:presence :included
:path ["object" "definition" "type"]
:spec :definition/type
:valueset #{"http://foo.org/activity-type"}
:all #{"http://foo.org/activity-type"}}
:valueset #{"http://foo.org/activity-type"}}
(parse-rule-valuegen
{:location "$.object.definition.type"
:presence "included"})))
(is (= {:location [[["context"] ["contextActivities"] ["category"] [0]]]
:presence :included
:path ["context" "contextActivities" "category" '*]
:spec ::xs/activity
:valueset #{{"id" "http://foo.org/activity"
"objectType" "Activity"
"definition" {"type" "http://foo.org/activity-type"}}}}
(parse-rule-valuegen
{:location "$.context.contextActivities.category[0]"
:presence "included"}))))
(testing "Add valuesets (substatements)"
(is (= {:location [[["object"] ["verb"]]]
:presence :included
:path ["object" "verb"]
:spec ::xs/verb
:valueset #{{:id "http://foo.org/verb" :type "Verb"}}
:all #{{:id "http://foo.org/verb" :type "Verb"}}}
:valueset #{{"id" "http://foo.org/verb"}}}
(parse-rule-sub-valuegen
{:location "$.object.verb"
:presence "included"})))
(is (= {:location [[["object"] ["verb"] ["id"]]]
:presence :included
:path ["object" "verb" "id"]
:spec :verb/id
:valueset #{"http://foo.org/verb"}
:all #{"http://foo.org/verb"}}
:valueset #{"http://foo.org/verb"}}
(parse-rule-sub-valuegen
{:location "$.object.verb.id"
:presence "included"})))
(is (= {:location [[["object"] ["object"]]]
:presence :included
:path ["object" "object"]
:spec ::xs/activity
:valueset #{{:id "http://foo.org/activity"
:type "Activity"
:definition {:type "http://foo.org/activity-type"}}}
:all #{{:id "http://foo.org/activity"
:type "Activity"
:definition {:type "http://foo.org/activity-type"}}}}
:valueset #{{"id" "http://foo.org/activity"
"objectType" "Activity"
"definition" {"type" "http://foo.org/activity-type"}}}}
(parse-rule-sub-valuegen
{:location "$.object.object"
:presence "included"})))
(is (= {:location [[["object"] ["object"] ["id"]]]
:presence :included
:path ["object" "object" "id"]
:spec :activity/id
:valueset #{"http://foo.org/activity"}
:all #{"http://foo.org/activity"}}
:valueset #{"http://foo.org/activity"}}
(parse-rule-sub-valuegen
{:location "$.object.object.id"
:presence "included"})))
(is (= {:location [[["object"] ["object"] ["definition"] ["type"]]]
:presence :included
:path ["object" "object" "definition" "type"]
:spec :definition/type
:valueset #{"http://foo.org/activity-type"}
:all #{"http://foo.org/activity-type"}}
:valueset #{"http://foo.org/activity-type"}}
(parse-rule-sub-valuegen
{:location "$.object.object.definition.type"
:presence "included"}))))
Expand Down Expand Up @@ -1018,7 +1013,13 @@
{:location "$.verb.display.zh-CN"
:all ["展开"]}
{:location "$.verb.display.zh-CN" ; overwrites previous rule
:none ["展开"]}))))
:none ["展开"]}))
(testing "don't replace verb not in profile cosmos with one that is"
(is-verb {"id" "http://example.org/nonexistent"}
{:location "$.verb.id"
:all ["http://example.org/nonexistent"]}
{:location "$.verb.id"
:presence "included"}))))

(deftest apply-context-rules
(testing "Context rules:"
Expand Down Expand Up @@ -1268,7 +1269,21 @@
:all ["https://xapinet.com/xapi/blooms/activitytypes/cognitive-process-dimension"]}
{:location "$.context.contextActivities.grouping[0].definition.type"
:presence "included"
:all ["https://xapinet.com/xapi/blooms/activities/objectives/procedural"]}))))
:all ["https://xapinet.com/xapi/blooms/activities/objectives/procedural"]}))
(testing "don't replace activity not in profile cosmos with one that is"
;; This case particularly applies to adding the profile ID
;; as a category context activity
(is-ctx-activities
"category"
[{"id" "http://foo.org/my-profile-id"
"objectType" "Activity"
"definition" {"name" {"en" "team meeting"}
"description" {"en" "A category of meeting used for regular team meetings."}
"type" "http://example.com/expapi/activities/meetingcategory"}}]
{:location "$.context.contextActivities.category[*].id"
:all ["http://foo.org/my-profile-id"]}
{:location "$.context.contextActivities.category[*].id"
:presence "included"}))))

(deftest apply-rules-distinct-test
(testing "uses all 3 distinct `all` values for 3 locations"
Expand Down
55 changes: 55 additions & 0 deletions src/test/com/yetanalytics/datasim/xapi/statement_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@
"es" "satisfecho"}}
(get statement "verb")))))

(testing "inclusion only"
(let [statement
(gen-statement
{:rules [{:location "$.verb"
:presence "included"}]})]
(is (s/valid? ::xs/statement statement))
(is (statement-inputs? statement))
(is (= {"id" "https://w3id.org/xapi/adl/verbs/waived"
"display" {"en" "waived"}}
(get statement "verb")))))

(testing "ID inclusion only"
(let [statement
(gen-statement
{:rules [{:location "$.verb.id"
:presence "included"}]})]
(is (s/valid? ::xs/statement statement))
(is (statement-inputs? statement))
(is (= {"id" "https://w3id.org/xapi/adl/verbs/abandoned"
"display" {"en" "abandoned"}}
(get statement "verb")))))

(testing "display rule only - spec generation"
(let [statement
(gen-statement
Expand Down Expand Up @@ -305,6 +327,39 @@
(is (= {"id" "https://example.org/course/1550503926"
"objectType" "Activity"
"definition" {"type" "https://w3id.org/xapi/cmi5/activitytype/course"}}
(get statement "object")))))

(testing "inclusion only"
(let [statement
(gen-statement
{:rules [{:location "$.object"
:presence "included"}]})]
(is (s/valid? ::xs/statement statement))
(is (statement-inputs? statement))
(is (= {"id" "https://example.org/block/1432714272"
"definition" {"type" "https://w3id.org/xapi/cmi5/activitytype/block"}}
(get statement "object")))))

(testing "ID inclusion only"
(let [statement
(gen-statement
{:rules [{:location "$.object.id"
:presence "included"}]})]
(is (s/valid? ::xs/statement statement))
(is (statement-inputs? statement))
(is (= {"id" "https://example.org/course/418707894"
"definition" {"type" "https://w3id.org/xapi/cmi5/activities/course"}}
(get statement "object")))))

(testing "activity type inclusion only"
(let [statement
(gen-statement
{:rules [{:location "$.object.definition.type"
:presence "included"}]})]
(is (s/valid? ::xs/statement statement))
(is (statement-inputs? statement))
(is (= {"id" "https://example.org/course/1550503926"
"definition" {"type" "https://w3id.org/xapi/cmi5/activitytype/course"}}
(get statement "object"))))))

;; Agent/Group Object
Expand Down

0 comments on commit 2d9eb43

Please sign in to comment.