I use "intern" function for generate runtime funtions, but I can't test generted function.
In core.clj I defined functions that generate runtime functions like this.
(ns cftf.core)
(defn- generation-function [function-name ratio]
(let [function-symbol (symbol function-name)]
(intern 'cftf.core function-symbol (fn [input] (cftf.core/convert ratio input)))))
...
(defn generate-function-by-units [units]
(->> units
(units->function-name-and-ratio)
(map #(generation-function (first %) (second %)))))
I wrote the following test code.
(ns cftf.core-test
(:require [clojure.test :refer :all]
[cftf.core :as c]))
(defn amount-of-alcohol-per-one-bottle [bottle-size abv]
(* bottle-size (/ abv 100)))
(def alcohol-units
{:soju (amount-of-alcohol-per-one-bottle 360 16.5)
:beer (amount-of-alcohol-per-one-bottle 500 5)
:whisky (amount-of-alcohol-per-one-bottle 700 40)
})
(c/generate-function-by-units alcohol-units)
(deftest a-test
(testing "soju->beer test"
(is (= (int (c/soju->beer 1)) 2))))
After calling "generate-function-by-units" in the repl, you can use the "soju->beer" function.
But in the test I get the error "No such var: c/soju->beer".
I've tried using a fixture or calling " generate-function-by-units" the top in test.clj, but I'm still getting the error.