Add a function to invert the table in a decoded json.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[cipher-analytical-machine.ciphers.simple-substitution :as ss]
|
[cipher-analytical-machine.ciphers.simple-substitution :as ss]
|
||||||
[cipher-analytical-machine.parsers.parsers :as ps]
|
[cipher-analytical-machine.parsers.parsers :as ps]
|
||||||
|
[clojure.set :as set]
|
||||||
[cheshire.core :as cc])
|
[cheshire.core :as cc])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
@@ -42,3 +43,12 @@
|
|||||||
(assoc "table" (ss/generate-substitution-table symbols)))
|
(assoc "table" (ss/generate-substitution-table symbols)))
|
||||||
(decode-key-and-substitution-table-from-json key-or-json)))
|
(decode-key-and-substitution-table-from-json key-or-json)))
|
||||||
|
|
||||||
|
(defn invert-table-in-map
|
||||||
|
"Invert the table in a decoded json (key, table)"
|
||||||
|
[decoded-json]
|
||||||
|
(->>
|
||||||
|
(-> decoded-json
|
||||||
|
(get "table")
|
||||||
|
(set/map-invert))
|
||||||
|
(assoc decoded-json "table")))
|
||||||
|
|
||||||
|
|||||||
@@ -39,3 +39,11 @@
|
|||||||
"1" {"key" 1 "table" {0 \a 1 \b 2 \c}}
|
"1" {"key" 1 "table" {0 \a 1 \b 2 \c}}
|
||||||
"2" {"key" 2 "table" {\a 0 \b 1 \c 2}}))))
|
"2" {"key" 2 "table" {\a 0 \b 1 \c 2}}))))
|
||||||
|
|
||||||
|
(deftest invert-table-in-map-test
|
||||||
|
(testing "The function invert the table in a decoded json."
|
||||||
|
(are [decoded-json expected-data]
|
||||||
|
(= expected-data
|
||||||
|
(invert-table-in-map decoded-json))
|
||||||
|
{"key" 1 "table" {0 \a 1 \b 2 \c}} {"key" 1 "table" {\a 0 \b 1 \c 2}}
|
||||||
|
{"key" 2 "table" {\a 0 \b 1 \c 2}} {"key" 2 "table" {0 \a 1 \b 2 \c}})))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user