-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
213c6fe
commit e37c2ef
Showing
4 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns utils.vector) | ||
|
||
(defn insert-element-at | ||
[data element index] | ||
(let [before (take index data) | ||
after (drop index data)] | ||
(vec (concat before [element] after)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns utils.vector-test | ||
(:require | ||
[cljs.test :refer-macros [deftest is testing]] | ||
[utils.vector :as vector])) | ||
|
||
(deftest test-insert-element-at | ||
(testing "Inserting into an empty vector" | ||
(is (= [42] (vector/insert-element-at [] 42 0)))) | ||
|
||
(testing "Inserting at the beginning of a vector" | ||
(is (= [42 1 2 3] (vector/insert-element-at [1 2 3] 42 0)))) | ||
|
||
(testing "Inserting in the middle of a vector" | ||
(is (= [1 42 2 3] (vector/insert-element-at [1 2 3] 42 1)))) | ||
|
||
(testing "Inserting at the end of a vector" | ||
(is (= [1 2 3 42] (vector/insert-element-at [1 2 3] 42 3))))) |