-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test files for ex-2-73 and ex-2-75 and improve derivation functions
Created new test files for exercises 2-73 and 2-75. The test cases for these exercises are now fully covered. Also, made some improvements in the derivation functions in exercise 2-73 by replacing `put` with `put-op` and `get` with `get-op` methods to manage operations in a more optimized way.
- Loading branch information
Denis Smet
committed
Feb 11, 2024
1 parent
668f42e
commit a0721ad
Showing
3 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(ns sicp.chapter-2.part-4.ex-2-73-test | ||
(:require | ||
[clojure.test :refer [deftest is]] | ||
[sicp.chapter-2.part-4.ex-2-73 :as ex-2-73] | ||
[sicp.misc :as m])) | ||
|
||
(ex-2-73/install-sum-derivation) | ||
(ex-2-73/install-product-derivation) | ||
(ex-2-73/install-exponent-derivation) | ||
|
||
(deftest deriv-test | ||
(is (= 0 (ex-2-73/deriv 10 5))) | ||
(is (= 0 (ex-2-73/deriv 'x 5))) | ||
(is (= 0 (ex-2-73/deriv 'x 'y))) | ||
(is (= 0 (ex-2-73/deriv '+ 'y))) | ||
(is (= 0 (ex-2-73/deriv '(+ 2 2) 'x))) | ||
(is (= 0 (ex-2-73/deriv '(* 2 2) 'x))) | ||
(is (= true (m/is-exception? (ex-2-73/deriv '(** 2 2) 'x) "unknown expression type: DERIV (** 2 2)")))) | ||
|
||
(deftest deriv-v2-test | ||
(is (= 0 (ex-2-73/deriv-v2 10 5))) | ||
(is (= 0 (ex-2-73/deriv-v2 'x 5))) | ||
(is (= 0 (ex-2-73/deriv-v2 'x 'y))) | ||
(is (= 0 (ex-2-73/deriv-v2 '+ 'y))) | ||
(is (= true (m/is-exception? (ex-2-73/deriv-v2 '(* 2 2) 'x) "unknown expression type: DERIV (* 2 2)")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(ns sicp.chapter-2.part-4.ex-2-75-test | ||
(:require | ||
[clojure.test :refer :all] | ||
[sicp.chapter-2.part-4.ex-2-75 :refer [make-from-mag-ang]] | ||
[sicp.misc :as m])) | ||
|
||
(def angle-60 (/ Math/PI 3)) | ||
(def radius 2.0) | ||
(def x 1.0000000000000002) | ||
(def y 1.7320508075688772) | ||
|
||
(deftest make-from-mag-ang-test | ||
(is (= x ((make-from-mag-ang radius angle-60) :real-part))) | ||
(is (= y ((make-from-mag-ang radius angle-60) :imag-part))) | ||
(is (= radius ((make-from-mag-ang radius angle-60) :magnitude))) | ||
(is (= angle-60 ((make-from-mag-ang radius angle-60) :angle))) | ||
(is (= true (m/is-exception? ((make-from-mag-ang radius angle-60) :undefined) | ||
"Unknown op: MAKE-FROM-REAL-IMAG :undefined")))) |