-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flatten-array: Update to latest (#829)
* sync tests * add generators and generate tests * update function template * add instructions.append * update contributors * update instructions.append
- Loading branch information
1 parent
7c3e39a
commit 94ca857
Showing
7 changed files
with
130 additions
and
21 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
exercises/practice/flatten-array/.docs/instructions.append.md
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,11 @@ | ||
# Instructions append | ||
|
||
## Appendix | ||
|
||
~~~~exercism/note | ||
The instructions above are synchronized with a shared repository to ensure consistency across all language tracks. | ||
This appendix provides additional clarification or modifies the instructions as needed to better align with the goals of the Clojure track. | ||
~~~~ | ||
|
||
For this exercise in the Clojure track, you may **assume the input is any nested combination of vectors, and the output is a vector**, as indicated by the tests. | ||
However, this is not a strict requirement; you are free to assume that the input is any nested combination of sequential things (lists, vectors, etc.), and the output is a sequence. |
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,12 @@ | ||
(ns flatten-array-generator | ||
(:require [clojure.string :as str])) | ||
|
||
(defn update-description [description] | ||
(-> description | ||
(str/replace #"null" "nil") | ||
(str/replace #"array" "vector"))) | ||
|
||
(defn update-test-case [test-case] | ||
(->> (:description test-case) | ||
update-description | ||
(assoc test-case :context))) |
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,10 @@ | ||
(ns flatten-array-test | ||
(:require [clojure.test :refer [deftest testing is]] | ||
flatten-array)) | ||
|
||
{{#test_cases.flatten}} | ||
(deftest flatten_test_{{idx}} | ||
(testing {{context}} | ||
(is (= {{expected}} | ||
(flatten-array/flatten {{input.array}}))))) | ||
{{/test_cases.flatten}} |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
(ns flatten-array) | ||
|
||
(defn flatten [arr] ;; <- arglist goes here | ||
;; your code goes here | ||
) | ||
(defn flatten | ||
"Flattens the given sequential collection. | ||
Nil values are excluded from the result." | ||
[coll] | ||
;; function body | ||
) |
58 changes: 44 additions & 14 deletions
58
exercises/practice/flatten-array/test/flatten_array_test.clj
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 |
---|---|---|
@@ -1,28 +1,58 @@ | ||
(ns flatten-array-test | ||
(:require [clojure.test :refer [deftest is testing]] | ||
[flatten-array])) | ||
(:require [clojure.test :refer [deftest testing is]] | ||
flatten-array)) | ||
|
||
(deftest flattens-array-of-ints | ||
(testing "flattens array with just integers present" | ||
(deftest flatten_test_1 | ||
(testing "empty" | ||
(is (= [] | ||
(flatten-array/flatten []))))) | ||
|
||
(deftest flatten_test_2 | ||
(testing "no nesting" | ||
(is (= [0 1 2] | ||
(flatten-array/flatten [0 1 2]))))) | ||
|
||
(deftest flatten_test_3 | ||
(testing "flattens a nested vector" | ||
(is (= [] | ||
(flatten-array/flatten [[[]]]))))) | ||
|
||
(deftest flatten_test_4 | ||
(testing "flattens vector with just integers present" | ||
(is (= [1 2 3 4 5 6 7 8] | ||
(flatten-array/flatten [1 [2 3 4 5 6 7] 8]))))) | ||
|
||
(deftest five-level-nesting | ||
(testing "5 level nested list" | ||
(deftest flatten_test_5 | ||
(testing "5 level nesting" | ||
(is (= [0 2 2 3 8 100 4 50 -2] | ||
(flatten-array/flatten [0 2 [[2 3] 8 100 4 [[[50]]]] -2]))))) | ||
|
||
(deftest six-level-nesting | ||
(testing "6 level nested list" | ||
(deftest flatten_test_6 | ||
(testing "6 level nesting" | ||
(is (= [1 2 3 4 5 6 7 8] | ||
(flatten-array/flatten [1 [2 [[3]] [4 [[5]]] 6 7] 8]))))) | ||
|
||
(deftest six-level-nested-with-nils | ||
(testing "6 level nested list with nil values" | ||
(deftest flatten_test_7 | ||
(testing "nil values are omitted from the final result" | ||
(is (= [1 2] | ||
(flatten-array/flatten [1 2 nil]))))) | ||
|
||
(deftest flatten_test_8 | ||
(testing "consecutive nil values at the front of the vector are omitted from the final result" | ||
(is (= [3] | ||
(flatten-array/flatten [nil nil 3]))))) | ||
|
||
(deftest flatten_test_9 | ||
(testing "consecutive nil values in the middle of the vector are omitted from the final result" | ||
(is (= [1 4] | ||
(flatten-array/flatten [1 nil nil 4]))))) | ||
|
||
(deftest flatten_test_10 | ||
(testing "6 level nested vector with nil values" | ||
(is (= [0 2 2 3 8 100 -2] | ||
(flatten-array/flatten [0 2 [[2 3] 8 [[100]] nil [[nil]]] -2]))))) | ||
|
||
(deftest all-nils-list | ||
(testing "All values in nested list are nil" | ||
(is (empty? | ||
(flatten-array/flatten [nil [[[nil]]] nil nil [[nil nil] nil] nil]))))) | ||
(deftest flatten_test_11 | ||
(testing "all values in nested vector are nil" | ||
(is (= [] | ||
(flatten-array/flatten [nil [[[nil]]] nil nil [[nil nil] nil] nil]))))) |