summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clj/clojure/gvec.clj8
-rw-r--r--test/clojure/test_clojure/vectors.clj28
2 files changed, 36 insertions, 0 deletions
diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj
index 7da8e49e..c8a70e47 100644
--- a/src/clj/clojure/gvec.clj
+++ b/src/clj/clojure/gvec.clj
@@ -245,6 +245,14 @@
(if (clojure.lang.Util/isInteger k)
(.assocN this k v)
(throw (IllegalArgumentException. "Key must be integer"))))
+ (containsKey [this k]
+ (and (clojure.lang.Util/isInteger k)
+ (<= 0 (int k))
+ (< (int k) cnt)))
+ (entryAt [this k]
+ (if (.containsKey this k)
+ (clojure.lang.MapEntry. k (.nth this (int k)))
+ nil))
clojure.lang.ILookup
(valAt [this k not-found]
diff --git a/test/clojure/test_clojure/vectors.clj b/test/clojure/test_clojure/vectors.clj
index 00408d22..45eb98ff 100644
--- a/test/clojure/test_clojure/vectors.clj
+++ b/test/clojure/test_clojure/vectors.clj
@@ -274,3 +274,31 @@
(:rand-lesser-3 int-vecs)
(:rand-lesser-3 long-vecs)
(:rand-lesser-3 regular-vecs))))))
+
+(deftest test-vec
+ (let [empty-v (vector-of :long)
+ v (into empty-v (range 1 6))]
+ (testing "Associative.containsKey"
+ (are [x] (.containsKey v x)
+ 0 1 2 3 4)
+ (are [x] (not (.containsKey v x))
+ -1 -100 nil [] "" #"" #{} 5 100)
+ (are [x] (not (.containsKey empty-v x))
+ 0 1))
+ (testing "contains?"
+ (are [x] (contains? v x)
+ 0 2 4)
+ (are [x] (not (contains? v x))
+ -1 -100 nil "" 5 100)
+ (are [x] (not (contains? empty-v x))
+ 0 1))
+ (testing "Associative.entryAt"
+ (are [idx val] (= (clojure.lang.MapEntry. idx val)
+ (.entryAt v idx))
+ 0 1
+ 2 3
+ 4 5)
+ (are [idx] (nil? (.entryAt v idx))
+ -5 -1 5 10 nil "")
+ (are [idx] (nil? (.entryAt empty-v idx))
+ 0 1))))