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

Cars-assemble: fix tests failing due to floating point precision #610

Merged
merged 2 commits into from
Mar 12, 2024
Merged
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
16 changes: 10 additions & 6 deletions exercises/concept/cars-assemble/test/cars_assemble_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@
(:require cars-assemble
[clojure.test :refer [deftest is testing]]))

(defn- float-equal?
[x y]
(= (float x) (float y)))

(deftest ^{:task 1} production-rate-speed-0-test
(testing "Production rate for speed 0"
(is (= 0.0 (cars-assemble/production-rate 0)))))
(is (float-equal? 0.0 (cars-assemble/production-rate 0)))))

(deftest ^{:task 1} production-rate-speed-1-test
(testing "Production rate for speed 1"
(is (= 221.0 (cars-assemble/production-rate 1)))))
(is (float-equal? 221.0 (cars-assemble/production-rate 1)))))

(deftest ^{:task 1} production-rate-speed-4-test
(testing "Production rate for speed 4"
(is (= 884.0 (cars-assemble/production-rate 4)))))
(is (float-equal? 884.0 (cars-assemble/production-rate 4)))))

(deftest ^{:task 1} production-rate-speed-7-test
(testing "Production rate for speed 7"
(is (= 1392.3 (cars-assemble/production-rate 7)))))
(is (float-equal? 1392.3 (cars-assemble/production-rate 7)))))

(deftest ^{:task 1} production-rate-speed-9-test
(testing "Production rate for speed 9"
(is (= 1591.2 (cars-assemble/production-rate 9)))))
(is (float-equal? 1591.2 (cars-assemble/production-rate 9)))))

(deftest ^{:task 1} production-rate-speed-10-test
(testing "Production rate for speed 10"
(is (= 1701.7 (cars-assemble/production-rate 10)))))
(is (float-equal? 1701.7 (cars-assemble/production-rate 10)))))

(deftest ^{:task 2} working-items-speed-0-test
(testing "Working items for speed 0"
Expand Down
Loading