Skip to content

Commit

Permalink
common-lisp/pangram: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 26, 2024
1 parent 69e0be3 commit d28c7d9
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 24 deletions.
1 change: 1 addition & 0 deletions common-lisp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,4 @@ Bye.
- [difference-of-squares](./difference-of-squares/README.md)
- [robot-name](./robot-name/README.md)
- [matching-brackets](./matching-brackets/README.md)
- [pangram](./pangram/README.md)
7 changes: 6 additions & 1 deletion common-lisp/pangram/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ For this exercise, a sentence is a pangram if it contains each of the 26 letters

### Based on

Wikipedia - https://en.wikipedia.org/wiki/Pangram
Wikipedia - https://en.wikipedia.org/wiki/Pangram
### My Solution

- [my solution](./pangram.lisp)
- [run-tests script](./run-tests.lisp)
- [run-tests output](./run-tests-lisp.txt)
44 changes: 22 additions & 22 deletions common-lisp/pangram/pangram-test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,48 @@
(def-suite* pangram-suite)

(test empty-sentence
(let ((sentence ""))
(is-false (pangram:pangramp sentence))))
(let ((sentence ""))
(is-false (pangram:pangramp sentence))))

(test perfect-lower-case
(let ((sentence "abcdefghijklmnopqrstuvwxyz"))
(is-true (pangram:pangramp sentence))))
(let ((sentence "abcdefghijklmnopqrstuvwxyz"))
(is-true (pangram:pangramp sentence))))

(test only-lower-case
(let ((sentence "the quick brown fox jumps over the lazy dog"))
(is-true (pangram:pangramp sentence))))
(let ((sentence "the quick brown fox jumps over the lazy dog"))
(is-true (pangram:pangramp sentence))))

(test missing-the-letter-x
(let ((sentence "a quick movement of the enemy will jeopardize five gunboats"))
(is-false (pangram:pangramp sentence))))
(let ((sentence "a quick movement of the enemy will jeopardize five gunboats"))
(is-false (pangram:pangramp sentence))))

(test missing-the-letter-h
(let ((sentence "five boxing wizards jump quickly at it"))
(is-false (pangram:pangramp sentence))))
(let ((sentence "five boxing wizards jump quickly at it"))
(is-false (pangram:pangramp sentence))))

(test with-underscores
(let ((sentence "the_quick_brown_fox_jumps_over_the_lazy_dog"))
(is-true (pangram:pangramp sentence))))
(let ((sentence "the_quick_brown_fox_jumps_over_the_lazy_dog"))
(is-true (pangram:pangramp sentence))))

(test with-numbers
(let ((sentence "the 1 quick brown fox jumps over the 2 lazy dogs"))
(is-true (pangram:pangramp sentence))))
(let ((sentence "the 1 quick brown fox jumps over the 2 lazy dogs"))
(is-true (pangram:pangramp sentence))))

(test missing-letters-replaced-by-numbers
(let ((sentence "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))
(is-false (pangram:pangramp sentence))))
(let ((sentence "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))
(is-false (pangram:pangramp sentence))))

(test mixed-case-and-punctuation
(let ((sentence "\"Five quacking Zephyrs jolt my wax bed.\""))
(is-true (pangram:pangramp sentence))))
(let ((sentence "\"Five quacking Zephyrs jolt my wax bed.\""))
(is-true (pangram:pangramp sentence))))

(test case-insensitive
(let ((sentence "the quick brown fox jumps over with lazy FX"))
(is-false (pangram:pangramp sentence))))
(let ((sentence "the quick brown fox jumps over with lazy FX"))
(is-false (pangram:pangramp sentence))))

(test a-m-and-a-m-are-26-different-characters-but-not-a-pangram
(let ((sentence "abcdefghijklm ABCDEFGHIJKLM"))
(is-false (pangram:pangramp sentence))))
(let ((sentence "abcdefghijklm ABCDEFGHIJKLM"))
(is-false (pangram:pangramp sentence))))

(defun run-tests (&optional (test-or-suite 'pangram-suite))
"Provides human readable results of test run. Default to entire suite."
Expand Down
13 changes: 12 additions & 1 deletion common-lisp/pangram/pangram.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@

(in-package :pangram)

(defun pangramp (sentence))
(defun pangramp (text)
(setf lcase (string-downcase text))
(setf lchars (coerce lcase 'list))

(eq
(length
(remove-duplicates
(remove-if-not #'alpha-char-p lchars)
)
)
26)
)
71 changes: 71 additions & 0 deletions common-lisp/pangram/run-tests-lisp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Running automated test file(s):


===============================================================================

Running: clisp ./run-tests.lisp
To load "fiveam":
Load 1 ASDF system:
fiveam
; Loading "fiveam"


Running test suite PANGRAM-SUITE
Running test A-M-AND-A-M-ARE-26-DIFFERENT-CHARACTERS-BUT-NOT-A-PANGRAM .
Running test CASE-INSENSITIVE .
Running test MIXED-CASE-AND-PUNCTUATION .
Running test MISSING-LETTERS-REPLACED-BY-NUMBERS .
Running test WITH-NUMBERS .
Running test WITH-UNDERSCORES .
Running test MISSING-THE-LETTER-H .
Running test MISSING-THE-LETTER-X .
Running test ONLY-LOWER-CASE .
Running test PERFECT-LOWER-CASE .
Running test EMPTY-SENTENCE .
Did 11 checks.
Pass: 11 (100%)
Skip: 0 ( 0%)
Fail: 0 ( 0%)


real 0m1.898s
user 0m1.792s
sys 0m0.106s

===============================================================================

sblint -v ./pangram.lisp ./pangram-test.lisp ./run-tests.lisp
[INFO] Lint file pangram.lisp
pangram.lisp:9:17: simple-warning: undefined variable: PANGRAM::LCASE
pangram.lisp:8:4: simple-warning: undefined variable: PANGRAM::LCASE
pangram.lisp:14:7: simple-warning: undefined variable: PANGRAM::LCHARS
pangram.lisp:9:4: simple-warning: undefined variable: PANGRAM::LCHARS

real 0m0.444s
user 0m0.389s
sys 0m0.055s

===============================================================================

lisp-format -verbose -style=llvm -i ./pangram.lisp ./pangram-test.lisp ./run-tests.lisp
Indenting region...
Indenting region...done
Indenting region...
Indenting region...done
Indenting region...
Indenting region...done

real 0m0.135s
user 0m0.096s
sys 0m0.042s

===============================================================================

Running: misspell .

real 0m0.025s
user 0m0.022s
sys 0m0.010s

===============================================================================

7 changes: 7 additions & 0 deletions common-lisp/pangram/run-tests.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(load "~/.clisprc.lisp")

(load "./pangram-test.lisp")

(pangram-test:run-tests)

(quit)

0 comments on commit d28c7d9

Please sign in to comment.