You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1004 B
26 lines
1004 B
(ns cipher-analytical-machine.cipher-analyzers-test
|
|
(:require
|
|
[clojure.test :refer :all]
|
|
[cipher-analytical-machine.cipher-analyzers :refer :all]))
|
|
|
|
(deftest count-characters-test
|
|
(testing "Count two dublicates and one uniq character from a string."
|
|
(is (= {\a 2 \b 1}
|
|
(count-characters "aba")))))
|
|
|
|
(deftest chi-squared-letter-statistic-test
|
|
(testing "If the frequence of A is 0.1, the text length is 100 and contains 20 times, then the chi-squared is 10."
|
|
(is (= 10.0
|
|
(chi-squared-letter-statistic 20 0.1 100))))
|
|
|
|
(testing "If the frequence of A is 0.1, the text length is 10 and contains 5 times, then the chi-squared is 16.0."
|
|
(is (= 16.0
|
|
(chi-squared-letter-statistic 5 0.1 10)))))
|
|
|
|
(deftest chi-squared-statistic-test
|
|
(let [text "aaaaabbbbb"]
|
|
(testing "If the frequences of a and b is 0.1, the text length is 10 and contains them 5 times, then score is 32."
|
|
(is (= 32.0
|
|
(chi-squared-statistic text {\a 0.1 \b 0.1}))))))
|
|
|