Skip to content

Commit

Permalink
tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie committed Apr 8, 2024
1 parent 5287511 commit 16df6c1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/emmy/numerical/derivative.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
;; First, a function that will print nicely rendered infix versions
;; of (simplified) symbolic expressions:

(->clerk-only
(->clerk
(defn- show [e]
(nextjournal.clerk/tex
(->TeX
(g/simplify e)))))

;; And a function to play with:

(->clerk-only
(->clerk
(def func
(af/literal-function 'f)))

Expand All @@ -70,7 +70,7 @@

;; Here's the taylor series expansions of $f(x + h)$:

(->clerk-only
(->clerk
(def fx+h
(-> ((d/taylor-series func 'x) 'h)
(series/sum 4))))
Expand Down Expand Up @@ -110,7 +110,7 @@

;; We could also expand $f(x - h)$:

(->clerk-only
(->clerk
(def fx-h
(-> ((d/taylor-series func 'x) (g/negate 'h))
(series/sum 4))))
Expand Down
17 changes: 16 additions & 1 deletion test/emmy/abstract/function_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

(ns emmy.abstract.function-test
(:refer-clojure :exclude [partial =])
(:require [clojure.test :refer [is deftest testing use-fixtures]]
(:require [clojure.pprint :as pprint]

Check warning on line 5 in test/emmy/abstract/function_test.cljc

View workflow job for this annotation

GitHub Actions / lint

namespace cljs.pprint is required but never used
[clojure.test :refer [is deftest testing use-fixtures]]
[clojure.test.check.generators :as gen]
[com.gfredericks.test.chuck.clojure-test :refer [checking]]
[emmy.abstract.function :as af]
Expand Down Expand Up @@ -57,6 +58,20 @@
(is (= ::af/function kind))
(is (isa? kind ::v/function)))))

(deftest printing-tests
#?(:clj
(let [f-name '(D f)
f (af/literal-function f-name)]
(is (= (with-out-str
(pprint/pprint f))
(with-out-str
(pprint/pprint f-name)))
"pprint prints the fn name")
(is (= (str f "\n")
(with-out-str
(pprint/pprint f)))
"pprint matches the string rep for short names"))))

(deftest equations-moved-from-simplify
(testing "moved-from-simplify"
(let [xy (s/up (af/literal-function 'x)
Expand Down
17 changes: 16 additions & 1 deletion test/emmy/structure_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,22 @@
[s (-> (sg/reasonable-real 100)
(sg/structure 3))]
(is (ish? (reduce g/+ (flatten s))
(s/sumr identity s)))))
(s/sumr identity s))))

(checking "fold-chain matches sumr" 100
[s (-> (sg/reasonable-real 100)
(sg/structure 3))]
(let [f (fn
([] 0)
([acc] acc)
([acc [x _ _]] (g/+ acc x)))]
(is (ish? (s/sumr identity s)
(s/fold-chain f s)))

(is (= (s/fold-chain f 0.0 identity s)
(s/fold-chain f 0.0 s)
(s/fold-chain f s))
"All fold-chain arities match"))))

(is (== (ua/sum g/square 0 10)
(s/sumr g/square
Expand Down

0 comments on commit 16df6c1

Please sign in to comment.