Fix generation bug: "...a MD-50..."

This commit is contained in:
John Wiseman 2019-12-28 22:26:47 -08:00
parent 516ec4bd24
commit 3c7d1c25f6
2 changed files with 25 additions and 12 deletions

View File

@ -68,7 +68,9 @@
(def filters (def filters
{:a-an (fn a-an [s] {:a-an (fn a-an [s]
(if (starts-with-consonant? s) (if (starts-with-consonant? s)
(str "a " s) (if (re-find #"^[FHLMNRSX](\b|[A-Z0-9])" s)
(str "an " s)
(str "a " s))
(str "an " s)))}) (str "an " s)))})

View File

@ -1,5 +1,5 @@
(ns lemondronor.circlebot.generation-test (ns lemondronor.circlebot.generation-test
(:require [cljs.test :refer (deftest is)] (:require [cljs.test :refer (deftest is testing)]
[lemondronor.circlebot.generation :as generation])) [lemondronor.circlebot.generation :as generation]))
(deftest parse-template (deftest parse-template
@ -27,7 +27,7 @@
(generation/generate-all (generation/generate-all
[(generation/parse-template "Hello!")] [(generation/parse-template "Hello!")]
{}))) {})))
(is (= "Hello!" (is (= "Hello!"
(generation/generate (generation/generate
[(generation/parse-template "Hello!")] [(generation/parse-template "Hello!")]
{})))) {}))))
@ -74,15 +74,26 @@
(deftest filters (deftest filters
(let [templates [(generation/parse-template "It is {thing|a-an}")]] (testing "a-an"
(is (= "It is a bird" (let [templates [(generation/parse-template "It is {thing|a-an}")]]
(generation/generate templates {:thing "bird"}))) (is (= "It is a bird"
(is (= "It is an animal" (generation/generate templates {:thing "bird"})))
(generation/generate templates {:thing "animal"}))) (is (= "It is an animal"
(is (= "It is an Animal" (generation/generate templates {:thing "animal"})))
(generation/generate templates {:thing "Animal"}))) (is (= "It is an Animal"
(is (= "It is a Eurocopter" (generation/generate templates {:thing "Animal"})))
(generation/generate templates {:thing "Eurocopter"}))))) (is (= "It is a Eurocopter"
(generation/generate templates {:thing "Eurocopter"})))
(is (= "It is an MD-500"
(generation/generate templates {:thing "MD-500"})))
(is (= "It is an F-15"
(generation/generate templates {:thing "F-15"})))
(is (= "It is an X-15"
(generation/generate templates {:thing "X-15"})))
(is (= "It is a KXL-10"
(generation/generate templates {:thing "KXL-10"})))
)))
;; (deftest var-paths ;; (deftest var-paths
;; (is (= "Hello, John" ;; (is (= "Hello, John"