Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minesweeper: Implement tests #704

Merged
merged 5 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exercises/practice/minesweeper/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
],
"contributors": [
"AndreaCrotti",
"haus"
"haus",
"tasxatzial"
],
"files": {
"solution": [
Expand Down
1 change: 1 addition & 0 deletions exercises/practice/minesweeper/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

[0c5ec4bd-dea7-4138-8651-1203e1cb9f44]
description = "no rows"
include = false

[650ac4c0-ad6b-4b41-acde-e4ea5852c3b8]
description = "no columns"
Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/minesweeper/src/minesweeper.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns minesweeper)

(defn draw [] ;; <- arglist goes here
;; your code goes here
)
(defn draw
[board]
;; function body
)
184 changes: 124 additions & 60 deletions exercises/practice/minesweeper/test/minesweeper_test.clj
Original file line number Diff line number Diff line change
@@ -1,62 +1,126 @@
(ns minesweeper-test
(:require [clojure.test :refer [deftest is]]
[clojure.string :refer [join]]
[minesweeper :refer [draw]]))

(def line-separator (System/getProperty "line.separator"))

(deftest zero-size-board
(is (= (draw "") "")))

(deftest empty-board
(is (= (draw (join line-separator [" "
" "
" "]))
(join line-separator [" "
" "
" "]))))

(deftest surrounded
(is (= (draw (join line-separator ["***"
"* *"
"***"]))
(join line-separator ["***"
"*8*"
"***"]))))

(deftest board-full-of-mines
(is (= (draw (join line-separator ["***"
"***"
"***"]))
(join line-separator ["***"
"***"
"***"]))))

(deftest horizontal-line
(is (= (draw " * * ")
"1*2*1")))

(deftest vertical-line
(is (= (draw (join line-separator [" "
"*"
" "
"*"
" "]))
(join line-separator ["1"
"*"
"2"
"*"
"1"]))))

(deftest cross
(is (= (draw (join line-separator [" * "
" * "
"*****"
" * "
" * "]))
(join line-separator [" 2*2 "
"25*52"
"*****"
"25*52"
" 2*2 "]))))
(:require [clojure.test :refer [deftest testing is]]
minesweeper))

(def separator (System/getProperty "line.separator"))

(defn join-with-line-separator
[coll]
(clojure.string/join separator coll))

(deftest test-650ac4c0-ad6b-4b41-acde-e4ea5852c3b8
(testing "no columns"
(is (= (join-with-line-separator [""])
(minesweeper/draw
(join-with-line-separator [""]))))))

(deftest test-6fbf8f6d-a03b-42c9-9a58-b489e9235478
(testing "no mines"
(is (= (join-with-line-separator [" "
" "
" "])
(minesweeper/draw
(join-with-line-separator [" "
" "
" "]))))))

(deftest test-61aff1c4-fb31-4078-acad-cd5f1e635655
(testing "minefield with only mines"
(is (= (join-with-line-separator ["***"
"***"
"***"])
(minesweeper/draw
(join-with-line-separator ["***"
"***"
"***"]))))))

(deftest test-84167147-c504-4896-85d7-246b01dea7c5
(testing "mine surrounded by spaces"
(is (= (join-with-line-separator ["111"
"1*1"
"111"])
(minesweeper/draw
(join-with-line-separator [" "
" * "
" "]))))))


(deftest test-cb878f35-43e3-4c9d-93d9-139012cccc4a
(testing "space surrounded by mines"
(is (= (join-with-line-separator ["***"
"*8*"
"***"])
(minesweeper/draw
(join-with-line-separator ["***"
"* *"
"***"]))))))

(deftest test-7037f483-ddb4-4b35-b005-0d0f4ef4606f
(testing "horizontal line"
(is (= (join-with-line-separator ["1*2*1"])
(minesweeper/draw
(join-with-line-separator [" * * "]))))))

(deftest test-e359820f-bb8b-4eda-8762-47b64dba30a6
(testing "horizontal line, mines at edges"
(is (= (join-with-line-separator ["*1 1*"])
(minesweeper/draw
(join-with-line-separator ["* *"]))))))

(deftest test-c5198b50-804f-47e9-ae02-c3b42f7ce3ab
(testing "vertical line"
(is (= (join-with-line-separator ["1"
"*"
"2"
"*"
"1"])
(minesweeper/draw
(join-with-line-separator [" "
"*"
" "
"*"
" "]))))))

(deftest test-0c79a64d-703d-4660-9e90-5adfa5408939
(testing "vertical line, mines at edges"
(is (= (join-with-line-separator ["*"
"1"
" "
"1"
"*"])
(minesweeper/draw
(join-with-line-separator ["*"
" "
" "
" "
"*"]))))))

(deftest test-4b098563-b7f3-401c-97c6-79dd1b708f34
(testing "cross"
(is (= (join-with-line-separator [" 2*2 "
"25*52"
"*****"
"25*52"
" 2*2 "])
(minesweeper/draw
(join-with-line-separator [" * "
" * "
"*****"
" * "
" * "]))))))

(deftest test-04a260f1-b40a-4e89-839e-8dd8525abe0e
(testing "large minefield"
(is (= (join-with-line-separator ["1*22*1"
"12*322"
" 123*2"
"112*4*"
"1*22*2"
"111111"])
(minesweeper/draw
(join-with-line-separator [" * * "
" * "
" * "
" * *"
" * * "
" "]))))))
Loading