Fork me on GitHub
#testing
<
2019-07-08
>
trinity22:07:40

what’s the best way to test multiple assertions from defined variables? ex. i have this but feel there must be a more idiomatic way:

(def pangrams
  ["the quick brown fox jumps over the lazy dog"
   "My girl wove six dozen plaid jackets before she quit!"
   "J.Q. Schwartz flung V.D. Pike my box"])

(def not-pangrams
  ["Sadly, I am not a pangram :("])

(deftest pangram-1-test
  (testing "is the given string a pangram according to pangram-1 fn?"
    (dorun (map #(is (= true (pangram-1? %))) pangrams))
    (dorun (map #(is (= false (pangram-1? %))) not-pangrams))))

aisamu01:07:06

That looks alright to me! It's possible to change (dorun (map with doseq. Adding messages to the assertions can also be useful to distinguish them while inspecting the test results:

(testing "is the given string a pangram according to pangram-1 fn?"
  (doseq [pangram pangrams]
    (is (true? (pangram-1? pangram)) "for known valid pangrams"))
  (doseq [pangram not-pangrams]
    (is (false? (pangram-1? pangram) "for known invalid pangrams"))))

aisamu01:07:06

That looks alright to me! It's possible to change (dorun (map with doseq. Adding messages to the assertions can also be useful to distinguish them while inspecting the test results:

(testing "is the given string a pangram according to pangram-1 fn?"
  (doseq [pangram pangrams]
    (is (true? (pangram-1? pangram)) "for known valid pangrams"))
  (doseq [pangram not-pangrams]
    (is (false? (pangram-1? pangram) "for known invalid pangrams"))))