[bug] fix #2329 Generate username as Unknown for nil and 0 public key

This commit is contained in:
m'hammed 2017-11-12 17:08:21 +01:00 committed by Andrey Shovkoplyas
parent 6882dc7bcd
commit 319a770872
2 changed files with 17 additions and 6 deletions

View File

@ -9,11 +9,20 @@
[gen vector]
(str/capitalize (rnd/seeded-rand-nth gen vector)))
(defn- build-gfy
[public-key]
(let [gen (rnd/rand-gen public-key)
first-adjective (pick-random gen adjectives/data)
second-adjective (pick-random gen adjectives/data)
animal (pick-random gen animals/data)]
(str first-adjective " " second-adjective " " animal)))
(def unknown-gfy "Unknown")
(defn generate-gfy
([public-key]
(let [gen (rnd/rand-gen public-key)
first-adjective (pick-random gen adjectives/data)
second-adjective (pick-random gen adjectives/data)
animal (pick-random gen animals/data)]
(str first-adjective " " second-adjective " " animal)))
(case public-key
nil unknown-gfy
"0" unknown-gfy
(build-gfy public-key)))
([] (generate-gfy (now-ms))))

View File

@ -9,4 +9,6 @@
(is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message)
(is (= (gfy/generate-gfy "57348975ff9199ca636207a396b915d6b6a675b4") "Winged Fitting Mosquito") message)
(is (= (gfy/generate-gfy "26cf649aebb252a75aebc588e0d9ce93789dbe0b") "Educated Upright Arcticseal") message)
(is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message))
(is (= (gfy/generate-gfy "e63d083d2d7a13a14632983b5820529445ca8109") "Mediumvioletred Melodic Waterdogs") message)
(is (= (gfy/generate-gfy nil) gfy/unknown-gfy) message)
(is (= (gfy/generate-gfy "0") gfy/unknown-gfy) message))