From 1e45771b3e56184dbe8eb045dc105ece3b4e8681 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 1 Nov 2023 15:05:08 +0200 Subject: [PATCH] Add key? to check if a string is a gamma key. --- .../parsers/gamma.clj | 9 +++++++++ .../parsers/gamma_test.clj | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/cipher_analytical_machine/parsers/gamma.clj create mode 100644 test/cipher_analytical_machine/parsers/gamma_test.clj 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))) +