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

Improvements in auto test #19

Merged
merged 1 commit into from
Oct 19, 2023
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
7 changes: 3 additions & 4 deletions .cljfmt.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{:split-keypairs-over-multiple-lines? true
:sort-ns-references? true
:indentation? false
:paths ["src" "dev" "test"]}
{:indentation? false
:paths ["src" "test"]
:sort-ns-references? true}
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -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")}}
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
4 changes: 2 additions & 2 deletions src/sicp/chapter_1/part_2/ex_1_22.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_1/ex_1_3_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_1/ex_1_4_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_1/ex_1_5_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/sicp/chapter_1/part_1/ex_1_6_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))))
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_1/ex_1_7_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_1/ex_1_8_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_10_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
54 changes: 27 additions & 27 deletions test/sicp/chapter_1/part_2/ex_1_11_test.clj
Original file line number Diff line number Diff line change
@@ -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"
)
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_12_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_14_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_15_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_16_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions test/sicp/chapter_1/part_2/ex_1_17_test.clj
Original file line number Diff line number Diff line change
@@ -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"
)
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_18_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_19_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_20_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_21_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_22_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sicp/chapter_1/part_2/ex_1_9_test.clj
Original file line number Diff line number Diff line change
@@ -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
Expand Down