From e43ba25528e4bf595eeb01443c63765b30dafaba Mon Sep 17 00:00:00 2001 From: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> Date: Wed, 13 Mar 2024 01:21:14 +0200 Subject: [PATCH] Cars-assemble: fix tests failing due to floating point precision (#610) * Cars-assemble: fix tests failing due to floating point precision * fix typo --- .../cars-assemble/test/cars_assemble_test.clj | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/exercises/concept/cars-assemble/test/cars_assemble_test.clj b/exercises/concept/cars-assemble/test/cars_assemble_test.clj index 1eeec2e3..0cce00ad 100644 --- a/exercises/concept/cars-assemble/test/cars_assemble_test.clj +++ b/exercises/concept/cars-assemble/test/cars_assemble_test.clj @@ -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"