Skip to content

Instantly share code, notes, and snippets.

@serioga
Last active December 29, 2021 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serioga/23bbe9149c664b5723d97d4304213192 to your computer and use it in GitHub Desktop.
Save serioga/23bbe9149c664b5723d97d4304213192 to your computer and use it in GitHub Desktop.
flexiana-test-task
(ns user.flexiana-test-task
"https://twitter.com/itunderhood/status/1475580051571757065
https://github.com/Terbiy/flexiana-test-task/blob/main/test/flexiana_test_task/core_test.clj"
(:require [clojure.test :refer :all]))
(set! *warn-on-reflection* true)
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(defn scramble? [a b]
(throw (AssertionError. (pr-str 'scramble [a b]))))
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(deftest incorrect-input
(testing
"Any type of non-string parameter leads to an exception."
(let [DIFFERENT_NON_STRING_VALUES [nil 1 1/2 1.0 36786883868216818816N
3.14159265358M \a :a '() [] {} #{}]]
(doseq [a DIFFERENT_NON_STRING_VALUES,
b DIFFERENT_NON_STRING_VALUES]
(is (thrown? AssertionError (scramble? a b)))))))
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(defmacro non-string-tests-macro
[values]
`(are [~'a ~'b] (~'thrown? AssertionError (scramble? ~'a ~'b))
~@(apply concat (for [a values b values] [a b]))))
(comment
(macroexpand-1 '(non-string-tests-macro [nil 1 1/2 1.0]))
(clojure.walk/macroexpand-all '(non-string-tests-macro [nil 1 1/2 1.0])))
(deftest incorrect-input-using-macro
(testing
"Any type of non-string parameter leads to an exception."
(non-string-tests-macro [nil 1 1/2 1.0 36786883868216818816N
3.14159265358M \a :a '() [] {} #{}])))
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
(defmacro non-string-tests-macro2
[values]
`(do ~@(for [a values b values]
`(is (~'thrown? AssertionError (scramble? ~a ~b))))))
(comment
(macroexpand-1 '(non-string-tests-macro2 [nil 1 1/2 1.0]))
(clojure.walk/macroexpand-all '(non-string-tests-macro2 [nil 1 1/2 1.0])))
(deftest incorrect-input-using-macro2
(testing
"Any type of non-string parameter leads to an exception."
(non-string-tests-macro2 [nil 1 1/2 1.0 36786883868216818816N
3.14159265358M \a :a '() [] {} #{}])))
;;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment