Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

a sample testsuite for the (any/type) base types

Submitted by vlado on Tue, 2006-02-14 13:25.code | programming | scheme | work in progress

Here comes a sample test suite (it is too long, so only the beginning features in here) for the any/types, I described earlier. I like the clenliness of the schemeunit library. It features a rich set of assertions, simple but powerful grouping and both text and gui result interfaces. In order to use it you need plt scheme. Then you can grab the unit test suite from planet: (require (planet "test.ss" ("schematics" "schemeunit.plt" 1 2)))

The code here shows testing only the any/text type and all relevant auxilary functions, using this datatatype. Looking at the code, it could be turned into a macro, so we could generate type tests automatically, rather than writing this long code..

(define any-types-tests (make-test-suite "Tests for any/types" (let ((var (make-any/text 1 "test/text" "lorem ipsum" 0 #t 'text/plain))) (make-test-suite "any/text tests" (make-test-case "x '? 'any/text " (assert-true (var '? 'any/text))) (make-test-case "x '? 'not/any/text " (assert-false (var '? 'not/any/text))) (make-test-case "any/stext? x " (assert-false (any/stext? var))) (make-test-case "any/float? x " (assert-false (any/float? var))) (make-test-case "any/int? x " (assert-false (any/int? var))) (make-test-case "any/date? x " (assert-false (any/date? var))) (make-test-case "type? x " (assert-equal? 'any/text (type? var))) (make-test-case "id? x " (assert-equal? 1 (id? var))) (make-test-case "name? x " (assert-equal? "test/text" (name? var))) (make-test-case "data? x " (assert-equal? "lorem ipsum" (data? var))) (make-test-case "delta? x " (assert-equal? 0 (delta? var))) (make-test-case "required? x " (assert-equal? #t (required? var))) (make-test-case "format? x " (assert-equal? 'text/plain (format? var))) (make-test-case "delta= x x " (assert-equal? #t (delta= var var))) (make-test-case "id! x 2" (begin (id! var 2) (assert-equal? 2 (id? var)))) (make-test-case "name! x test1" (begin (name! var "test1") (assert-equal? "test1" (name? var)))) (make-test-case "data! x data" (begin (data! var "data") (assert-equal? "data" (data? var)))) (make-test-case "delta! x 1" (begin (delta! var 1) (assert-equal? 1 (delta? var)))) (make-test-case "required! x 2" #f (begin (required! var #f) (assert-false (required? var)))) (make-test-case "format! x text/html" #f (begin (format! var 'text/html) (assert-equal? 'text/html (format? var)))))) ;====================================================== ;similarly define test suites for the rest of the types ;======================================================

read more | vlado's blog | add new comment

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <br /> <br> <div> <a> <em> <strong> <cite> <pre> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <img> <blockquote> <q> <strike> <small> <h4> <h5> <h6>
  • Link to content with [[some text]], where "some text" is the title of existing content or the title of a new piece of content to create. You can also link text to a different title by using [[link to this title|show this text]]. Link to outside URLs with [[http://www.example.com|some text]], or even [[http://www.example.com]].
  • Lines and paragraphs break automatically.
More information about formatting options
Home ยป a sample testsuite for the (any/type) base types

dikini.net

spreading confusion by accident since 1970