Add functions with tests for generating responses
Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
This commit is contained in:
parent
ec9e3d80eb
commit
6e0f0237b3
|
@ -0,0 +1,42 @@
|
|||
;; SPDX-License-Identifier: Apache-2.0
|
||||
;; SPDX-FileCopyrightText: 2022 Sebastian Crane <seabass-labrax@gmx.com>
|
||||
|
||||
(ns bot
|
||||
(:require [clojure.string :as str]
|
||||
[game]
|
||||
[irclj.core]))
|
||||
|
||||
(defn sorted-players-of-game [state game]
|
||||
(->> game
|
||||
(str/lower-case)
|
||||
(keyword)
|
||||
(game/get-players-of-game state)
|
||||
(sort)))
|
||||
|
||||
(defn match-string [state game]
|
||||
(str "Anyone ready for "
|
||||
game
|
||||
"? "
|
||||
(str/join " " (sorted-players-of-game state game))))
|
||||
|
||||
(defn list-players-string [state game]
|
||||
(let [players (str/join (map #(str " _" % "_")
|
||||
(sorted-players-of-game state game)))]
|
||||
(str "Players of "
|
||||
game
|
||||
":"
|
||||
players)))
|
||||
|
||||
(defn add-player-string [player game]
|
||||
(str "Added "
|
||||
player
|
||||
" to the list of players for "
|
||||
game
|
||||
"!"))
|
||||
|
||||
(defn remove-player-string [player game]
|
||||
(str "Removed "
|
||||
player
|
||||
" from the list of players for "
|
||||
game
|
||||
"!"))
|
|
@ -0,0 +1,26 @@
|
|||
;; SPDX-License-Identifier: Apache-2.0
|
||||
;; SPDX-FileCopyrightText: 2022 Sebastian Crane <seabass-labrax@gmx.com>
|
||||
|
||||
(ns bot-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[bot :refer :all]))
|
||||
|
||||
(def test-state '{:games {:hypothetical-shooter #{"abc" "xyz" "123"}
|
||||
:quasi-rts #{"abc" "123"}
|
||||
:imaginary-rpg #{"xyz" "abc"}}})
|
||||
|
||||
(deftest match-string-test
|
||||
(is (= '"Anyone ready for quasi-Rts? 123 abc"
|
||||
(match-string test-state "quasi-Rts"))))
|
||||
|
||||
(deftest list-players-string-test
|
||||
(is (= "Players of HYPOTHETICAL-shooter: _123_ _abc_ _xyz_"
|
||||
(list-players-string test-state "HYPOTHETICAL-shooter"))))
|
||||
|
||||
(deftest add-player-string-test
|
||||
(is (= "Added abc to the list of players for Quasi-Rts!"
|
||||
(add-player-string "abc" "Quasi-Rts"))))
|
||||
|
||||
(deftest remove-player-string-test
|
||||
(is (= "Removed abc from the list of players for hypothetical-shooter!"
|
||||
(remove-player-string "abc" "hypothetical-shooter"))))
|
Loading…
Reference in New Issue