Skip to content

Commit

Permalink
Cars-assemble: fix tests failing due to floating point precision (#610)
Browse files Browse the repository at this point in the history
* Cars-assemble: fix tests failing due to floating point precision

* fix typo
  • Loading branch information
tasxatzial committed Mar 12, 2024
1 parent 20eaa6c commit e43ba25
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions exercises/concept/cars-assemble/test/cars_assemble_test.clj
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

0 comments on commit e43ba25

Please sign in to comment.