Skip to content

Commit

Permalink
flatten-array: Update to latest (#829)
Browse files Browse the repository at this point in the history
* sync tests

* add generators and generate tests

* update function template

* add instructions.append

* update contributors

* update instructions.append
  • Loading branch information
tasxatzial authored Mar 7, 2025
1 parent 7c3e39a commit 94ca857
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 21 deletions.
11 changes: 11 additions & 0 deletions exercises/practice/flatten-array/.docs/instructions.append.md
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.
3 changes: 2 additions & 1 deletion exercises/practice/flatten-array/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"mwfogleman",
"object88",
"sjwarner-bp",
"yurrriq"
"yurrriq",
"tasxatzial"
],
"files": {
"solution": [
Expand Down
12 changes: 12 additions & 0 deletions exercises/practice/flatten-array/.meta/generator.clj
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)))
10 changes: 10 additions & 0 deletions exercises/practice/flatten-array/.meta/generator.tpl
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}}
48 changes: 45 additions & 3 deletions exercises/practice/flatten-array/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[8c71dabd-da60-422d-a290-4a571471fb14]
description = "empty"

[d268b919-963c-442d-9f07-82b93f1b518c]
description = "no nesting"

[3f15bede-c856-479e-bb71-1684b20c6a30]
description = "flattens a nested array"

[c84440cc-bb3a-48a6-862c-94cf23f2815d]
description = "flattens array with just integers present"

Expand All @@ -14,8 +27,37 @@ description = "5 level nesting"
[d572bdba-c127-43ed-bdcd-6222ac83d9f7]
description = "6 level nesting"

[0705a8e5-dc86-4cec-8909-150c5e54fa9c]
description = "null values are omitted from the final result"

[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc]
description = "consecutive null values at the front of the list are omitted from the final result"
include = false

[bc72da10-5f55-4ada-baf3-50e4da02ec8e]
description = "consecutive null values at the front of the array are omitted from the final result"
reimplements = "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc"

[382c5242-587e-4577-b8ce-a5fb51e385a1]
description = "consecutive null values in the middle of the list are omitted from the final result"
include = false

[6991836d-0d9b-4703-80a0-3f1f23eb5981]
description = "consecutive null values in the middle of the array are omitted from the final result"
reimplements = "382c5242-587e-4577-b8ce-a5fb51e385a1"

[ef1d4790-1b1e-4939-a179-51ace0829dbd]
description = "6 level nest list with null values"
include = false

[dc90a09c-5376-449c-a7b3-c2d20d540069]
description = "6 level nested array with null values"
reimplements = "ef1d4790-1b1e-4939-a179-51ace0829dbd"

[85721643-705a-4150-93ab-7ae398e2942d]
description = "all values in nested list are null"
include = false

[51f5d9af-8f7f-4fb5-a156-69e8282cb275]
description = "all values in nested array are null"
reimplements = "85721643-705a-4150-93ab-7ae398e2942d"
9 changes: 6 additions & 3 deletions exercises/practice/flatten-array/src/flatten_array.clj
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 exercises/practice/flatten-array/test/flatten_array_test.clj
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])))))

0 comments on commit 94ca857

Please sign in to comment.