Skip to content

Commit fac128a

Browse files
committed
Update acronym tests
1 parent 615668c commit fac128a

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

exercises/practice/acronym/.meta/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
],
55
"contributors": [
66
"daveyarwood",
7-
"dnmfarrell"
7+
"dnmfarrell",
8+
"BNAndras"
89
],
910
"files": {
1011
"solution": [
+13-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
(in-package :cl-user)
21
(defpackage :acronym
32
(:use :cl)
43
(:export :acronym))
54

65
(in-package :acronym)
76

8-
(defun acronym (str)
9-
(labels ((recur (st ls)
10-
(cond
11-
((equal "" st)
12-
ls)
13-
((both-case-p (elt st 0))
14-
(recur (string-left-trim
15-
"abcdefghijklmnopqrstuvwxyz"
16-
(string-left-trim
17-
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
18-
st))
19-
(cons (elt st 0)
20-
ls)))
21-
(t (recur (subseq st 1) ls)))))
22-
(map 'string
23-
#'char-upcase
24-
(nreverse (recur str nil)))))
7+
(defun acronym (phrase)
8+
(let ((chars ())
9+
(inside-word nil))
10+
(loop for char across phrase
11+
do (cond
12+
((eql char #\')
13+
nil)
14+
((and (alpha-char-p char) (not inside-word))
15+
(push (char-upcase char) chars)
16+
(setf inside-word t))
17+
((not (alpha-char-p char))
18+
(setf inside-word nil))))
19+
(format nil "~{~A~}" (reverse chars))))

exercises/practice/acronym/acronym-test.lisp

+30-9
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,41 @@
1515
;; Define and enter a new FiveAM test-suite
1616
(def-suite* acronym-suite)
1717

18-
(test empty-gives-empty (is (equal "" (acronym:acronym ""))))
18+
(test basic
19+
(let ((phrase "Portable Network Graphics"))
20+
(is (string= "PNG" (acronym:acronym phrase)))))
1921

20-
(test png-test (is (equal "PNG" (acronym:acronym "Portable Network Graphics"))))
22+
(test lowercase-words
23+
(let ((phrase "Ruby on Rails"))
24+
(is (string= "ROR" (acronym:acronym phrase)))))
2125

22-
(test ror-test (is (equal "ROR" (acronym:acronym "Ruby on Rails"))))
26+
(test punctuation
27+
(let ((phrase "First In, First Out"))
28+
(is (string= "FIFO" (acronym:acronym phrase)))))
2329

24-
(test fifo-test (is (equal "FIFO" (acronym:acronym "First In, First Out"))))
30+
(test all-caps-word
31+
(let ((phrase "GNU Image Manipulation Program"))
32+
(is (string= "GIMP" (acronym:acronym phrase)))))
2533

26-
(test php-test
27-
(is (equal "PHP" (acronym:acronym "PHP: Hypertext Preprocessor"))))
34+
(test punctuation-without-whitespace
35+
(let ((phrase "Complementary metal-oxide semiconductor"))
36+
(is (string= "CMOS" (acronym:acronym phrase)))))
2837

29-
(test cmos-test
30-
(is
31-
(equal "CMOS" (acronym:acronym "Complementary metal-oxide semiconductor"))))
38+
(test very-long-abbreviation
39+
(let ((phrase "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"))
40+
(is (string= "ROTFLSHTMDCOALM" (acronym:acronym phrase)))))
41+
42+
(test consecutive-delimiters
43+
(let ((phrase "Something - I made up from thin air"))
44+
(is (string= "SIMUFTA" (acronym:acronym phrase)))))
45+
46+
(test apostrophes
47+
(let ((phrase "Halley's Comet"))
48+
(is (string= "HC" (acronym:acronym phrase)))))
49+
50+
(test underscore-emphasis
51+
(let ((phrase "The Road _Not_ Taken"))
52+
(is (string= "TRNT" (acronym:acronym phrase)))))
3253

3354
(defun run-tests (&optional (test-or-suite 'acronym-suite))
3455
"Provides human readable results of test run. Default to entire suite."

exercises/practice/acronym/acronym.lisp

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
(in-package :acronym)
66

7-
(defun acronym (str)
8-
"Returns the acronym for a noun of tech jargon."
9-
)
7+
(defun acronym (phrase))

0 commit comments

Comments
 (0)