diff --git a/.cljfmt.edn b/.cljfmt.edn index 3facc9d..efdf92e 100644 --- a/.cljfmt.edn +++ b/.cljfmt.edn @@ -1,4 +1,3 @@ -{:split-keypairs-over-multiple-lines? true - :sort-ns-references? true - :indentation? false - :paths ["src" "dev" "test"]} \ No newline at end of file +{:indentation? false + :paths ["src" "test"] + :sort-ns-references? true} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a765d81 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = false +max_line_length = 120 +tab_width = 4 + +[*.clj] +indent_size = 2 +tab_width = 2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2307e22..9a4a199 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,9 +26,10 @@ jobs: cli: 'latest' bb: 'latest' cljfmt: 'latest' + clj-kondo: 'latest' - name: Codestyle - run: bb lint:cs:check + run: bb lint - name: Unit tests run: bb test diff --git a/bb.edn b/bb.edn index 284846b..9b61888 100644 --- a/bb.edn +++ b/bb.edn @@ -1,8 +1,8 @@ {:tasks - {test (shell "clojure -X:test") - lint (do - (run 'lint:cs) - (run 'lint:kondo)) - lint:cs (shell "cljfmt fix") - lint:cs:check (shell "cljfmt check") - lint:kondo (shell "clj-kondo --lint src:dev")}} + {test (shell "clojure -X:test") + lint (do + (run 'lint:check) + (run 'lint:kondo)) + lint:fix (shell "cljfmt fix") + lint:check (shell "cljfmt check") + lint:kondo (shell "clj-kondo --lint test --fail-level error")}} diff --git a/deps.edn b/deps.edn index b875684..7c1e5d1 100644 --- a/deps.edn +++ b/deps.edn @@ -2,4 +2,4 @@ :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}} :main-opts ["-m" "cognitect.test-runner"] :exec-fn cognitect.test-runner.api/test}} - :paths ["src"]} + :paths ["src" "test"]} diff --git a/src/sicp/chapter_1/part_2/ex_1_22.clj b/src/sicp/chapter_1/part_2/ex_1_22.clj index b74dd8e..45a5a56 100644 --- a/src/sicp/chapter_1/part_2/ex_1_22.clj +++ b/src/sicp/chapter_1/part_2/ex_1_22.clj @@ -33,9 +33,9 @@ (defn find-primes [from to] (cond (>= from to) (do - (println "finish") + ; (println "finish") from) (even? from) (find-primes (+ from 1) to) ; Just skip to the next odd :else (do - (println from) + ; (println from) (find-primes (+ from 2) to)))) ; Takes only odds diff --git a/test/sicp/chapter_1/part_1/ex_1_3_test.clj b/test/sicp/chapter_1/part_1/ex_1_3_test.clj index 56cf98a..75e5c98 100644 --- a/test/sicp/chapter_1/part_1/ex_1_3_test.clj +++ b/test/sicp/chapter_1/part_1/ex_1_3_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_1.ex-1-3-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_1.ex-1-3 :refer [sum-larger-numbers-square]])) (deftest sum-larger-numbers-square-test diff --git a/test/sicp/chapter_1/part_1/ex_1_4_test.clj b/test/sicp/chapter_1/part_1/ex_1_4_test.clj index 378b531..e6f71bd 100644 --- a/test/sicp/chapter_1/part_1/ex_1_4_test.clj +++ b/test/sicp/chapter_1/part_1/ex_1_4_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_1.ex-1-4-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_1.ex-1-4 :refer [a-plus-abs-b]])) (deftest a-plus-abs-b-test diff --git a/test/sicp/chapter_1/part_1/ex_1_5_test.clj b/test/sicp/chapter_1/part_1/ex_1_5_test.clj index 2368f3c..0679632 100644 --- a/test/sicp/chapter_1/part_1/ex_1_5_test.clj +++ b/test/sicp/chapter_1/part_1/ex_1_5_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_1.ex-1-5-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_1.ex-1-5 :refer [test_1_5 p]])) (deftest test_1_5-test diff --git a/test/sicp/chapter_1/part_1/ex_1_6_test.clj b/test/sicp/chapter_1/part_1/ex_1_6_test.clj index 6cc951a..7b6cafe 100644 --- a/test/sicp/chapter_1/part_1/ex_1_6_test.clj +++ b/test/sicp/chapter_1/part_1/ex_1_6_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_1.ex-1-6-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_1.ex-1-6 :refer [sqrt-iter sqrt-iter-new-if]])) (deftest sqrt-iter-test @@ -12,5 +12,5 @@ ; Arguments are not until whole statement is comprised only of primitive operations. (try (is (= 6 (sqrt-iter-new-if 6 36))) - (catch Exception e + (catch Exception _ (is true)))) diff --git a/test/sicp/chapter_1/part_1/ex_1_7_test.clj b/test/sicp/chapter_1/part_1/ex_1_7_test.clj index 2d76ccd..9e13ffa 100644 --- a/test/sicp/chapter_1/part_1/ex_1_7_test.clj +++ b/test/sicp/chapter_1/part_1/ex_1_7_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_1.ex-1-7-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_1.ex-1-7 :refer [sqrt-iter sqrt-iter-v2]])) (deftest sqrt-iter-test diff --git a/test/sicp/chapter_1/part_1/ex_1_8_test.clj b/test/sicp/chapter_1/part_1/ex_1_8_test.clj index 4f8d324..14cff8e 100644 --- a/test/sicp/chapter_1/part_1/ex_1_8_test.clj +++ b/test/sicp/chapter_1/part_1/ex_1_8_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_1.ex-1-8-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_1.ex-1-8 :refer [cube-root-iter]])) (deftest cube-root-iter-test diff --git a/test/sicp/chapter_1/part_2/ex_1_10_test.clj b/test/sicp/chapter_1/part_2/ex_1_10_test.clj index dab2847..ed9eeed 100644 --- a/test/sicp/chapter_1/part_2/ex_1_10_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_10_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-10-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-10 :refer [A f g h k]])) (deftest A-test diff --git a/test/sicp/chapter_1/part_2/ex_1_11_test.clj b/test/sicp/chapter_1/part_2/ex_1_11_test.clj index b46edb2..c017b25 100644 --- a/test/sicp/chapter_1/part_2/ex_1_11_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_11_test.clj @@ -1,37 +1,37 @@ (ns sicp.chapter-1.part_2.ex-1-11-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-11 :refer [f f-v2]])) (deftest f-test ; ~ O(3^n) - (time (is (= (f 1) 1))) ; "Elapsed time: 3.541558 msecs" - (time (is (= (f 2) 2))) ; "Elapsed time: 2.143086 msecs" - (time (is (= (f 3) 4))) ; "Elapsed time: 1.413709 msecs" - (time (is (= (f 4) 11))) ; "Elapsed time: 1.343298 msecs" - (time (is (= (f 5) 25))) ; "Elapsed time: 1.148649 msecs" - (time (is (= (f 6) 59))) ; "Elapsed time: 1.667051 msecs" - (time (is (= (f 7) 142))) ; "Elapsed time: 1.326258 msecs" - (time (is (= (f 8) 335))) ; "Elapsed time: 1.483437 msecs" - (time (is (= (f 9) 796))) ; "Elapsed time: 3.40105 msecs" - (time (is (= (f 10) 1892))) ; "Elapsed time: 2.025039 msecs" - (time (is (= (f 20) 10771211))) ; "Elapsed time: 32.969995 msecs - (time (is (= (f 25) 812934961))) ; "Elapsed time: 77.825729 msecs - (time (is (= (f 30) 61354575194))) ; "Elapsed time: 470.359975 msecs" + (is (= (f 1) 1)) ; "Elapsed time: 3.541558 msecs" + (is (= (f 2) 2)) ; "Elapsed time: 2.143086 msecs" + (is (= (f 3) 4)) ; "Elapsed time: 1.413709 msecs" + (is (= (f 4) 11)) ; "Elapsed time: 1.343298 msecs" + (is (= (f 5) 25)) ; "Elapsed time: 1.148649 msecs" + (is (= (f 6) 59)) ; "Elapsed time: 1.667051 msecs" + (is (= (f 7) 142)) ; "Elapsed time: 1.326258 msecs" + (is (= (f 8) 335)) ; "Elapsed time: 1.483437 msecs" + (is (= (f 9) 796)) ; "Elapsed time: 3.40105 msecs" + (is (= (f 10) 1892)) ; "Elapsed time: 2.025039 msecs" + (is (= (f 20) 10771211)) ; "Elapsed time: 32.969995 msecs + (is (= (f 25) 812934961)) ; "Elapsed time: 77.825729 msecs + (is (= (f 30) 61354575194)) ; "Elapsed time: 470.359975 msecs" ) (deftest f-v2-test ; ~ O(n) - (time (is (= (f-v2 1) 1))) ; "Elapsed time: 3.209596 msecs" - (time (is (= (f-v2 2) 2))) ; "Elapsed time: 1.38101 msecs" - (time (is (= (f-v2 3) 4))) ; "Elapsed time: 2.122814 msecs" - (time (is (= (f-v2 4) 11))) ; "Elapsed time: 1.531897 msecs" - (time (is (= (f-v2 5) 25))) ; "Elapsed time: 1.403303 msecs" - (time (is (= (f-v2 6) 59))) ; "Elapsed time: 1.383425 msecs" - (time (is (= (f-v2 7) 142))) ; "Elapsed time: 1.335105 msecs" - (time (is (= (f-v2 8) 335))) ; "Elapsed time: 1.88524 msecs" - (time (is (= (f-v2 9) 796))) ; "Elapsed time: 2.091203 msecs" - (time (is (= (f-v2 10) 1892))) ; "Elapsed time: 3.245716 msecs" - (time (is (= (f-v2 20) 10771211))) ; "Elapsed time: 3.275056 msecs" - (time (is (= (f-v2 25) 812934961))) ; "Elapsed time: 1.989168 msecs" - (time (is (= (f-v2 30) 61354575194))) ; "Elapsed time: 2.462203 msecs" + (is (= (f-v2 1) 1)) ; "Elapsed time: 3.209596 msecs" + (is (= (f-v2 2) 2)) ; "Elapsed time: 1.38101 msecs" + (is (= (f-v2 3) 4)) ; "Elapsed time: 2.122814 msecs" + (is (= (f-v2 4) 11)) ; "Elapsed time: 1.531897 msecs" + (is (= (f-v2 5) 25)) ; "Elapsed time: 1.403303 msecs" + (is (= (f-v2 6) 59)) ; "Elapsed time: 1.383425 msecs" + (is (= (f-v2 7) 142)) ; "Elapsed time: 1.335105 msecs" + (is (= (f-v2 8) 335)) ; "Elapsed time: 1.88524 msecs" + (is (= (f-v2 9) 796)) ; "Elapsed time: 2.091203 msecs" + (is (= (f-v2 10) 1892)) ; "Elapsed time: 3.245716 msecs" + (is (= (f-v2 20) 10771211)) ; "Elapsed time: 3.275056 msecs" + (is (= (f-v2 25) 812934961)) ; "Elapsed time: 1.989168 msecs" + (is (= (f-v2 30) 61354575194)) ; "Elapsed time: 2.462203 msecs" ) diff --git a/test/sicp/chapter_1/part_2/ex_1_12_test.clj b/test/sicp/chapter_1/part_2/ex_1_12_test.clj index 4b20506..4fc2f8b 100644 --- a/test/sicp/chapter_1/part_2/ex_1_12_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_12_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-12-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-12 :refer [pascal]])) (deftest pascal-test diff --git a/test/sicp/chapter_1/part_2/ex_1_14_test.clj b/test/sicp/chapter_1/part_2/ex_1_14_test.clj index 830bb16..da58876 100644 --- a/test/sicp/chapter_1/part_2/ex_1_14_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_14_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-14-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-14 :refer [money-change]])) (deftest count-change-test diff --git a/test/sicp/chapter_1/part_2/ex_1_15_test.clj b/test/sicp/chapter_1/part_2/ex_1_15_test.clj index 0267568..66df11e 100644 --- a/test/sicp/chapter_1/part_2/ex_1_15_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_15_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex_1_15-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex_1_15 :refer [sine]])) (deftest sine-test diff --git a/test/sicp/chapter_1/part_2/ex_1_16_test.clj b/test/sicp/chapter_1/part_2/ex_1_16_test.clj index 581788c..9018c23 100644 --- a/test/sicp/chapter_1/part_2/ex_1_16_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_16_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-16-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-16 :refer [expt]])) (deftest expt-test diff --git a/test/sicp/chapter_1/part_2/ex_1_17_test.clj b/test/sicp/chapter_1/part_2/ex_1_17_test.clj index 2281ae8..5027435 100644 --- a/test/sicp/chapter_1/part_2/ex_1_17_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_17_test.clj @@ -1,17 +1,17 @@ (ns sicp.chapter-1.part_2.ex-1-17-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-17 :refer [multi multi-fast]])) (deftest multi-test - (time (is (= 2 (multi 1 2)))) ; "Elapsed time: 2.383128 msecs" - (time (is (= 50 (multi 10 5)))) ; "Elapsed time: 1.087389 msecs" - (time (is (= 6703582689499996764 - (multi 12345340404 543005091)))) ; "Elapsed time: 0.852849 msecs" + (is (= 2 (multi 1 2))) ; "Elapsed time: 2.383128 msecs" + (is (= 50 (multi 10 5))) ; "Elapsed time: 1.087389 msecs" + (is (= 6703582689499996764 + (multi 12345340404 543005091))) ; "Elapsed time: 0.852849 msecs" ) (deftest multi-fast-test - (time (is (= 2 (multi-fast 1 2)))) ; "Elapsed time: 1.258788 msecs" - (time (is (= 50 (multi-fast 10 5)))) ; "Elapsed time: 1.582771 msecs" - (time (is (= 6703582689499996764 - (multi-fast 12345340404 543005091)))) ; "Elapsed time: 1.01612 msecs" + (is (= 2 (multi-fast 1 2))) ; "Elapsed time: 1.258788 msecs" + (is (= 50 (multi-fast 10 5))) ; "Elapsed time: 1.582771 msecs" + (is (= 6703582689499996764 + (multi-fast 12345340404 543005091))) ; "Elapsed time: 1.01612 msecs" ) \ No newline at end of file diff --git a/test/sicp/chapter_1/part_2/ex_1_18_test.clj b/test/sicp/chapter_1/part_2/ex_1_18_test.clj index 2c6bcb7..c5ff09c 100644 --- a/test/sicp/chapter_1/part_2/ex_1_18_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_18_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-18-test - (:require [clojure.test :refer :all]) + (:require [clojure.test :refer [deftest is]]) (:require [sicp.chapter-1.part_2.ex-1-18 :refer [mult]])) (deftest mult-test diff --git a/test/sicp/chapter_1/part_2/ex_1_19_test.clj b/test/sicp/chapter_1/part_2/ex_1_19_test.clj index 5994c44..1cf2342 100644 --- a/test/sicp/chapter_1/part_2/ex_1_19_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_19_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-19-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-19 :refer [fib fib-v2]])) (deftest fib-test diff --git a/test/sicp/chapter_1/part_2/ex_1_20_test.clj b/test/sicp/chapter_1/part_2/ex_1_20_test.clj index 503839b..0caae2b 100644 --- a/test/sicp/chapter_1/part_2/ex_1_20_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_20_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-20-test - (:require [clojure.test :refer :all]) + (:require [clojure.test :refer [deftest is]]) (:require [sicp.chapter-1.part_2.ex-1-20 :refer [gcd]])) (deftest gcd-test diff --git a/test/sicp/chapter_1/part_2/ex_1_21_test.clj b/test/sicp/chapter_1/part_2/ex_1_21_test.clj index 336fa28..3601f18 100644 --- a/test/sicp/chapter_1/part_2/ex_1_21_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_21_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-21-test - (:require [clojure.test :refer :all]) + (:require [clojure.test :refer [deftest is]]) (:require [sicp.chapter-1.part_2.ex-1-21 :refer [smallest-divisor]])) (deftest smallest-divisor-test diff --git a/test/sicp/chapter_1/part_2/ex_1_22_test.clj b/test/sicp/chapter_1/part_2/ex_1_22_test.clj index a7696c9..d79214b 100644 --- a/test/sicp/chapter_1/part_2/ex_1_22_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_22_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-22-test - (:require [clojure.test :refer :all]) + (:require [clojure.test :refer [deftest is]]) (:require [sicp.chapter-1.part_2.ex-1-22 :refer [find-primes]])) (deftest find-primes-test diff --git a/test/sicp/chapter_1/part_2/ex_1_9_test.clj b/test/sicp/chapter_1/part_2/ex_1_9_test.clj index 7a15faf..de076fa 100644 --- a/test/sicp/chapter_1/part_2/ex_1_9_test.clj +++ b/test/sicp/chapter_1/part_2/ex_1_9_test.clj @@ -1,5 +1,5 @@ (ns sicp.chapter-1.part_2.ex-1-9-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is]] [sicp.chapter-1.part_2.ex-1-9 :refer [plus plus-v2]])) (deftest plus-test