aboutsummaryrefslogtreecommitdiff
path: root/test/genpass/gen_test.clj
blob: 05d8994a4df1e01614972e88885d52dd405563ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(ns genpass.gen-test
  (:require [clojure.test :refer :all]
            [genpass.gen :refer :all]))

(def valid-char-regex #"^[a-zA-Z0-1\!\@\#\%\^\&\*\(\)\{\}\[\]\-\+\=\~]*$")
(def not-nil? (complement nil?))

(deftest rand-char-test
  (testing "check if return a valid char"
    (is (some (partial = (rand-char)) all-char))
    (is (some (partial = (rand-char)) all-char))
    (is (some (partial = (rand-char)) all-char))))

(deftest genpwd-test
  (testing "check it return 12 chars by defaul"
    (is (= 12 (count (genpwd)))))
  (testing "check it return x chars"
    (is (= 12 (count (genpwd 12))))
    (is (= 0 (count (genpwd 0))))
    (is (= 1 (count (genpwd 1))))
    (is (= 1000 (count (genpwd 1000)))))
  (testing "check if generate valid chars"
    (is (not-nil? (re-matches valid-char-regex (genpwd))))
    (is (not-nil? (re-matches valid-char-regex (genpwd 1))))
    (is (not-nil? (re-matches valid-char-regex (genpwd 1000))))
    (is (not-nil? (re-matches valid-char-regex (genpwd 4))))
    ))