Skip to content
Open
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
8 changes: 8 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.8.0"}
org.clojure/math.numeric-tower {:mvn/version "0.0.4"}
;org.clojure/tools.namespace {:mvn/verson "0.2.11"}
}
:aliases {:uberjar {:extra-deps {uberdeps {:mvn/version "0.1.4"}}
:main-opts ["-m" "uberdeps.uberjar"]}}}

8 changes: 4 additions & 4 deletions src/boggle/core.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns boggle.core
(:use [clojure.math.numeric-tower :only [abs]]
[clojure.java.io :as io])
(:require [clojure.string :as string])
(:gen-class))
(:require [clojure.string :as string]
[clojure.java.io :as io]
[clojure.math.numeric-tower :refer [abs]])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask what the reasoning is behind this change?

Copy link
Author

@jasonmm jasonmm Jul 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My motivation for the change was mostly based on this section of the style guide (and this post). I think the motivation for preferring :require is because :use makes it easier to overwrite or shadow var names since it automatically refers them into the current namespace.

(:gen-class))

(def dict (io/resource "ospd.txt"))

Expand Down
16 changes: 16 additions & 0 deletions src/boggle/utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns boggle.utils
(:require [clojure.string :as str]
[clojure.math.numeric-tower :refer [sqrt]]))

(defn str->board
"Converts a string, `s`, into a board formatted to be accepted by
`boggle.core/load-board`. nil is returned if `s` cannot be a square board."
[s]
(let [board-size (sqrt (count s))]
(when (integer? board-size)
(->> s
str/upper-case
(map #(if (= \Q %) "QU" %))
(partition board-size)
(map #(str/join \ %))
(str/join "\n")))))
13 changes: 12 additions & 1 deletion test/boggle/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns boggle.core-test
(:require [clojure.test :refer :all]
[boggle.core :refer :all]))
[boggle.core :refer :all]
[boggle.utils]))

(deftest test-valid-word?
(testing "valid-word?"
Expand Down Expand Up @@ -127,3 +128,13 @@
[["A" "B" "C"]
["D" "E" "F"]
["P" "QU" "R"]])))))

(deftest test-load-board-from-string
(testing "correctly parses a 1-line string into a board matrix"
(let [board (boggle.utils/str->board "abcdefpqr")
actual (load-board board)
expected [["A" "B" "C"]
["D" "E" "F"]
["P" "QU" "R"]]]
(is (= "A B C\nD E F\nP QU R" board))
(is (= expected actual)))))