diff --git a/src/cipher_analytical_machine/parsers/gamma.clj b/src/cipher_analytical_machine/parsers/gamma.clj new file mode 100644 index 0000000..22e2ac3 --- /dev/null +++ b/src/cipher_analytical_machine/parsers/gamma.clj @@ -0,0 +1,9 @@ +(ns cipher-analytical-machine.parsers.gamma + (:gen-class)) + +(defn key? + "Return true if the string is an key of three integers." + [str] + (if (re-matches #"[+-]?\b\d+\b,[+-]?\b\d+\b,[+-]?\b\d+\b" str) + true false)) + diff --git a/test/cipher_analytical_machine/parsers/gamma_test.clj b/test/cipher_analytical_machine/parsers/gamma_test.clj new file mode 100644 index 0000000..11992b2 --- /dev/null +++ b/test/cipher_analytical_machine/parsers/gamma_test.clj @@ -0,0 +1,20 @@ +(ns cipher-analytical-machine.parsers.gamma-test + (:require + [clojure.test :refer :all] + [cipher-analytical-machine.parsers.gamma :refer :all])) + +(deftest key?-test + (testing "The function return true only if the key in the format '%d,%d,%d'." + (are [str expected] + (= expected + (key? str)) + "9" false + "9,10" false + "10,9,8" true + "-10,9,-8" true + "-10,-9,-8" true + "asd 10 " false + " 10 " false + "-10" false + "abc" false))) +