Acceptance tests have been refactored

This commit is contained in:
Mike Cifelli 2017-03-02 16:36:23 -05:00
parent 0eb8db36a8
commit 86def27f5c
7 changed files with 82 additions and 130 deletions

View File

@ -1,39 +1,9 @@
---
Test
---
A simple lexical closure.
| script | lisp interpreter fixture |
| show | evaluate | (defun adderx (x) (lambda (y) (+ x y))) |
| show | evaluate | (setf adder20 (adderx 20)) |
| check | evaluate | (funcall adder20 2) | 22 |
| script | lisp interpreter fixture |
| # | Let Over Lambda Over Let Over Lambda |
| show | evaluate |!-
(let ((direction 'up))
(defun toggle-counter-direction ()
(setq direction
(if (eq direction 'up)
'down
'up)))
(defun counter-class ()
(let ((counter 0))
(lambda ()
(if (eq direction 'up)
(setq counter (+ counter 1))
(setq counter (- counter 1)))))))
-!|
| show | evaluate | (setq my-counter (counter-class)) |
| check | evaluate | (funcall my-counter) | 1 |
| check | evaluate | (funcall my-counter) | 2 |
| check | evaluate | (funcall my-counter) | 3 |
| show | evaluate | (toggle-counter-direction) |
| check | evaluate | (funcall my-counter) | 2 |
| check | evaluate | (funcall my-counter) | 1 |
| check | evaluate | (funcall my-counter) | 0 |
| show | evaluate | (toggle-counter-direction) |
| check | evaluate | (funcall my-counter) | 1 |
| check | evaluate | (funcall my-counter) | 2 |
| check | evaluate | (funcall my-counter) | 3 |

View File

@ -1,95 +0,0 @@
---
Test
---
| script | lisp interpreter fixture |
| # | Object with multiple methods |
| show | evaluate |!-
(defun counter-class ()
(let ((counter 0))
(lambda (msg)
(case msg
((:inc)
(setq counter (+ counter 1)))
((:dec)
(setq counter (- counter 1)))))))
-!|
| show | evaluate | (setq my-counter (counter-class)) |
| check | evaluate | (funcall my-counter :inc) | 1 |
| check | evaluate | (funcall my-counter :inc) | 2 |
| check | evaluate | (funcall my-counter :inc) | 3 |
| check | evaluate | (funcall my-counter :dec) | 2 |
| check | evaluate | (funcall my-counter :dec) | 1 |
| check | evaluate | (funcall my-counter :dec) | 0 |
| script | lisp interpreter fixture |
| # | dlambda |
| show | evaluate |!-
(defun map (fn ls)
(if (null ls)
()
(cons (funcall fn (first ls))
(map fn (rest ls))
)
)
)
(define-macro dlambda (&rest methods)
(cons
(quote lambda)
(cons
(quote (&rest arguments))
(list
(cons
(quote case)
(cons
(quote (first arguments))
(map
(lambda (method)
(cons
(first method)
(list
(cons
(quote apply)
(cons
(cons
(quote lambda)
(rest method)
)
(list (quote (rest arguments)))
)
)
)
)
)
methods
)
)
)
)
)
)
)
(defun apple-counter ()
(let ((apple-count 0))
(eval
(dlambda
(:inc () (setf apple-count (+ apple-count 1)))
(:dec () (setf apple-count (- apple-count 1)))
)
)
)
)
-!|
| show | evaluate | (setf a (apple-counter)) |
| check | evaluate | (funcall a :inc) | 1 |
| check | evaluate | (funcall a :inc) | 2 |
| check | evaluate | (funcall a :inc) | 3 |
| check | evaluate | (funcall a :dec) | 2 |
| check | evaluate | (funcall a :dec) | 1 |
| check | evaluate | (funcall a :dec) | 0 |
| show | evaluate | (funcall a :inc 1) |

View File

@ -0,0 +1,25 @@
---
Test
---
An object with multiple methods.
| script | lisp interpreter fixture |
| show | evaluate |!-
(defun counter-class ()
(let ((counter 0))
(lambda (msg)
(case msg
((:inc)
(setq counter (+ counter 1)))
((:dec)
(setq counter (- counter 1)))))))
-!|
| show | evaluate | (setq my-counter (counter-class)) |
| check | evaluate | (funcall my-counter :inc) | 1 |
| check | evaluate | (funcall my-counter :inc) | 2 |
| check | evaluate | (funcall my-counter :inc) | 3 |
| check | evaluate | (funcall my-counter :dec) | 2 |
| check | evaluate | (funcall my-counter :dec) | 1 |
| check | evaluate | (funcall my-counter :dec) | 0 |

View File

@ -0,0 +1,14 @@
---
Test
---
Shows object composition, a default method, and two different ways of referencing objects.
| script | lisp interpreter fixture |
| show | evaluate | (load "../lisp/dlambda.lisp") |
| show | evaluate | (load "../lisp/fruit-counter.lisp") |
| check | evaluate | (my-counter :inc-apples) | 1 |
| check | evaluate | (my-counter :inc-apples) | 2 |
| check | evaluate | (funcall my-counter2 :dec-bananas) | 9999 |
| check | evaluate | (my-counter :set-coconuts 12) | 12 |
| check | evaluate | (my-counter) |(APPLES 2 BANANAS 0 COCONUTS 12) |
| check | evaluate | (funcall my-counter2) |(APPLES 10000 BANANAS 9999 COCONUTS 10000) |

View File

@ -0,0 +1,35 @@
---
Test
---
Shows the usage of a static variable.
''"Let Over Lambda Over Let Over Lambda"''
| script | lisp interpreter fixture |
| show | evaluate | !-
(let ((direction 'up))
(defun toggle-counter-direction ()
(setq direction
(if (eq direction 'up)
'down
'up)))
(defun counter-class ()
(let ((counter 0))
(lambda ()
(if (eq direction 'up)
(setq counter (+ counter 1))
(setq counter (- counter 1)))))))
-!|
| show | evaluate | (setq my-counter (counter-class)) |
| check | evaluate | (funcall my-counter) | 1 |
| check | evaluate | (funcall my-counter) | 2 |
| check | evaluate | (funcall my-counter) | 3 |
| show | evaluate | (toggle-counter-direction) |
| check | evaluate | (funcall my-counter) | 2 |
| check | evaluate | (funcall my-counter) | 1 |
| check | evaluate | (funcall my-counter) | 0 |
| show | evaluate | (toggle-counter-direction) |
| check | evaluate | (funcall my-counter) | 1 |
| check | evaluate | (funcall my-counter) | 2 |
| check | evaluate | (funcall my-counter) | 3 |

View File

@ -1,6 +1,9 @@
|LispInterpreter.LexicalClosures||16:31:40 Thu, Mar 02, 2017|
|LispInterpreter.LexicalClosure||16:26:49 Thu, Mar 02, 2017|
|LispInterpreter.FruitCounter||16:13:51 Thu, Mar 02, 2017|
|LispInterpreter.SimpleClosure||16:12:31 Thu, Mar 02, 2017|
|LispInterpreter.MultipleMethodClosure||16:11:28 Thu, Mar 02, 2017|
|LispInterpreter.SetUp||15:09:12 Thu, Mar 02, 2017|
|LispInterpreter.MultipleMethodClosure||16:02:22 Wed, Mar 01, 2017|
|LispInterpreter.LexicalClosures||12:10:13 Mon, Feb 27, 2017|
|LispInterpreter.TestClosure||11:24:27 Mon, Feb 27, 2017|
|LispInterpreter.TestOne||09:26:08 Fri, Feb 24, 2017|
|LispInterpreter.SuiteSetUp||14:27:52 Wed, Feb 22, 2017|

View File

@ -8,4 +8,4 @@ import fitnesse.junit.FitNesseRunner;
@FitNesseRunner.Suite("LispInterpreter")
@FitNesseRunner.FitnesseDir("fitnesse")
@FitNesseRunner.OutputDir("fitnesse/fitnesse-results")
public class FitNesseRunnerTester {}
public class AcceptanceTester {}