Back
subset? (clj)
(source)function
(subset? set1 set2)
Is set1 a subset of set2?
Examples
clojure
(ns clojure.test-clojure.java-interop
(:use clojure.test)
(:require [clojure.data :as data]
[clojure.inspector]
[clojure.pprint :as pp]
[clojure.set :as set]
[clojure.test-clojure.proxy.examples :as proxy-examples])
(:import java.util.Base64
(java.util.concurrent.atomic AtomicLong AtomicInteger)))
(deftest test-bases
(are [x] (nil? (bases x))
java.lang.Object ;; no super classes/interfaces
java.lang.Comparable) ;; no super interfaces
(are [x y] (set/subset? (set y) (set x))
(bases java.lang.Math) [java.lang.Object]
(bases java.util.Collection) [java.lang.Iterable]
(bases java.lang.Integer) [java.lang.Number java.lang.Comparable]))
(deftest test-supers
(are [x y] (set/subset? y (set x))
(supers java.lang.Math)
#{java.lang.Object}
(supers java.lang.Integer)
#{java.lang.Number java.lang.Object
java.lang.Comparable java.io.Serializable} ))
clojure
(ns clojure.test-clojure.clojure-set
(:use clojure.test)
(:require [clojure.set :as set]))
(deftest test-subset?
(are [sub super] (set/subset? sub super)
#{} #{}
#{} #{1}
#{1} #{1}
#{1 2} #{1 2}
#{1 2} #{1 2 42}
#{false} #{false}
#{nil} #{nil}
#{nil} #{nil false}
#{1 2 nil} #{1 2 nil 4})
(are [notsub super] (not (set/subset? notsub super))
#{1} #{}
#{2} #{1}
#{1 3} #{1}
#{nil} #{false}
#{false} #{nil}
#{false nil} #{nil}
#{1 2 nil} #{1 2}))
metabase/metabase
(ns ^:mb/once metabase.task.task-history-cleanup-test
(:require
[clojure.set :as set]
[clojure.test :refer :all]
[java-time.api :as t]
[metabase.models.task-history :refer [TaskHistory]]
[metabase.models.task-history-test :as tht]
[metabase.task.task-history-cleanup :as cleanup-task]
[metabase.test :as mt]
[metabase.util :as u]
[toucan2.core :as t2]))
(deftest cleanup-test
(let [task-1 (u/qualified-name ::task-1)
task-2 (u/qualified-name ::task-2)
task-3 (u/qualified-name ::task-3)
t1-start (t/offset-date-time) ; now
t2-start (tht/add-second t1-start) ; 1 second from now
t3-start (tht/add-second t2-start)] ; 2 seconds from now
(letfn [(do-with-tasks [{:keys [rows-to-keep]} thunk]
(mt/with-temp [TaskHistory t1 (assoc (tht/make-10-millis-task t1-start)
:task task-1)
TaskHistory t2 (assoc (tht/make-10-millis-task t2-start)
:task task-2)
TaskHistory t3 (assoc (tht/make-10-millis-task t3-start)
:task task-3)]
(t2/delete! TaskHistory :id [:not-in (map u/the-id [t1 t2 t3])])
(with-redefs [cleanup-task/history-rows-to-keep rows-to-keep]
(#'cleanup-task/task-history-cleanup!))
(thunk)))
(task-history-tasks []
(set (map :task (t2/select TaskHistory))))]
(testing "Basic run of the cleanup task when it needs to remove rows. Should also add a TaskHistory row once complete"
(do-with-tasks
{:rows-to-keep 2}
(fn []
(is (set/subset? #{task-2 task-3 "task-history-cleanup"}
(task-history-tasks))))))
(testing "When the task runs and nothing is removed, it should still insert a new TaskHistory row"
(do-with-tasks
{:rows-to-keep 10}
(fn []
(is (set/subset? #{task-1 task-2 task-3 "task-history-cleanup"}
(task-history-tasks)))))))))
clojure/clojurescript
(ns clojure.set-test
(:require [clojure.test :refer [are deftest is]]
[clojure.set :as set]))
(deftest test-subset?
(are [sub super] (set/subset? sub super)
#{} #{}
#{} #{1}
#{1} #{1}
#{1 2} #{1 2}
#{1 2} #{1 2 42}
#{false} #{false}
#{nil} #{nil}
#{nil} #{nil false}
#{1 2 nil} #{1 2 nil 4})
(are [notsub super] (not (set/subset? notsub super))
#{1} #{}
#{2} #{1}
#{1 3} #{1}
#{nil} #{false}
#{false} #{nil}
#{false nil} #{nil}
#{1 2 nil} #{1 2}))
arcadia-unity/Arcadia
(ns clojure.test-clojure.clojure-set
(:use clojure.test)
(:require [clojure.set :as set]))
(deftest test-map-invert
(are [x y] (= x y)
(set/map-invert {:a "one" :b "two"}) {"one" :a "two" :b}))
(deftest test-subset?
(are [sub super] (set/subset? sub super)
#{} #{}
#{} #{1}
#{1} #{1}
#{1 2} #{1 2}
#{1 2} #{1 2 42}
#{false} #{false}
#{nil} #{nil}
#{nil} #{nil false}
#{1 2 nil} #{1 2 nil 4})
(are [notsub super] (not (set/subset? notsub super))
#{1} #{}
#{2} #{1}
#{1 3} #{1}
#{nil} #{false}
#{false} #{nil}
#{false nil} #{nil}
#{1 2 nil} #{1 2}))
accelerated-text/accelerated-text
(ns api.nlg.parser-test
(:require [acc-text.nlg.semantic-graph :as sg]
[api.db-fixtures :as db]
[api.nlg.parser :as parser]
[clojure.set :as set]
[clojure.test :refer [deftest testing is use-fixtures]]))
(deftest document-plan-parsing
(testing "Simple document plan parsing"
(let [document-plan {:documentPlan {:segments [{:children [{:child {:name "title" :type "Cell"}
:name "good"
:type "Dictionary-item-modifier"
:itemId "NN-good"}]
:type "Segment"}]
:type "Document-plan"}}
{::sg/keys [concepts relations]} (parser/document-plan->semantic-graph document-plan)]
(is (set/subset? #{:document-plan :segment :data :dictionary-item} (set (map :type concepts))))
(is (set/subset? #{:segment :instance :modifier} (set (map :role relations))))))
(testing "AMR parsing"
(let [document-plan {:documentPlan {:roles [{:children [{:name "written"
:type "Dictionary-item"
:itemId "written"}]
:name "lexicon"}
{:children [{:name "authors" :type "Cell"}]
:name "agent"}
{:children [{:name "title" :type "Cell"}]
:name "co-agent"}
{:children [nil] :name "theme"}]
:type "AMR"
:conceptId "author"}}
{::sg/keys [concepts relations]} (parser/document-plan->semantic-graph document-plan)]
(is (set/subset? #{:amr :data :dictionary-item} (set (map :type concepts))))
(is (set/subset? #{:arg} (set (map :role relations))))))
(testing "Modifier parsing"
(let [document-plan {:documentPlan {:name "good"
:type "Dictionary-item-modifier"
:child {:name "famous"
:type "Dictionary-item-modifier"
:child {:name "authors" :type "Cell"}
:itemId "famous"}
:itemId "good"}}
{::sg/keys [concepts relations]} (parser/document-plan->semantic-graph document-plan)]
(is (set/subset? #{:data :dictionary-item} (set (map :type concepts))))
(is (set/subset? #{:modifier} (set (map :role relations))))
(is (= 3 (count relations))))))
lambdaisland/kaocha
(ns kaocha.plugin.gc-profiling-test
(:require [clojure.test :refer [deftest is testing]]
[clojure.set]
[kaocha.test-helper :refer :all]
[kaocha.testable :as testable]
[kaocha.plugin :as plugin]
[kaocha.test-util :refer [with-test-ctx]]
[kaocha.plugin.gc-profiling :as gc]))
(deftest gc-profiling-test
(plugin/with-plugins plugin-chain
(is
(match? {:kaocha.plugin.gc-profiling/gc-profiling? true
:kaocha.plugin.gc-profiling/gc-profiling-individual false}
(plugin/run-hook :kaocha.hooks/config {})))
(let [result ( plugin/run-hook :kaocha.hooks/cli-options [])]
(is
(clojure.set/subset? #{"--[no-]gc-profiling"
"--[no-]gc-profiling-individual"}
(set (map second result)))))
(is