Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
Conway
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Adrian Kosmaczewski
Conway
Commits
3d558671
Commit
3d558671
authored
Oct 18, 2020
by
Adrian Kosmaczewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests
parent
d6e07ba1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
CommonLisp/README.adoc
CommonLisp/README.adoc
+1
-1
CommonLisp/conway/world.lisp
CommonLisp/conway/world.lisp
+10
-1
CommonLisp/tests.lisp
CommonLisp/tests.lisp
+32
-0
No files found.
CommonLisp/README.adoc
View file @
3d558671
...
...
@@ -4,5 +4,5 @@ This version can be executed using https://lisp-lang.org/[Common Lisp] with the
== Tests
TBD
Execute the tests with the command `CL_SOURCE_REGISTRY=$(pwd)/conway sbcl --script tests.lisp`.
CommonLisp/conway/world.lisp
View file @
3d558671
(
defclass
world
()
((
size
:accessor
size
:initarg
:size
)
(
cells
:initarg
:cells
))
(
cells
:
accessor
cells
:
initarg
:cells
))
(
:documentation
"A lattice of cells referenced by coord values."
))
(
defun
find-in-list
(
object
list
)
...
...
@@ -18,6 +18,15 @@
(
setf
(
gethash
c
cells
)
'dead
)))))
(
make-instance
'world
:size
size
:cells
cells
))
(
defun
equal-world
(
this
other
)
(
with-slots
(
size
cells
)
this
(
defvar
equal-size
(
=
size
(
size
other
)))
(
defvar
equal-cells
t
)
(
loop
for
key
being
the
hash-keys
of
cells
using
(
hash-value
value
)
do
(
let
((
othercell
(
gethash
key
(
cells
other
))))
(
setq
equal-cells
(
and
equal-cells
(
equalp
othercell
value
)))))
(
and
equal-size
equal-cells
)))
(
defmethod
evolve
((
object
world
))
(
with-slots
(
size
cells
)
object
(
defvar
alive-cells
)
...
...
CommonLisp/tests.lisp
0 → 100644
View file @
3d558671
(
require
"asdf"
)
(
asdf:operate
'asdf:load-op
'conway
)
(
load
"~/.quicklisp/setup.lisp"
)
(
ql:quickload
:lisp-unit
)
(
use-package
:lisp-unit
)
(
define-test
test-block
(
let
((
alive
(
make-block
(
make-coord
:x
0
:y
0
))))
(
let
((
original
(
make-world
5
alive
)))
(
let
((
next
(
evolve
original
)))
(
assert-true
(
equal-world
original
next
))))))
(
define-test
test-tub
(
let
((
alive
(
make-tub
(
make-coord
:x
0
:y
0
))))
(
let
((
original
(
make-world
5
alive
)))
(
let
((
next
(
evolve
original
)))
(
assert-true
(
equal-world
original
next
))))))
(
define-test
test-blinker
(
let
((
alive
(
make-blinker
(
make-coord
:x
0
:y
1
))))
(
let
((
original
(
make-world
3
alive
)))
(
let
((
gen1
(
evolve
original
)))
(
let
((
expected-alive
(
list
(
make-coord
:x
1
:y
0
)
(
make-coord
:x
1
:y
1
)
(
make-coord
:x
1
:y
2
))))
(
let
((
expected
(
make-world
3
expected-alive
)))
(
assert-true
(
equal-world
expected
gen1
))
(
let
((
gen2
(
evolve
gen1
)))
(
assert-true
(
equal-world
original
gen2
)))))))))
(
run-tests
:all
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment