From 0a91e1f022b61ad7d143d0998f27a80bb4689779 Mon Sep 17 00:00:00 2001 From: rafonsecad Date: Tue, 17 Jun 2025 17:12:21 -0500 Subject: [PATCH 1/2] Add tests for hash-map, hash-set, and set --- test/clojure/core_test/hash_map.cljc | 16 ++++++++++++++++ test/clojure/core_test/hash_set.cljc | 19 +++++++++++++++++++ test/clojure/core_test/set.cljc | 23 +++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 test/clojure/core_test/hash_map.cljc create mode 100644 test/clojure/core_test/hash_set.cljc create mode 100644 test/clojure/core_test/set.cljc diff --git a/test/clojure/core_test/hash_map.cljc b/test/clojure/core_test/hash_map.cljc new file mode 100644 index 0000000..3f8cd2f --- /dev/null +++ b/test/clojure/core_test/hash_map.cljc @@ -0,0 +1,16 @@ +(ns clojure.core-test.hash-map + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/hash-map + (deftest test-hash-map + (testing "common" + (is (= {} (hash-map))) + (is (= {:a 1} (hash-map :a 1))) + (is (= {:a 2} (hash-map :a 1 :a 2))) + (is (= {:a 1 :b "2"} (hash-map :a 1, :b "2"))) + (is (= {"a" 1, [:b :c] "2", \d nil} (hash-map "a" 1, [:b :c] "2", \d nil))) + (is (= {\a {}} (hash-map \a (hash-map)))) + #?@(:clj [(is (thrown? Exception (hash-map :a)))] + :cljs [(is (thrown? js/Error (hash-map :a)))])))) diff --git a/test/clojure/core_test/hash_set.cljc b/test/clojure/core_test/hash_set.cljc new file mode 100644 index 0000000..b85cbeb --- /dev/null +++ b/test/clojure/core_test/hash_set.cljc @@ -0,0 +1,19 @@ +(ns clojure.core-test.hash-set + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/hash-set + (deftest test-hash-set + (testing "common" + (is (= #{} (hash-set))) + (is (= #{:a} (hash-set :a))) + (is (= #{"a"} (hash-set "a"))) + (is (= #{1} (hash-set 1 1))) + (is (= #{nil} (hash-set nil))) + (is (= #{\space} (hash-set \space))) + (is (= #{'()} (hash-set '()))) + (is (= #{[]} (hash-set []))) + (is (= #{'(1 2 3)} (hash-set '(1 2 3)))) + (is (= #{[1 2 3]} (hash-set [1 2 3]))) + (is (= #{nil #{}} (hash-set nil (hash-set))))))) diff --git a/test/clojure/core_test/set.cljc b/test/clojure/core_test/set.cljc new file mode 100644 index 0000000..818a922 --- /dev/null +++ b/test/clojure/core_test/set.cljc @@ -0,0 +1,23 @@ +(ns clojure.core-test.set + (:require clojure.core + [clojure.test :as t :refer [deftest testing is are]] + [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) + +(when-var-exists clojure.core/set + (deftest test-set + (testing "common" + (is (= #{} (set nil))) + (is (= #{} (set []))) + (is (= #{} (set '()))) + (is (= #{\a \b \c} (set "abc"))) + (is (= #{} (set #{}))) + (is (= #{:a} (set #{:a}))) + (is (= #{:a 1 "a"} (set '(:a 1 "a")))) + (is (= #{:a 1 "a"} (set [:a 1 "a"]))) + (is (= #{:a 1 "a" [\space]} (set [:a 1 "a" [\space]]))) + #?@(:clj [(is (thrown? Exception (set 1))) + (is (thrown? Exception (set \space))) + (is (thrown? Exception (set :a)))] + :cljs [(is (= #{\space} (set \space))) + (is (thrown? js/Error (set 1))) + (is (thrown? js/Error (set :a)))])))) From 3c9331ec2200faae59b0e1acd0027aca04946bce Mon Sep 17 00:00:00 2001 From: rafonsecad Date: Thu, 19 Jun 2025 14:45:18 -0500 Subject: [PATCH 2/2] Add tests for hash-map, hash-set, and set --- test/clojure/core_test/hash_map.cljc | 1 + test/clojure/core_test/set.cljc | 1 + 2 files changed, 2 insertions(+) diff --git a/test/clojure/core_test/hash_map.cljc b/test/clojure/core_test/hash_map.cljc index 3f8cd2f..d37fa82 100644 --- a/test/clojure/core_test/hash_map.cljc +++ b/test/clojure/core_test/hash_map.cljc @@ -12,5 +12,6 @@ (is (= {:a 1 :b "2"} (hash-map :a 1, :b "2"))) (is (= {"a" 1, [:b :c] "2", \d nil} (hash-map "a" 1, [:b :c] "2", \d nil))) (is (= {\a {}} (hash-map \a (hash-map)))) + (is (= {:a {:b {:c 1} :d 2}} (hash-map :a (hash-map :b (hash-map :c 1) :d 2)))) #?@(:clj [(is (thrown? Exception (hash-map :a)))] :cljs [(is (thrown? js/Error (hash-map :a)))])))) diff --git a/test/clojure/core_test/set.cljc b/test/clojure/core_test/set.cljc index 818a922..774b42a 100644 --- a/test/clojure/core_test/set.cljc +++ b/test/clojure/core_test/set.cljc @@ -12,6 +12,7 @@ (is (= #{\a \b \c} (set "abc"))) (is (= #{} (set #{}))) (is (= #{:a} (set #{:a}))) + (is (= #{1 2 3} (set [1 1 2 2 3 3 3]))) (is (= #{:a 1 "a"} (set '(:a 1 "a")))) (is (= #{:a 1 "a"} (set [:a 1 "a"]))) (is (= #{:a 1 "a" [\space]} (set [:a 1 "a" [\space]])))