humidity/test/humidity/wet_bulb_test.clj

66 lines
2.9 KiB
Clojure

(ns humidity.wet-bulb-test
(:require [clojure.test :refer [deftest is testing]]
[humidity.wet-bulb-temperature-celsius :refer [wet-bulb-temperature-celsius-fn]]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Copyright (C) 2026 Simon Brooke
;;;
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License
;;; as published by the Free Software Foundation; either version 2
;;; of the License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;;; USA.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftest wet-bulb-test
(testing "Example from paper"
(let [expected 13.7
temperature 20
rel-humidity 50
actual (wet-bulb-temperature-celsius-fn :temperature-celsius temperature :relative-humidity rel-humidity)]
(println (format "Expected: %s; actual: %s" expected actual))
(is (< (abs (- expected actual)) 0.001))))
(testing "Interpolations from graph"
(let [min-expected 31
max-expected 33
temperature 37
rel-humidity 70
actual (wet-bulb-temperature-celsius-fn :temperature-celsius temperature :relative-humidity rel-humidity)]
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
(is (< min-expected actual max-expected)))
(let [min-expected 34
max-expected 36
temperature 39.7
rel-humidity 70
actual (wet-bulb-temperature-celsius-fn :temperature-celsius temperature :relative-humidity rel-humidity)]
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
(is (< min-expected actual max-expected)))
(let [min-expected 31
max-expected 34
temperature 40
rel-humidity 60
actual (wet-bulb-temperature-celsius-fn :temperature-celsius temperature :relative-humidity rel-humidity)]
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
(is (< min-expected actual max-expected)))
(let [min-expected 32
max-expected 35
temperature 51
rel-humidity 30
actual (wet-bulb-temperature-celsius-fn :temperature-celsius temperature :relative-humidity rel-humidity)]
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
(is (< min-expected actual max-expected)))))