diff --git a/tests/older-tests/all-tests.rkt b/tests/older-tests/all-tests.rkt new file mode 100644 index 0000000..df6b1ae --- /dev/null +++ b/tests/older-tests/all-tests.rkt @@ -0,0 +1,4 @@ +#lang s-exp "../lang/base.rkt" + +(require "mz-tests/all-tests.rkt" + "moby-programs/all-tests.rkt") diff --git a/tests/older-tests/benchmarks/conform.rkt b/tests/older-tests/benchmarks/conform.rkt new file mode 100644 index 0000000..0254fb2 --- /dev/null +++ b/tests/older-tests/benchmarks/conform.rkt @@ -0,0 +1,621 @@ +#lang s-exp "../../lang/base.rkt" + +(require "run-benchmark.rkt") +(provide confirm-benchmark) + +; +; conform.scm [portable/R^399RS version] +; By Jim Miller [mods by oz] +; [call to run-benchmark added by wdc 14 Feb 1997] + +; (declare (usual-integrations)) + +;; SORT + +(define (vector-copy v) + (let* ((length (vector-length v)) + (result (make-vector length))) + (let loop ((n 0)) + (vector-set! result n (vector-ref v n)) + (if (= n length) + v + (loop (+ n 1)))))) + +(define (sort obj pred) + (define (loop l) + (if (and (pair? l) (pair? (cdr l))) + (split l '() '()) + l)) + + (define (split l one two) + (if (pair? l) + (split (cdr l) two (cons (car l) one)) + (merge (loop one) (loop two)))) + + (define (merge one two) + (cond ((null? one) two) + ((pred (car two) (car one)) + (cons (car two) + (merge (cdr two) one))) + (else + (cons (car one) + (merge (cdr one) two))))) + + (cond ((or (pair? obj) (null? obj)) + (loop obj)) + ((vector? obj) + (sort! (vector-copy obj) pred)) + (else + (error "sort: argument should be a list or vector" obj)))) + +;; This merge sort is stable for partial orders (for predicates like +;; <=, rather than like <). + +(define (sort! v pred) + (define (sort-internal! vec temp low high) + (when (< low high) + (let* ((middle (quotient (+ low high) 2)) + (next (+ middle 1))) + (sort-internal! temp vec low middle) + (sort-internal! temp vec next high) + (let loop ((p low) (p1 low) (p2 next)) + (when (not (> p high)) + (cond ((> p1 middle) + (vector-set! vec p (vector-ref temp p2)) + (loop (+ p 1) p1 (+ p2 1))) + ((or (> p2 high) + (pred (vector-ref temp p1) + (vector-ref temp p2))) + (vector-set! vec p (vector-ref temp p1)) + (loop (+ p 1) (+ p1 1) p2)) + (else + (vector-set! vec p (vector-ref temp p2)) + (loop (+ p 1) p1 (+ p2 1))))))))) + + (when (not (vector? v)) + (error "sort!: argument not a vector" v)) + + (sort-internal! v + (vector-copy v) + 0 + (- (vector-length v) 1)) + v) + +;; SET OPERATIONS +; (representation as lists with distinct elements) + +(define (adjoin element set) + (if (memq element set) set (cons element set))) + +(define (eliminate element set) + (cond ((null? set) set) + ((eq? element (car set)) (cdr set)) + (else (cons (car set) (eliminate element (cdr set)))))) + +(define (intersect list1 list2) + (let loop ((l list1)) + (cond ((null? l) '()) + ((memq (car l) list2) (cons (car l) (loop (cdr l)))) + (else (loop (cdr l)))))) + +(define (union list1 list2) + (if (null? list1) + list2 + (union (cdr list1) + (adjoin (car list1) list2)))) + +;; GRAPH NODES + +; (define-structure +; (internal-node +; (print-procedure (unparser/standard-method +; 'graph-node +; (lambda (state node) +; (unparse-object state (internal-node-name node)))))) +; name +; (green-edges '()) +; (red-edges '()) +; blue-edges) + +; Above is MIT version; below is portable + +(define make-internal-node vector) +(define (internal-node-name node) (vector-ref node 0)) +(define (internal-node-green-edges node) (vector-ref node 1)) +(define (internal-node-red-edges node) (vector-ref node 2)) +(define (internal-node-blue-edges node) (vector-ref node 3)) +(define (set-internal-node-name! node name) (vector-set! node 0 name)) +(define (set-internal-node-green-edges! node edges) (vector-set! node 1 edges)) +(define (set-internal-node-red-edges! node edges) (vector-set! node 2 edges)) +(define (set-internal-node-blue-edges! node edges) (vector-set! node 3 edges)) + +; End of portability stuff + +(define (make-node name . blue-edges) ; User's constructor + (let ((name (if (symbol? name) (symbol->string name) name)) + (blue-edges (if (null? blue-edges) 'NOT-A-NODE-YET (car blue-edges)))) + (make-internal-node name '() '() blue-edges))) + +(define (copy-node node) + (make-internal-node (name node) '() '() (blue-edges node))) + +; Selectors + +(define name internal-node-name) +(define (make-edge-getter selector) + (lambda (node) + (if (or (none-node? node) (any-node? node)) + (error "Can't get edges from the ANY or NONE nodes") + (selector node)))) +(define red-edges (make-edge-getter internal-node-red-edges)) +(define green-edges (make-edge-getter internal-node-green-edges)) +(define blue-edges (make-edge-getter internal-node-blue-edges)) + +; Mutators + +(define (make-edge-setter mutator!) + (lambda (node value) + (cond ((any-node? node) (error "Can't set edges from the ANY node")) + ((none-node? node) 'OK) + (else (mutator! node value))))) +(define set-red-edges! (make-edge-setter set-internal-node-red-edges!)) +(define set-green-edges! (make-edge-setter set-internal-node-green-edges!)) +(define set-blue-edges! (make-edge-setter set-internal-node-blue-edges!)) + +;; BLUE EDGES + +; (define-structure +; (blue-edge +; (print-procedure +; (unparser/standard-method +; 'blue-edge +; (lambda (state edge) +; (unparse-object state (blue-edge-operation edge)))))) +; operation arg-node res-node) + +; Above is MIT version; below is portable + +(define make-blue-edge vector) +(define (blue-edge-operation edge) (vector-ref edge 0)) +(define (blue-edge-arg-node edge) (vector-ref edge 1)) +(define (blue-edge-res-node edge) (vector-ref edge 2)) +(define (set-blue-edge-operation! edge value) (vector-set! edge 0 value)) +(define (set-blue-edge-arg-node! edge value) (vector-set! edge 1 value)) +(define (set-blue-edge-res-node! edge value) (vector-set! edge 2 value)) + +; End of portability stuff + +; Selectors +(define operation blue-edge-operation) +(define arg-node blue-edge-arg-node) +(define res-node blue-edge-res-node) + +; Mutators +(define set-arg-node! set-blue-edge-arg-node!) +(define set-res-node! set-blue-edge-res-node!) + +; Higher level operations on blue edges + +(define (lookup-op op node) + (let loop ((edges (blue-edges node))) + (cond ((null? edges) '()) + ((eq? op (operation (car edges))) (car edges)) + (else (loop (cdr edges)))))) + +(define (has-op? op node) + (not (null? (lookup-op op node)))) + +; Add a (new) blue edge to a node + +; (define (adjoin-blue-edge! blue-edge node) +; (let ((current-one (lookup-op (operation blue-edge) node))) +; (cond ((null? current-one) +; (set-blue-edges! node +; (cons blue-edge (blue-edges node)))) +; ((and (eq? (arg-node current-one) (arg-node blue-edge)) +; (eq? (res-node current-one) (res-node blue-edge))) +; 'OK) +; (else (error "Two non-equivalent blue edges for op" +; blue-edge node))))) + +;; GRAPHS + +; (define-structure +; (internal-graph +; (print-procedure +; (unparser/standard-method 'graph +; (lambda (state edge) +; (unparse-object state (map name (internal-graph-nodes edge))))))) +; nodes already-met already-joined) + +; Above is MIT version; below is portable + +(define make-internal-graph vector) +(define (internal-graph-nodes graph) (vector-ref graph 0)) +(define (internal-graph-already-met graph) (vector-ref graph 1)) +(define (internal-graph-already-joined graph) (vector-ref graph 2)) +(define (set-internal-graph-nodes! graph nodes) (vector-set! graph 0 nodes)) + +; End of portability stuff + +; Constructor + +(define (make-graph . nodes) + (make-internal-graph nodes (make-empty-table) (make-empty-table))) + +; Selectors + +(define graph-nodes internal-graph-nodes) +(define already-met internal-graph-already-met) +(define already-joined internal-graph-already-joined) + +; Higher level functions on graphs + +(define (add-graph-nodes! graph nodes) + (set-internal-graph-nodes! graph (cons nodes (graph-nodes graph)))) + +(define (copy-graph g) + (define (copy-list l) (vector->list (list->vector l))) + (make-internal-graph + (copy-list (graph-nodes g)) + (already-met g) + (already-joined g))) + +(define (clean-graph g) + (define (clean-node node) + (when (not (or (any-node? node) (none-node? node))) + (begin + (set-green-edges! node '()) + (set-red-edges! node '())))) + (for-each clean-node (graph-nodes g)) + g) + +(define (canonicalize-graph graph classes) + (define (fix node) + (define (fix-set object selector mutator) + (mutator object + (map (lambda (node) + (find-canonical-representative node classes)) + (selector object)))) + (when (not (or (none-node? node) (any-node? node))) + (begin + (fix-set node green-edges set-green-edges!) + (fix-set node red-edges set-red-edges!) + (for-each + (lambda (blue-edge) + (set-arg-node! blue-edge + (find-canonical-representative (arg-node blue-edge) classes)) + (set-res-node! blue-edge + (find-canonical-representative (res-node blue-edge) classes))) + (blue-edges node)))) + node) + (define (fix-table table) + (define (canonical? node) (eq? node (find-canonical-representative node classes))) + (define (filter-and-fix predicate-fn update-fn list) + (let loop ((list list)) + (cond ((null? list) '()) + ((predicate-fn (car list)) + (cons (update-fn (car list)) (loop (cdr list)))) + (else (loop (cdr list)))))) + (define (fix-line line) + (filter-and-fix + (lambda (entry) (canonical? (car entry))) + (lambda (entry) (cons (car entry) + (find-canonical-representative (cdr entry) classes))) + line)) + (if (null? table) + '() + (cons (car table) + (filter-and-fix + (lambda (entry) (canonical? (car entry))) + (lambda (entry) (cons (car entry) (fix-line (cdr entry)))) + (cdr table))))) + (make-internal-graph + (map (lambda (class) (fix (car class))) classes) + (fix-table (already-met graph)) + (fix-table (already-joined graph)))) + +;; USEFUL NODES + +(define none-node (make-node 'none #t)) +(define (none-node? node) (eq? node none-node)) + +(define any-node (make-node 'any '())) +(define (any-node? node) (eq? node any-node)) + +;; COLORED EDGE TESTS + + +(define (green-edge? from-node to-node) + (cond ((any-node? from-node) #f) + ((none-node? from-node) #t) + ((memq to-node (green-edges from-node)) #t) + (else #f))) + +(define (red-edge? from-node to-node) + (cond ((any-node? from-node) #f) + ((none-node? from-node) #t) + ((memq to-node (red-edges from-node)) #t) + (else #f))) + +;; SIGNATURE + +; Return signature (i.e. ) given an operation and a node + +(define sig + (let ((none-comma-any (cons none-node any-node))) + (lambda (op node) ; Returns (arg, res) + (let ((the-edge (lookup-op op node))) + (if (not (null? the-edge)) + (cons (arg-node the-edge) (res-node the-edge)) + none-comma-any))))) + +; Selectors from signature + +(define (arg pair) (car pair)) +(define (res pair) (cdr pair)) + +;; CONFORMITY + +(define (conforms? t1 t2) + (define nodes-with-red-edges-out '()) + (define (add-red-edge! from-node to-node) + (set-red-edges! from-node (adjoin to-node (red-edges from-node))) + (set! nodes-with-red-edges-out + (adjoin from-node nodes-with-red-edges-out))) + (define (greenify-red-edges! from-node) + (set-green-edges! from-node + (append (red-edges from-node) (green-edges from-node))) + (set-red-edges! from-node '())) + (define (delete-red-edges! from-node) + (set-red-edges! from-node '())) + (define (does-conform t1 t2) + (cond ((or (none-node? t1) (any-node? t2)) #t) + ((or (any-node? t1) (none-node? t2)) #f) + ((green-edge? t1 t2) #t) + ((red-edge? t1 t2) #t) + (else + (add-red-edge! t1 t2) + (let loop ((blues (blue-edges t2))) + (if (null? blues) + #t + (let* ((current-edge (car blues)) + (phi (operation current-edge))) + (and (has-op? phi t1) + (does-conform + (res (sig phi t1)) + (res (sig phi t2))) + (does-conform + (arg (sig phi t2)) + (arg (sig phi t1))) + (loop (cdr blues))))))))) + (let ((result (does-conform t1 t2))) + (for-each (if result greenify-red-edges! delete-red-edges!) + nodes-with-red-edges-out) + result)) + +(define (equivalent? a b) + (and (conforms? a b) (conforms? b a))) + +;; EQUIVALENCE CLASSIFICATION +; Given a list of nodes, return a list of equivalence classes + +(define (classify nodes) + (let node-loop ((classes '()) + (nodes nodes)) + (if (null? nodes) + (map (lambda (class) + (sort class + (lambda (node1 node2) + (< (string-length (name node1)) + (string-length (name node2)))))) + classes) + (let ((this-node (car nodes))) + (define (add-node classes) + (cond ((null? classes) (list (list this-node))) + ((equivalent? this-node (caar classes)) + (cons (cons this-node (car classes)) + (cdr classes))) + (else (cons (car classes) + (add-node (cdr classes)))))) + (node-loop (add-node classes) + (cdr nodes)))))) + +; Given a node N and a classified set of nodes, +; find the canonical member corresponding to N + +(define (find-canonical-representative element classification) + (let loop ((classes classification)) + (cond ((null? classes) (error "Can't classify" element)) + ((memq element (car classes)) (car (car classes))) + (else (loop (cdr classes)))))) + +; Reduce a graph by taking only one member of each equivalence +; class and canonicalizing all outbound pointers + +(define (reduce graph) + (let ((classes (classify (graph-nodes graph)))) + (canonicalize-graph graph classes))) + +;; TWO DIMENSIONAL TABLES + +(define (make-empty-table) (list 'TABLE)) + +(define (lookup table x y) + (let ((one (assq x (cdr table)))) + (if one + (let ((two (assq y (cdr one)))) + (if two (cdr two) #f)) + #f))) + +(define (insert! table x y value) + (define (make-singleton-table x y) + (list (cons x y))) + (let ((one (assq x (cdr table)))) + (if one + (set-cdr! one (cons (cons y value) (cdr one))) + (set-cdr! table (cons (cons x (make-singleton-table y value)) + (cdr table)))))) + +;; MEET/JOIN +; These update the graph when computing the node for node1*node2 + +(define (blue-edge-operate arg-fn res-fn graph op sig1 sig2) + (make-blue-edge op + (arg-fn graph (arg sig1) (arg sig2)) + (res-fn graph (res sig1) (res sig2)))) + +(define (meet graph node1 node2) + (cond ((eq? node1 node2) node1) + ((or (any-node? node1) (any-node? node2)) any-node) ; canonicalize + ((none-node? node1) node2) + ((none-node? node2) node1) + ((lookup (already-met graph) node1 node2)) ; return it if found + ((conforms? node1 node2) node2) + ((conforms? node2 node1) node1) + (else + (let ((result + (make-node (string-append "(" (name node1) " ^ " (name node2) ")")))) + (add-graph-nodes! graph result) + (insert! (already-met graph) node1 node2 result) + (set-blue-edges! result + (map + (lambda (op) + (blue-edge-operate join meet graph op (sig op node1) (sig op node2))) + (intersect (map operation (blue-edges node1)) + (map operation (blue-edges node2))))) + result)))) + +(define (join graph node1 node2) + (cond ((eq? node1 node2) node1) + ((any-node? node1) node2) + ((any-node? node2) node1) + ((or (none-node? node1) (none-node? node2)) none-node) ; canonicalize + ((lookup (already-joined graph) node1 node2)) ; return it if found + ((conforms? node1 node2) node1) + ((conforms? node2 node1) node2) + (else + (let ((result + (make-node (string-append "(" (name node1) " v " (name node2) ")")))) + (add-graph-nodes! graph result) + (insert! (already-joined graph) node1 node2 result) + (set-blue-edges! result + (map + (lambda (op) + (blue-edge-operate meet join graph op (sig op node1) (sig op node2))) + (union (map operation (blue-edges node1)) + (map operation (blue-edges node2))))) + result)))) + +;; MAKE A LATTICE FROM A GRAPH + +(define (make-lattice g print?) + (define (step g) + (let* ((copy (copy-graph g)) + (nodes (graph-nodes copy))) + (for-each (lambda (first) + (for-each (lambda (second) + (meet copy first second) + (join copy first second)) + nodes)) + nodes) + copy)) + (define (loop g count) + (if print? (display count)) + (let ((lattice (step g))) + (if print? (begin (display " -> ") + (display (length (graph-nodes lattice))))) + (let* ((new-g (reduce lattice)) + (new-count (length (graph-nodes new-g)))) + (if (= new-count count) + (begin + (if print? (newline)) + new-g) + (begin + (if print? (begin (display " -> ") + (display new-count) (newline))) + (loop new-g new-count)))))) + (let ((graph + (apply make-graph + (adjoin any-node (adjoin none-node (graph-nodes (clean-graph g))))))) + (loop graph (length (graph-nodes graph))))) + +;; DEBUG and TEST + +(define a '()) +(define b '()) +(define c '()) +(define d '()) + +(define (reset) + (set! a (make-node 'a)) + (set! b (make-node 'b)) + (set-blue-edges! a (list (make-blue-edge 'phi any-node b))) + (set-blue-edges! b (list (make-blue-edge 'phi any-node a) + (make-blue-edge 'theta any-node b))) + (set! c (make-node "c")) + (set! d (make-node "d")) + (set-blue-edges! c (list (make-blue-edge 'theta any-node b))) + (set-blue-edges! d (list (make-blue-edge 'phi any-node c) + (make-blue-edge 'theta any-node d))) + '(made a b c d)) + +(define (test) + (reset) + (map name + (graph-nodes + (make-lattice (make-graph a b c d any-node none-node) #t)))) + ;;; note printflag #t +;(define (time-test) +; (let ((t (runtime))) +; (let ((ans (test))) +; (cons ans (- (runtime) t))))) + +; +; run and make sure result is correct +; +(define (go) + (reset) + (let ((result '("(((b v d) ^ a) v c)" + "(c ^ d)" + "(b v (a ^ d))" + "((a v d) ^ b)" + "(b v d)" + "(b ^ (a v c))" + "(a v (c ^ d))" + "((b v d) ^ a)" + "(c v (a v d))" + "(a v c)" + "(d v (b ^ (a v c)))" + "(d ^ (a v c))" + "((a ^ d) v c)" + "((a ^ b) v d)" + "(((a v d) ^ b) v (a ^ d))" + "(b ^ d)" + "(b v (a v d))" + "(a ^ c)" + "(b ^ (c v d))" + "(a ^ b)" + "(a v b)" + "((a ^ d) ^ b)" + "(a ^ d)" + "(a v d)" + "d" + "(c v d)" + "a" + "b" + "c" + "any" + "none"))) + + (if (equal? (test) result) + (display " ok.") + (display " um.")) + (newline))) + +;[mods made by wdc] +;(go) +;(exit) + +(define (conform-benchmark . rest) + (apply run-benchmark "conform" go rest)) diff --git a/tests/older-tests/benchmarks/do-measures.rkt b/tests/older-tests/benchmarks/do-measures.rkt new file mode 100644 index 0000000..0119390 --- /dev/null +++ b/tests/older-tests/benchmarks/do-measures.rkt @@ -0,0 +1,22 @@ +#lang s-exp "../../lang/base.rkt" + +(require "nboyer.rkt" + "sboyer.rkt" + "tak.rkt" + "nfa.rkt" + "graphs.rkt") + +"(tak-benchmark)" +(tak-benchmark) + + + +"(nboyer-benchmark 0)" +(nboyer-benchmark 0) + +"(nboyer-benchmark 4)" +(nboyer-benchmark 4) + + +"sboyer" + diff --git a/tests/older-tests/benchmarks/graphs.rkt b/tests/older-tests/benchmarks/graphs.rkt new file mode 100644 index 0000000..72cf47d --- /dev/null +++ b/tests/older-tests/benchmarks/graphs.rkt @@ -0,0 +1,650 @@ +#lang s-exp "../../lang/base.rkt" + +(require "run-benchmark.rkt") +(provide graphs-benchmark) + + +; Modified 2 March 1997 by Will Clinger to add graphs-benchmark +; and to expand the four macros below. +; Modified 11 June 1997 by Will Clinger to eliminate assertions +; and to replace a use of "recur" with a named let. +; +; Performance note: (graphs-benchmark 7) allocates +; 34509143 pairs +; 389625 vectors with 2551590 elements +; 56653504 closures (not counting top level and known procedures) + +(define (graphs-benchmark . rest) + (let ((N (if (null? rest) 7 (car rest)))) + (run-benchmark (string-append "graphs" (number->string N)) + (lambda () + (fold-over-rdg N + 2 + cons + '()))))) + +; End of new code. + +;;; ==== std.ss ==== + +; (define-syntax assert +; (syntax-rules () +; ((assert test info-rest ...) +; #F))) +; +; (define-syntax deny +; (syntax-rules () +; ((deny test info-rest ...) +; #F))) +; +; (define-syntax when +; (syntax-rules () +; ((when test e-first e-rest ...) +; (if test +; (begin e-first +; e-rest ...))))) +; +; (define-syntax unless +; (syntax-rules () +; ((unless test e-first e-rest ...) +; (if (not test) +; (begin e-first +; e-rest ...))))) + +(define assert + (lambda (test . info) + #f)) + +;;; ==== util.ss ==== + + +; Fold over list elements, associating to the left. +(define fold + (lambda (lst folder state) + '(assert (list? lst) + lst) + '(assert (procedure? folder) + folder) + (do ((lst lst + (cdr lst)) + (state state + (folder (car lst) + state))) + ((null? lst) + state)))) + +; Given the size of a vector and a procedure which +; sends indicies to desired vector elements, create +; and return the vector. +(define proc->vector + (lambda (size f) + '(assert (and (integer? size) + (exact? size) + (>= size 0)) + size) + '(assert (procedure? f) + f) + (if (zero? size) + (vector) + (let ((x (make-vector size (f 0)))) + (let loop ((i 1)) + (when (< i size) (begin ; [wdc - was when] + (vector-set! x i (f i)) + (loop (+ i 1))))) + x)))) + +(define vector-fold + (lambda (vec folder state) + '(assert (vector? vec) + vec) + '(assert (procedure? folder) + folder) + (let ((len + (vector-length vec))) + (do ((i 0 + (+ i 1)) + (state state + (folder (vector-ref vec i) + state))) + ((= i len) + state))))) + +(define vector-map + (lambda (vec proc) + (proc->vector (vector-length vec) + (lambda (i) + (proc (vector-ref vec i)))))) + +; Given limit, return the list 0, 1, ..., limit-1. +(define giota + (lambda (limit) + '(assert (and (integer? limit) + (exact? limit) + (>= limit 0)) + limit) + (let -*- + ((limit + limit) + (res + '())) + (if (zero? limit) + res + (let ((limit + (- limit 1))) + (-*- limit + (cons limit res))))))) + +; Fold over the integers [0, limit). +(define gnatural-fold + (lambda (limit folder state) + '(assert (and (integer? limit) + (exact? limit) + (>= limit 0)) + limit) + '(assert (procedure? folder) + folder) + (do ((i 0 + (+ i 1)) + (state state + (folder i state))) + ((= i limit) + state)))) + +; Iterate over the integers [0, limit). +(define gnatural-for-each + (lambda (limit proc!) + '(assert (and (integer? limit) + (exact? limit) + (>= limit 0)) + limit) + '(assert (procedure? proc!) + proc!) + (do ((i 0 + (+ i 1))) + ((= i limit)) + (proc! i)))) + +(define natural-for-all? + (lambda (limit ok?) + '(assert (and (integer? limit) + (exact? limit) + (>= limit 0)) + limit) + '(assert (procedure? ok?) + ok?) + (let -*- + ((i 0)) + (or (= i limit) + (and (ok? i) + (-*- (+ i 1))))))) + +(define natural-there-exists? + (lambda (limit ok?) + '(assert (and (integer? limit) + (exact? limit) + (>= limit 0)) + limit) + '(assert (procedure? ok?) + ok?) + (let -*- + ((i 0)) + (and (not (= i limit)) + (or (ok? i) + (-*- (+ i 1))))))) + +(define there-exists? + (lambda (lst ok?) + '(assert (list? lst) + lst) + '(assert (procedure? ok?) + ok?) + (let -*- + ((lst lst)) + (and (not (null? lst)) + (or (ok? (car lst)) + (-*- (cdr lst))))))) + + +;;; ==== ptfold.ss ==== + + +; Fold over the tree of permutations of a universe. +; Each branch (from the root) is a permutation of universe. +; Each node at depth d corresponds to all permutations which pick the +; elements spelled out on the branch from the root to that node as +; the first d elements. +; Their are two components to the state: +; The b-state is only a function of the branch from the root. +; The t-state is a function of all nodes seen so far. +; At each node, b-folder is called via +; (b-folder elem b-state t-state deeper accross) +; where elem is the next element of the universe picked. +; If b-folder can determine the result of the total tree fold at this stage, +; it should simply return the result. +; If b-folder can determine the result of folding over the sub-tree +; rooted at the resulting node, it should call accross via +; (accross new-t-state) +; where new-t-state is that result. +; Otherwise, b-folder should call deeper via +; (deeper new-b-state new-t-state) +; where new-b-state is the b-state for the new node and new-t-state is +; the new folded t-state. +; At the leaves of the tree, t-folder is called via +; (t-folder b-state t-state accross) +; If t-folder can determine the result of the total tree fold at this stage, +; it should simply return that result. +; If not, it should call accross via +; (accross new-t-state) +; Note, fold-over-perm-tree always calls b-folder in depth-first order. +; I.e., when b-folder is called at depth d, the branch leading to that +; node is the most recent calls to b-folder at all the depths less than d. +; This is a gross efficiency hack so that b-folder can use mutation to +; keep the current branch. +(define fold-over-perm-tree + (lambda (universe b-folder b-state t-folder t-state) + '(assert (list? universe) + universe) + '(assert (procedure? b-folder) + b-folder) + '(assert (procedure? t-folder) + t-folder) + (let -*- + ((universe + universe) + (b-state + b-state) + (t-state + t-state) + (accross + (lambda (final-t-state) + final-t-state))) + (if (null? universe) + (t-folder b-state t-state accross) + (let -**- + ((in + universe) + (out + '()) + (t-state + t-state)) + (let* ((first + (car in)) + (rest + (cdr in)) + (accross + (if (null? rest) + accross + (lambda (new-t-state) + (-**- rest + (cons first out) + new-t-state))))) + (b-folder first + b-state + t-state + (lambda (new-b-state new-t-state) + (-*- (fold out cons rest) + new-b-state + new-t-state + accross)) + accross))))))) + + +;;; ==== minimal.ss ==== + + +; A directed graph is stored as a connection matrix (vector-of-vectors) +; where the first index is the `from' vertex and the second is the `to' +; vertex. Each entry is a bool indicating if the edge exists. +; The diagonal of the matrix is never examined. +; Make-minimal? returns a procedure which tests if a labelling +; of the verticies is such that the matrix is minimal. +; If it is, then the procedure returns the result of folding over +; the elements of the automoriphism group. If not, it returns #F. +; The folding is done by calling folder via +; (folder perm state accross) +; If the folder wants to continue, it should call accross via +; (accross new-state) +; If it just wants the entire minimal? procedure to return something, +; it should return that. +; The ordering used is lexicographic (with #T > #F) and entries +; are examined in the following order: +; 1->0, 0->1 +; +; 2->0, 0->2 +; 2->1, 1->2 +; +; 3->0, 0->3 +; 3->1, 1->3 +; 3->2, 2->3 +; ... +(define make-minimal? + (lambda (max-size) + '(assert (and (integer? max-size) + (exact? max-size) + (>= max-size 0)) + max-size) + (let ((iotas + (proc->vector (+ max-size 1) + giota)) + (perm + (make-vector max-size 0))) + (lambda (size graph folder state) + '(assert (and (integer? size) + (exact? size) + (<= 0 size max-size)) + size + max-size) + '(assert (vector? graph) + graph) + '(assert (procedure? folder) + folder) + (fold-over-perm-tree (vector-ref iotas size) + (lambda (perm-x x state deeper accross) + (case (cmp-next-vertex graph perm x perm-x) + ((less) + #F) + ((equal) + (vector-set! perm x perm-x) + (deeper (+ x 1) + state)) + ((more) + (accross state)) + (else + (assert #F)))) + 0 + (lambda (leaf-depth state accross) + '(assert (eqv? leaf-depth size) + leaf-depth + size) + (folder perm state accross)) + state))))) + +; Given a graph, a partial permutation vector, the next input and the next +; output, return 'less, 'equal or 'more depending on the lexicographic +; comparison between the permuted and un-permuted graph. +(define cmp-next-vertex + (lambda (graph perm x perm-x) + (let ((from-x + (vector-ref graph x)) + (from-perm-x + (vector-ref graph perm-x))) + (let -*- + ((y + 0)) + (if (= x y) + 'equal + (let ((x->y? + (vector-ref from-x y)) + (perm-y + (vector-ref perm y))) + (cond ((eq? x->y? + (vector-ref from-perm-x perm-y)) + (let ((y->x? + (vector-ref (vector-ref graph y) + x))) + (cond ((eq? y->x? + (vector-ref (vector-ref graph perm-y) + perm-x)) + (-*- (+ y 1))) + (y->x? + 'less) + (else + 'more)))) + (x->y? + 'less) + (else + 'more)))))))) + + +;;; ==== rdg.ss ==== + + +; Fold over rooted directed graphs with bounded out-degree. +; Size is the number of verticies (including the root). Max-out is the +; maximum out-degree for any vertex. Folder is called via +; (folder edges state) +; where edges is a list of length size. The ith element of the list is +; a list of the verticies j for which there is an edge from i to j. +; The last vertex is the root. +(define fold-over-rdg + (lambda (size max-out folder state) + '(assert (and (exact? size) + (integer? size) + (> size 0)) + size) + '(assert (and (exact? max-out) + (integer? max-out) + (>= max-out 0)) + max-out) + '(assert (procedure? folder) + folder) + (let* ((root + (- size 1)) + (edge? + (proc->vector size + (lambda (from) + (make-vector size #F)))) + (edges + (make-vector size '())) + (out-degrees + (make-vector size 0)) + (minimal-folder + (make-minimal? root)) + (non-root-minimal? + (let ((cont + (lambda (perm state accross) + '(assert (eq? state #T) + state) + (accross #T)))) + (lambda (size) + (minimal-folder size + edge? + cont + #T)))) + (root-minimal? + (let ((cont + (lambda (perm state accross) + '(assert (eq? state #T) + state) + (case (cmp-next-vertex edge? perm root root) + ((less) + #F) + ((equal more) + (accross #T)) + (else + (assert #F)))))) + (lambda () + (minimal-folder root + edge? + cont + #T))))) + (let -*- + ((vertex + 0) + (state + state)) + (cond ((not (non-root-minimal? vertex)) + state) + ((= vertex root) + '(assert + (begin + (gnatural-for-each root + (lambda (v) + '(assert (= (vector-ref out-degrees v) + (length (vector-ref edges v))) + v + (vector-ref out-degrees v) + (vector-ref edges v)))) + #T)) + (let ((reach? + (make-reach? root edges)) + (from-root + (vector-ref edge? root))) + (let -*- + ((v + 0) + (outs + 0) + (efr + '()) + (efrr + '()) + (state + state)) + (cond ((not (or (= v root) + (= outs max-out))) + (vector-set! from-root v #T) + (let ((state + (-*- (+ v 1) + (+ outs 1) + (cons v efr) + (cons (vector-ref reach? v) + efrr) + state))) + (vector-set! from-root v #F) + (-*- (+ v 1) + outs + efr + efrr + state))) + ((and (natural-for-all? root + (lambda (v) + (there-exists? efrr + (lambda (r) + (vector-ref r v))))) + (root-minimal?)) + (vector-set! edges root efr) + (folder + (proc->vector size + (lambda (i) + (vector-ref edges i))) + state)) + (else + state))))) + (else + (let ((from-vertex + (vector-ref edge? vertex))) + (let -**- + ((sv + 0) + (outs + 0) + (state + state)) + (if (= sv vertex) + (begin + (vector-set! out-degrees vertex outs) + (-*- (+ vertex 1) + state)) + (let* ((state + ; no sv->vertex, no vertex->sv + (-**- (+ sv 1) + outs + state)) + (from-sv + (vector-ref edge? sv)) + (sv-out + (vector-ref out-degrees sv)) + (state + (if (= sv-out max-out) + state + (begin + (vector-set! edges + sv + (cons vertex + (vector-ref edges sv))) + (vector-set! from-sv vertex #T) + (vector-set! out-degrees sv (+ sv-out 1)) + (let* ((state + ; sv->vertex, no vertex->sv + (-**- (+ sv 1) + outs + state)) + (state + (if (= outs max-out) + state + (begin + (vector-set! from-vertex sv #T) + (vector-set! edges + vertex + (cons sv + (vector-ref edges vertex))) + (let ((state + ; sv->vertex, vertex->sv + (-**- (+ sv 1) + (+ outs 1) + state))) + (vector-set! edges + vertex + (cdr (vector-ref edges vertex))) + (vector-set! from-vertex sv #F) + state))))) + (vector-set! out-degrees sv sv-out) + (vector-set! from-sv vertex #F) + (vector-set! edges + sv + (cdr (vector-ref edges sv))) + state))))) + (if (= outs max-out) + state + (begin + (vector-set! edges + vertex + (cons sv + (vector-ref edges vertex))) + (vector-set! from-vertex sv #T) + (let ((state + ; no sv->vertex, vertex->sv + (-**- (+ sv 1) + (+ outs 1) + state))) + (vector-set! from-vertex sv #F) + (vector-set! edges + vertex + (cdr (vector-ref edges vertex))) + state))))))))))))) + +; Given a vector which maps vertex to out-going-edge list, +; return a vector which gives reachability. +(define make-reach? + (lambda (size vertex->out) + (let ((res + (proc->vector size + (lambda (v) + (let ((from-v + (make-vector size #F))) + (vector-set! from-v v #T) + (for-each + (lambda (x) + (vector-set! from-v x #T)) + (vector-ref vertex->out v)) + from-v))))) + (gnatural-for-each size + (lambda (m) + (let ((from-m + (vector-ref res m))) + (gnatural-for-each size + (lambda (f) + (let ((from-f + (vector-ref res f))) + (when (vector-ref from-f m); [wdc - was when] + (begin + (gnatural-for-each size + (lambda (t) + (when (vector-ref from-m t) + (begin ; [wdc - was when] + (vector-set! from-f t #T))))))))))))) + res))) + + +;;; ==== test input ==== + +; Produces all directed graphs with N verticies, distinguished root, +; and out-degree bounded by 2, upto isomorphism (there are 44). + +;(define go +; (let ((N 7)) +; (fold-over-rdg N +; 2 +; cons +; '()))) diff --git a/tests/older-tests/benchmarks/nboyer.rkt b/tests/older-tests/benchmarks/nboyer.rkt new file mode 100644 index 0000000..d36b1a6 --- /dev/null +++ b/tests/older-tests/benchmarks/nboyer.rkt @@ -0,0 +1,777 @@ +#lang s-exp "../../lang/base.rkt" +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; File: nboyer.sch +; Description: The Boyer benchmark +; Author: Bob Boyer +; Created: 5-Apr-85 +; Modified: 10-Apr-85 14:52:20 (Bob Shaw) +; 22-Jul-87 (Will Clinger) +; 2-Jul-88 (Will Clinger -- distinguished #f and the empty list) +; 13-Feb-97 (Will Clinger -- fixed bugs in unifier and rules, +; rewrote to eliminate property lists, and added +; a scaling parameter suggested by Bob Boyer) +; 19-Mar-99 (Will Clinger -- cleaned up comments) +; 4-Apr-01 (Will Clinger -- changed four 1- symbols to sub1) +; Language: Scheme +; Status: Public Domain +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;; NBOYER -- Logic programming benchmark, originally written by Bob Boyer. +;;; Fairly CONS intensive. + +; Note: The version of this benchmark that appears in Dick Gabriel's book +; contained several bugs that are corrected here. These bugs are discussed +; by Henry Baker, "The Boyer Benchmark Meets Linear Logic", ACM SIGPLAN Lisp +; Pointers 6(4), October-December 1993, pages 3-10. The fixed bugs are: +; +; The benchmark now returns a boolean result. +; FALSEP and TRUEP use TERM-MEMBER? rather than MEMV (which is called MEMBER +; in Common Lisp) +; ONE-WAY-UNIFY1 now treats numbers correctly +; ONE-WAY-UNIFY1-LST now treats empty lists correctly +; Rule 19 has been corrected (this rule was not touched by the original +; benchmark, but is used by this version) +; Rules 84 and 101 have been corrected (but these rules are never touched +; by the benchmark) +; +; According to Baker, these bug fixes make the benchmark 10-25% slower. +; Please do not compare the timings from this benchmark against those of +; the original benchmark. +; +; This version of the benchmark also prints the number of rewrites as a sanity +; check, because it is too easy for a buggy version to return the correct +; boolean result. The correct number of rewrites is +; +; n rewrites peak live storage (approximate, in bytes) +; 0 95024 520,000 +; 1 591777 2,085,000 +; 2 1813975 5,175,000 +; 3 5375678 +; 4 16445406 +; 5 51507739 + +; Nboyer is a 2-phase benchmark. +; The first phase attaches lemmas to symbols. This phase is not timed, +; but it accounts for very little of the runtime anyway. +; The second phase creates the test problem, and tests to see +; whether it is implied by the lemmas. + + +(require "run-benchmark.rkt") + +(provide nboyer-benchmark) + +(define (nboyer-benchmark . args) + (let ((n (if (null? args) 0 (car args)))) + (setup-boyer) + (run-benchmark (string-append "nboyer" + (number->string n)) + 1 + (lambda () (test-boyer n)) + (lambda (rewrites) + (and (number? rewrites) + (case n + ((0) (= rewrites 95024)) + ((1) (= rewrites 591777)) + ((2) (= rewrites 1813975)) + ((3) (= rewrites 5375678)) + ((4) (= rewrites 16445406)) + ((5) (= rewrites 51507739)) + ; If it works for n <= 5, assume it works. + (else #t))))))) + +(define (setup-boyer) #t) ; assigned below +(define (test-boyer) #t) ; assigned below + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; The first phase. +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; In the original benchmark, it stored a list of lemmas on the +; property lists of symbols. +; In the new benchmark, it maintains an association list of +; symbols and symbol-records, and stores the list of lemmas +; within the symbol-records. + +(void +(let () + + (define (setup) + (add-lemma-lst + (quote ((equal (compile form) + (reverse (codegen (optimize form) + (nil)))) + (equal (eqp x y) + (equal (fix x) + (fix y))) + (equal (greaterp x y) + (lessp y x)) + (equal (lesseqp x y) + (not (lessp y x))) + (equal (greatereqp x y) + (not (lessp x y))) + (equal (boolean x) + (or (equal x (t)) + (equal x (f)))) + (equal (iff x y) + (and (implies x y) + (implies y x))) + (equal (even1 x) + (if (zerop x) + (t) + (odd (sub1 x)))) + (equal (countps- l pred) + (countps-loop l pred (zero))) + (equal (fact- i) + (fact-loop i 1)) + (equal (reverse- x) + (reverse-loop x (nil))) + (equal (divides x y) + (zerop (remainder y x))) + (equal (assume-true var alist) + (cons (cons var (t)) + alist)) + (equal (assume-false var alist) + (cons (cons var (f)) + alist)) + (equal (tautology-checker x) + (tautologyp (normalize x) + (nil))) + (equal (falsify x) + (falsify1 (normalize x) + (nil))) + (equal (prime x) + (and (not (zerop x)) + (not (equal x (add1 (zero)))) + (prime1 x (sub1 x)))) + (equal (and p q) + (if p (if q (t) + (f)) + (f))) + (equal (or p q) + (if p (t) + (if q (t) + (f)))) + (equal (not p) + (if p (f) + (t))) + (equal (implies p q) + (if p (if q (t) + (f)) + (t))) + (equal (fix x) + (if (numberp x) + x + (zero))) + (equal (if (if a b c) + d e) + (if a (if b d e) + (if c d e))) + (equal (zerop x) + (or (equal x (zero)) + (not (numberp x)))) + (equal (plus (plus x y) + z) + (plus x (plus y z))) + (equal (equal (plus a b) + (zero)) + (and (zerop a) + (zerop b))) + (equal (difference x x) + (zero)) + (equal (equal (plus a b) + (plus a c)) + (equal (fix b) + (fix c))) + (equal (equal (zero) + (difference x y)) + (not (lessp y x))) + (equal (equal x (difference x y)) + (and (numberp x) + (or (equal x (zero)) + (zerop y)))) + (equal (meaning (plus-tree (append x y)) + a) + (plus (meaning (plus-tree x) + a) + (meaning (plus-tree y) + a))) + (equal (meaning (plus-tree (plus-fringe x)) + a) + (fix (meaning x a))) + (equal (append (append x y) + z) + (append x (append y z))) + (equal (reverse (append a b)) + (append (reverse b) + (reverse a))) + (equal (times x (plus y z)) + (plus (times x y) + (times x z))) + (equal (times (times x y) + z) + (times x (times y z))) + (equal (equal (times x y) + (zero)) + (or (zerop x) + (zerop y))) + (equal (exec (append x y) + pds envrn) + (exec y (exec x pds envrn) + envrn)) + (equal (mc-flatten x y) + (append (flatten x) + y)) + (equal (member x (append a b)) + (or (member x a) + (member x b))) + (equal (member x (reverse y)) + (member x y)) + (equal (length (reverse x)) + (length x)) + (equal (member a (intersect b c)) + (and (member a b) + (member a c))) + (equal (nth (zero) + i) + (zero)) + (equal (exp i (plus j k)) + (times (exp i j) + (exp i k))) + (equal (exp i (times j k)) + (exp (exp i j) + k)) + (equal (reverse-loop x y) + (append (reverse x) + y)) + (equal (reverse-loop x (nil)) + (reverse x)) + (equal (count-list z (sort-lp x y)) + (plus (count-list z x) + (count-list z y))) + (equal (equal (append a b) + (append a c)) + (equal b c)) + (equal (plus (remainder x y) + (times y (quotient x y))) + (fix x)) + (equal (power-eval (big-plus1 l i base) + base) + (plus (power-eval l base) + i)) + (equal (power-eval (big-plus x y i base) + base) + (plus i (plus (power-eval x base) + (power-eval y base)))) + (equal (remainder y 1) + (zero)) + (equal (lessp (remainder x y) + y) + (not (zerop y))) + (equal (remainder x x) + (zero)) + (equal (lessp (quotient i j) + i) + (and (not (zerop i)) + (or (zerop j) + (not (equal j 1))))) + (equal (lessp (remainder x y) + x) + (and (not (zerop y)) + (not (zerop x)) + (not (lessp x y)))) + (equal (power-eval (power-rep i base) + base) + (fix i)) + (equal (power-eval (big-plus (power-rep i base) + (power-rep j base) + (zero) + base) + base) + (plus i j)) + (equal (gcd x y) + (gcd y x)) + (equal (nth (append a b) + i) + (append (nth a i) + (nth b (difference i (length a))))) + (equal (difference (plus x y) + x) + (fix y)) + (equal (difference (plus y x) + x) + (fix y)) + (equal (difference (plus x y) + (plus x z)) + (difference y z)) + (equal (times x (difference c w)) + (difference (times c x) + (times w x))) + (equal (remainder (times x z) + z) + (zero)) + (equal (difference (plus b (plus a c)) + a) + (plus b c)) + (equal (difference (add1 (plus y z)) + z) + (add1 y)) + (equal (lessp (plus x y) + (plus x z)) + (lessp y z)) + (equal (lessp (times x z) + (times y z)) + (and (not (zerop z)) + (lessp x y))) + (equal (lessp y (plus x y)) + (not (zerop x))) + (equal (gcd (times x z) + (times y z)) + (times z (gcd x y))) + (equal (value (normalize x) + a) + (value x a)) + (equal (equal (flatten x) + (cons y (nil))) + (and (nlistp x) + (equal x y))) + (equal (listp (gopher x)) + (listp x)) + (equal (samefringe x y) + (equal (flatten x) + (flatten y))) + (equal (equal (greatest-factor x y) + (zero)) + (and (or (zerop y) + (equal y 1)) + (equal x (zero)))) + (equal (equal (greatest-factor x y) + 1) + (equal x 1)) + (equal (numberp (greatest-factor x y)) + (not (and (or (zerop y) + (equal y 1)) + (not (numberp x))))) + (equal (times-list (append x y)) + (times (times-list x) + (times-list y))) + (equal (prime-list (append x y)) + (and (prime-list x) + (prime-list y))) + (equal (equal z (times w z)) + (and (numberp z) + (or (equal z (zero)) + (equal w 1)))) + (equal (greatereqp x y) + (not (lessp x y))) + (equal (equal x (times x y)) + (or (equal x (zero)) + (and (numberp x) + (equal y 1)))) + (equal (remainder (times y x) + y) + (zero)) + (equal (equal (times a b) + 1) + (and (not (equal a (zero))) + (not (equal b (zero))) + (numberp a) + (numberp b) + (equal (sub1 a) + (zero)) + (equal (sub1 b) + (zero)))) + (equal (lessp (length (delete x l)) + (length l)) + (member x l)) + (equal (sort2 (delete x l)) + (delete x (sort2 l))) + (equal (dsort x) + (sort2 x)) + (equal (length (cons x1 + (cons x2 + (cons x3 (cons x4 + (cons x5 + (cons x6 x7))))))) + (plus 6 (length x7))) + (equal (difference (add1 (add1 x)) + 2) + (fix x)) + (equal (quotient (plus x (plus x y)) + 2) + (plus x (quotient y 2))) + (equal (sigma (zero) + i) + (quotient (times i (add1 i)) + 2)) + (equal (plus x (add1 y)) + (if (numberp y) + (add1 (plus x y)) + (add1 x))) + (equal (equal (difference x y) + (difference z y)) + (if (lessp x y) + (not (lessp y z)) + (if (lessp z y) + (not (lessp y x)) + (equal (fix x) + (fix z))))) + (equal (meaning (plus-tree (delete x y)) + a) + (if (member x y) + (difference (meaning (plus-tree y) + a) + (meaning x a)) + (meaning (plus-tree y) + a))) + (equal (times x (add1 y)) + (if (numberp y) + (plus x (times x y)) + (fix x))) + (equal (nth (nil) + i) + (if (zerop i) + (nil) + (zero))) + (equal (last (append a b)) + (if (listp b) + (last b) + (if (listp a) + (cons (car (last a)) + b) + b))) + (equal (equal (lessp x y) + z) + (if (lessp x y) + (equal (t) z) + (equal (f) z))) + (equal (assignment x (append a b)) + (if (assignedp x a) + (assignment x a) + (assignment x b))) + (equal (car (gopher x)) + (if (listp x) + (car (flatten x)) + (zero))) + (equal (flatten (cdr (gopher x))) + (if (listp x) + (cdr (flatten x)) + (cons (zero) + (nil)))) + (equal (quotient (times y x) + y) + (if (zerop y) + (zero) + (fix x))) + (equal (get j (set i val mem)) + (if (eqp j i) + val + (get j mem))))))) + + (define (add-lemma-lst lst) + (cond ((null? lst) + #t) + (else (add-lemma (car lst)) + (add-lemma-lst (cdr lst))))) + + (define (add-lemma term) + (cond ((and (pair? term) + (eq? (car term) + (quote equal)) + (pair? (cadr term))) + (put (car (cadr term)) + (quote lemmas) + (cons + (translate-term term) + (get (car (cadr term)) (quote lemmas))))) + (else (error "ADD-LEMMA did not like term: " term)))) + + ; Translates a term by replacing its constructor symbols by symbol-records. + + (define (translate-term term) + (cond ((not (pair? term)) + term) + (else (cons (symbol->symbol-record (car term)) + (translate-args (cdr term)))))) + + (define (translate-args lst) + (cond ((null? lst) + '()) + (else (cons (translate-term (car lst)) + (translate-args (cdr lst)))))) + + ; For debugging only, so the use of MAP does not change + ; the first-order character of the benchmark. + + (define (untranslate-term term) + (cond ((not (pair? term)) + term) + (else (cons (get-name (car term)) + (map untranslate-term (cdr term)))))) + + ; A symbol-record is represented as a vector with two fields: + ; the symbol (for debugging) and + ; the list of lemmas associated with the symbol. + + (define (put sym property value) + (put-lemmas! (symbol->symbol-record sym) value)) + + (define (get sym property) + (get-lemmas (symbol->symbol-record sym))) + + (define (symbol->symbol-record sym) + (let ((x (assq sym *symbol-records-alist*))) + (if x + (cdr x) + (let ((r (make-symbol-record sym))) + (set! *symbol-records-alist* + (cons (cons sym r) + *symbol-records-alist*)) + r)))) + + ; Association list of symbols and symbol-records. + + (define *symbol-records-alist* '()) + + ; A symbol-record is represented as a vector with two fields: + ; the symbol (for debugging) and + ; the list of lemmas associated with the symbol. + + (define (make-symbol-record sym) + (vector sym '())) + + (define (put-lemmas! symbol-record lemmas) + (vector-set! symbol-record 1 lemmas)) + + (define (get-lemmas symbol-record) + (vector-ref symbol-record 1)) + + (define (get-name symbol-record) + (vector-ref symbol-record 0)) + + (define (symbol-record-equal? r1 r2) + (eq? r1 r2)) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; + ; The second phase. + ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + (define (test n) + (let ((term + (apply-subst + (translate-alist + (quote ((x f (plus (plus a b) + (plus c (zero)))) + (y f (times (times a b) + (plus c d))) + (z f (reverse (append (append a b) + (nil)))) + (u equal (plus a b) + (difference x y)) + (w lessp (remainder a b) + (member a (length b)))))) + (translate-term + (do ((term + (quote (implies (and (implies x y) + (and (implies y z) + (and (implies z u) + (implies u w)))) + (implies x w))) + (list 'or term '(f))) + (n n (- n 1))) + ((zero? n) term)))))) + (tautp term))) + + (define (translate-alist alist) + (cond ((null? alist) + '()) + (else (cons (cons (caar alist) + (translate-term (cdar alist))) + (translate-alist (cdr alist)))))) + + (define (apply-subst alist term) + (cond ((not (pair? term)) + (let ((temp-temp (assq term alist))) + (if temp-temp + (cdr temp-temp) + term))) + (else (cons (car term) + (apply-subst-lst alist (cdr term)))))) + + (define (apply-subst-lst alist lst) + (cond ((null? lst) + '()) + (else (cons (apply-subst alist (car lst)) + (apply-subst-lst alist (cdr lst)))))) + + (define (tautp x) + (tautologyp (rewrite x) + '() '())) + + (define (tautologyp x true-lst false-lst) + (cond ((truep x true-lst) + #t) + ((falsep x false-lst) + #f) + ((not (pair? x)) + #f) + ((eq? (car x) if-constructor) + (cond ((truep (cadr x) + true-lst) + (tautologyp (caddr x) + true-lst false-lst)) + ((falsep (cadr x) + false-lst) + (tautologyp (cadddr x) + true-lst false-lst)) + (else (and (tautologyp (caddr x) + (cons (cadr x) + true-lst) + false-lst) + (tautologyp (cadddr x) + true-lst + (cons (cadr x) + false-lst)))))) + (else #f))) + + (define if-constructor '*) ; becomes (symbol->symbol-record 'if) + + (define rewrite-count 0) ; sanity check + + (define (rewrite term) + (set! rewrite-count (+ rewrite-count 1)) + (cond ((not (pair? term)) + term) + (else (rewrite-with-lemmas (cons (car term) + (rewrite-args (cdr term))) + (get-lemmas (car term)))))) + + (define (rewrite-args lst) + (cond ((null? lst) + '()) + (else (cons (rewrite (car lst)) + (rewrite-args (cdr lst)))))) + + (define (rewrite-with-lemmas term lst) + (cond ((null? lst) + term) + ((one-way-unify term (cadr (car lst))) + (rewrite (apply-subst unify-subst (caddr (car lst))))) + (else (rewrite-with-lemmas term (cdr lst))))) + + (define unify-subst '*) + + (define (one-way-unify term1 term2) + (begin (set! unify-subst '()) + (one-way-unify1 term1 term2))) + + (define (one-way-unify1 term1 term2) + (cond ((not (pair? term2)) + (let ((temp-temp (assq term2 unify-subst))) + (cond (temp-temp + (term-equal? term1 (cdr temp-temp))) + ((number? term2) ; This bug fix makes + (equal? term1 term2)) ; nboyer 10-25% slower! + (else + (set! unify-subst (cons (cons term2 term1) + unify-subst)) + #t)))) + ((not (pair? term1)) + #f) + ((eq? (car term1) + (car term2)) + (one-way-unify1-lst (cdr term1) + (cdr term2))) + (else #f))) + + (define (one-way-unify1-lst lst1 lst2) + (cond ((null? lst1) + (null? lst2)) + ((null? lst2) + #f) + ((one-way-unify1 (car lst1) + (car lst2)) + (one-way-unify1-lst (cdr lst1) + (cdr lst2))) + (else #f))) + + (define (falsep x lst) + (or (term-equal? x false-term) + (term-member? x lst))) + + (define (truep x lst) + (or (term-equal? x true-term) + (term-member? x lst))) + + (define false-term '*) ; becomes (translate-term '(f)) + (define true-term '*) ; becomes (translate-term '(t)) + + ; The next two procedures were in the original benchmark + ; but were never used. + + (define (trans-of-implies n) + (translate-term + (list (quote implies) + (trans-of-implies1 n) + (list (quote implies) + 0 n)))) + + (define (trans-of-implies1 n) + (cond ((equal? n 1) + (list (quote implies) + 0 1)) + (else (list (quote and) + (list (quote implies) + (- n 1) + n) + (trans-of-implies1 (- n 1)))))) + + ; Translated terms can be circular structures, which can't be + ; compared using Scheme's equal? and member procedures, so we + ; use these instead. + + (define (term-equal? x y) + (cond ((pair? x) + (and (pair? y) + (symbol-record-equal? (car x) (car y)) + (term-args-equal? (cdr x) (cdr y)))) + (else (equal? x y)))) + + (define (term-args-equal? lst1 lst2) + (cond ((null? lst1) + (null? lst2)) + ((null? lst2) + #f) + ((term-equal? (car lst1) (car lst2)) + (term-args-equal? (cdr lst1) (cdr lst2))) + (else #f))) + + (define (term-member? x lst) + (cond ((null? lst) + #f) + ((term-equal? x (car lst)) + #t) + (else (term-member? x (cdr lst))))) + + (set! setup-boyer + (lambda () + (set! *symbol-records-alist* '()) + (set! if-constructor (symbol->symbol-record 'if)) + (set! false-term (translate-term '(f))) + (set! true-term (translate-term '(t))) + (setup))) + + (set! test-boyer + (lambda (n) + (set! rewrite-count 0) + (let ((answer (test n))) + (write rewrite-count) + (display " rewrites") + (newline) + (if answer + rewrite-count + #f)))))) diff --git a/tests/older-tests/benchmarks/nfa.rkt b/tests/older-tests/benchmarks/nfa.rkt new file mode 100644 index 0000000..4c05bc5 --- /dev/null +++ b/tests/older-tests/benchmarks/nfa.rkt @@ -0,0 +1,50 @@ +#lang s-exp "../../lang/base.rkt" + +(require "run-benchmark.rkt") +(provide recursive-nfa-benchmark) + +; The recursive-nfa benchmark. (Figure 45, page 143.) + +(define (recursive-nfa input) + + (define (state0 input) + (or (state1 input) (state3 input) #f)) + + (define (state1 input) + (and (not (null? input)) + (or (and (char=? (car input) #\a) + (state1 (cdr input))) + (and (char=? (car input) #\c) + (state1 input)) + (state2 input)))) + + (define (state2 input) + (and (not (null? input)) + (char=? (car input) #\b) + (not (null? (cdr input))) + (char=? (cadr input) #\c) + (not (null? (cddr input))) + (char=? (caddr input) #\d) + 'state2)) + + (define (state3 input) + (and (not (null? input)) + (or (and (char=? (car input) #\a) + (state3 (cdr input))) + (state4 input)))) + + (define (state4 input) + (and (not (null? input)) + (char=? (car input) #\b) + (not (null? (cdr input))) + (char=? (cadr input) #\c) + 'state4)) + + (or (state0 (string->list input)) + 'fail)) + +(define (recursive-nfa-benchmark) + (let ((input (string-append (make-string 133 #\a) "bc"))) + (run-benchmark "Recursive nfa" + (lambda () (recursive-nfa input)) + 1000))) diff --git a/tests/older-tests/benchmarks/nucleic2.rkt b/tests/older-tests/benchmarks/nucleic2.rkt new file mode 100644 index 0000000..b86f8a1 --- /dev/null +++ b/tests/older-tests/benchmarks/nucleic2.rkt @@ -0,0 +1,3779 @@ +#lang s-exp "../../lang/base.rkt" + +(require "run-benchmark.rkt") +(provide nucleic2-benchmark) + +(require (for-syntax racket/base)) + +; File: "nucleic2.scm" +; +; Author: Marc Feeley (feeley@iro.umontreal.ca) +; Last modification by Feeley: June 6, 1994. +; Modified for R5RS Scheme by William D Clinger: 22 October 1996. +; Last modification by Clinger: 19 March 1999. +; +; This program is a modified version of the program described in +; +; M. Feeley, M. Turcotte, G. Lapalme. Using Multilisp for Solving +; Constraint Satisfaction Problems: an Application to Nucleic Acid 3D +; Structure Determination. Lisp and Symbolic Computation 7(2/3), +; 231-246, 1994. +; +; The differences between this program and the original are described in +; +; P.H. Hartel, M. Feeley, et al. Benchmarking Implementations of +; Functional Languages with "Pseudoknot", a Float-Intensive Benchmark. +; Journal of Functional Programming 6(4), 621-655, 1996. + +; This procedure uses Marc Feeley's run-benchmark procedure to time +; the benchmark. + +(define (nucleic2-benchmark . rest) + (let ((n (if (null? rest) 1 (car rest)))) + (run-benchmark (string-append "nucleic2" + (if (> n 1) + (string-append " (" + (number->string n) + " iterations)") + "")) + n + run + (lambda (x) + (and (number? x) + (real? x) + (< (abs (- x 33.797594890762696)) 0.01)))))) + +; PORTABILITY. +; +; This program should run in any R5RS-conforming implementation of Scheme. +; To run this program in an implementation that does not support the R5RS +; macro system, however, you will have to place a single quotation mark (') +; on the following line and also modify the "SYSTEM DEPENDENT CODE" below. + +; ********** R5RS Scheme + +(begin + +(define-syntax FLOAT+ (syntax-rules () ((FLOAT+ x ...) (+ x ...)))) +(define-syntax FLOAT- (syntax-rules () ((FLOAT- x ...) (- x ...)))) +(define-syntax FLOAT* (syntax-rules () ((FLOAT* x ...) (* x ...)))) +(define-syntax FLOAT/ (syntax-rules () ((FLOAT/ x ...) (/ x ...)))) +(define-syntax FLOAT= (syntax-rules () ((FLOAT= x y) (= x y)))) +(define-syntax FLOAT< (syntax-rules () ((FLOAT< x y) (< x y)))) +(define-syntax FLOAT<= (syntax-rules () ((FLOAT<= x y) (<= x y)))) +(define-syntax FLOAT> (syntax-rules () ((FLOAT> x y) (> x y)))) +(define-syntax FLOAT>= (syntax-rules () ((FLOAT>= x y) (>= x y)))) +(define-syntax FLOATsin (syntax-rules () ((FLOATsin x) (sin x)))) +(define-syntax FLOATcos (syntax-rules () ((FLOATcos x) (cos x)))) +(define-syntax FLOATatan (syntax-rules () ((FLOATatan x) (atan x)))) +(define-syntax FLOATsqrt (syntax-rules () ((FLOATsqrt x) (sqrt x)))) + +(define-syntax FUTURE (syntax-rules () ((FUTURE x) x))) +(define-syntax TOUCH (syntax-rules () ((TOUCH x) x))) + +(define-syntax def-macro (syntax-rules () ((def-macro stuff ...) #t))) +(define-syntax def-struct (syntax-rules () ((def-macro stuff ...) #t))) +(define-syntax def-nuc (syntax-rules () ((def-nuc stuff ...) #t))) + +(define-syntax define-structure + (syntax-rules () + ((define-structure #f + name make make-constant (select1 ...) (set1 ...)) + (begin (define-syntax make + (syntax-rules () + ((make select1 ...) + (vector select1 ...)))) + (define-syntax make-constant + (syntax-rules () + ; The vectors that are passed to make-constant aren't quoted. + ((make-constant . args) + (constant-maker make . args)))) + (define-selectors (select1 ...) + (0 1 2 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 17 18 19 + 20 21 22 23 24 25 26 27 28 29 + 30 31 32 33 34 35 36 37 38 39 + 40 41 42 43 44 45 46 47 48 49)) + (define-setters (set1 ...) + (0 1 2 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 17 18 19 + 20 21 22 23 24 25 26 27 28 29 + 30 31 32 33 34 35 36 37 38 39 + 40 41 42 43 44 45 46 47 48 49)))) + ((define-structure pred? + name make make-constant (select1 ...) (set1 ...)) + (begin (define-syntax pred? + (syntax-rules () + ((pred? v) + (and (vector? v) (eq? (vector-ref v 0) 'name))))) + (define-syntax make + (syntax-rules () + ((make select1 ...) + (vector 'name select1 ...)))) + (define-syntax make-constant + (syntax-rules () + ; The vectors that are passed to make-constant aren't quoted. + ((make-constant . args) + (constant-maker make . args)))) + (define-selectors (select1 ...) + (1 2 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 17 18 19 + 20 21 22 23 24 25 26 27 28 29 + 30 31 32 33 34 35 36 37 38 39 + 40 41 42 43 44 45 46 47 48 49)) + (define-setters (set1 ...) + (1 2 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 17 18 19 + 20 21 22 23 24 25 26 27 28 29 + 30 31 32 33 34 35 36 37 38 39 + 40 41 42 43 44 45 46 47 48 49)))))) +(define-syntax constant-maker + (syntax-rules () + ; The quotation marks are added here. + ((constant-maker make arg ...) + (make 'arg ...)))) +(define-syntax define-selectors + (syntax-rules () + ((define-selectors (select) (i i1 ...)) + (define-syntax select + (syntax-rules () + ((select v) (vector-ref v i))))) + ((define-selectors (select select1 ...) (i i1 ...)) + (begin (define-syntax select + (syntax-rules () + ((select v) (vector-ref v i)))) + (define-selectors (select1 ...) (i1 ...)))))) +(define-syntax define-setters + (syntax-rules () + ((define-setters (set) (i i1 ...)) + (define-syntax set + (syntax-rules () + ((set v x) (vector-set! v i x))))) + ((define-setters (set set1 ...) (i i1 ...)) + (begin (define-syntax set + (syntax-rules () + ((set v x) (vector-set! v i x)))) + (define-setters (set1 ...) (i1 ...)))))) + +(define-structure #f pt + make-pt make-constant-pt + (pt-x pt-y pt-z) + (pt-x-set! pt-y-set! pt-z-set!)) + +(define-structure #f tfo + make-tfo make-constant-tfo + (tfo-a tfo-b tfo-c tfo-d tfo-e tfo-f tfo-g tfo-h tfo-i tfo-tx tfo-ty tfo-tz) + (tfo-a-set! tfo-b-set! tfo-c-set! tfo-d-set! tfo-e-set! tfo-f-set! + tfo-g-set! tfo-h-set! tfo-i-set! tfo-tx-set! tfo-ty-set! tfo-tz-set!)) + +(define-structure nuc? nuc + make-nuc make-constant-nuc + (nuc-dgf-base-tfo ; defines the standard position for wc and wc-dumas + nuc-P-O3*-275-tfo ; defines the standard position for the connect function + nuc-P-O3*-180-tfo + nuc-P-O3*-60-tfo + nuc-P nuc-O1P nuc-O2P nuc-O5* nuc-C5* + nuc-H5* nuc-H5** + nuc-C4* nuc-H4* nuc-O4* nuc-C1* nuc-H1* + nuc-C2* nuc-H2** + nuc-O2* nuc-H2* nuc-C3* nuc-H3* nuc-O3* + nuc-N1 nuc-N3 nuc-C2 nuc-C4 nuc-C5 nuc-C6) + (nuc-dgf-base-tfo-set! + nuc-P-O3*-275-tfo-set! + nuc-P-O3*-180-tfo-set! + nuc-P-O3*-60-tfo-set! + nuc-P-set! nuc-O1P-set! nuc-O2P-set! nuc-O5*-set! nuc-C5*-set! + nuc-H5*-set! nuc-H5**-set! + nuc-C4*-set! nuc-H4*-set! nuc-O4*-set! nuc-C1*-set! nuc-H1*-set! + nuc-C2*-set! nuc-H2**-set! + nuc-O2*-set! nuc-H2*-set! nuc-C3*-set! nuc-H3*-set! nuc-O3*-set! + nuc-N1-set! nuc-N3-set! nuc-C2-set! nuc-C4-set! nuc-C5-set! nuc-C6-set!)) + +(define-structure rA? rA + make-rA make-constant-rA + (nuc-dgf-base-tfo ; defines the standard position for wc and wc-dumas + nuc-P-O3*-275-tfo ; defines the standard position for the connect function + nuc-P-O3*-180-tfo + nuc-P-O3*-60-tfo + nuc-P nuc-O1P nuc-O2P nuc-O5* nuc-C5* + nuc-H5* nuc-H5** + nuc-C4* nuc-H4* nuc-O4* nuc-C1* nuc-H1* + nuc-C2* nuc-H2** + nuc-O2* nuc-H2* nuc-C3* nuc-H3* nuc-O3* + nuc-N1 nuc-N3 nuc-C2 nuc-C4 nuc-C5 nuc-C6 + rA-N6 rA-N7 rA-N9 rA-C8 + rA-H2 rA-H61 rA-H62 rA-H8) + (nuc-dgf-base-tfo-set! + nuc-P-O3*-275-tfo-set! + nuc-P-O3*-180-tfo-set! + nuc-P-O3*-60-tfo-set! + nuc-P-set! nuc-O1P-set! nuc-O2P-set! nuc-O5*-set! nuc-C5*-set! + nuc-H5*-set! nuc-H5**-set! + nuc-C4*-set! nuc-H4*-set! nuc-O4*-set! nuc-C1*-set! nuc-H1*-set! + nuc-C2*-set! nuc-H2**-set! + nuc-O2*-set! nuc-H2*-set! nuc-C3*-set! nuc-H3*-set! nuc-O3*-set! + nuc-N1-set! nuc-N3-set! nuc-C2-set! nuc-C4-set! nuc-C5-set! nuc-C6-set! + rA-N6-set! rA-N7-set! rA-N9-set! rA-C8-set! + rA-H2-set! rA-H61-set! rA-H62-set! rA-H8-set!)) + +(define-structure rC? rC + make-rC make-constant-rC + (nuc-dgf-base-tfo ; defines the standard position for wc and wc-dumas + nuc-P-O3*-275-tfo ; defines the standard position for the connect function + nuc-P-O3*-180-tfo + nuc-P-O3*-60-tfo + nuc-P nuc-O1P nuc-O2P nuc-O5* nuc-C5* + nuc-H5* nuc-H5** + nuc-C4* nuc-H4* nuc-O4* nuc-C1* nuc-H1* + nuc-C2* nuc-H2** + nuc-O2* nuc-H2* nuc-C3* nuc-H3* nuc-O3* + nuc-N1 nuc-N3 nuc-C2 nuc-C4 nuc-C5 nuc-C6 + rC-N4 rC-O2 rC-H41 rC-H42 rC-H5 rC-H6) + (nuc-dgf-base-tfo-set! + nuc-P-O3*-275-tfo-set! + nuc-P-O3*-180-tfo-set! + nuc-P-O3*-60-tfo-set! + nuc-P-set! nuc-O1P-set! nuc-O2P-set! nuc-O5*-set! nuc-C5*-set! + nuc-H5*-set! nuc-H5**-set! + nuc-C4*-set! nuc-H4*-set! nuc-O4*-set! nuc-C1*-set! nuc-H1*-set! + nuc-C2*-set! nuc-H2**-set! + nuc-O2*-set! nuc-H2*-set! nuc-C3*-set! nuc-H3*-set! nuc-O3*-set! + nuc-N1-set! nuc-N3-set! nuc-C2-set! nuc-C4-set! nuc-C5-set! nuc-C6-set! + rC-N4-set! rC-O2-set! rC-H41-set! rC-H42-set! rC-H5-set! rC-H6-set!)) + +(define-structure rG? rG + make-rG make-constant-rG + (nuc-dgf-base-tfo ; defines the standard position for wc and wc-dumas + nuc-P-O3*-275-tfo ; defines the standard position for the connect function + nuc-P-O3*-180-tfo + nuc-P-O3*-60-tfo + nuc-P nuc-O1P nuc-O2P nuc-O5* nuc-C5* + nuc-H5* nuc-H5** + nuc-C4* nuc-H4* nuc-O4* nuc-C1* nuc-H1* + nuc-C2* nuc-H2** + nuc-O2* nuc-H2* nuc-C3* nuc-H3* nuc-O3* + nuc-N1 nuc-N3 nuc-C2 nuc-C4 nuc-C5 nuc-C6 + rG-N2 rG-N7 rG-N9 rG-C8 rG-O6 + rG-H1 rG-H21 rG-H22 rG-H8) + (nuc-dgf-base-tfo-set! + nuc-P-O3*-275-tfo-set! + nuc-P-O3*-180-tfo-set! + nuc-P-O3*-60-tfo-set! + nuc-P-set! nuc-O1P-set! nuc-O2P-set! nuc-O5*-set! nuc-C5*-set! + nuc-H5*-set! nuc-H5**-set! + nuc-C4*-set! nuc-H4*-set! nuc-O4*-set! nuc-C1*-set! nuc-H1*-set! + nuc-C2*-set! nuc-H2**-set! + nuc-O2*-set! nuc-H2*-set! nuc-C3*-set! nuc-H3*-set! nuc-O3*-set! + nuc-N1-set! nuc-N3-set! nuc-C2-set! nuc-C4-set! nuc-C5-set! nuc-C6-set! + rG-N2-set! rG-N7-set! rG-N9-set! rG-C8-set! rG-O6-set! + rG-H1-set! rG-H21-set! rG-H22-set! rG-H8-set!)) + +(define-structure rU? rU + make-rU make-constant-rU + (nuc-dgf-base-tfo ; defines the standard position for wc and wc-dumas + nuc-P-O3*-275-tfo ; defines the standard position for the connect function + nuc-P-O3*-180-tfo + nuc-P-O3*-60-tfo + nuc-P nuc-O1P nuc-O2P nuc-O5* nuc-C5* + nuc-H5* nuc-H5** + nuc-C4* nuc-H4* nuc-O4* nuc-C1* nuc-H1* + nuc-C2* nuc-H2** + nuc-O2* nuc-H2* nuc-C3* nuc-H3* nuc-O3* + nuc-N1 nuc-N3 nuc-C2 nuc-C4 nuc-C5 nuc-C6 + rU-O2 rU-O4 rU-H3 rU-H5 rU-H6) + (nuc-dgf-base-tfo-set! + nuc-P-O3*-275-tfo-set! + nuc-P-O3*-180-tfo-set! + nuc-P-O3*-60-tfo-set! + nuc-P-set! nuc-O1P-set! nuc-O2P-set! nuc-O5*-set! nuc-C5*-set! + nuc-H5*-set! nuc-H5**-set! + nuc-C4*-set! nuc-H4*-set! nuc-O4*-set! nuc-C1*-set! nuc-H1*-set! + nuc-C2*-set! nuc-H2**-set! + nuc-O2*-set! nuc-H2*-set! nuc-C3*-set! nuc-H3*-set! nuc-O3*-set! + nuc-N1-set! nuc-N3-set! nuc-C2-set! nuc-C4-set! nuc-C5-set! nuc-C6-set! + rU-O2-set! rU-O4-set! rU-H3-set! rU-H5-set! rU-H6-set!)) + +(define-structure #f var + make-var make-constant-var + (var-id var-tfo var-nuc) + (var-id-set! var-tfo-set! var-nuc-set!)) + +; Comment out the next three syntax definitions if you want +; lazy computation. + +(define-syntax mk-var + (syntax-rules () + ((mk-var i tfo nuc) + (make-var i tfo nuc)))) + +(define-syntax absolute-pos + (syntax-rules () + ((absolute-pos var p) + (tfo-apply (var-tfo var) p)))) + +(define-syntax lazy-computation-of + (syntax-rules () + ((lazy-computation-of expr) + expr))) + +; Uncomment the next three syntax definitions if you want +; lazy computation. + +; (define-syntax mk-var +; (syntax-rules () +; ((mk-var i tfo nuc) +; (make-var i tfo (make-relative-nuc tfo nuc))))) +; +; (define-syntax absolute-pos +; (syntax-rules () +; ((absolute-pos var p) +; (force p)))) +; +; (define-syntax lazy-computation-of +; (syntax-rules () +; ((lazy-computation-of expr) +; (delay expr)))) + +(define-syntax atom-pos + (syntax-rules () + ((atom-pos atom var) + (let ((v var)) + (absolute-pos v (atom (var-nuc v))))))) + +) + +; -- SYSTEM DEPENDENT CODE ---------------------------------------------------- + +; The code in this section is not portable. It must be adapted to +; the Scheme system you are using. + +; ********** GAMBIT 2.2 + +'; Add a single-quote at the start of this line if you are NOT using Gambit +(begin + +(declare ; Compiler declarations for fast code: + (multilisp) ; - Enable the FUTURE special-form + (block) ; - Assume this file contains the entire program + (standard-bindings) ; - Assume standard bindings (this permits open-coding) + (extended-bindings) ; - Same for extensions (such as "##flonum.+") + (fixnum) ; - Use fixnum arithmetic by default + (not safe) ; - Remove all runtime type checks +) + +(define-macro (def-macro form . body) + `(DEFINE-MACRO ,form (LET () ,@body))) + +(def-macro (FLOAT+ x . l) `(,(string->symbol "##flonum.+") ,x ,@l)) +(def-macro (FLOAT- x . l) `(,(string->symbol "##flonum.-") ,x ,@l)) +(def-macro (FLOAT* x . l) `(,(string->symbol "##flonum.*") ,x ,@l)) +(def-macro (FLOAT/ x . l) `(,(string->symbol "##flonum./") ,x ,@l)) +(def-macro (FLOAT= x y) `(,(string->symbol "##flonum.=") ,x ,y)) +(def-macro (FLOAT< x y) `(,(string->symbol "##flonum.<") ,x ,y)) +(def-macro (FLOAT<= x y) `(not (,(string->symbol "##flonum.<") ,y ,x))) +(def-macro (FLOAT> x y) `(,(string->symbol "##flonum.<") ,y ,x)) +(def-macro (FLOAT>= x y) `(not (,(string->symbol "##flonum.<") ,x ,y))) +(def-macro (FLOATsin x) `(,(string->symbol "##flonum.sin") ,x)) +(def-macro (FLOATcos x) `(,(string->symbol "##flonum.cos") ,x)) +(def-macro (FLOATatan x) `(,(string->symbol "##flonum.atan") ,x)) +(def-macro (FLOATsqrt x) `(,(string->symbol "##flonum.sqrt") ,x)) +) + +; ********** MIT-SCHEME + +'; Remove the single-quote from this line if you are using MIT-Scheme +(begin + +(declare (usual-integrations)) + +(define-macro (def-macro form . body) + `(DEFINE-MACRO ,form (LET () ,@body))) + +(def-macro (nary-function op1 op2 args) + (if (null? (cdr args)) + `(,op1 ,@args) + (let loop ((args args)) + (if (null? (cdr args)) + (car args) + (loop (cons (list op2 (car args) (cadr args)) (cddr args))))))) + +(def-macro (FLOAT+ x . l) `(nary-function begin flo:+ ,(cons x l))) +(def-macro (FLOAT- x . l) `(nary-function flo:negate flo:- ,(cons x l))) +(def-macro (FLOAT* x . l) `(nary-function begin flo:* ,(cons x l))) +(def-macro (FLOAT/ x . l) `(nary-function error flo:/ ,(cons x l))) +(def-macro (FLOAT= x y) `(flo:= ,x ,y)) +(def-macro (FLOAT< x y) `(flo:< ,x ,y)) +(def-macro (FLOAT<= x y) `(not (flo:< ,y ,x))) +(def-macro (FLOAT> x y) `(flo:< ,y ,x)) +(def-macro (FLOAT>= x y) `(not (flo:< ,x ,y))) +(def-macro (FLOATsin x) `(flo:sin ,x)) +(def-macro (FLOATcos x) `(flo:cos ,x)) +(def-macro (FLOATatan x) `(flo:atan ,x)) +(def-macro (FLOATsqrt x) `(flo:sqrt ,x)) + +(def-macro (FUTURE x) x) +(def-macro (TOUCH x) x) +) + +; ********** SCM + +'; Remove the single-quote from this line if you are using SCM +(begin + +(defmacro def-macro (form . body) + `(DEFMACRO ,(car form) ,(cdr form) (LET () ,@body))) + +(def-macro (FLOAT+ x . l) `(+ ,x ,@l)) +(def-macro (FLOAT- x . l) `(- ,x ,@l)) +(def-macro (FLOAT* x . l) `(* ,x ,@l)) +(def-macro (FLOAT/ x . l) `(/ ,x ,@l)) +(def-macro (FLOAT= x y) `(= ,x ,y)) +(def-macro (FLOAT< x y) `(< ,x ,y)) +(def-macro (FLOAT<= x y) `(not (< ,y ,x))) +(def-macro (FLOAT> x y) `(< ,y ,x)) +(def-macro (FLOAT>= x y) `(not (< ,x ,y))) +(def-macro (FLOATsin x) `(sin ,x)) +(def-macro (FLOATcos x) `(cos ,x)) +(def-macro (FLOATatan x) `(atan ,x)) +(def-macro (FLOATsqrt x) `(sqrt ,x)) + +(def-macro (FUTURE x) x) +(def-macro (TOUCH x) x) +) + +; -- STRUCTURE DEFINITION MACRO ----------------------------------------------- + +; The macro "def-struct" provides a simple mechanism to define record +; structures out of vectors. The first argument to "def-struct" is a boolean +; indicating whether the vector should be tagged (to allow the type of the +; structure to be tested). The second argument is the name of the structure. +; The remaining arguments are the names of the structure's fields. A call +; to "def-struct" defines macros to +; +; 1) construct a record object of this type +; 2) fetch and store each field +; 3) test a record to see if it is of this type (only if tags are used) +; 4) define subclasses of this record with additional fields +; +; The call "(def-struct #t foo a b c)" will define the following macros: +; +; (make-foo x y) -- make a record +; (make-constant-foo x y) -- make a record (args must be constants) +; (foo? x) -- test a record +; (foo-a x) -- get field "a" +; (foo-b x) -- get field "b" +; (foo-a-set! x y) -- mutate field "a" +; (foo-b-set! x y) -- mutate field "b" +; (def-foo tag? name fields...) -- define subclass of "foo" + +(def-macro (def-struct tag? name . fields) + `(DEF-SUBSTRUCT () () 0 ,tag? ,name ,@fields)) + +(def-macro (def-substruct sup-fields sup-tags sup-length tag? name . fields) + + (define (err) + (error "Ill-formed `def-substruct'") #f) + + (define (sym . strings) + (string->symbol (apply string-append strings))) + + (if (symbol? name) + (let* ((name-str (symbol->string name)) + (tag (sym "." name-str ".")) + (all-tags (append sup-tags + (if tag? + (list (cons tag sup-length)) + '())))) + (let loop ((l1 fields) + (l2 '()) + (l3 '()) + (i (+ sup-length (if tag? 1 0)))) + (if (pair? l1) + (let ((rest (cdr l1)) (field (car l1))) + (if (symbol? field) + (let* ((field-str (symbol->string field)) + (field-ref (sym name-str "-" field-str)) + (field-set! (sym name-str "-" field-str "-set!"))) + (loop rest + (cons `(DEF-MACRO (,field-set! X Y) + `(VECTOR-SET! ,X ,,i ,Y)) + (cons `(DEF-MACRO (,field-ref X) + `(VECTOR-REF ,X ,,i)) + l2)) + (cons (cons field i) l3) + (+ i 1))) + (err))) + (let ((all-fields (append sup-fields (reverse l3)))) + `(BEGIN + ,@l2 + (DEFINE ,(sym "fields-of-" name-str) + ',all-fields) + (DEF-MACRO (,(sym "def-" name-str) TAG? NAME . FIELDS) + `(DEF-SUBSTRUCT ,',all-fields ,',all-tags ,',i + ,TAG? ,NAME ,@FIELDS)) + (DEF-MACRO (,(sym "make-constant-" name-str) . REST) + (DEFINE (ADD-TAGS I TAGS LST) + (COND ((NULL? TAGS) + LST) + ((= I (CDAR TAGS)) + (CONS (CAAR TAGS) + (ADD-TAGS (+ I 1) (CDR TAGS) LST))) + (ELSE + (CONS (CAR LST) + (ADD-TAGS (+ I 1) TAGS (CDR LST)))))) + `'#(,@(ADD-TAGS 0 ',all-tags REST))) + (DEF-MACRO (,(sym "make-" name-str) . REST) + (DEFINE (ADD-TAGS I TAGS LST) + (COND ((NULL? TAGS) + LST) + ((= I (CDAR TAGS)) + (CONS `',(CAAR TAGS) + (ADD-TAGS (+ I 1) (CDR TAGS) LST))) + (ELSE + (CONS (CAR LST) + (ADD-TAGS (+ I 1) TAGS (CDR LST)))))) + `(VECTOR ,@(ADD-TAGS 0 ',all-tags REST))) + ,@(if tag? + `((DEF-MACRO (,(sym name-str "?") X) + `(EQ? (VECTOR-REF ,X ,,sup-length) ',',tag))) + '()) + ',name))))) + (err))) + +; -- MATH UTILITIES ----------------------------------------------------------- + +(define constant-pi 3.14159265358979323846) +(define constant-minus-pi -3.14159265358979323846) +(define constant-pi/2 1.57079632679489661923) +(define constant-minus-pi/2 -1.57079632679489661923) + +(define (math-atan2 y x) + (cond ((FLOAT> x 0.0) + (FLOATatan (FLOAT/ y x))) + ((FLOAT< y 0.0) + (if (FLOAT= x 0.0) + constant-minus-pi/2 + (FLOAT+ (FLOATatan (FLOAT/ y x)) constant-minus-pi))) + (else + (if (FLOAT= x 0.0) + constant-pi/2 + (FLOAT+ (FLOATatan (FLOAT/ y x)) constant-pi))))) + +; -- POINTS ------------------------------------------------------------------- + +(def-struct #f pt x y z) + +(define (pt-sub p1 p2) + (make-pt (FLOAT- (pt-x p1) (pt-x p2)) + (FLOAT- (pt-y p1) (pt-y p2)) + (FLOAT- (pt-z p1) (pt-z p2)))) + +(define (pt-dist p1 p2) + (let ((dx (FLOAT- (pt-x p1) (pt-x p2))) + (dy (FLOAT- (pt-y p1) (pt-y p2))) + (dz (FLOAT- (pt-z p1) (pt-z p2)))) + (FLOATsqrt (FLOAT+ (FLOAT* dx dx) (FLOAT* dy dy) (FLOAT* dz dz))))) + +(define (pt-phi p) + (let* ((x (pt-x p)) + (y (pt-y p)) + (z (pt-z p)) + (b (math-atan2 x z))) + (math-atan2 (FLOAT+ (FLOAT* (FLOATcos b) z) (FLOAT* (FLOATsin b) x)) y))) + +(define (pt-theta p) + (math-atan2 (pt-x p) (pt-z p))) + +; -- COORDINATE TRANSFORMATIONS ----------------------------------------------- + +; The notation for the transformations follows "Paul, R.P. (1981) Robot +; Manipulators. MIT Press." with the exception that our transformation +; matrices don't have the perspective terms and are the transpose of +; Paul's one. See also "M\"antyl\"a, M. (1985) An Introduction to +; Solid Modeling, Computer Science Press" Appendix A. +; +; The components of a transformation matrix are named like this: +; +; a b c +; d e f +; g h i +; tx ty tz +; +; The components tx, ty, and tz are the translation vector. + +(def-struct #f tfo a b c d e f g h i tx ty tz) + +(define tfo-id ; the identity transformation matrix + '#(1.0 0.0 0.0 + 0.0 1.0 0.0 + 0.0 0.0 1.0 + 0.0 0.0 0.0)) + +; The function "tfo-apply" multiplies a transformation matrix, tfo, by a +; point vector, p. The result is a new point. + +(define (tfo-apply tfo p) + (let ((x (pt-x p)) + (y (pt-y p)) + (z (pt-z p))) + (make-pt + (FLOAT+ (FLOAT* x (tfo-a tfo)) + (FLOAT* y (tfo-d tfo)) + (FLOAT* z (tfo-g tfo)) + (tfo-tx tfo)) + (FLOAT+ (FLOAT* x (tfo-b tfo)) + (FLOAT* y (tfo-e tfo)) + (FLOAT* z (tfo-h tfo)) + (tfo-ty tfo)) + (FLOAT+ (FLOAT* x (tfo-c tfo)) + (FLOAT* y (tfo-f tfo)) + (FLOAT* z (tfo-i tfo)) + (tfo-tz tfo))))) + +; The function "tfo-combine" multiplies two transformation matrices A and B. +; The result is a new matrix which cumulates the transformations described +; by A and B. + +(define (tfo-combine A B) + (make-tfo + (FLOAT+ (FLOAT* (tfo-a A) (tfo-a B)) + (FLOAT* (tfo-b A) (tfo-d B)) + (FLOAT* (tfo-c A) (tfo-g B))) + (FLOAT+ (FLOAT* (tfo-a A) (tfo-b B)) + (FLOAT* (tfo-b A) (tfo-e B)) + (FLOAT* (tfo-c A) (tfo-h B))) + (FLOAT+ (FLOAT* (tfo-a A) (tfo-c B)) + (FLOAT* (tfo-b A) (tfo-f B)) + (FLOAT* (tfo-c A) (tfo-i B))) + (FLOAT+ (FLOAT* (tfo-d A) (tfo-a B)) + (FLOAT* (tfo-e A) (tfo-d B)) + (FLOAT* (tfo-f A) (tfo-g B))) + (FLOAT+ (FLOAT* (tfo-d A) (tfo-b B)) + (FLOAT* (tfo-e A) (tfo-e B)) + (FLOAT* (tfo-f A) (tfo-h B))) + (FLOAT+ (FLOAT* (tfo-d A) (tfo-c B)) + (FLOAT* (tfo-e A) (tfo-f B)) + (FLOAT* (tfo-f A) (tfo-i B))) + (FLOAT+ (FLOAT* (tfo-g A) (tfo-a B)) + (FLOAT* (tfo-h A) (tfo-d B)) + (FLOAT* (tfo-i A) (tfo-g B))) + (FLOAT+ (FLOAT* (tfo-g A) (tfo-b B)) + (FLOAT* (tfo-h A) (tfo-e B)) + (FLOAT* (tfo-i A) (tfo-h B))) + (FLOAT+ (FLOAT* (tfo-g A) (tfo-c B)) + (FLOAT* (tfo-h A) (tfo-f B)) + (FLOAT* (tfo-i A) (tfo-i B))) + (FLOAT+ (FLOAT* (tfo-tx A) (tfo-a B)) + (FLOAT* (tfo-ty A) (tfo-d B)) + (FLOAT* (tfo-tz A) (tfo-g B)) + (tfo-tx B)) + (FLOAT+ (FLOAT* (tfo-tx A) (tfo-b B)) + (FLOAT* (tfo-ty A) (tfo-e B)) + (FLOAT* (tfo-tz A) (tfo-h B)) + (tfo-ty B)) + (FLOAT+ (FLOAT* (tfo-tx A) (tfo-c B)) + (FLOAT* (tfo-ty A) (tfo-f B)) + (FLOAT* (tfo-tz A) (tfo-i B)) + (tfo-tz B)))) + +; The function "tfo-inv-ortho" computes the inverse of a homogeneous +; transformation matrix. + +(define (tfo-inv-ortho tfo) + (let* ((tx (tfo-tx tfo)) + (ty (tfo-ty tfo)) + (tz (tfo-tz tfo))) + (make-tfo + (tfo-a tfo) (tfo-d tfo) (tfo-g tfo) + (tfo-b tfo) (tfo-e tfo) (tfo-h tfo) + (tfo-c tfo) (tfo-f tfo) (tfo-i tfo) + (FLOAT- (FLOAT+ (FLOAT* (tfo-a tfo) tx) + (FLOAT* (tfo-b tfo) ty) + (FLOAT* (tfo-c tfo) tz))) + (FLOAT- (FLOAT+ (FLOAT* (tfo-d tfo) tx) + (FLOAT* (tfo-e tfo) ty) + (FLOAT* (tfo-f tfo) tz))) + (FLOAT- (FLOAT+ (FLOAT* (tfo-g tfo) tx) + (FLOAT* (tfo-h tfo) ty) + (FLOAT* (tfo-i tfo) tz)))))) + +; Given three points p1, p2, and p3, the function "tfo-align" computes +; a transformation matrix such that point p1 gets mapped to (0,0,0), p2 gets +; mapped to the Y axis and p3 gets mapped to the YZ plane. + +(define (tfo-align p1 p2 p3) + (let* ((x1 (pt-x p1)) (y1 (pt-y p1)) (z1 (pt-z p1)) + (x3 (pt-x p3)) (y3 (pt-y p3)) (z3 (pt-z p3)) + (x31 (FLOAT- x3 x1)) (y31 (FLOAT- y3 y1)) (z31 (FLOAT- z3 z1)) + (rotpY (pt-sub p2 p1)) + (Phi (pt-phi rotpY)) + (Theta (pt-theta rotpY)) + (sinP (FLOATsin Phi)) + (sinT (FLOATsin Theta)) + (cosP (FLOATcos Phi)) + (cosT (FLOATcos Theta)) + (sinPsinT (FLOAT* sinP sinT)) + (sinPcosT (FLOAT* sinP cosT)) + (cosPsinT (FLOAT* cosP sinT)) + (cosPcosT (FLOAT* cosP cosT)) + (rotpZ + (make-pt + (FLOAT- (FLOAT* cosT x31) + (FLOAT* sinT z31)) + (FLOAT+ (FLOAT* sinPsinT x31) + (FLOAT* cosP y31) + (FLOAT* sinPcosT z31)) + (FLOAT+ (FLOAT* cosPsinT x31) + (FLOAT- (FLOAT* sinP y31)) + (FLOAT* cosPcosT z31)))) + (Rho (pt-theta rotpZ)) + (cosR (FLOATcos Rho)) + (sinR (FLOATsin Rho)) + (x (FLOAT+ (FLOAT- (FLOAT* x1 cosT)) + (FLOAT* z1 sinT))) + (y (FLOAT- (FLOAT- (FLOAT- (FLOAT* x1 sinPsinT)) + (FLOAT* y1 cosP)) + (FLOAT* z1 sinPcosT))) + (z (FLOAT- (FLOAT+ (FLOAT- (FLOAT* x1 cosPsinT)) + (FLOAT* y1 sinP)) + (FLOAT* z1 cosPcosT)))) + (make-tfo + (FLOAT- (FLOAT* cosT cosR) (FLOAT* cosPsinT sinR)) + sinPsinT + (FLOAT+ (FLOAT* cosT sinR) (FLOAT* cosPsinT cosR)) + (FLOAT* sinP sinR) + cosP + (FLOAT- (FLOAT* sinP cosR)) + (FLOAT- (FLOAT- (FLOAT* sinT cosR)) (FLOAT* cosPcosT sinR)) + sinPcosT + (FLOAT+ (FLOAT- (FLOAT* sinT sinR)) (FLOAT* cosPcosT cosR)) + (FLOAT- (FLOAT* x cosR) (FLOAT* z sinR)) + y + (FLOAT+ (FLOAT* x sinR) (FLOAT* z cosR))))) + +; -- NUCLEIC ACID CONFORMATIONS DATA BASE ------------------------------------- + +; Numbering of atoms follows the paper: +; +; IUPAC-IUB Joint Commission on Biochemical Nomenclature (JCBN) +; (1983) Abbreviations and Symbols for the Description of +; Conformations of Polynucleotide Chains. Eur. J. Biochem 131, +; 9-15. +; +; In the atom names, we have used "*" instead of "'". + +; Define part common to all 4 nucleotide types. + +(def-struct #f nuc + dgf-base-tfo ; defines the standard position for wc and wc-dumas + P-O3*-275-tfo ; defines the standard position for the connect function + P-O3*-180-tfo + P-O3*-60-tfo + P O1P O2P O5* C5* H5* H5** C4* H4* O4* C1* H1* C2* H2** O2* H2* C3* + H3* O3* N1 N3 C2 C4 C5 C6) + +; Define remaining atoms for each nucleotide type. + +(def-nuc #t rA N6 N7 N9 C8 H2 H61 H62 H8) +(def-nuc #t rC N4 O2 H41 H42 H5 H6) +(def-nuc #t rG N2 N7 N9 C8 O6 H1 H21 H22 H8) +(def-nuc #t rU O2 O4 H3 H5 H6) + +; Database of nucleotide conformations: + +(define rA + (make-constant-rA + #( -0.0018 -0.8207 0.5714 ; dgf-base-tfo + 0.2679 -0.5509 -0.7904 + 0.9634 0.1517 0.2209 + 0.0073 8.4030 0.6232) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 5.4550 8.2120 -2.8810) ; C5* + #( 5.4546 8.8508 -1.9978) ; H5* + #( 5.7588 8.6625 -3.8259) ; H5** + #( 6.4970 7.1480 -2.5980) ; C4* + #( 7.4896 7.5919 -2.5214) ; H4* + #( 6.1630 6.4860 -1.3440) ; O4* + #( 6.5400 5.1200 -1.4190) ; C1* + #( 7.2763 4.9681 -0.6297) ; H1* + #( 7.1940 4.8830 -2.7770) ; C2* + #( 6.8667 3.9183 -3.1647) ; H2** + #( 8.5860 5.0910 -2.6140) ; O2* + #( 8.9510 4.7626 -1.7890) ; H2* + #( 6.5720 6.0040 -3.6090) ; C3* + #( 5.5636 5.7066 -3.8966) ; H3* + #( 7.3801 6.3562 -4.7350) ; O3* + #( 4.7150 0.4910 -0.1360) ; N1 + #( 6.3490 2.1730 -0.6020) ; N3 + #( 5.9530 0.9650 -0.2670) ; C2 + #( 5.2900 2.9790 -0.8260) ; C4 + #( 3.9720 2.6390 -0.7330) ; C5 + #( 3.6770 1.3160 -0.3660) ; C6 + #( 2.4280 0.8450 -0.2360) ; N6 + #( 3.1660 3.7290 -1.0360) ; N7 + #( 5.3170 4.2990 -1.1930) ; N9 + #( 4.0100 4.6780 -1.2990) ; C8 + #( 6.6890 0.1903 -0.0518) ; H2 + #( 1.6470 1.4460 -0.4040) ; H61 + #( 2.2780 -0.1080 -0.0280) ; H62 + #( 3.4421 5.5744 -1.5482) ; H8 + )) + +(define rA01 + (make-constant-rA + #( -0.0043 -0.8175 0.5759 ; dgf-base-tfo + 0.2617 -0.5567 -0.7884 + 0.9651 0.1473 0.2164 + 0.0359 8.3929 0.5532) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 5.4352 8.2183 -2.7757) ; C5* + #( 5.3830 8.7883 -1.8481) ; H5* + #( 5.7729 8.7436 -3.6691) ; H5** + #( 6.4830 7.1518 -2.5252) ; C4* + #( 7.4749 7.5972 -2.4482) ; H4* + #( 6.1626 6.4620 -1.2827) ; O4* + #( 6.5431 5.0992 -1.3905) ; C1* + #( 7.2871 4.9328 -0.6114) ; H1* + #( 7.1852 4.8935 -2.7592) ; C2* + #( 6.8573 3.9363 -3.1645) ; H2** + #( 8.5780 5.1025 -2.6046) ; O2* + #( 8.9516 4.7577 -1.7902) ; H2* + #( 6.5522 6.0300 -3.5612) ; C3* + #( 5.5420 5.7356 -3.8459) ; H3* + #( 7.3487 6.4089 -4.6867) ; O3* + #( 4.7442 0.4514 -0.1390) ; N1 + #( 6.3687 2.1459 -0.5926) ; N3 + #( 5.9795 0.9335 -0.2657) ; C2 + #( 5.3052 2.9471 -0.8125) ; C4 + #( 3.9891 2.5987 -0.7230) ; C5 + #( 3.7016 1.2717 -0.3647) ; C6 + #( 2.4553 0.7925 -0.2390) ; N6 + #( 3.1770 3.6859 -1.0198) ; N7 + #( 5.3247 4.2695 -1.1710) ; N9 + #( 4.0156 4.6415 -1.2759) ; C8 + #( 6.7198 0.1618 -0.0547) ; H2 + #( 1.6709 1.3900 -0.4039) ; H61 + #( 2.3107 -0.1627 -0.0373) ; H62 + #( 3.4426 5.5361 -1.5199) ; H8 + )) + +(define rA02 + (make-constant-rA + #( 0.5566 0.0449 0.8296 ; dgf-base-tfo + 0.5125 0.7673 -0.3854 + -0.6538 0.6397 0.4041 + -9.1161 -3.7679 -2.9968) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.5778 6.6594 -4.0364) ; C5* + #( 4.9220 7.1963 -4.9204) ; H5* + #( 3.7996 5.9091 -4.1764) ; H5** + #( 5.7873 5.8869 -3.5482) ; C4* + #( 6.0405 5.0875 -4.2446) ; H4* + #( 6.9135 6.8036 -3.4310) ; O4* + #( 7.7293 6.4084 -2.3392) ; C1* + #( 8.7078 6.1815 -2.7624) ; H1* + #( 7.1305 5.1418 -1.7347) ; C2* + #( 7.2040 5.1982 -0.6486) ; H2** + #( 7.7417 4.0392 -2.3813) ; O2* + #( 8.6785 4.1443 -2.5630) ; H2* + #( 5.6666 5.2728 -2.1536) ; C3* + #( 5.1747 5.9805 -1.4863) ; H3* + #( 4.9997 4.0086 -2.1973) ; O3* + #( 10.3245 8.5459 1.5467) ; N1 + #( 9.8051 6.9432 -0.1497) ; N3 + #( 10.5175 7.4328 0.8408) ; C2 + #( 8.7523 7.7422 -0.4228) ; C4 + #( 8.4257 8.9060 0.2099) ; C5 + #( 9.2665 9.3242 1.2540) ; C6 + #( 9.0664 10.4462 1.9610) ; N6 + #( 7.2750 9.4537 -0.3428) ; N7 + #( 7.7962 7.5519 -1.3859) ; N9 + #( 6.9479 8.6157 -1.2771) ; C8 + #( 11.4063 6.9047 1.1859) ; H2 + #( 8.2845 11.0341 1.7552) ; H61 + #( 9.6584 10.6647 2.7198) ; H62 + #( 6.0430 8.9853 -1.7594) ; H8 + )) + +(define rA03 + (make-constant-rA + #( -0.5021 0.0731 0.8617 ; dgf-base-tfo + -0.8112 0.3054 -0.4986 + -0.2996 -0.9494 -0.0940 + 6.4273 -5.1944 -3.7807) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.1214 6.7116 -1.9049) ; C5* + #( 3.3465 5.9610 -2.0607) ; H5* + #( 4.0789 7.2928 -0.9837) ; H5** + #( 5.4170 5.9293 -1.8186) ; C4* + #( 5.4506 5.3400 -0.9023) ; H4* + #( 5.5067 5.0417 -2.9703) ; O4* + #( 6.8650 4.9152 -3.3612) ; C1* + #( 7.1090 3.8577 -3.2603) ; H1* + #( 7.7152 5.7282 -2.3894) ; C2* + #( 8.5029 6.2356 -2.9463) ; H2** + #( 8.1036 4.8568 -1.3419) ; O2* + #( 8.3270 3.9651 -1.6184) ; H2* + #( 6.7003 6.7565 -1.8911) ; C3* + #( 6.5898 7.5329 -2.6482) ; H3* + #( 7.0505 7.2878 -0.6105) ; O3* + #( 9.6740 4.7656 -7.6614) ; N1 + #( 9.0739 4.3013 -5.3941) ; N3 + #( 9.8416 4.2192 -6.4581) ; C2 + #( 7.9885 5.0632 -5.6446) ; C4 + #( 7.6822 5.6856 -6.8194) ; C5 + #( 8.5831 5.5215 -7.8840) ; C6 + #( 8.4084 6.0747 -9.0933) ; N6 + #( 6.4857 6.3816 -6.7035) ; N7 + #( 6.9740 5.3703 -4.7760) ; N9 + #( 6.1133 6.1613 -5.4808) ; C8 + #( 10.7627 3.6375 -6.4220) ; H2 + #( 7.6031 6.6390 -9.2733) ; H61 + #( 9.1004 5.9708 -9.7893) ; H62 + #( 5.1705 6.6830 -5.3167) ; H8 + )) + +(define rA04 + (make-constant-rA + #( -0.5426 -0.8175 0.1929 ; dgf-base-tfo + 0.8304 -0.5567 -0.0237 + 0.1267 0.1473 0.9809 + -0.5075 8.3929 0.2229) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 5.4352 8.2183 -2.7757) ; C5* + #( 5.3830 8.7883 -1.8481) ; H5* + #( 5.7729 8.7436 -3.6691) ; H5** + #( 6.4830 7.1518 -2.5252) ; C4* + #( 7.4749 7.5972 -2.4482) ; H4* + #( 6.1626 6.4620 -1.2827) ; O4* + #( 6.5431 5.0992 -1.3905) ; C1* + #( 7.2871 4.9328 -0.6114) ; H1* + #( 7.1852 4.8935 -2.7592) ; C2* + #( 6.8573 3.9363 -3.1645) ; H2** + #( 8.5780 5.1025 -2.6046) ; O2* + #( 8.9516 4.7577 -1.7902) ; H2* + #( 6.5522 6.0300 -3.5612) ; C3* + #( 5.5420 5.7356 -3.8459) ; H3* + #( 7.3487 6.4089 -4.6867) ; O3* + #( 3.6343 2.6680 2.0783) ; N1 + #( 5.4505 3.9805 1.2446) ; N3 + #( 4.7540 3.3816 2.1851) ; C2 + #( 4.8805 3.7951 0.0354) ; C4 + #( 3.7416 3.0925 -0.2305) ; C5 + #( 3.0873 2.4980 0.8606) ; C6 + #( 1.9600 1.7805 0.7462) ; N6 + #( 3.4605 3.1184 -1.5906) ; N7 + #( 5.3247 4.2695 -1.1710) ; N9 + #( 4.4244 3.8244 -2.0953) ; C8 + #( 5.0814 3.4352 3.2234) ; H2 + #( 1.5423 1.6454 -0.1520) ; H61 + #( 1.5716 1.3398 1.5392) ; H62 + #( 4.2675 3.8876 -3.1721) ; H8 + )) + +(define rA05 + (make-constant-rA + #( -0.5891 0.0449 0.8068 ; dgf-base-tfo + 0.5375 0.7673 0.3498 + -0.6034 0.6397 -0.4762 + -0.3019 -3.7679 -9.5913) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.5778 6.6594 -4.0364) ; C5* + #( 4.9220 7.1963 -4.9204) ; H5* + #( 3.7996 5.9091 -4.1764) ; H5** + #( 5.7873 5.8869 -3.5482) ; C4* + #( 6.0405 5.0875 -4.2446) ; H4* + #( 6.9135 6.8036 -3.4310) ; O4* + #( 7.7293 6.4084 -2.3392) ; C1* + #( 8.7078 6.1815 -2.7624) ; H1* + #( 7.1305 5.1418 -1.7347) ; C2* + #( 7.2040 5.1982 -0.6486) ; H2** + #( 7.7417 4.0392 -2.3813) ; O2* + #( 8.6785 4.1443 -2.5630) ; H2* + #( 5.6666 5.2728 -2.1536) ; C3* + #( 5.1747 5.9805 -1.4863) ; H3* + #( 4.9997 4.0086 -2.1973) ; O3* + #( 10.2594 10.6774 -1.0056) ; N1 + #( 9.7528 8.7080 -2.2631) ; N3 + #( 10.4471 9.7876 -1.9791) ; C2 + #( 8.7271 8.5575 -1.3991) ; C4 + #( 8.4100 9.3803 -0.3580) ; C5 + #( 9.2294 10.5030 -0.1574) ; C6 + #( 9.0349 11.3951 0.8250) ; N6 + #( 7.2891 8.9068 0.3121) ; N7 + #( 7.7962 7.5519 -1.3859) ; N9 + #( 6.9702 7.8292 -0.3353) ; C8 + #( 11.3132 10.0537 -2.5851) ; H2 + #( 8.2741 11.2784 1.4629) ; H61 + #( 9.6733 12.1368 0.9529) ; H62 + #( 6.0888 7.3990 0.1403) ; H8 + )) + +(define rA06 + (make-constant-rA + #( -0.9815 0.0731 -0.1772 ; dgf-base-tfo + 0.1912 0.3054 -0.9328 + -0.0141 -0.9494 -0.3137 + 5.7506 -5.1944 4.7470) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.1214 6.7116 -1.9049) ; C5* + #( 3.3465 5.9610 -2.0607) ; H5* + #( 4.0789 7.2928 -0.9837) ; H5** + #( 5.4170 5.9293 -1.8186) ; C4* + #( 5.4506 5.3400 -0.9023) ; H4* + #( 5.5067 5.0417 -2.9703) ; O4* + #( 6.8650 4.9152 -3.3612) ; C1* + #( 7.1090 3.8577 -3.2603) ; H1* + #( 7.7152 5.7282 -2.3894) ; C2* + #( 8.5029 6.2356 -2.9463) ; H2** + #( 8.1036 4.8568 -1.3419) ; O2* + #( 8.3270 3.9651 -1.6184) ; H2* + #( 6.7003 6.7565 -1.8911) ; C3* + #( 6.5898 7.5329 -2.6482) ; H3* + #( 7.0505 7.2878 -0.6105) ; O3* + #( 6.6624 3.5061 -8.2986) ; N1 + #( 6.5810 3.2570 -5.9221) ; N3 + #( 6.5151 2.8263 -7.1625) ; C2 + #( 6.8364 4.5817 -5.8882) ; C4 + #( 7.0116 5.4064 -6.9609) ; C5 + #( 6.9173 4.8260 -8.2361) ; C6 + #( 7.0668 5.5163 -9.3763) ; N6 + #( 7.2573 6.7070 -6.5394) ; N7 + #( 6.9740 5.3703 -4.7760) ; N9 + #( 7.2238 6.6275 -5.2453) ; C8 + #( 6.3146 1.7741 -7.3641) ; H2 + #( 7.2568 6.4972 -9.3456) ; H61 + #( 7.0437 5.0478 -10.2446) ; H62 + #( 7.4108 7.6227 -4.8418) ; H8 + )) + +(define rA07 + (make-constant-rA + #( 0.2379 0.1310 -0.9624 ; dgf-base-tfo + -0.5876 -0.7696 -0.2499 + -0.7734 0.6249 -0.1061 + 30.9870 -26.9344 42.6416) + #( 0.7529 0.1548 0.6397 ; P-O3*-275-tfo + 0.2952 -0.9481 -0.1180 + 0.5882 0.2777 -0.7595 + -58.8919 -11.3095 6.0866) + #( -0.0239 0.9667 -0.2546 ; P-O3*-180-tfo + 0.9731 -0.0359 -0.2275 + -0.2290 -0.2532 -0.9399 + 3.5401 -29.7913 52.2796) + #( -0.8912 -0.4531 0.0242 ; P-O3*-60-tfo + -0.1183 0.1805 -0.9764 + 0.4380 -0.8730 -0.2145 + 19.9023 54.8054 15.2799) + #( 41.8210 8.3880 43.5890) ; P + #( 42.5400 8.0450 44.8330) ; O1P + #( 42.2470 9.6920 42.9910) ; O2P + #( 40.2550 8.2030 43.7340) ; O5* + #( 39.3505 8.4697 42.6565) ; C5* + #( 39.1377 7.5433 42.1230) ; H5* + #( 39.7203 9.3119 42.0717) ; H5** + #( 38.0405 8.9195 43.2869) ; C4* + #( 37.3687 9.3036 42.5193) ; H4* + #( 37.4319 7.8146 43.9387) ; O4* + #( 37.1959 8.1354 45.3237) ; C1* + #( 36.1788 8.5202 45.3970) ; H1* + #( 38.1721 9.2328 45.6504) ; C2* + #( 39.1555 8.7939 45.8188) ; H2** + #( 37.7862 10.0617 46.7013) ; O2* + #( 37.3087 9.6229 47.4092) ; H2* + #( 38.1844 10.0268 44.3367) ; C3* + #( 39.1578 10.5054 44.2289) ; H3* + #( 37.0547 10.9127 44.3441) ; O3* + #( 34.8811 4.2072 47.5784) ; N1 + #( 35.1084 6.1336 46.1818) ; N3 + #( 34.4108 5.1360 46.7207) ; C2 + #( 36.3908 6.1224 46.6053) ; C4 + #( 36.9819 5.2334 47.4697) ; C5 + #( 36.1786 4.1985 48.0035) ; C6 + #( 36.6103 3.2749 48.8452) ; N6 + #( 38.3236 5.5522 47.6595) ; N7 + #( 37.3887 7.0024 46.2437) ; N9 + #( 38.5055 6.6096 46.9057) ; C8 + #( 33.3553 5.0152 46.4771) ; H2 + #( 37.5730 3.2804 49.1507) ; H61 + #( 35.9775 2.5638 49.1828) ; H62 + #( 39.5461 6.9184 47.0041) ; H8 + )) + +(define rA08 + (make-constant-rA + #( 0.1084 -0.0895 -0.9901 ; dgf-base-tfo + 0.9789 -0.1638 0.1220 + -0.1731 -0.9824 0.0698 + -2.9039 47.2655 33.0094) + #( 0.7529 0.1548 0.6397 ; P-O3*-275-tfo + 0.2952 -0.9481 -0.1180 + 0.5882 0.2777 -0.7595 + -58.8919 -11.3095 6.0866) + #( -0.0239 0.9667 -0.2546 ; P-O3*-180-tfo + 0.9731 -0.0359 -0.2275 + -0.2290 -0.2532 -0.9399 + 3.5401 -29.7913 52.2796) + #( -0.8912 -0.4531 0.0242 ; P-O3*-60-tfo + -0.1183 0.1805 -0.9764 + 0.4380 -0.8730 -0.2145 + 19.9023 54.8054 15.2799) + #( 41.8210 8.3880 43.5890) ; P + #( 42.5400 8.0450 44.8330) ; O1P + #( 42.2470 9.6920 42.9910) ; O2P + #( 40.2550 8.2030 43.7340) ; O5* + #( 39.4850 8.9301 44.6977) ; C5* + #( 39.0638 9.8199 44.2296) ; H5* + #( 40.0757 9.0713 45.6029) ; H5** + #( 38.3102 8.0414 45.0789) ; C4* + #( 37.7842 8.4637 45.9351) ; H4* + #( 37.4200 7.9453 43.9769) ; O4* + #( 37.2249 6.5609 43.6273) ; C1* + #( 36.3360 6.2168 44.1561) ; H1* + #( 38.4347 5.8414 44.1590) ; C2* + #( 39.2688 5.9974 43.4749) ; H2** + #( 38.2344 4.4907 44.4348) ; O2* + #( 37.6374 4.0386 43.8341) ; H2* + #( 38.6926 6.6079 45.4637) ; C3* + #( 39.7585 6.5640 45.6877) ; H3* + #( 37.8238 6.0705 46.4723) ; O3* + #( 33.9162 6.2598 39.7758) ; N1 + #( 34.6709 6.5759 42.0215) ; N3 + #( 33.7257 6.5186 41.0858) ; C2 + #( 35.8935 6.3324 41.5018) ; C4 + #( 36.2105 6.0601 40.1932) ; C5 + #( 35.1538 6.0151 39.2537) ; C6 + #( 35.3088 5.7642 37.9649) ; N6 + #( 37.5818 5.8677 40.0507) ; N7 + #( 37.0932 6.3197 42.1810) ; N9 + #( 38.0509 6.0354 41.2635) ; C8 + #( 32.6830 6.6898 41.3532) ; H2 + #( 36.2305 5.5855 37.5925) ; H61 + #( 34.5056 5.7512 37.3528) ; H62 + #( 39.1318 5.8993 41.2285) ; H8 + )) + +(define rA09 + (make-constant-rA + #( 0.8467 0.4166 -0.3311 ; dgf-base-tfo + -0.3962 0.9089 0.1303 + 0.3552 0.0209 0.9346 + -42.7319 -26.6223 -29.8163) + #( 0.7529 0.1548 0.6397 ; P-O3*-275-tfo + 0.2952 -0.9481 -0.1180 + 0.5882 0.2777 -0.7595 + -58.8919 -11.3095 6.0866) + #( -0.0239 0.9667 -0.2546 ; P-O3*-180-tfo + 0.9731 -0.0359 -0.2275 + -0.2290 -0.2532 -0.9399 + 3.5401 -29.7913 52.2796) + #( -0.8912 -0.4531 0.0242 ; P-O3*-60-tfo + -0.1183 0.1805 -0.9764 + 0.4380 -0.8730 -0.2145 + 19.9023 54.8054 15.2799) + #( 41.8210 8.3880 43.5890) ; P + #( 42.5400 8.0450 44.8330) ; O1P + #( 42.2470 9.6920 42.9910) ; O2P + #( 40.2550 8.2030 43.7340) ; O5* + #( 39.3505 8.4697 42.6565) ; C5* + #( 39.1377 7.5433 42.1230) ; H5* + #( 39.7203 9.3119 42.0717) ; H5** + #( 38.0405 8.9195 43.2869) ; C4* + #( 37.6479 8.1347 43.9335) ; H4* + #( 38.2691 10.0933 44.0524) ; O4* + #( 37.3999 11.1488 43.5973) ; C1* + #( 36.5061 11.1221 44.2206) ; H1* + #( 37.0364 10.7838 42.1836) ; C2* + #( 37.8636 11.0489 41.5252) ; H2** + #( 35.8275 11.3133 41.7379) ; O2* + #( 35.6214 12.1896 42.0714) ; H2* + #( 36.9316 9.2556 42.2837) ; C3* + #( 37.1778 8.8260 41.3127) ; H3* + #( 35.6285 8.9334 42.7926) ; O3* + #( 38.1482 15.2833 46.4641) ; N1 + #( 37.3641 13.0968 45.9007) ; N3 + #( 37.5032 14.1288 46.7300) ; C2 + #( 37.9570 13.3377 44.7113) ; C4 + #( 38.6397 14.4660 44.3267) ; C5 + #( 38.7473 15.5229 45.2609) ; C6 + #( 39.3720 16.6649 45.0297) ; N6 + #( 39.1079 14.3351 43.0223) ; N7 + #( 38.0132 12.4868 43.6280) ; N9 + #( 38.7058 13.1402 42.6620) ; C8 + #( 37.0731 14.0857 47.7306) ; H2 + #( 39.8113 16.8281 44.1350) ; H61 + #( 39.4100 17.3741 45.7478) ; H62 + #( 39.0412 12.9660 41.6397) ; H8 + )) + +(define rA10 + (make-constant-rA + #( 0.7063 0.6317 -0.3196 ; dgf-base-tfo + -0.0403 -0.4149 -0.9090 + -0.7068 0.6549 -0.2676 + 6.4402 -52.1496 30.8246) + #( 0.7529 0.1548 0.6397 ; P-O3*-275-tfo + 0.2952 -0.9481 -0.1180 + 0.5882 0.2777 -0.7595 + -58.8919 -11.3095 6.0866) + #( -0.0239 0.9667 -0.2546 ; P-O3*-180-tfo + 0.9731 -0.0359 -0.2275 + -0.2290 -0.2532 -0.9399 + 3.5401 -29.7913 52.2796) + #( -0.8912 -0.4531 0.0242 ; P-O3*-60-tfo + -0.1183 0.1805 -0.9764 + 0.4380 -0.8730 -0.2145 + 19.9023 54.8054 15.2799) + #( 41.8210 8.3880 43.5890) ; P + #( 42.5400 8.0450 44.8330) ; O1P + #( 42.2470 9.6920 42.9910) ; O2P + #( 40.2550 8.2030 43.7340) ; O5* + #( 39.4850 8.9301 44.6977) ; C5* + #( 39.0638 9.8199 44.2296) ; H5* + #( 40.0757 9.0713 45.6029) ; H5** + #( 38.3102 8.0414 45.0789) ; C4* + #( 37.7099 7.8166 44.1973) ; H4* + #( 38.8012 6.8321 45.6380) ; O4* + #( 38.2431 6.6413 46.9529) ; C1* + #( 37.3505 6.0262 46.8385) ; H1* + #( 37.8484 8.0156 47.4214) ; C2* + #( 38.7381 8.5406 47.7690) ; H2** + #( 36.8286 8.0368 48.3701) ; O2* + #( 36.8392 7.3063 48.9929) ; H2* + #( 37.3576 8.6512 46.1132) ; C3* + #( 37.5207 9.7275 46.1671) ; H3* + #( 35.9985 8.2392 45.9032) ; O3* + #( 39.9117 2.2278 48.8527) ; N1 + #( 38.6207 3.6941 47.4757) ; N3 + #( 38.9872 2.4888 47.9057) ; C2 + #( 39.2961 4.6720 48.1174) ; C4 + #( 40.2546 4.5307 49.0912) ; C5 + #( 40.5932 3.2189 49.4985) ; C6 + #( 41.4938 2.9317 50.4229) ; N6 + #( 40.7195 5.7755 49.5060) ; N7 + #( 39.1730 6.0305 47.9170) ; N9 + #( 40.0413 6.6250 48.7728) ; C8 + #( 38.5257 1.5960 47.4838) ; H2 + #( 41.9907 3.6753 50.8921) ; H61 + #( 41.6848 1.9687 50.6599) ; H62 + #( 40.3571 7.6321 49.0452) ; H8 + )) + +(define rAs + (list rA01 rA02 rA03 rA04 rA05 rA06 rA07 rA08 rA09 rA10)) + +(define rC + (make-constant-rC + #( -0.0359 -0.8071 0.5894 ; dgf-base-tfo + -0.2669 0.5761 0.7726 + -0.9631 -0.1296 -0.2361 + 0.1584 8.3434 0.5434) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 5.2430 -8.2420 2.8260) ; C5* + #( 5.1974 -8.8497 1.9223) ; H5* + #( 5.5548 -8.7348 3.7469) ; H5** + #( 6.3140 -7.2060 2.5510) ; C4* + #( 7.2954 -7.6762 2.4898) ; H4* + #( 6.0140 -6.5420 1.2890) ; O4* + #( 6.4190 -5.1840 1.3620) ; C1* + #( 7.1608 -5.0495 0.5747) ; H1* + #( 7.0760 -4.9560 2.7270) ; C2* + #( 6.7770 -3.9803 3.1099) ; H2** + #( 8.4500 -5.1930 2.5810) ; O2* + #( 8.8309 -4.8755 1.7590) ; H2* + #( 6.4060 -6.0590 3.5580) ; C3* + #( 5.4021 -5.7313 3.8281) ; H3* + #( 7.1570 -6.4240 4.7070) ; O3* + #( 5.2170 -4.3260 1.1690) ; N1 + #( 4.2960 -2.2560 0.6290) ; N3 + #( 5.4330 -3.0200 0.7990) ; C2 + #( 2.9930 -2.6780 0.7940) ; C4 + #( 2.8670 -4.0630 1.1830) ; C5 + #( 3.9570 -4.8300 1.3550) ; C6 + #( 2.0187 -1.8047 0.5874) ; N4 + #( 6.5470 -2.5560 0.6290) ; O2 + #( 1.0684 -2.1236 0.7109) ; H41 + #( 2.2344 -0.8560 0.3162) ; H42 + #( 1.8797 -4.4972 1.3404) ; H5 + #( 3.8479 -5.8742 1.6480) ; H6 + )) + +(define rC01 + (make-constant-rC + #( -0.0137 -0.8012 0.5983 ; dgf-base-tfo + -0.2523 0.5817 0.7733 + -0.9675 -0.1404 -0.2101 + 0.2031 8.3874 0.4228) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 5.2416 -8.2422 2.8181) ; C5* + #( 5.2050 -8.8128 1.8901) ; H5* + #( 5.5368 -8.7738 3.7227) ; H5** + #( 6.3232 -7.2037 2.6002) ; C4* + #( 7.3048 -7.6757 2.5577) ; H4* + #( 6.0635 -6.5092 1.3456) ; O4* + #( 6.4697 -5.1547 1.4629) ; C1* + #( 7.2354 -5.0043 0.7018) ; H1* + #( 7.0856 -4.9610 2.8521) ; C2* + #( 6.7777 -3.9935 3.2487) ; H2** + #( 8.4627 -5.1992 2.7423) ; O2* + #( 8.8693 -4.8638 1.9399) ; H2* + #( 6.3877 -6.0809 3.6362) ; C3* + #( 5.3770 -5.7562 3.8834) ; H3* + #( 7.1024 -6.4754 4.7985) ; O3* + #( 5.2764 -4.2883 1.2538) ; N1 + #( 4.3777 -2.2062 0.7229) ; N3 + #( 5.5069 -2.9779 0.9088) ; C2 + #( 3.0693 -2.6246 0.8500) ; C4 + #( 2.9279 -4.0146 1.2149) ; C5 + #( 4.0101 -4.7892 1.4017) ; C6 + #( 2.1040 -1.7437 0.6331) ; N4 + #( 6.6267 -2.5166 0.7728) ; O2 + #( 1.1496 -2.0600 0.7287) ; H41 + #( 2.3303 -0.7921 0.3815) ; H42 + #( 1.9353 -4.4465 1.3419) ; H5 + #( 3.8895 -5.8371 1.6762) ; H6 + )) + +(define rC02 + (make-constant-rC + #( 0.5141 0.0246 0.8574 ; dgf-base-tfo + -0.5547 -0.7529 0.3542 + 0.6542 -0.6577 -0.3734 + -9.1111 -3.4598 -3.2939) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 4.3825 -6.6585 4.0489) ; C5* + #( 4.6841 -7.2019 4.9443) ; H5* + #( 3.6189 -5.8889 4.1625) ; H5** + #( 5.6255 -5.9175 3.5998) ; C4* + #( 5.8732 -5.1228 4.3034) ; H4* + #( 6.7337 -6.8605 3.5222) ; O4* + #( 7.5932 -6.4923 2.4548) ; C1* + #( 8.5661 -6.2983 2.9064) ; H1* + #( 7.0527 -5.2012 1.8322) ; C2* + #( 7.1627 -5.2525 0.7490) ; H2** + #( 7.6666 -4.1249 2.4880) ; O2* + #( 8.5944 -4.2543 2.6981) ; H2* + #( 5.5661 -5.3029 2.2009) ; C3* + #( 5.0841 -6.0018 1.5172) ; H3* + #( 4.9062 -4.0452 2.2042) ; O3* + #( 7.6298 -7.6136 1.4752) ; N1 + #( 8.6945 -8.7046 -0.2857) ; N3 + #( 8.6943 -7.6514 0.6066) ; C2 + #( 7.7426 -9.6987 -0.3801) ; C4 + #( 6.6642 -9.5742 0.5722) ; C5 + #( 6.6391 -8.5592 1.4526) ; C6 + #( 7.9033 -10.6371 -1.3010) ; N4 + #( 9.5840 -6.8186 0.6136) ; O2 + #( 7.2009 -11.3604 -1.3619) ; H41 + #( 8.7058 -10.6168 -1.9140) ; H42 + #( 5.8585 -10.3083 0.5822) ; H5 + #( 5.8197 -8.4773 2.1667) ; H6 + )) + +(define rC03 + (make-constant-rC + #( -0.4993 0.0476 0.8651 ; dgf-base-tfo + 0.8078 -0.3353 0.4847 + 0.3132 0.9409 0.1290 + 6.2989 -5.2303 -3.8577) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 3.9938 -6.7042 1.9023) ; C5* + #( 3.2332 -5.9343 2.0319) ; H5* + #( 3.9666 -7.2863 0.9812) ; H5** + #( 5.3098 -5.9546 1.8564) ; C4* + #( 5.3863 -5.3702 0.9395) ; H4* + #( 5.3851 -5.0642 3.0076) ; O4* + #( 6.7315 -4.9724 3.4462) ; C1* + #( 7.0033 -3.9202 3.3619) ; H1* + #( 7.5997 -5.8018 2.4948) ; C2* + #( 8.3627 -6.3254 3.0707) ; H2** + #( 8.0410 -4.9501 1.4724) ; O2* + #( 8.2781 -4.0644 1.7570) ; H2* + #( 6.5701 -6.8129 1.9714) ; C3* + #( 6.4186 -7.5809 2.7299) ; H3* + #( 6.9357 -7.3841 0.7235) ; O3* + #( 6.8024 -5.4718 4.8475) ; N1 + #( 7.9218 -5.5700 6.8877) ; N3 + #( 7.8908 -5.0886 5.5944) ; C2 + #( 6.9789 -6.3827 7.4823) ; C4 + #( 5.8742 -6.7319 6.6202) ; C5 + #( 5.8182 -6.2769 5.3570) ; C6 + #( 7.1702 -6.7511 8.7402) ; N4 + #( 8.7747 -4.3728 5.1568) ; O2 + #( 6.4741 -7.3461 9.1662) ; H41 + #( 7.9889 -6.4396 9.2429) ; H42 + #( 5.0736 -7.3713 6.9922) ; H5 + #( 4.9784 -6.5473 4.7170) ; H6 + )) + +(define rC04 + (make-constant-rC + #( -0.5669 -0.8012 0.1918 ; dgf-base-tfo + -0.8129 0.5817 0.0273 + -0.1334 -0.1404 -0.9811 + -0.3279 8.3874 0.3355) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 5.2416 -8.2422 2.8181) ; C5* + #( 5.2050 -8.8128 1.8901) ; H5* + #( 5.5368 -8.7738 3.7227) ; H5** + #( 6.3232 -7.2037 2.6002) ; C4* + #( 7.3048 -7.6757 2.5577) ; H4* + #( 6.0635 -6.5092 1.3456) ; O4* + #( 6.4697 -5.1547 1.4629) ; C1* + #( 7.2354 -5.0043 0.7018) ; H1* + #( 7.0856 -4.9610 2.8521) ; C2* + #( 6.7777 -3.9935 3.2487) ; H2** + #( 8.4627 -5.1992 2.7423) ; O2* + #( 8.8693 -4.8638 1.9399) ; H2* + #( 6.3877 -6.0809 3.6362) ; C3* + #( 5.3770 -5.7562 3.8834) ; H3* + #( 7.1024 -6.4754 4.7985) ; O3* + #( 5.2764 -4.2883 1.2538) ; N1 + #( 3.8961 -3.0896 -0.1893) ; N3 + #( 5.0095 -3.8907 -0.0346) ; C2 + #( 3.0480 -2.6632 0.8116) ; C4 + #( 3.4093 -3.1310 2.1292) ; C5 + #( 4.4878 -3.9124 2.3088) ; C6 + #( 2.0216 -1.8941 0.4804) ; N4 + #( 5.7005 -4.2164 -0.9842) ; O2 + #( 1.4067 -1.5873 1.2205) ; H41 + #( 1.8721 -1.6319 -0.4835) ; H42 + #( 2.8048 -2.8507 2.9918) ; H5 + #( 4.7491 -4.2593 3.3085) ; H6 + )) + +(define rC05 + (make-constant-rC + #( -0.6298 0.0246 0.7763 ; dgf-base-tfo + -0.5226 -0.7529 -0.4001 + 0.5746 -0.6577 0.4870 + -0.0208 -3.4598 -9.6882) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 4.3825 -6.6585 4.0489) ; C5* + #( 4.6841 -7.2019 4.9443) ; H5* + #( 3.6189 -5.8889 4.1625) ; H5** + #( 5.6255 -5.9175 3.5998) ; C4* + #( 5.8732 -5.1228 4.3034) ; H4* + #( 6.7337 -6.8605 3.5222) ; O4* + #( 7.5932 -6.4923 2.4548) ; C1* + #( 8.5661 -6.2983 2.9064) ; H1* + #( 7.0527 -5.2012 1.8322) ; C2* + #( 7.1627 -5.2525 0.7490) ; H2** + #( 7.6666 -4.1249 2.4880) ; O2* + #( 8.5944 -4.2543 2.6981) ; H2* + #( 5.5661 -5.3029 2.2009) ; C3* + #( 5.0841 -6.0018 1.5172) ; H3* + #( 4.9062 -4.0452 2.2042) ; O3* + #( 7.6298 -7.6136 1.4752) ; N1 + #( 8.5977 -9.5977 0.7329) ; N3 + #( 8.5951 -8.5745 1.6594) ; C2 + #( 7.7372 -9.7371 -0.3364) ; C4 + #( 6.7596 -8.6801 -0.4476) ; C5 + #( 6.7338 -7.6721 0.4408) ; C6 + #( 7.8849 -10.7881 -1.1289) ; N4 + #( 9.3993 -8.5377 2.5743) ; O2 + #( 7.2499 -10.8809 -1.9088) ; H41 + #( 8.6122 -11.4649 -0.9468) ; H42 + #( 6.0317 -8.6941 -1.2588) ; H5 + #( 5.9901 -6.8809 0.3459) ; H6 + )) + +(define rC06 + (make-constant-rC + #( -0.9837 0.0476 -0.1733 ; dgf-base-tfo + -0.1792 -0.3353 0.9249 + -0.0141 0.9409 0.3384 + 5.7793 -5.2303 4.5997) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 3.9938 -6.7042 1.9023) ; C5* + #( 3.2332 -5.9343 2.0319) ; H5* + #( 3.9666 -7.2863 0.9812) ; H5** + #( 5.3098 -5.9546 1.8564) ; C4* + #( 5.3863 -5.3702 0.9395) ; H4* + #( 5.3851 -5.0642 3.0076) ; O4* + #( 6.7315 -4.9724 3.4462) ; C1* + #( 7.0033 -3.9202 3.3619) ; H1* + #( 7.5997 -5.8018 2.4948) ; C2* + #( 8.3627 -6.3254 3.0707) ; H2** + #( 8.0410 -4.9501 1.4724) ; O2* + #( 8.2781 -4.0644 1.7570) ; H2* + #( 6.5701 -6.8129 1.9714) ; C3* + #( 6.4186 -7.5809 2.7299) ; H3* + #( 6.9357 -7.3841 0.7235) ; O3* + #( 6.8024 -5.4718 4.8475) ; N1 + #( 6.6920 -5.0495 7.1354) ; N3 + #( 6.6201 -4.5500 5.8506) ; C2 + #( 6.9254 -6.3614 7.4926) ; C4 + #( 7.1046 -7.2543 6.3718) ; C5 + #( 7.0391 -6.7951 5.1106) ; C6 + #( 6.9614 -6.6648 8.7815) ; N4 + #( 6.4083 -3.3696 5.6340) ; O2 + #( 7.1329 -7.6280 9.0324) ; H41 + #( 6.8204 -5.9469 9.4777) ; H42 + #( 7.2954 -8.3135 6.5440) ; H5 + #( 7.1753 -7.4798 4.2735) ; H6 + )) + +(define rC07 + (make-constant-rC + #( 0.0033 0.2720 -0.9623 ; dgf-base-tfo + 0.3013 -0.9179 -0.2584 + -0.9535 -0.2891 -0.0850 + 43.0403 13.7233 34.5710) + #( 0.9187 0.2887 0.2694 ; P-O3*-275-tfo + 0.0302 -0.7316 0.6811 + 0.3938 -0.6176 -0.6808 + -48.4330 26.3254 13.6383) + #( -0.1504 0.7744 -0.6145 ; P-O3*-180-tfo + 0.7581 0.4893 0.4311 + 0.6345 -0.4010 -0.6607 + -31.9784 -13.4285 44.9650) + #( -0.6236 -0.7810 -0.0337 ; P-O3*-60-tfo + -0.6890 0.5694 -0.4484 + 0.3694 -0.2564 -0.8932 + 12.1105 30.8774 46.0946) + #( 33.3400 11.0980 46.1750) ; P + #( 34.5130 10.2320 46.4660) ; O1P + #( 33.4130 12.3960 46.9340) ; O2P + #( 31.9810 10.3390 46.4820) ; O5* + #( 30.8152 11.1619 46.2003) ; C5* + #( 30.4519 10.9454 45.1957) ; H5* + #( 31.0379 12.2016 46.4400) ; H5** + #( 29.7081 10.7448 47.1428) ; C4* + #( 28.8710 11.4416 47.0982) ; H4* + #( 29.2550 9.4394 46.8162) ; O4* + #( 29.3907 8.5625 47.9460) ; C1* + #( 28.4416 8.5669 48.4819) ; H1* + #( 30.4468 9.2031 48.7952) ; C2* + #( 31.4222 8.9651 48.3709) ; H2** + #( 30.3701 8.9157 50.1624) ; O2* + #( 30.0652 8.0304 50.3740) ; H2* + #( 30.1622 10.6879 48.6120) ; C3* + #( 31.0952 11.2399 48.7254) ; H3* + #( 29.1076 11.1535 49.4702) ; O3* + #( 29.7883 7.2209 47.5235) ; N1 + #( 29.1825 5.0438 46.8275) ; N3 + #( 28.8008 6.2912 47.2263) ; C2 + #( 30.4888 4.6890 46.7186) ; C4 + #( 31.5034 5.6405 47.0249) ; C5 + #( 31.1091 6.8691 47.4156) ; C6 + #( 30.8109 3.4584 46.3336) ; N4 + #( 27.6171 6.5989 47.3189) ; O2 + #( 31.7923 3.2301 46.2638) ; H41 + #( 30.0880 2.7857 46.1215) ; H42 + #( 32.5542 5.3634 46.9395) ; H5 + #( 31.8523 7.6279 47.6603) ; H6 + )) + +(define rC08 + (make-constant-rC + #( 0.0797 -0.6026 -0.7941 ; dgf-base-tfo + 0.7939 0.5201 -0.3150 + 0.6028 -0.6054 0.5198 + -36.8341 41.5293 1.6628) + #( 0.9187 0.2887 0.2694 ; P-O3*-275-tfo + 0.0302 -0.7316 0.6811 + 0.3938 -0.6176 -0.6808 + -48.4330 26.3254 13.6383) + #( -0.1504 0.7744 -0.6145 ; P-O3*-180-tfo + 0.7581 0.4893 0.4311 + 0.6345 -0.4010 -0.6607 + -31.9784 -13.4285 44.9650) + #( -0.6236 -0.7810 -0.0337 ; P-O3*-60-tfo + -0.6890 0.5694 -0.4484 + 0.3694 -0.2564 -0.8932 + 12.1105 30.8774 46.0946) + #( 33.3400 11.0980 46.1750) ; P + #( 34.5130 10.2320 46.4660) ; O1P + #( 33.4130 12.3960 46.9340) ; O2P + #( 31.9810 10.3390 46.4820) ; O5* + #( 31.8779 9.9369 47.8760) ; C5* + #( 31.3239 10.6931 48.4322) ; H5* + #( 32.8647 9.6624 48.2489) ; H5** + #( 31.0429 8.6773 47.9401) ; C4* + #( 31.0779 8.2331 48.9349) ; H4* + #( 29.6956 8.9669 47.5983) ; O4* + #( 29.2784 8.1700 46.4782) ; C1* + #( 28.8006 7.2731 46.8722) ; H1* + #( 30.5544 7.7940 45.7875) ; C2* + #( 30.8837 8.6410 45.1856) ; H2** + #( 30.5100 6.6007 45.0582) ; O2* + #( 29.6694 6.4168 44.6326) ; H2* + #( 31.5146 7.5954 46.9527) ; C3* + #( 32.5255 7.8261 46.6166) ; H3* + #( 31.3876 6.2951 47.5516) ; O3* + #( 28.3976 8.9302 45.5933) ; N1 + #( 26.2155 9.6135 44.9910) ; N3 + #( 27.0281 8.8961 45.8192) ; C2 + #( 26.7044 10.3489 43.9595) ; C4 + #( 28.1088 10.3837 43.7247) ; C5 + #( 28.8978 9.6708 44.5535) ; C6 + #( 25.8715 11.0249 43.1749) ; N4 + #( 26.5733 8.2371 46.7484) ; O2 + #( 26.2707 11.5609 42.4177) ; H41 + #( 24.8760 10.9939 43.3427) ; H42 + #( 28.5089 10.9722 42.8990) ; H5 + #( 29.9782 9.6687 44.4097) ; H6 + )) + +(define rC09 + (make-constant-rC + #( 0.8727 0.4760 -0.1091 ; dgf-base-tfo + -0.4188 0.6148 -0.6682 + -0.2510 0.6289 0.7359 + -8.1687 -52.0761 -25.0726) + #( 0.9187 0.2887 0.2694 ; P-O3*-275-tfo + 0.0302 -0.7316 0.6811 + 0.3938 -0.6176 -0.6808 + -48.4330 26.3254 13.6383) + #( -0.1504 0.7744 -0.6145 ; P-O3*-180-tfo + 0.7581 0.4893 0.4311 + 0.6345 -0.4010 -0.6607 + -31.9784 -13.4285 44.9650) + #( -0.6236 -0.7810 -0.0337 ; P-O3*-60-tfo + -0.6890 0.5694 -0.4484 + 0.3694 -0.2564 -0.8932 + 12.1105 30.8774 46.0946) + #( 33.3400 11.0980 46.1750) ; P + #( 34.5130 10.2320 46.4660) ; O1P + #( 33.4130 12.3960 46.9340) ; O2P + #( 31.9810 10.3390 46.4820) ; O5* + #( 30.8152 11.1619 46.2003) ; C5* + #( 30.4519 10.9454 45.1957) ; H5* + #( 31.0379 12.2016 46.4400) ; H5** + #( 29.7081 10.7448 47.1428) ; C4* + #( 29.4506 9.6945 47.0059) ; H4* + #( 30.1045 10.9634 48.4885) ; O4* + #( 29.1794 11.8418 49.1490) ; C1* + #( 28.4388 11.2210 49.6533) ; H1* + #( 28.5211 12.6008 48.0367) ; C2* + #( 29.1947 13.3949 47.7147) ; H2** + #( 27.2316 13.0683 48.3134) ; O2* + #( 27.0851 13.3391 49.2227) ; H2* + #( 28.4131 11.5507 46.9391) ; C3* + #( 28.4451 12.0512 45.9713) ; H3* + #( 27.2707 10.6955 47.1097) ; O3* + #( 29.8751 12.7405 50.0682) ; N1 + #( 30.7172 13.1841 52.2328) ; N3 + #( 30.0617 12.3404 51.3847) ; C2 + #( 31.1834 14.3941 51.8297) ; C4 + #( 30.9913 14.8074 50.4803) ; C5 + #( 30.3434 13.9610 49.6548) ; C6 + #( 31.8090 15.1847 52.6957) ; N4 + #( 29.6470 11.2494 51.7616) ; O2 + #( 32.1422 16.0774 52.3606) ; H41 + #( 31.9392 14.8893 53.6527) ; H42 + #( 31.3632 15.7771 50.1491) ; H5 + #( 30.1742 14.2374 48.6141) ; H6 + )) + +(define rC10 + (make-constant-rC + #( 0.1549 0.8710 -0.4663 ; dgf-base-tfo + 0.6768 -0.4374 -0.5921 + -0.7197 -0.2239 -0.6572 + 25.2447 -14.1920 50.3201) + #( 0.9187 0.2887 0.2694 ; P-O3*-275-tfo + 0.0302 -0.7316 0.6811 + 0.3938 -0.6176 -0.6808 + -48.4330 26.3254 13.6383) + #( -0.1504 0.7744 -0.6145 ; P-O3*-180-tfo + 0.7581 0.4893 0.4311 + 0.6345 -0.4010 -0.6607 + -31.9784 -13.4285 44.9650) + #( -0.6236 -0.7810 -0.0337 ; P-O3*-60-tfo + -0.6890 0.5694 -0.4484 + 0.3694 -0.2564 -0.8932 + 12.1105 30.8774 46.0946) + #( 33.3400 11.0980 46.1750) ; P + #( 34.5130 10.2320 46.4660) ; O1P + #( 33.4130 12.3960 46.9340) ; O2P + #( 31.9810 10.3390 46.4820) ; O5* + #( 31.8779 9.9369 47.8760) ; C5* + #( 31.3239 10.6931 48.4322) ; H5* + #( 32.8647 9.6624 48.2489) ; H5** + #( 31.0429 8.6773 47.9401) ; C4* + #( 30.0440 8.8473 47.5383) ; H4* + #( 31.6749 7.6351 47.2119) ; O4* + #( 31.9159 6.5022 48.0616) ; C1* + #( 31.0691 5.8243 47.9544) ; H1* + #( 31.9300 7.0685 49.4493) ; C2* + #( 32.9024 7.5288 49.6245) ; H2** + #( 31.5672 6.1750 50.4632) ; O2* + #( 31.8416 5.2663 50.3200) ; H2* + #( 30.8618 8.1514 49.3749) ; C3* + #( 31.1122 8.9396 50.0850) ; H3* + #( 29.5351 7.6245 49.5409) ; O3* + #( 33.1890 5.8629 47.7343) ; N1 + #( 34.4004 4.2636 46.4828) ; N3 + #( 33.2062 4.8497 46.7851) ; C2 + #( 35.5600 4.6374 47.0822) ; C4 + #( 35.5444 5.6751 48.0577) ; C5 + #( 34.3565 6.2450 48.3432) ; C6 + #( 36.6977 4.0305 46.7598) ; N4 + #( 32.1661 4.5034 46.2348) ; O2 + #( 37.5405 4.3347 47.2259) ; H41 + #( 36.7033 3.2923 46.0706) ; H42 + #( 36.4713 5.9811 48.5428) ; H5 + #( 34.2986 7.0426 49.0839) ; H6 + )) + +(define rCs + (list rC01 rC02 rC03 rC04 rC05 rC06 rC07 rC08 rC09 rC10)) + +(define rG + (make-constant-rG + #( -0.0018 -0.8207 0.5714 ; dgf-base-tfo + 0.2679 -0.5509 -0.7904 + 0.9634 0.1517 0.2209 + 0.0073 8.4030 0.6232) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 5.4550 8.2120 -2.8810) ; C5* + #( 5.4546 8.8508 -1.9978) ; H5* + #( 5.7588 8.6625 -3.8259) ; H5** + #( 6.4970 7.1480 -2.5980) ; C4* + #( 7.4896 7.5919 -2.5214) ; H4* + #( 6.1630 6.4860 -1.3440) ; O4* + #( 6.5400 5.1200 -1.4190) ; C1* + #( 7.2763 4.9681 -0.6297) ; H1* + #( 7.1940 4.8830 -2.7770) ; C2* + #( 6.8667 3.9183 -3.1647) ; H2** + #( 8.5860 5.0910 -2.6140) ; O2* + #( 8.9510 4.7626 -1.7890) ; H2* + #( 6.5720 6.0040 -3.6090) ; C3* + #( 5.5636 5.7066 -3.8966) ; H3* + #( 7.3801 6.3562 -4.7350) ; O3* + #( 4.7150 0.4910 -0.1360) ; N1 + #( 6.3490 2.1730 -0.6020) ; N3 + #( 5.9530 0.9650 -0.2670) ; C2 + #( 5.2900 2.9790 -0.8260) ; C4 + #( 3.9720 2.6390 -0.7330) ; C5 + #( 3.6770 1.3160 -0.3660) ; C6 + #( 6.8426 0.0056 -0.0019) ; N2 + #( 3.1660 3.7290 -1.0360) ; N7 + #( 5.3170 4.2990 -1.1930) ; N9 + #( 4.0100 4.6780 -1.2990) ; C8 + #( 2.4280 0.8450 -0.2360) ; O6 + #( 4.6151 -0.4677 0.1305) ; H1 + #( 6.6463 -0.9463 0.2729) ; H21 + #( 7.8170 0.2642 -0.0640) ; H22 + #( 3.4421 5.5744 -1.5482) ; H8 + )) + +(define rG01 + (make-constant-rG + #( -0.0043 -0.8175 0.5759 ; dgf-base-tfo + 0.2617 -0.5567 -0.7884 + 0.9651 0.1473 0.2164 + 0.0359 8.3929 0.5532) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 5.4352 8.2183 -2.7757) ; C5* + #( 5.3830 8.7883 -1.8481) ; H5* + #( 5.7729 8.7436 -3.6691) ; H5** + #( 6.4830 7.1518 -2.5252) ; C4* + #( 7.4749 7.5972 -2.4482) ; H4* + #( 6.1626 6.4620 -1.2827) ; O4* + #( 6.5431 5.0992 -1.3905) ; C1* + #( 7.2871 4.9328 -0.6114) ; H1* + #( 7.1852 4.8935 -2.7592) ; C2* + #( 6.8573 3.9363 -3.1645) ; H2** + #( 8.5780 5.1025 -2.6046) ; O2* + #( 8.9516 4.7577 -1.7902) ; H2* + #( 6.5522 6.0300 -3.5612) ; C3* + #( 5.5420 5.7356 -3.8459) ; H3* + #( 7.3487 6.4089 -4.6867) ; O3* + #( 4.7442 0.4514 -0.1390) ; N1 + #( 6.3687 2.1459 -0.5926) ; N3 + #( 5.9795 0.9335 -0.2657) ; C2 + #( 5.3052 2.9471 -0.8125) ; C4 + #( 3.9891 2.5987 -0.7230) ; C5 + #( 3.7016 1.2717 -0.3647) ; C6 + #( 6.8745 -0.0224 -0.0058) ; N2 + #( 3.1770 3.6859 -1.0198) ; N7 + #( 5.3247 4.2695 -1.1710) ; N9 + #( 4.0156 4.6415 -1.2759) ; C8 + #( 2.4553 0.7925 -0.2390) ; O6 + #( 4.6497 -0.5095 0.1212) ; H1 + #( 6.6836 -0.9771 0.2627) ; H21 + #( 7.8474 0.2424 -0.0653) ; H22 + #( 3.4426 5.5361 -1.5199) ; H8 + )) + +(define rG02 + (make-constant-rG + #( 0.5566 0.0449 0.8296 ; dgf-base-tfo + 0.5125 0.7673 -0.3854 + -0.6538 0.6397 0.4041 + -9.1161 -3.7679 -2.9968) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.5778 6.6594 -4.0364) ; C5* + #( 4.9220 7.1963 -4.9204) ; H5* + #( 3.7996 5.9091 -4.1764) ; H5** + #( 5.7873 5.8869 -3.5482) ; C4* + #( 6.0405 5.0875 -4.2446) ; H4* + #( 6.9135 6.8036 -3.4310) ; O4* + #( 7.7293 6.4084 -2.3392) ; C1* + #( 8.7078 6.1815 -2.7624) ; H1* + #( 7.1305 5.1418 -1.7347) ; C2* + #( 7.2040 5.1982 -0.6486) ; H2** + #( 7.7417 4.0392 -2.3813) ; O2* + #( 8.6785 4.1443 -2.5630) ; H2* + #( 5.6666 5.2728 -2.1536) ; C3* + #( 5.1747 5.9805 -1.4863) ; H3* + #( 4.9997 4.0086 -2.1973) ; O3* + #( 10.3245 8.5459 1.5467) ; N1 + #( 9.8051 6.9432 -0.1497) ; N3 + #( 10.5175 7.4328 0.8408) ; C2 + #( 8.7523 7.7422 -0.4228) ; C4 + #( 8.4257 8.9060 0.2099) ; C5 + #( 9.2665 9.3242 1.2540) ; C6 + #( 11.6077 6.7966 1.2752) ; N2 + #( 7.2750 9.4537 -0.3428) ; N7 + #( 7.7962 7.5519 -1.3859) ; N9 + #( 6.9479 8.6157 -1.2771) ; C8 + #( 9.0664 10.4462 1.9610) ; O6 + #( 10.9838 8.7524 2.2697) ; H1 + #( 12.2274 7.0896 2.0170) ; H21 + #( 11.8502 5.9398 0.7984) ; H22 + #( 6.0430 8.9853 -1.7594) ; H8 + )) + +(define rG03 + (make-constant-rG + #( -0.5021 0.0731 0.8617 ; dgf-base-tfo + -0.8112 0.3054 -0.4986 + -0.2996 -0.9494 -0.0940 + 6.4273 -5.1944 -3.7807) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.1214 6.7116 -1.9049) ; C5* + #( 3.3465 5.9610 -2.0607) ; H5* + #( 4.0789 7.2928 -0.9837) ; H5** + #( 5.4170 5.9293 -1.8186) ; C4* + #( 5.4506 5.3400 -0.9023) ; H4* + #( 5.5067 5.0417 -2.9703) ; O4* + #( 6.8650 4.9152 -3.3612) ; C1* + #( 7.1090 3.8577 -3.2603) ; H1* + #( 7.7152 5.7282 -2.3894) ; C2* + #( 8.5029 6.2356 -2.9463) ; H2** + #( 8.1036 4.8568 -1.3419) ; O2* + #( 8.3270 3.9651 -1.6184) ; H2* + #( 6.7003 6.7565 -1.8911) ; C3* + #( 6.5898 7.5329 -2.6482) ; H3* + #( 7.0505 7.2878 -0.6105) ; O3* + #( 9.6740 4.7656 -7.6614) ; N1 + #( 9.0739 4.3013 -5.3941) ; N3 + #( 9.8416 4.2192 -6.4581) ; C2 + #( 7.9885 5.0632 -5.6446) ; C4 + #( 7.6822 5.6856 -6.8194) ; C5 + #( 8.5831 5.5215 -7.8840) ; C6 + #( 10.9733 3.5117 -6.4286) ; N2 + #( 6.4857 6.3816 -6.7035) ; N7 + #( 6.9740 5.3703 -4.7760) ; N9 + #( 6.1133 6.1613 -5.4808) ; C8 + #( 8.4084 6.0747 -9.0933) ; O6 + #( 10.3759 4.5855 -8.3504) ; H1 + #( 11.6254 3.3761 -7.1879) ; H21 + #( 11.1917 3.0460 -5.5593) ; H22 + #( 5.1705 6.6830 -5.3167) ; H8 + )) + +(define rG04 + (make-constant-rG + #( -0.5426 -0.8175 0.1929 ; dgf-base-tfo + 0.8304 -0.5567 -0.0237 + 0.1267 0.1473 0.9809 + -0.5075 8.3929 0.2229) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 5.4352 8.2183 -2.7757) ; C5* + #( 5.3830 8.7883 -1.8481) ; H5* + #( 5.7729 8.7436 -3.6691) ; H5** + #( 6.4830 7.1518 -2.5252) ; C4* + #( 7.4749 7.5972 -2.4482) ; H4* + #( 6.1626 6.4620 -1.2827) ; O4* + #( 6.5431 5.0992 -1.3905) ; C1* + #( 7.2871 4.9328 -0.6114) ; H1* + #( 7.1852 4.8935 -2.7592) ; C2* + #( 6.8573 3.9363 -3.1645) ; H2** + #( 8.5780 5.1025 -2.6046) ; O2* + #( 8.9516 4.7577 -1.7902) ; H2* + #( 6.5522 6.0300 -3.5612) ; C3* + #( 5.5420 5.7356 -3.8459) ; H3* + #( 7.3487 6.4089 -4.6867) ; O3* + #( 3.6343 2.6680 2.0783) ; N1 + #( 5.4505 3.9805 1.2446) ; N3 + #( 4.7540 3.3816 2.1851) ; C2 + #( 4.8805 3.7951 0.0354) ; C4 + #( 3.7416 3.0925 -0.2305) ; C5 + #( 3.0873 2.4980 0.8606) ; C6 + #( 5.1433 3.4373 3.4609) ; N2 + #( 3.4605 3.1184 -1.5906) ; N7 + #( 5.3247 4.2695 -1.1710) ; N9 + #( 4.4244 3.8244 -2.0953) ; C8 + #( 1.9600 1.7805 0.7462) ; O6 + #( 3.2489 2.2879 2.9191) ; H1 + #( 4.6785 3.0243 4.2568) ; H21 + #( 5.9823 3.9654 3.6539) ; H22 + #( 4.2675 3.8876 -3.1721) ; H8 + )) + +(define rG05 + (make-constant-rG + #( -0.5891 0.0449 0.8068 ; dgf-base-tfo + 0.5375 0.7673 0.3498 + -0.6034 0.6397 -0.4762 + -0.3019 -3.7679 -9.5913) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.5778 6.6594 -4.0364) ; C5* + #( 4.9220 7.1963 -4.9204) ; H5* + #( 3.7996 5.9091 -4.1764) ; H5** + #( 5.7873 5.8869 -3.5482) ; C4* + #( 6.0405 5.0875 -4.2446) ; H4* + #( 6.9135 6.8036 -3.4310) ; O4* + #( 7.7293 6.4084 -2.3392) ; C1* + #( 8.7078 6.1815 -2.7624) ; H1* + #( 7.1305 5.1418 -1.7347) ; C2* + #( 7.2040 5.1982 -0.6486) ; H2** + #( 7.7417 4.0392 -2.3813) ; O2* + #( 8.6785 4.1443 -2.5630) ; H2* + #( 5.6666 5.2728 -2.1536) ; C3* + #( 5.1747 5.9805 -1.4863) ; H3* + #( 4.9997 4.0086 -2.1973) ; O3* + #( 10.2594 10.6774 -1.0056) ; N1 + #( 9.7528 8.7080 -2.2631) ; N3 + #( 10.4471 9.7876 -1.9791) ; C2 + #( 8.7271 8.5575 -1.3991) ; C4 + #( 8.4100 9.3803 -0.3580) ; C5 + #( 9.2294 10.5030 -0.1574) ; C6 + #( 11.5110 10.1256 -2.7114) ; N2 + #( 7.2891 8.9068 0.3121) ; N7 + #( 7.7962 7.5519 -1.3859) ; N9 + #( 6.9702 7.8292 -0.3353) ; C8 + #( 9.0349 11.3951 0.8250) ; O6 + #( 10.9013 11.4422 -0.9512) ; H1 + #( 12.1031 10.9341 -2.5861) ; H21 + #( 11.7369 9.5180 -3.4859) ; H22 + #( 6.0888 7.3990 0.1403) ; H8 + )) + +(define rG06 + (make-constant-rG + #( -0.9815 0.0731 -0.1772 ; dgf-base-tfo + 0.1912 0.3054 -0.9328 + -0.0141 -0.9494 -0.3137 + 5.7506 -5.1944 4.7470) + #( -0.8143 -0.5091 -0.2788 ; P-O3*-275-tfo + -0.0433 -0.4257 0.9038 + -0.5788 0.7480 0.3246 + 1.5227 6.9114 -7.0765) + #( 0.3822 -0.7477 0.5430 ; P-O3*-180-tfo + 0.4552 0.6637 0.5935 + -0.8042 0.0203 0.5941 + -6.9472 -4.1186 -5.9108) + #( 0.5640 0.8007 -0.2022 ; P-O3*-60-tfo + -0.8247 0.5587 -0.0878 + 0.0426 0.2162 0.9754 + 6.2694 -7.0540 3.3316) + #( 2.8930 8.5380 -3.3280) ; P + #( 1.6980 7.6960 -3.5570) ; O1P + #( 3.2260 9.5010 -4.4020) ; O2P + #( 4.1590 7.6040 -3.0340) ; O5* + #( 4.1214 6.7116 -1.9049) ; C5* + #( 3.3465 5.9610 -2.0607) ; H5* + #( 4.0789 7.2928 -0.9837) ; H5** + #( 5.4170 5.9293 -1.8186) ; C4* + #( 5.4506 5.3400 -0.9023) ; H4* + #( 5.5067 5.0417 -2.9703) ; O4* + #( 6.8650 4.9152 -3.3612) ; C1* + #( 7.1090 3.8577 -3.2603) ; H1* + #( 7.7152 5.7282 -2.3894) ; C2* + #( 8.5029 6.2356 -2.9463) ; H2** + #( 8.1036 4.8568 -1.3419) ; O2* + #( 8.3270 3.9651 -1.6184) ; H2* + #( 6.7003 6.7565 -1.8911) ; C3* + #( 6.5898 7.5329 -2.6482) ; H3* + #( 7.0505 7.2878 -0.6105) ; O3* + #( 6.6624 3.5061 -8.2986) ; N1 + #( 6.5810 3.2570 -5.9221) ; N3 + #( 6.5151 2.8263 -7.1625) ; C2 + #( 6.8364 4.5817 -5.8882) ; C4 + #( 7.0116 5.4064 -6.9609) ; C5 + #( 6.9173 4.8260 -8.2361) ; C6 + #( 6.2717 1.5402 -7.4250) ; N2 + #( 7.2573 6.7070 -6.5394) ; N7 + #( 6.9740 5.3703 -4.7760) ; N9 + #( 7.2238 6.6275 -5.2453) ; C8 + #( 7.0668 5.5163 -9.3763) ; O6 + #( 6.5754 2.9964 -9.1545) ; H1 + #( 6.1908 1.1105 -8.3354) ; H21 + #( 6.1346 0.9352 -6.6280) ; H22 + #( 7.4108 7.6227 -4.8418) ; H8 + )) + +(define rG07 + (make-constant-rG + #( 0.0894 -0.6059 0.7905 ; dgf-base-tfo + -0.6810 0.5420 0.4924 + -0.7268 -0.5824 -0.3642 + 34.1424 45.9610 -11.8600) + #( -0.8644 -0.4956 -0.0851 ; P-O3*-275-tfo + -0.0427 0.2409 -0.9696 + 0.5010 -0.8345 -0.2294 + 4.0167 54.5377 12.4779) + #( 0.3706 -0.6167 0.6945 ; P-O3*-180-tfo + -0.2867 -0.7872 -0.5460 + 0.8834 0.0032 -0.4686 + -52.9020 18.6313 -0.6709) + #( 0.4155 0.9025 -0.1137 ; P-O3*-60-tfo + 0.9040 -0.4236 -0.0582 + -0.1007 -0.0786 -0.9918 + -7.6624 -25.2080 49.5181) + #( 31.3810 0.1400 47.5810) ; P + #( 29.9860 0.6630 47.6290) ; O1P + #( 31.7210 -0.6460 48.8090) ; O2P + #( 32.4940 1.2540 47.2740) ; O5* + #( 33.8709 0.7918 47.2113) ; C5* + #( 34.1386 0.5870 46.1747) ; H5* + #( 34.0186 -0.0095 47.9353) ; H5** + #( 34.7297 1.9687 47.6685) ; C4* + #( 35.7723 1.6845 47.8113) ; H4* + #( 34.6455 2.9768 46.6660) ; O4* + #( 34.1690 4.1829 47.2627) ; C1* + #( 35.0437 4.7633 47.5560) ; H1* + #( 33.4145 3.7532 48.4954) ; C2* + #( 32.4340 3.3797 48.2001) ; H2** + #( 33.3209 4.6953 49.5217) ; O2* + #( 33.2374 5.6059 49.2295) ; H2* + #( 34.2724 2.5970 48.9773) ; C3* + #( 33.6373 1.8935 49.5157) ; H3* + #( 35.3453 3.1884 49.7285) ; O3* + #( 34.0511 7.8930 43.7791) ; N1 + #( 34.9937 6.3369 45.3199) ; N3 + #( 35.0882 7.3126 44.4200) ; C2 + #( 33.7190 5.9650 45.5374) ; C4 + #( 32.5845 6.4770 44.9458) ; C5 + #( 32.7430 7.5179 43.9914) ; C6 + #( 36.3030 7.7827 44.1036) ; N2 + #( 31.4499 5.8335 45.4368) ; N7 + #( 33.2760 4.9817 46.4043) ; N9 + #( 31.9235 4.9639 46.2934) ; C8 + #( 31.8602 8.1000 43.3695) ; O6 + #( 34.2623 8.6223 43.1283) ; H1 + #( 36.5188 8.5081 43.4347) ; H21 + #( 37.0888 7.3524 44.5699) ; H22 + #( 31.0815 4.4201 46.7218) ; H8 + )) + +(define rG08 + (make-constant-rG + #( 0.2224 0.6335 0.7411 ; dgf-base-tfo + -0.3644 -0.6510 0.6659 + 0.9043 -0.4181 0.0861 + -47.6824 -0.5823 -31.7554) + #( -0.8644 -0.4956 -0.0851 ; P-O3*-275-tfo + -0.0427 0.2409 -0.9696 + 0.5010 -0.8345 -0.2294 + 4.0167 54.5377 12.4779) + #( 0.3706 -0.6167 0.6945 ; P-O3*-180-tfo + -0.2867 -0.7872 -0.5460 + 0.8834 0.0032 -0.4686 + -52.9020 18.6313 -0.6709) + #( 0.4155 0.9025 -0.1137 ; P-O3*-60-tfo + 0.9040 -0.4236 -0.0582 + -0.1007 -0.0786 -0.9918 + -7.6624 -25.2080 49.5181) + #( 31.3810 0.1400 47.5810) ; P + #( 29.9860 0.6630 47.6290) ; O1P + #( 31.7210 -0.6460 48.8090) ; O2P + #( 32.4940 1.2540 47.2740) ; O5* + #( 32.5924 2.3488 48.2255) ; C5* + #( 33.3674 2.1246 48.9584) ; H5* + #( 31.5994 2.5917 48.6037) ; H5** + #( 33.0722 3.5577 47.4258) ; C4* + #( 33.0310 4.4778 48.0089) ; H4* + #( 34.4173 3.3055 47.0316) ; O4* + #( 34.5056 3.3910 45.6094) ; C1* + #( 34.7881 4.4152 45.3663) ; H1* + #( 33.1122 3.1198 45.1010) ; C2* + #( 32.9230 2.0469 45.1369) ; H2** + #( 32.7946 3.6590 43.8529) ; O2* + #( 33.5170 3.6707 43.2207) ; H2* + #( 32.2730 3.8173 46.1566) ; C3* + #( 31.3094 3.3123 46.2244) ; H3* + #( 32.2391 5.2039 45.7807) ; O3* + #( 39.3337 2.7157 44.1441) ; N1 + #( 37.4430 3.8242 45.0824) ; N3 + #( 38.7276 3.7646 44.7403) ; C2 + #( 36.7791 2.6963 44.7704) ; C4 + #( 37.2860 1.5653 44.1678) ; C5 + #( 38.6647 1.5552 43.8235) ; C6 + #( 39.5123 4.8216 44.9936) ; N2 + #( 36.2829 0.6110 44.0078) ; N7 + #( 35.4394 2.4314 44.9931) ; N9 + #( 35.2180 1.1815 44.5128) ; C8 + #( 39.2907 0.6514 43.2796) ; O6 + #( 40.3076 2.8048 43.9352) ; H1 + #( 40.4994 4.9066 44.7977) ; H21 + #( 39.0738 5.6108 45.4464) ; H22 + #( 34.3856 0.4842 44.4185) ; H8 + )) + +(define rG09 + (make-constant-rG + #( -0.9699 -0.1688 -0.1753 ; dgf-base-tfo + -0.1050 -0.3598 0.9271 + -0.2196 0.9176 0.3312 + 45.6217 -38.9484 -12.3208) + #( -0.8644 -0.4956 -0.0851 ; P-O3*-275-tfo + -0.0427 0.2409 -0.9696 + 0.5010 -0.8345 -0.2294 + 4.0167 54.5377 12.4779) + #( 0.3706 -0.6167 0.6945 ; P-O3*-180-tfo + -0.2867 -0.7872 -0.5460 + 0.8834 0.0032 -0.4686 + -52.9020 18.6313 -0.6709) + #( 0.4155 0.9025 -0.1137 ; P-O3*-60-tfo + 0.9040 -0.4236 -0.0582 + -0.1007 -0.0786 -0.9918 + -7.6624 -25.2080 49.5181) + #( 31.3810 0.1400 47.5810) ; P + #( 29.9860 0.6630 47.6290) ; O1P + #( 31.7210 -0.6460 48.8090) ; O2P + #( 32.4940 1.2540 47.2740) ; O5* + #( 33.8709 0.7918 47.2113) ; C5* + #( 34.1386 0.5870 46.1747) ; H5* + #( 34.0186 -0.0095 47.9353) ; H5** + #( 34.7297 1.9687 47.6685) ; C4* + #( 34.5880 2.8482 47.0404) ; H4* + #( 34.3575 2.2770 49.0081) ; O4* + #( 35.5157 2.1993 49.8389) ; C1* + #( 35.9424 3.2010 49.8893) ; H1* + #( 36.4701 1.2820 49.1169) ; C2* + #( 36.1545 0.2498 49.2683) ; H2** + #( 37.8262 1.4547 49.4008) ; O2* + #( 38.0227 1.6945 50.3094) ; H2* + #( 36.2242 1.6797 47.6725) ; C3* + #( 36.4297 0.8197 47.0351) ; H3* + #( 37.0289 2.8480 47.4426) ; O3* + #( 34.3005 3.5042 54.6070) ; N1 + #( 34.7693 3.7936 52.2874) ; N3 + #( 34.4484 4.2541 53.4939) ; C2 + #( 34.9354 2.4584 52.2785) ; C4 + #( 34.8092 1.5915 53.3422) ; C5 + #( 34.4646 2.1367 54.6085) ; C6 + #( 34.2514 5.5708 53.6503) ; N2 + #( 35.0641 0.2835 52.9337) ; N7 + #( 35.2669 1.6690 51.1915) ; N9 + #( 35.3288 0.3954 51.6563) ; C8 + #( 34.3151 1.5317 55.6650) ; O6 + #( 34.0623 3.9797 55.4539) ; H1 + #( 33.9950 6.0502 54.5016) ; H21 + #( 34.3512 6.1432 52.8242) ; H22 + #( 35.5414 -0.6006 51.2679) ; H8 + )) + +(define rG10 + (make-constant-rG + #( -0.0980 -0.9723 0.2122 ; dgf-base-tfo + -0.9731 0.1383 0.1841 + -0.2083 -0.1885 -0.9597 + 17.8469 38.8265 37.0475) + #( -0.8644 -0.4956 -0.0851 ; P-O3*-275-tfo + -0.0427 0.2409 -0.9696 + 0.5010 -0.8345 -0.2294 + 4.0167 54.5377 12.4779) + #( 0.3706 -0.6167 0.6945 ; P-O3*-180-tfo + -0.2867 -0.7872 -0.5460 + 0.8834 0.0032 -0.4686 + -52.9020 18.6313 -0.6709) + #( 0.4155 0.9025 -0.1137 ; P-O3*-60-tfo + 0.9040 -0.4236 -0.0582 + -0.1007 -0.0786 -0.9918 + -7.6624 -25.2080 49.5181) + #( 31.3810 0.1400 47.5810) ; P + #( 29.9860 0.6630 47.6290) ; O1P + #( 31.7210 -0.6460 48.8090) ; O2P + #( 32.4940 1.2540 47.2740) ; O5* + #( 32.5924 2.3488 48.2255) ; C5* + #( 33.3674 2.1246 48.9584) ; H5* + #( 31.5994 2.5917 48.6037) ; H5** + #( 33.0722 3.5577 47.4258) ; C4* + #( 34.0333 3.3761 46.9447) ; H4* + #( 32.0890 3.8338 46.4332) ; O4* + #( 31.6377 5.1787 46.5914) ; C1* + #( 32.2499 5.8016 45.9392) ; H1* + #( 31.9167 5.5319 48.0305) ; C2* + #( 31.1507 5.0820 48.6621) ; H2** + #( 32.0865 6.8890 48.3114) ; O2* + #( 31.5363 7.4819 47.7942) ; H2* + #( 33.2398 4.8224 48.2563) ; C3* + #( 33.3166 4.5570 49.3108) ; H3* + #( 34.2528 5.7056 47.7476) ; O3* + #( 28.2782 6.3049 42.9364) ; N1 + #( 30.4001 5.8547 43.9258) ; N3 + #( 29.6195 6.1568 42.8913) ; C2 + #( 29.7005 5.7006 45.0649) ; C4 + #( 28.3383 5.8221 45.2343) ; C5 + #( 27.5519 6.1461 44.0958) ; C6 + #( 30.1838 6.3385 41.6890) ; N2 + #( 27.9936 5.5926 46.5651) ; N7 + #( 30.2046 5.3825 46.3136) ; N9 + #( 29.1371 5.3398 47.1506) ; C8 + #( 26.3361 6.3024 44.0495) ; O6 + #( 27.8122 6.5394 42.0833) ; H1 + #( 29.7125 6.5595 40.8235) ; H21 + #( 31.1859 6.2231 41.6389) ; H22 + #( 28.9406 5.1504 48.2059) ; H8 + )) + +(define rGs + (list rG01 rG02 rG03 rG04 rG05 rG06 rG07 rG08 rG09 rG10)) + +(define rU + (make-constant-rU + #( -0.0359 -0.8071 0.5894 ; dgf-base-tfo + -0.2669 0.5761 0.7726 + -0.9631 -0.1296 -0.2361 + 0.1584 8.3434 0.5434) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 5.2430 -8.2420 2.8260) ; C5* + #( 5.1974 -8.8497 1.9223) ; H5* + #( 5.5548 -8.7348 3.7469) ; H5** + #( 6.3140 -7.2060 2.5510) ; C4* + #( 7.2954 -7.6762 2.4898) ; H4* + #( 6.0140 -6.5420 1.2890) ; O4* + #( 6.4190 -5.1840 1.3620) ; C1* + #( 7.1608 -5.0495 0.5747) ; H1* + #( 7.0760 -4.9560 2.7270) ; C2* + #( 6.7770 -3.9803 3.1099) ; H2** + #( 8.4500 -5.1930 2.5810) ; O2* + #( 8.8309 -4.8755 1.7590) ; H2* + #( 6.4060 -6.0590 3.5580) ; C3* + #( 5.4021 -5.7313 3.8281) ; H3* + #( 7.1570 -6.4240 4.7070) ; O3* + #( 5.2170 -4.3260 1.1690) ; N1 + #( 4.2960 -2.2560 0.6290) ; N3 + #( 5.4330 -3.0200 0.7990) ; C2 + #( 2.9930 -2.6780 0.7940) ; C4 + #( 2.8670 -4.0630 1.1830) ; C5 + #( 3.9570 -4.8300 1.3550) ; C6 + #( 6.5470 -2.5560 0.6290) ; O2 + #( 2.0540 -1.9000 0.6130) ; O4 + #( 4.4300 -1.3020 0.3600) ; H3 + #( 1.9590 -4.4570 1.3250) ; H5 + #( 3.8460 -5.7860 1.6240) ; H6 + )) + +(define rU01 + (make-constant-rU + #( -0.0137 -0.8012 0.5983 ; dgf-base-tfo + -0.2523 0.5817 0.7733 + -0.9675 -0.1404 -0.2101 + 0.2031 8.3874 0.4228) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 5.2416 -8.2422 2.8181) ; C5* + #( 5.2050 -8.8128 1.8901) ; H5* + #( 5.5368 -8.7738 3.7227) ; H5** + #( 6.3232 -7.2037 2.6002) ; C4* + #( 7.3048 -7.6757 2.5577) ; H4* + #( 6.0635 -6.5092 1.3456) ; O4* + #( 6.4697 -5.1547 1.4629) ; C1* + #( 7.2354 -5.0043 0.7018) ; H1* + #( 7.0856 -4.9610 2.8521) ; C2* + #( 6.7777 -3.9935 3.2487) ; H2** + #( 8.4627 -5.1992 2.7423) ; O2* + #( 8.8693 -4.8638 1.9399) ; H2* + #( 6.3877 -6.0809 3.6362) ; C3* + #( 5.3770 -5.7562 3.8834) ; H3* + #( 7.1024 -6.4754 4.7985) ; O3* + #( 5.2764 -4.2883 1.2538) ; N1 + #( 4.3777 -2.2062 0.7229) ; N3 + #( 5.5069 -2.9779 0.9088) ; C2 + #( 3.0693 -2.6246 0.8500) ; C4 + #( 2.9279 -4.0146 1.2149) ; C5 + #( 4.0101 -4.7892 1.4017) ; C6 + #( 6.6267 -2.5166 0.7728) ; O2 + #( 2.1383 -1.8396 0.6581) ; O4 + #( 4.5223 -1.2489 0.4716) ; H3 + #( 2.0151 -4.4065 1.3290) ; H5 + #( 3.8886 -5.7486 1.6535) ; H6 + )) + +(define rU02 + (make-constant-rU + #( 0.5141 0.0246 0.8574 ; dgf-base-tfo + -0.5547 -0.7529 0.3542 + 0.6542 -0.6577 -0.3734 + -9.1111 -3.4598 -3.2939) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 4.3825 -6.6585 4.0489) ; C5* + #( 4.6841 -7.2019 4.9443) ; H5* + #( 3.6189 -5.8889 4.1625) ; H5** + #( 5.6255 -5.9175 3.5998) ; C4* + #( 5.8732 -5.1228 4.3034) ; H4* + #( 6.7337 -6.8605 3.5222) ; O4* + #( 7.5932 -6.4923 2.4548) ; C1* + #( 8.5661 -6.2983 2.9064) ; H1* + #( 7.0527 -5.2012 1.8322) ; C2* + #( 7.1627 -5.2525 0.7490) ; H2** + #( 7.6666 -4.1249 2.4880) ; O2* + #( 8.5944 -4.2543 2.6981) ; H2* + #( 5.5661 -5.3029 2.2009) ; C3* + #( 5.0841 -6.0018 1.5172) ; H3* + #( 4.9062 -4.0452 2.2042) ; O3* + #( 7.6298 -7.6136 1.4752) ; N1 + #( 8.6945 -8.7046 -0.2857) ; N3 + #( 8.6943 -7.6514 0.6066) ; C2 + #( 7.7426 -9.6987 -0.3801) ; C4 + #( 6.6642 -9.5742 0.5722) ; C5 + #( 6.6391 -8.5592 1.4526) ; C6 + #( 9.5840 -6.8186 0.6136) ; O2 + #( 7.8505 -10.5925 -1.2223) ; O4 + #( 9.4601 -8.7514 -0.9277) ; H3 + #( 5.9281 -10.2509 0.5782) ; H5 + #( 5.8831 -8.4931 2.1028) ; H6 + )) + +(define rU03 + (make-constant-rU + #( -0.4993 0.0476 0.8651 ; dgf-base-tfo + 0.8078 -0.3353 0.4847 + 0.3132 0.9409 0.1290 + 6.2989 -5.2303 -3.8577) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 3.9938 -6.7042 1.9023) ; C5* + #( 3.2332 -5.9343 2.0319) ; H5* + #( 3.9666 -7.2863 0.9812) ; H5** + #( 5.3098 -5.9546 1.8564) ; C4* + #( 5.3863 -5.3702 0.9395) ; H4* + #( 5.3851 -5.0642 3.0076) ; O4* + #( 6.7315 -4.9724 3.4462) ; C1* + #( 7.0033 -3.9202 3.3619) ; H1* + #( 7.5997 -5.8018 2.4948) ; C2* + #( 8.3627 -6.3254 3.0707) ; H2** + #( 8.0410 -4.9501 1.4724) ; O2* + #( 8.2781 -4.0644 1.7570) ; H2* + #( 6.5701 -6.8129 1.9714) ; C3* + #( 6.4186 -7.5809 2.7299) ; H3* + #( 6.9357 -7.3841 0.7235) ; O3* + #( 6.8024 -5.4718 4.8475) ; N1 + #( 7.9218 -5.5700 6.8877) ; N3 + #( 7.8908 -5.0886 5.5944) ; C2 + #( 6.9789 -6.3827 7.4823) ; C4 + #( 5.8742 -6.7319 6.6202) ; C5 + #( 5.8182 -6.2769 5.3570) ; C6 + #( 8.7747 -4.3728 5.1568) ; O2 + #( 7.1154 -6.7509 8.6509) ; O4 + #( 8.7055 -5.3037 7.4491) ; H3 + #( 5.1416 -7.3178 6.9665) ; H5 + #( 5.0441 -6.5310 4.7784) ; H6 + )) + +(define rU04 + (make-constant-rU + #( -0.5669 -0.8012 0.1918 ; dgf-base-tfo + -0.8129 0.5817 0.0273 + -0.1334 -0.1404 -0.9811 + -0.3279 8.3874 0.3355) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 5.2416 -8.2422 2.8181) ; C5* + #( 5.2050 -8.8128 1.8901) ; H5* + #( 5.5368 -8.7738 3.7227) ; H5** + #( 6.3232 -7.2037 2.6002) ; C4* + #( 7.3048 -7.6757 2.5577) ; H4* + #( 6.0635 -6.5092 1.3456) ; O4* + #( 6.4697 -5.1547 1.4629) ; C1* + #( 7.2354 -5.0043 0.7018) ; H1* + #( 7.0856 -4.9610 2.8521) ; C2* + #( 6.7777 -3.9935 3.2487) ; H2** + #( 8.4627 -5.1992 2.7423) ; O2* + #( 8.8693 -4.8638 1.9399) ; H2* + #( 6.3877 -6.0809 3.6362) ; C3* + #( 5.3770 -5.7562 3.8834) ; H3* + #( 7.1024 -6.4754 4.7985) ; O3* + #( 5.2764 -4.2883 1.2538) ; N1 + #( 3.8961 -3.0896 -0.1893) ; N3 + #( 5.0095 -3.8907 -0.0346) ; C2 + #( 3.0480 -2.6632 0.8116) ; C4 + #( 3.4093 -3.1310 2.1292) ; C5 + #( 4.4878 -3.9124 2.3088) ; C6 + #( 5.7005 -4.2164 -0.9842) ; O2 + #( 2.0800 -1.9458 0.5503) ; O4 + #( 3.6834 -2.7882 -1.1190) ; H3 + #( 2.8508 -2.8721 2.9172) ; H5 + #( 4.7188 -4.2247 3.2295) ; H6 + )) + +(define rU05 + (make-constant-rU + #( -0.6298 0.0246 0.7763 ; dgf-base-tfo + -0.5226 -0.7529 -0.4001 + 0.5746 -0.6577 0.4870 + -0.0208 -3.4598 -9.6882) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 4.3825 -6.6585 4.0489) ; C5* + #( 4.6841 -7.2019 4.9443) ; H5* + #( 3.6189 -5.8889 4.1625) ; H5** + #( 5.6255 -5.9175 3.5998) ; C4* + #( 5.8732 -5.1228 4.3034) ; H4* + #( 6.7337 -6.8605 3.5222) ; O4* + #( 7.5932 -6.4923 2.4548) ; C1* + #( 8.5661 -6.2983 2.9064) ; H1* + #( 7.0527 -5.2012 1.8322) ; C2* + #( 7.1627 -5.2525 0.7490) ; H2** + #( 7.6666 -4.1249 2.4880) ; O2* + #( 8.5944 -4.2543 2.6981) ; H2* + #( 5.5661 -5.3029 2.2009) ; C3* + #( 5.0841 -6.0018 1.5172) ; H3* + #( 4.9062 -4.0452 2.2042) ; O3* + #( 7.6298 -7.6136 1.4752) ; N1 + #( 8.5977 -9.5977 0.7329) ; N3 + #( 8.5951 -8.5745 1.6594) ; C2 + #( 7.7372 -9.7371 -0.3364) ; C4 + #( 6.7596 -8.6801 -0.4476) ; C5 + #( 6.7338 -7.6721 0.4408) ; C6 + #( 9.3993 -8.5377 2.5743) ; O2 + #( 7.8374 -10.6990 -1.1008) ; O4 + #( 9.2924 -10.3081 0.8477) ; H3 + #( 6.0932 -8.6982 -1.1929) ; H5 + #( 6.0481 -6.9515 0.3446) ; H6 + )) + +(define rU06 + (make-constant-rU + #( -0.9837 0.0476 -0.1733 ; dgf-base-tfo + -0.1792 -0.3353 0.9249 + -0.0141 0.9409 0.3384 + 5.7793 -5.2303 4.5997) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 3.9938 -6.7042 1.9023) ; C5* + #( 3.2332 -5.9343 2.0319) ; H5* + #( 3.9666 -7.2863 0.9812) ; H5** + #( 5.3098 -5.9546 1.8564) ; C4* + #( 5.3863 -5.3702 0.9395) ; H4* + #( 5.3851 -5.0642 3.0076) ; O4* + #( 6.7315 -4.9724 3.4462) ; C1* + #( 7.0033 -3.9202 3.3619) ; H1* + #( 7.5997 -5.8018 2.4948) ; C2* + #( 8.3627 -6.3254 3.0707) ; H2** + #( 8.0410 -4.9501 1.4724) ; O2* + #( 8.2781 -4.0644 1.7570) ; H2* + #( 6.5701 -6.8129 1.9714) ; C3* + #( 6.4186 -7.5809 2.7299) ; H3* + #( 6.9357 -7.3841 0.7235) ; O3* + #( 6.8024 -5.4718 4.8475) ; N1 + #( 6.6920 -5.0495 7.1354) ; N3 + #( 6.6201 -4.5500 5.8506) ; C2 + #( 6.9254 -6.3614 7.4926) ; C4 + #( 7.1046 -7.2543 6.3718) ; C5 + #( 7.0391 -6.7951 5.1106) ; C6 + #( 6.4083 -3.3696 5.6340) ; O2 + #( 6.9679 -6.6901 8.6800) ; O4 + #( 6.5626 -4.3957 7.8812) ; H3 + #( 7.2781 -8.2254 6.5350) ; H5 + #( 7.1657 -7.4312 4.3503) ; H6 + )) + +(define rU07 + (make-constant-rU + #( -0.9434 0.3172 0.0971 ; dgf-base-tfo + 0.2294 0.4125 0.8816 + 0.2396 0.8539 -0.4619 + 8.3625 -52.7147 1.3745) + #( 0.2765 -0.1121 -0.9545 ; P-O3*-275-tfo + -0.8297 0.4733 -0.2959 + 0.4850 0.8737 0.0379 + -14.7774 -45.2464 21.9088) + #( 0.1063 -0.6334 -0.7665 ; P-O3*-180-tfo + -0.5932 -0.6591 0.4624 + -0.7980 0.4055 -0.4458 + 43.7634 4.3296 28.4890) + #( 0.7136 -0.5032 -0.4873 ; P-O3*-60-tfo + 0.6803 0.3317 0.6536 + -0.1673 -0.7979 0.5791 + -17.1858 41.4390 -27.0751) + #( 21.3880 15.0780 45.5770) ; P + #( 21.9980 14.5500 46.8210) ; O1P + #( 21.1450 14.0270 44.5420) ; O2P + #( 22.1250 16.3600 44.9460) ; O5* + #( 21.5037 16.8594 43.7323) ; C5* + #( 20.8147 17.6663 43.9823) ; H5* + #( 21.1086 16.0230 43.1557) ; H5** + #( 22.5654 17.4874 42.8616) ; C4* + #( 22.1584 17.7243 41.8785) ; H4* + #( 23.0557 18.6826 43.4751) ; O4* + #( 24.4788 18.6151 43.6455) ; C1* + #( 24.9355 19.0840 42.7739) ; H1* + #( 24.7958 17.1427 43.6474) ; C2* + #( 24.5652 16.7400 44.6336) ; H2** + #( 26.1041 16.8773 43.2455) ; O2* + #( 26.7516 17.5328 43.5149) ; H2* + #( 23.8109 16.5979 42.6377) ; C3* + #( 23.5756 15.5686 42.9084) ; H3* + #( 24.2890 16.7447 41.2729) ; O3* + #( 24.9420 19.2174 44.8923) ; N1 + #( 25.2655 20.5636 44.8883) ; N3 + #( 25.1663 21.2219 43.8561) ; C2 + #( 25.6911 21.1219 46.0494) ; C4 + #( 25.8051 20.4068 47.2048) ; C5 + #( 26.2093 20.9962 48.2534) ; C6 + #( 25.4692 19.0221 47.2053) ; O2 + #( 25.0502 18.4827 46.0370) ; O4 + #( 25.9599 22.1772 46.0966) ; H3 + #( 25.5545 18.4409 48.1234) ; H5 + #( 24.7854 17.4265 45.9883) ; H6 + )) + +(define rU08 + (make-constant-rU + #( -0.0080 -0.7928 0.6094 ; dgf-base-tfo + -0.7512 0.4071 0.5197 + -0.6601 -0.4536 -0.5988 + 44.1482 30.7036 2.1088) + #( 0.2765 -0.1121 -0.9545 ; P-O3*-275-tfo + -0.8297 0.4733 -0.2959 + 0.4850 0.8737 0.0379 + -14.7774 -45.2464 21.9088) + #( 0.1063 -0.6334 -0.7665 ; P-O3*-180-tfo + -0.5932 -0.6591 0.4624 + -0.7980 0.4055 -0.4458 + 43.7634 4.3296 28.4890) + #( 0.7136 -0.5032 -0.4873 ; P-O3*-60-tfo + 0.6803 0.3317 0.6536 + -0.1673 -0.7979 0.5791 + -17.1858 41.4390 -27.0751) + #( 21.3880 15.0780 45.5770) ; P + #( 21.9980 14.5500 46.8210) ; O1P + #( 21.1450 14.0270 44.5420) ; O2P + #( 22.1250 16.3600 44.9460) ; O5* + #( 23.5096 16.1227 44.5783) ; C5* + #( 23.5649 15.8588 43.5222) ; H5* + #( 23.9621 15.4341 45.2919) ; H5** + #( 24.2805 17.4138 44.7151) ; C4* + #( 25.3492 17.2309 44.6030) ; H4* + #( 23.8497 18.3471 43.7208) ; O4* + #( 23.4090 19.5681 44.3321) ; C1* + #( 24.2595 20.2496 44.3524) ; H1* + #( 23.0418 19.1813 45.7407) ; C2* + #( 22.0532 18.7224 45.7273) ; H2** + #( 23.1307 20.2521 46.6291) ; O2* + #( 22.8888 21.1051 46.2611) ; H2* + #( 24.0799 18.1326 46.0700) ; C3* + #( 23.6490 17.4370 46.7900) ; H3* + #( 25.3329 18.7227 46.5109) ; O3* + #( 22.2515 20.1624 43.6698) ; N1 + #( 22.4760 21.0609 42.6406) ; N3 + #( 23.6229 21.3462 42.3061) ; C2 + #( 21.3986 21.6081 42.0236) ; C4 + #( 20.1189 21.3012 42.3804) ; C5 + #( 19.1599 21.8516 41.7578) ; C6 + #( 19.8919 20.3745 43.4387) ; O2 + #( 20.9790 19.8423 44.0440) ; O4 + #( 21.5235 22.3222 41.2097) ; H3 + #( 18.8732 20.1200 43.7312) ; H5 + #( 20.8545 19.1313 44.8608) ; H6 + )) + +(define rU09 + (make-constant-rU + #( -0.0317 0.1374 0.9900 ; dgf-base-tfo + -0.3422 -0.9321 0.1184 + 0.9391 -0.3351 0.0765 + -32.1929 25.8198 -28.5088) + #( 0.2765 -0.1121 -0.9545 ; P-O3*-275-tfo + -0.8297 0.4733 -0.2959 + 0.4850 0.8737 0.0379 + -14.7774 -45.2464 21.9088) + #( 0.1063 -0.6334 -0.7665 ; P-O3*-180-tfo + -0.5932 -0.6591 0.4624 + -0.7980 0.4055 -0.4458 + 43.7634 4.3296 28.4890) + #( 0.7136 -0.5032 -0.4873 ; P-O3*-60-tfo + 0.6803 0.3317 0.6536 + -0.1673 -0.7979 0.5791 + -17.1858 41.4390 -27.0751) + #( 21.3880 15.0780 45.5770) ; P + #( 21.9980 14.5500 46.8210) ; O1P + #( 21.1450 14.0270 44.5420) ; O2P + #( 22.1250 16.3600 44.9460) ; O5* + #( 21.5037 16.8594 43.7323) ; C5* + #( 20.8147 17.6663 43.9823) ; H5* + #( 21.1086 16.0230 43.1557) ; H5** + #( 22.5654 17.4874 42.8616) ; C4* + #( 23.0565 18.3036 43.3915) ; H4* + #( 23.5375 16.5054 42.4925) ; O4* + #( 23.6574 16.4257 41.0649) ; C1* + #( 24.4701 17.0882 40.7671) ; H1* + #( 22.3525 16.9643 40.5396) ; C2* + #( 21.5993 16.1799 40.6133) ; H2** + #( 22.4693 17.4849 39.2515) ; O2* + #( 23.0899 17.0235 38.6827) ; H2* + #( 22.0341 18.0633 41.5279) ; C3* + #( 20.9509 18.1709 41.5846) ; H3* + #( 22.7249 19.3020 41.2100) ; O3* + #( 23.8580 15.0648 40.5757) ; N1 + #( 25.1556 14.5982 40.4523) ; N3 + #( 26.1047 15.3210 40.7448) ; C2 + #( 25.3391 13.3315 40.0020) ; C4 + #( 24.2974 12.5148 39.6749) ; C5 + #( 24.5450 11.3410 39.2610) ; C6 + #( 22.9633 12.9979 39.8053) ; O2 + #( 22.8009 14.2648 40.2524) ; O4 + #( 26.3414 12.9194 39.8855) ; H3 + #( 22.1227 12.3533 39.5486) ; H5 + #( 21.7989 14.6788 40.3650) ; H6 + )) + +(define rU10 + (make-constant-rU + #( -0.9674 0.1021 -0.2318 ; dgf-base-tfo + -0.2514 -0.2766 0.9275 + 0.0306 0.9555 0.2933 + 27.8571 -42.1305 -24.4563) + #( 0.2765 -0.1121 -0.9545 ; P-O3*-275-tfo + -0.8297 0.4733 -0.2959 + 0.4850 0.8737 0.0379 + -14.7774 -45.2464 21.9088) + #( 0.1063 -0.6334 -0.7665 ; P-O3*-180-tfo + -0.5932 -0.6591 0.4624 + -0.7980 0.4055 -0.4458 + 43.7634 4.3296 28.4890) + #( 0.7136 -0.5032 -0.4873 ; P-O3*-60-tfo + 0.6803 0.3317 0.6536 + -0.1673 -0.7979 0.5791 + -17.1858 41.4390 -27.0751) + #( 21.3880 15.0780 45.5770) ; P + #( 21.9980 14.5500 46.8210) ; O1P + #( 21.1450 14.0270 44.5420) ; O2P + #( 22.1250 16.3600 44.9460) ; O5* + #( 23.5096 16.1227 44.5783) ; C5* + #( 23.5649 15.8588 43.5222) ; H5* + #( 23.9621 15.4341 45.2919) ; H5** + #( 24.2805 17.4138 44.7151) ; C4* + #( 23.8509 18.1819 44.0720) ; H4* + #( 24.2506 17.8583 46.0741) ; O4* + #( 25.5830 18.0320 46.5775) ; C1* + #( 25.8569 19.0761 46.4256) ; H1* + #( 26.4410 17.1555 45.7033) ; C2* + #( 26.3459 16.1253 46.0462) ; H2** + #( 27.7649 17.5888 45.6478) ; O2* + #( 28.1004 17.9719 46.4616) ; H2* + #( 25.7796 17.2997 44.3513) ; C3* + #( 25.9478 16.3824 43.7871) ; H3* + #( 26.2154 18.4984 43.6541) ; O3* + #( 25.7321 17.6281 47.9726) ; N1 + #( 25.5136 18.5779 48.9560) ; N3 + #( 25.2079 19.7276 48.6503) ; C2 + #( 25.6482 18.1987 50.2518) ; C4 + #( 25.9847 16.9266 50.6092) ; C5 + #( 26.0918 16.6439 51.8416) ; C6 + #( 26.2067 15.9515 49.5943) ; O2 + #( 26.0713 16.3497 48.3080) ; O4 + #( 25.4890 18.9105 51.0618) ; H3 + #( 26.4742 14.9310 49.8682) ; H5 + #( 26.2346 15.6394 47.4975) ; H6 + )) + +(define rUs + (list rU01 rU02 rU03 rU04 rU05 rU06 rU07 rU08 rU09 rU10)) + +(define rG* + (make-constant-rG + #( -0.2067 -0.0264 0.9780 ; dgf-base-tfo + 0.9770 -0.0586 0.2049 + 0.0519 0.9979 0.0379 + 1.0331 -46.8078 -36.4742) + #( -0.8644 -0.4956 -0.0851 ; P-O3*-275-tfo + -0.0427 0.2409 -0.9696 + 0.5010 -0.8345 -0.2294 + 4.0167 54.5377 12.4779) + #( 0.3706 -0.6167 0.6945 ; P-O3*-180-tfo + -0.2867 -0.7872 -0.5460 + 0.8834 0.0032 -0.4686 + -52.9020 18.6313 -0.6709) + #( 0.4155 0.9025 -0.1137 ; P-O3*-60-tfo + 0.9040 -0.4236 -0.0582 + -0.1007 -0.0786 -0.9918 + -7.6624 -25.2080 49.5181) + #( 31.3810 0.1400 47.5810) ; P + #( 29.9860 0.6630 47.6290) ; O1P + #( 31.7210 -0.6460 48.8090) ; O2P + #( 32.4940 1.2540 47.2740) ; O5* + #( 32.1610 2.2370 46.2560) ; C5* + #( 31.2986 2.8190 46.5812) ; H5* + #( 32.0980 1.7468 45.2845) ; H5** + #( 33.3476 3.1959 46.1947) ; C4* + #( 33.2668 3.8958 45.3630) ; H4* + #( 33.3799 3.9183 47.4216) ; O4* + #( 34.6515 3.7222 48.0398) ; C1* + #( 35.2947 4.5412 47.7180) ; H1* + #( 35.1756 2.4228 47.4827) ; C2* + #( 34.6778 1.5937 47.9856) ; H2** + #( 36.5631 2.2672 47.4798) ; O2* + #( 37.0163 2.6579 48.2305) ; H2* + #( 34.6953 2.5043 46.0448) ; C3* + #( 34.5444 1.4917 45.6706) ; H3* + #( 35.6679 3.3009 45.3487) ; O3* + #( 37.4804 4.0914 52.2559) ; N1 + #( 36.9670 4.1312 49.9281) ; N3 + #( 37.8045 4.2519 50.9550) ; C2 + #( 35.7171 3.8264 50.3222) ; C4 + #( 35.2668 3.6420 51.6115) ; C5 + #( 36.2037 3.7829 52.6706) ; C6 + #( 39.0869 4.5552 50.7092) ; N2 + #( 33.9075 3.3338 51.6102) ; N7 + #( 34.6126 3.6358 49.5108) ; N9 + #( 33.5805 3.3442 50.3425) ; C8 + #( 35.9958 3.6512 53.8724) ; O6 + #( 38.2106 4.2053 52.9295) ; H1 + #( 39.8218 4.6863 51.3896) ; H21 + #( 39.3420 4.6857 49.7407) ; H22 + #( 32.5194 3.1070 50.2664) ; H8 + )) + +(define rU* + (make-constant-rU + #( -0.0109 0.5907 0.8068 ; dgf-base-tfo + 0.2217 -0.7853 0.5780 + 0.9751 0.1852 -0.1224 + -1.4225 -11.0956 -2.5217) + #( -0.8313 -0.4738 -0.2906 ; P-O3*-275-tfo + 0.0649 0.4366 -0.8973 + 0.5521 -0.7648 -0.3322 + 1.6833 6.8060 -7.0011) + #( 0.3445 -0.7630 0.5470 ; P-O3*-180-tfo + -0.4628 -0.6450 -0.6082 + 0.8168 -0.0436 -0.5753 + -6.8179 -3.9778 -5.9887) + #( 0.5855 0.7931 -0.1682 ; P-O3*-60-tfo + 0.8103 -0.5790 0.0906 + -0.0255 -0.1894 -0.9816 + 6.1203 -7.1051 3.1984) + #( 2.6760 -8.4960 3.2880) ; P + #( 1.4950 -7.6230 3.4770) ; O1P + #( 2.9490 -9.4640 4.3740) ; O2P + #( 3.9730 -7.5950 3.0340) ; O5* + #( 5.2430 -8.2420 2.8260) ; C5* + #( 5.1974 -8.8497 1.9223) ; H5* + #( 5.5548 -8.7348 3.7469) ; H5** + #( 6.3140 -7.2060 2.5510) ; C4* + #( 5.8744 -6.2116 2.4731) ; H4* + #( 7.2798 -7.2260 3.6420) ; O4* + #( 8.5733 -6.9410 3.1329) ; C1* + #( 8.9047 -6.0374 3.6446) ; H1* + #( 8.4429 -6.6596 1.6327) ; C2* + #( 9.2880 -7.1071 1.1096) ; H2** + #( 8.2502 -5.2799 1.4754) ; O2* + #( 8.7676 -4.7284 2.0667) ; H2* + #( 7.1642 -7.4416 1.3021) ; C3* + #( 7.4125 -8.5002 1.2260) ; H3* + #( 6.5160 -6.9772 0.1267) ; O3* + #( 9.4531 -8.1107 3.4087) ; N1 + #( 11.5931 -9.0015 3.6357) ; N3 + #( 10.8101 -7.8950 3.3748) ; C2 + #( 11.1439 -10.2744 3.9206) ; C4 + #( 9.7056 -10.4026 3.9332) ; C5 + #( 8.9192 -9.3419 3.6833) ; C6 + #( 11.3013 -6.8063 3.1326) ; O2 + #( 11.9431 -11.1876 4.1375) ; O4 + #( 12.5840 -8.8673 3.6158) ; H3 + #( 9.2891 -11.2898 4.1313) ; H5 + #( 7.9263 -9.4537 3.6977) ; H6 + )) + + + +; -- PARTIAL INSTANTIATIONS --------------------------------------------------- + +(def-struct #f var id tfo nuc) + +; Add a single-quote at the start of this line if you want lazy computation +(begin + +(def-macro (mk-var i tfo nuc) + `(make-var ,i ,tfo ,nuc)) + +(def-macro (absolute-pos var p) + `(tfo-apply (var-tfo ,var) ,p)) + +(def-macro (lazy-computation-of expr) + expr) +) + +'; Remove the single-quote from this line if you want lazy computation +(begin + +(def-macro (mk-var i tfo nuc) + `(make-var ,i ,tfo (make-relative-nuc ,tfo ,nuc))) + +(def-macro (absolute-pos var p) + `(force ,p)) + +(def-macro (lazy-computation-of expr) + `(delay ,expr)) +) + +(def-macro (atom-pos atom var) + `(let ((v ,var)) + (absolute-pos v (,atom (var-nuc v))))) + +(define (get-var id lst) + (let ((v (car lst))) + (if (= id (var-id v)) + v + (get-var id (cdr lst))))) + +(define (make-relative-nuc tfo n) + (cond ((rA? n) + (make-rA + (nuc-dgf-base-tfo n) + (nuc-P-O3*-275-tfo n) + (nuc-P-O3*-180-tfo n) + (nuc-P-O3*-60-tfo n) + (lazy-computation-of (tfo-apply tfo (nuc-P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O1P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5** n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2** n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-N1 n))) + (lazy-computation-of (tfo-apply tfo (nuc-N3 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C6 n))) + (lazy-computation-of (tfo-apply tfo (rA-N6 n))) + (lazy-computation-of (tfo-apply tfo (rA-N7 n))) + (lazy-computation-of (tfo-apply tfo (rA-N9 n))) + (lazy-computation-of (tfo-apply tfo (rA-C8 n))) + (lazy-computation-of (tfo-apply tfo (rA-H2 n))) + (lazy-computation-of (tfo-apply tfo (rA-H61 n))) + (lazy-computation-of (tfo-apply tfo (rA-H62 n))) + (lazy-computation-of (tfo-apply tfo (rA-H8 n))))) + ((rC? n) + (make-rC + (nuc-dgf-base-tfo n) + (nuc-P-O3*-275-tfo n) + (nuc-P-O3*-180-tfo n) + (nuc-P-O3*-60-tfo n) + (lazy-computation-of (tfo-apply tfo (nuc-P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O1P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5** n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2** n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-N1 n))) + (lazy-computation-of (tfo-apply tfo (nuc-N3 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C6 n))) + (lazy-computation-of (tfo-apply tfo (rC-N4 n))) + (lazy-computation-of (tfo-apply tfo (rC-O2 n))) + (lazy-computation-of (tfo-apply tfo (rC-H41 n))) + (lazy-computation-of (tfo-apply tfo (rC-H42 n))) + (lazy-computation-of (tfo-apply tfo (rC-H5 n))) + (lazy-computation-of (tfo-apply tfo (rC-H6 n))))) + ((rG? n) + (make-rG + (nuc-dgf-base-tfo n) + (nuc-P-O3*-275-tfo n) + (nuc-P-O3*-180-tfo n) + (nuc-P-O3*-60-tfo n) + (lazy-computation-of (tfo-apply tfo (nuc-P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O1P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5** n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2** n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-N1 n))) + (lazy-computation-of (tfo-apply tfo (nuc-N3 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C6 n))) + (lazy-computation-of (tfo-apply tfo (rG-N2 n))) + (lazy-computation-of (tfo-apply tfo (rG-N7 n))) + (lazy-computation-of (tfo-apply tfo (rG-N9 n))) + (lazy-computation-of (tfo-apply tfo (rG-C8 n))) + (lazy-computation-of (tfo-apply tfo (rG-O6 n))) + (lazy-computation-of (tfo-apply tfo (rG-H1 n))) + (lazy-computation-of (tfo-apply tfo (rG-H21 n))) + (lazy-computation-of (tfo-apply tfo (rG-H22 n))) + (lazy-computation-of (tfo-apply tfo (rG-H8 n))))) + (else + (make-rU + (nuc-dgf-base-tfo n) + (nuc-P-O3*-275-tfo n) + (nuc-P-O3*-180-tfo n) + (nuc-P-O3*-60-tfo n) + (lazy-computation-of (tfo-apply tfo (nuc-P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O1P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2P n))) + (lazy-computation-of (tfo-apply tfo (nuc-O5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H5** n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O4* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H1* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2** n))) + (lazy-computation-of (tfo-apply tfo (nuc-O2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H2* n))) + (lazy-computation-of (tfo-apply tfo (nuc-C3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-H3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-O3* n))) + (lazy-computation-of (tfo-apply tfo (nuc-N1 n))) + (lazy-computation-of (tfo-apply tfo (nuc-N3 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C2 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C4 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C5 n))) + (lazy-computation-of (tfo-apply tfo (nuc-C6 n))) + (lazy-computation-of (tfo-apply tfo (rU-O2 n))) + (lazy-computation-of (tfo-apply tfo (rU-O4 n))) + (lazy-computation-of (tfo-apply tfo (rU-H3 n))) + (lazy-computation-of (tfo-apply tfo (rU-H5 n))) + (lazy-computation-of (tfo-apply tfo (rU-H6 n))))))) + +; -- SEARCH ------------------------------------------------------------------- + +; Sequential backtracking algorithm + +(define (search partial-inst domains constraint?) + (if (null? domains) + (list partial-inst) + (let ((remaining-domains (cdr domains))) + + (define (try-assignments lst) + (if (null? lst) + '() + (let ((var (car lst))) + (if (constraint? var partial-inst) + (let* ((subsols1 + (search + (cons var partial-inst) + remaining-domains + constraint?)) + (subsols2 + (try-assignments (cdr lst)))) + (append subsols1 subsols2)) + (try-assignments (cdr lst)))))) + + (try-assignments ((car domains) partial-inst))))) + +; -- DOMAINS ------------------------------------------------------------------ + +; Primary structure: strand A CUGCCACGUCUG, strand B CAGACGUGGCAG +; +; Secondary structure: strand A CUGCCACGUCUG +; |||||||||||| +; GACGGUGCAGAC strand B +; +; Tertiary structure: +; +; 5' end of strand A C1----G12 3' end of strand B +; U2-------A11 +; G3-------C10 +; C4-----G9 +; C5---G8 +; A6 +; G6-C7 +; C5----G8 +; A4-------U9 +; G3--------C10 +; A2-------U11 +; 5' end of strand B C1----G12 3' end of strand A +; +; "helix", "stacked" and "connected" describe the spatial relationship +; between two consecutive nucleotides. E.g. the nucleotides C1 and U2 +; from the strand A. +; +; "wc" (stands for Watson-Crick and is a type of base-pairing), +; and "wc-dumas" describe the spatial relationship between +; nucleotides from two chains that are growing in opposite directions. +; E.g. the nucleotides C1 from strand A and G12 from strand B. + +; Dynamic Domains + +; Given, +; "ref" a nucleotide which is already positioned, +; "nuc" the nucleotide to be placed, +; and "tfo" a transformation matrix which expresses the desired +; relationship between "ref" and "nuc", +; the function "dgf-base" computes the transformation matrix that +; places the nucleotide "nuc" in the given relationship to "ref". + +(define (dgf-base tfo ref nuc) + (let* ((ref-nuc (var-nuc ref)) + (align + (tfo-inv-ortho + (cond ((rA? ref-nuc) + (tfo-align (atom-pos nuc-C1* ref) + (atom-pos rA-N9 ref) + (atom-pos nuc-C4 ref))) + ((rC? ref-nuc) + (tfo-align (atom-pos nuc-C1* ref) + (atom-pos nuc-N1 ref) + (atom-pos nuc-C2 ref))) + ((rG? ref-nuc) + (tfo-align (atom-pos nuc-C1* ref) + (atom-pos rG-N9 ref) + (atom-pos nuc-C4 ref))) + (else + (tfo-align (atom-pos nuc-C1* ref) + (atom-pos nuc-N1 ref) + (atom-pos nuc-C2 ref))))))) + (tfo-combine (nuc-dgf-base-tfo nuc) + (tfo-combine tfo align)))) + +; Placement of first nucleotide. + +(define (reference nuc i) + (lambda (partial-inst) + (list (mk-var i tfo-id nuc)))) + +; The transformation matrix for wc is from: +; +; Chandrasekaran R. et al (1989) A Re-Examination of the Crystal +; Structure of A-DNA Using Fiber Diffraction Data. J. Biomol. +; Struct. & Dynamics 6(6):1189-1202. + +(define wc-tfo + '#(-1.0000 0.0028 -0.0019 + 0.0028 0.3468 -0.9379 + -0.0019 -0.9379 -0.3468 + -0.0080 6.0730 8.7208)) + +(define (wc nuc i j) + (lambda (partial-inst) + (let* ((ref (get-var j partial-inst)) + (tfo (dgf-base wc-tfo ref nuc))) + (list (mk-var i tfo nuc))))) + +(define wc-Dumas-tfo + '#(-0.9737 -0.1834 0.1352 + -0.1779 0.2417 -0.9539 + 0.1422 -0.9529 -0.2679 + 0.4837 6.2649 8.0285)) + +(define (wc-Dumas nuc i j) + (lambda (partial-inst) + (let* ((ref (get-var j partial-inst)) + (tfo (dgf-base wc-Dumas-tfo ref nuc))) + (list (mk-var i tfo nuc))))) + +(define helix5*-tfo + '#( 0.9886 -0.0961 0.1156 + 0.1424 0.8452 -0.5152 + -0.0482 0.5258 0.8492 + -3.8737 0.5480 3.8024)) + +(define (helix5* nuc i j) + (lambda (partial-inst) + (let* ((ref (get-var j partial-inst)) + (tfo (dgf-base helix5*-tfo ref nuc))) + (list (mk-var i tfo nuc))))) + +(define helix3*-tfo + '#( 0.9886 0.1424 -0.0482 + -0.0961 0.8452 0.5258 + 0.1156 -0.5152 0.8492 + 3.4426 2.0474 -3.7042)) + +(define (helix3* nuc i j) + (lambda (partial-inst) + (let* ((ref (get-var j partial-inst)) + (tfo (dgf-base helix3*-tfo ref nuc))) + (list (mk-var i tfo nuc))))) + +(define G37-A38-tfo + '#( 0.9991 0.0164 -0.0387 + -0.0375 0.7616 -0.6470 + 0.0189 0.6478 0.7615 + -3.3018 0.9975 2.5585)) + +(define (G37-A38 nuc i j) + (lambda (partial-inst) + (let* ((ref (get-var j partial-inst)) + (tfo (dgf-base G37-A38-tfo ref nuc))) + (mk-var i tfo nuc)))) + +(define (stacked5* nuc i j) + (lambda (partial-inst) + (cons ((G37-A38 nuc i j) partial-inst) + ((helix5* nuc i j) partial-inst)))) + +(define A38-G37-tfo + '#( 0.9991 -0.0375 0.0189 + 0.0164 0.7616 0.6478 + -0.0387 -0.6470 0.7615 + 3.3819 0.7718 -2.5321)) + +(define (A38-G37 nuc i j) + (lambda (partial-inst) + (let* ((ref (get-var j partial-inst)) + (tfo (dgf-base A38-G37-tfo ref nuc))) + (mk-var i tfo nuc)))) + +(define (stacked3* nuc i j) + (lambda (partial-inst) + (cons ((A38-G37 nuc i j) partial-inst) + ((helix3* nuc i j) partial-inst)))) + +(define (P-O3* nucs i j) + (lambda (partial-inst) + (let* ((ref (get-var j partial-inst)) + (align + (tfo-inv-ortho + (tfo-align (atom-pos nuc-O3* ref) + (atom-pos nuc-C3* ref) + (atom-pos nuc-C4* ref))))) + (let loop ((lst nucs) (domains '())) + (if (null? lst) + domains + (let ((nuc (car lst))) + (let ((tfo-60 (tfo-combine (nuc-P-O3*-60-tfo nuc) align)) + (tfo-180 (tfo-combine (nuc-P-O3*-180-tfo nuc) align)) + (tfo-275 (tfo-combine (nuc-P-O3*-275-tfo nuc) align))) + (loop (cdr lst) + (cons (mk-var i tfo-60 nuc) + (cons (mk-var i tfo-180 nuc) + (cons (mk-var i tfo-275 nuc) domains))))))))))) + +; -- PROBLEM STATEMENT -------------------------------------------------------- + +; Define anticodon problem -- Science 253:1255 Figure 3a, 3b and 3c + +(define anticodon-domains + (list + (reference rC 27 ) + (helix5* rC 28 27) + (helix5* rA 29 28) + (helix5* rG 30 29) + (helix5* rA 31 30) + (wc rU 39 31) + (helix5* rC 40 39) + (helix5* rU 41 40) + (helix5* rG 42 41) + (helix5* rG 43 42) + (stacked3* rA 38 39) + (stacked3* rG 37 38) + (stacked3* rA 36 37) + (stacked3* rA 35 36) + (stacked3* rG 34 35);<-. Distance + (P-O3* rCs 32 31); | Constraint + (P-O3* rUs 33 32);<-' 3.0 Angstroms + )) + +; Anticodon constraint + +(define (anticodon-constraint? v partial-inst) + (if (= (var-id v) 33) + (let ((p (atom-pos nuc-P (get-var 34 partial-inst))) ; P in nucleotide 34 + (o3* (atom-pos nuc-O3* v))) ; O3' in nucl. 33 + (FLOAT<= (pt-dist p o3*) 3.0)) ; check distance + #t)) + +(define (anticodon) + (search '() anticodon-domains anticodon-constraint?)) + +; Define pseudoknot problem -- Science 253:1255 Figure 4a and 4b + +(define pseudoknot-domains + (list + (reference rA 23 ) + (wc-Dumas rU 8 23) + (helix3* rG 22 23) + (wc-Dumas rC 9 22) + (helix3* rG 21 22) + (wc-Dumas rC 10 21) + (helix3* rC 20 21) + (wc-Dumas rG 11 20) + (helix3* rU* 19 20);<-. + (wc-Dumas rA 12 19); | Distance +; ; | Constraint +; Helix 1 ; | 4.0 Angstroms + (helix3* rC 3 19); | + (wc-Dumas rG 13 3); | + (helix3* rC 2 3); | + (wc-Dumas rG 14 2); | + (helix3* rC 1 2); | + (wc-Dumas rG* 15 1); | +; ; | +; L2 LOOP ; | + (P-O3* rUs 16 15); | + (P-O3* rCs 17 16); | + (P-O3* rAs 18 17);<-' +; +; L1 LOOP + (helix3* rU 7 8);<-. + (P-O3* rCs 4 3); | Constraint + (stacked5* rU 5 4); | 4.5 Angstroms + (stacked5* rC 6 5);<-' + )) + +; Pseudoknot constraint + +(define (pseudoknot-constraint? v partial-inst) + (case (var-id v) + ((18) + (let ((p (atom-pos nuc-P (get-var 19 partial-inst))) + (o3* (atom-pos nuc-O3* v))) + (FLOAT<= (pt-dist p o3*) 4.0))) + ((6) + (let ((p (atom-pos nuc-P (get-var 7 partial-inst))) + (o3* (atom-pos nuc-O3* v))) + (FLOAT<= (pt-dist p o3*) 4.5))) + (else + #t))) + +(define (pseudoknot) + (search '() pseudoknot-domains pseudoknot-constraint?)) + +; -- TESTING ----------------------------------------------------------------- + +(define (list-of-atoms n) + (append (list-of-common-atoms n) + (list-of-specific-atoms n))) + +(define (list-of-common-atoms n) + (list + (nuc-P n) + (nuc-O1P n) + (nuc-O2P n) + (nuc-O5* n) + (nuc-C5* n) + (nuc-H5* n) + (nuc-H5** n) + (nuc-C4* n) + (nuc-H4* n) + (nuc-O4* n) + (nuc-C1* n) + (nuc-H1* n) + (nuc-C2* n) + (nuc-H2** n) + (nuc-O2* n) + (nuc-H2* n) + (nuc-C3* n) + (nuc-H3* n) + (nuc-O3* n) + (nuc-N1 n) + (nuc-N3 n) + (nuc-C2 n) + (nuc-C4 n) + (nuc-C5 n) + (nuc-C6 n))) + +(define (list-of-specific-atoms n) + (cond ((rA? n) + (list + (rA-N6 n) + (rA-N7 n) + (rA-N9 n) + (rA-C8 n) + (rA-H2 n) + (rA-H61 n) + (rA-H62 n) + (rA-H8 n))) + ((rC? n) + (list + (rC-N4 n) + (rC-O2 n) + (rC-H41 n) + (rC-H42 n) + (rC-H5 n) + (rC-H6 n))) + ((rG? n) + (list + (rG-N2 n) + (rG-N7 n) + (rG-N9 n) + (rG-C8 n) + (rG-O6 n) + (rG-H1 n) + (rG-H21 n) + (rG-H22 n) + (rG-H8 n))) + (else + (list + (rU-O2 n) + (rU-O4 n) + (rU-H3 n) + (rU-H5 n) + (rU-H6 n))))) + +(define (var-most-distant-atom v) + + (define (distance pos) + (let ((abs-pos (absolute-pos v pos))) + (let ((x (pt-x abs-pos)) (y (pt-y abs-pos)) (z (pt-z abs-pos))) + (FLOATsqrt (FLOAT+ (FLOAT* x x) (FLOAT* y y) (FLOAT* z z)))))) + + (maximum (map distance (list-of-atoms (var-nuc v))))) + +(define (sol-most-distant-atom s) + (maximum (map var-most-distant-atom s))) + +(define (most-distant-atom sols) + (maximum (map sol-most-distant-atom sols))) + +(define (maximum lst) + (let loop ((m (car lst)) (l (cdr lst))) + (if (null? l) + m + (let ((x (car l))) + (loop (if (FLOAT> x m) x m) (cdr l)))))) + +(define (check) + (length (pseudoknot))) + +(define (run) + (most-distant-atom (pseudoknot))) + +; To run program, evaluate: (run) diff --git a/tests/older-tests/benchmarks/run-benchmark.rkt b/tests/older-tests/benchmarks/run-benchmark.rkt new file mode 100644 index 0000000..ed6c414 --- /dev/null +++ b/tests/older-tests/benchmarks/run-benchmark.rkt @@ -0,0 +1,56 @@ +#lang s-exp "../../lang/base.rkt" + +(provide run-benchmark) + + +;;; Gambit-style run-benchmark. +;;; +;;; Invoke this procedure to run a benchmark. +;;; The first argument is a string identifying the benchmark. +;;; The second argument is the number of times to run the benchmark. +;;; The third argument is a thunk that runs the benchmark. +;;; The fourth argument is a unary predicate that warns if the result +;;; returned by the benchmark is incorrect. +;;; +;;; Example: +;;; (run-benchmark "make-vector" +;;; 1 +;;; (lambda () (make-vector 1000000)) +;;; (lambda (v) (and (vector? v) (= (vector-length v) #e1e6)))) + +;;; For backward compatibility, this procedure also works with the +;;; arguments that we once used to run benchmarks in Larceny. + +(define (run-benchmark name arg2 . rest) + (let* ((old-style (procedure? arg2)) + (thunk (if old-style arg2 (car rest))) + (n (if old-style + (if (null? rest) 1 (car rest)) + arg2)) + (ok? (if (or old-style (null? (cdr rest))) + (lambda (result) #t) + (cadr rest))) + (result '*)) + (define (loop n) + (cond ((zero? n) #t) + ((= n 1) + (set! result (thunk))) + (else + (thunk) + (loop (- n 1))))) + (when old-style + (begin (newline) + (display "Warning: Using old-style run-benchmark") + (newline))) + (newline) + (display "--------------------------------------------------------") + (newline) + (display name) + (newline) + ; time is a macro supplied by Chez Scheme + (time (loop n)) + (when (not (ok? result)) + (begin (display "Error: Benchmark program returned wrong result: ") + (write result) + (newline))))) + diff --git a/tests/older-tests/benchmarks/run-do-measures.rkt b/tests/older-tests/benchmarks/run-do-measures.rkt new file mode 100644 index 0000000..f1d61ad --- /dev/null +++ b/tests/older-tests/benchmarks/run-do-measures.rkt @@ -0,0 +1,4 @@ +#lang racket/base +(require "../../main.rkt") + +(run-in-browser "do-measures.rkt") diff --git a/tests/older-tests/benchmarks/run-nboyer.rkt b/tests/older-tests/benchmarks/run-nboyer.rkt new file mode 100644 index 0000000..4cf5daf --- /dev/null +++ b/tests/older-tests/benchmarks/run-nboyer.rkt @@ -0,0 +1,3 @@ +#lang racket +(require (planet dyoo/js-vm)) +(run-in-browser "nboyer.rkt") \ No newline at end of file diff --git a/tests/older-tests/benchmarks/sboyer.rkt b/tests/older-tests/benchmarks/sboyer.rkt new file mode 100644 index 0000000..cf9d2e8 --- /dev/null +++ b/tests/older-tests/benchmarks/sboyer.rkt @@ -0,0 +1,790 @@ +#lang s-exp "../../lang/base.rkt" + +(require "run-benchmark.rkt") + +(provide sboyer-benchmark) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; File: sboyer.sch +; Description: The Boyer benchmark +; Author: Bob Boyer +; Created: 5-Apr-85 +; Modified: 10-Apr-85 14:52:20 (Bob Shaw) +; 22-Jul-87 (Will Clinger) +; 2-Jul-88 (Will Clinger -- distinguished #f and the empty list) +; 13-Feb-97 (Will Clinger -- fixed bugs in unifier and rules, +; rewrote to eliminate property lists, and added +; a scaling parameter suggested by Bob Boyer) +; 19-Mar-99 (Will Clinger -- cleaned up comments) +; 4-Apr-01 (Will Clinger -- changed four 1- symbols to sub1) +; Language: Scheme +; Status: Public Domain +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;; SBOYER -- Logic programming benchmark, originally written by Bob Boyer. +;;; Much less CONS-intensive than NBOYER because it uses Henry Baker's +;;; "sharing cons". + +; Note: The version of this benchmark that appears in Dick Gabriel's book +; contained several bugs that are corrected here. These bugs are discussed +; by Henry Baker, "The Boyer Benchmark Meets Linear Logic", ACM SIGPLAN Lisp +; Pointers 6(4), October-December 1993, pages 3-10. The fixed bugs are: +; +; The benchmark now returns a boolean result. +; FALSEP and TRUEP use TERM-MEMBER? rather than MEMV (which is called MEMBER +; in Common Lisp) +; ONE-WAY-UNIFY1 now treats numbers correctly +; ONE-WAY-UNIFY1-LST now treats empty lists correctly +; Rule 19 has been corrected (this rule was not touched by the original +; benchmark, but is used by this version) +; Rules 84 and 101 have been corrected (but these rules are never touched +; by the benchmark) +; +; According to Baker, these bug fixes make the benchmark 10-25% slower. +; Please do not compare the timings from this benchmark against those of +; the original benchmark. +; +; This version of the benchmark also prints the number of rewrites as a sanity +; check, because it is too easy for a buggy version to return the correct +; boolean result. The correct number of rewrites is +; +; n rewrites peak live storage (approximate, in bytes) +; 0 95024 +; 1 591777 +; 2 1813975 +; 3 5375678 +; 4 16445406 +; 5 51507739 + +; Sboyer is a 2-phase benchmark. +; The first phase attaches lemmas to symbols. This phase is not timed, +; but it accounts for very little of the runtime anyway. +; The second phase creates the test problem, and tests to see +; whether it is implied by the lemmas. + +(define (sboyer-benchmark . args) + (let ((n (if (null? args) 0 (car args)))) + (setup-boyer) + (run-benchmark (string-append "sboyer" + (number->string n)) + 1 + (lambda () (test-boyer n)) + (lambda (rewrites) + (and (number? rewrites) + (case n + ((0) (= rewrites 95024)) + ((1) (= rewrites 591777)) + ((2) (= rewrites 1813975)) + ((3) (= rewrites 5375678)) + ((4) (= rewrites 16445406)) + ((5) (= rewrites 51507739)) + ; If it works for n <= 5, assume it works. + (else #t))))))) + +(define (setup-boyer) #t) ; assigned below +(define (test-boyer) #t) ; assigned below + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; The first phase. +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; In the original benchmark, it stored a list of lemmas on the +; property lists of symbols. +; In the new benchmark, it maintains an association list of +; symbols and symbol-records, and stores the list of lemmas +; within the symbol-records. + +(let () + + (define (setup) + (add-lemma-lst + (quote ((equal (compile form) + (reverse (codegen (optimize form) + (nil)))) + (equal (eqp x y) + (equal (fix x) + (fix y))) + (equal (greaterp x y) + (lessp y x)) + (equal (lesseqp x y) + (not (lessp y x))) + (equal (greatereqp x y) + (not (lessp x y))) + (equal (boolean x) + (or (equal x (t)) + (equal x (f)))) + (equal (iff x y) + (and (implies x y) + (implies y x))) + (equal (even1 x) + (if (zerop x) + (t) + (odd (sub1 x)))) + (equal (countps- l pred) + (countps-loop l pred (zero))) + (equal (fact- i) + (fact-loop i 1)) + (equal (reverse- x) + (reverse-loop x (nil))) + (equal (divides x y) + (zerop (remainder y x))) + (equal (assume-true var alist) + (cons (cons var (t)) + alist)) + (equal (assume-false var alist) + (cons (cons var (f)) + alist)) + (equal (tautology-checker x) + (tautologyp (normalize x) + (nil))) + (equal (falsify x) + (falsify1 (normalize x) + (nil))) + (equal (prime x) + (and (not (zerop x)) + (not (equal x (add1 (zero)))) + (prime1 x (sub1 x)))) + (equal (and p q) + (if p (if q (t) + (f)) + (f))) + (equal (or p q) + (if p (t) + (if q (t) + (f)))) + (equal (not p) + (if p (f) + (t))) + (equal (implies p q) + (if p (if q (t) + (f)) + (t))) + (equal (fix x) + (if (numberp x) + x + (zero))) + (equal (if (if a b c) + d e) + (if a (if b d e) + (if c d e))) + (equal (zerop x) + (or (equal x (zero)) + (not (numberp x)))) + (equal (plus (plus x y) + z) + (plus x (plus y z))) + (equal (equal (plus a b) + (zero)) + (and (zerop a) + (zerop b))) + (equal (difference x x) + (zero)) + (equal (equal (plus a b) + (plus a c)) + (equal (fix b) + (fix c))) + (equal (equal (zero) + (difference x y)) + (not (lessp y x))) + (equal (equal x (difference x y)) + (and (numberp x) + (or (equal x (zero)) + (zerop y)))) + (equal (meaning (plus-tree (append x y)) + a) + (plus (meaning (plus-tree x) + a) + (meaning (plus-tree y) + a))) + (equal (meaning (plus-tree (plus-fringe x)) + a) + (fix (meaning x a))) + (equal (append (append x y) + z) + (append x (append y z))) + (equal (reverse (append a b)) + (append (reverse b) + (reverse a))) + (equal (times x (plus y z)) + (plus (times x y) + (times x z))) + (equal (times (times x y) + z) + (times x (times y z))) + (equal (equal (times x y) + (zero)) + (or (zerop x) + (zerop y))) + (equal (exec (append x y) + pds envrn) + (exec y (exec x pds envrn) + envrn)) + (equal (mc-flatten x y) + (append (flatten x) + y)) + (equal (member x (append a b)) + (or (member x a) + (member x b))) + (equal (member x (reverse y)) + (member x y)) + (equal (length (reverse x)) + (length x)) + (equal (member a (intersect b c)) + (and (member a b) + (member a c))) + (equal (nth (zero) + i) + (zero)) + (equal (exp i (plus j k)) + (times (exp i j) + (exp i k))) + (equal (exp i (times j k)) + (exp (exp i j) + k)) + (equal (reverse-loop x y) + (append (reverse x) + y)) + (equal (reverse-loop x (nil)) + (reverse x)) + (equal (count-list z (sort-lp x y)) + (plus (count-list z x) + (count-list z y))) + (equal (equal (append a b) + (append a c)) + (equal b c)) + (equal (plus (remainder x y) + (times y (quotient x y))) + (fix x)) + (equal (power-eval (big-plus1 l i base) + base) + (plus (power-eval l base) + i)) + (equal (power-eval (big-plus x y i base) + base) + (plus i (plus (power-eval x base) + (power-eval y base)))) + (equal (remainder y 1) + (zero)) + (equal (lessp (remainder x y) + y) + (not (zerop y))) + (equal (remainder x x) + (zero)) + (equal (lessp (quotient i j) + i) + (and (not (zerop i)) + (or (zerop j) + (not (equal j 1))))) + (equal (lessp (remainder x y) + x) + (and (not (zerop y)) + (not (zerop x)) + (not (lessp x y)))) + (equal (power-eval (power-rep i base) + base) + (fix i)) + (equal (power-eval (big-plus (power-rep i base) + (power-rep j base) + (zero) + base) + base) + (plus i j)) + (equal (gcd x y) + (gcd y x)) + (equal (nth (append a b) + i) + (append (nth a i) + (nth b (difference i (length a))))) + (equal (difference (plus x y) + x) + (fix y)) + (equal (difference (plus y x) + x) + (fix y)) + (equal (difference (plus x y) + (plus x z)) + (difference y z)) + (equal (times x (difference c w)) + (difference (times c x) + (times w x))) + (equal (remainder (times x z) + z) + (zero)) + (equal (difference (plus b (plus a c)) + a) + (plus b c)) + (equal (difference (add1 (plus y z)) + z) + (add1 y)) + (equal (lessp (plus x y) + (plus x z)) + (lessp y z)) + (equal (lessp (times x z) + (times y z)) + (and (not (zerop z)) + (lessp x y))) + (equal (lessp y (plus x y)) + (not (zerop x))) + (equal (gcd (times x z) + (times y z)) + (times z (gcd x y))) + (equal (value (normalize x) + a) + (value x a)) + (equal (equal (flatten x) + (cons y (nil))) + (and (nlistp x) + (equal x y))) + (equal (listp (gopher x)) + (listp x)) + (equal (samefringe x y) + (equal (flatten x) + (flatten y))) + (equal (equal (greatest-factor x y) + (zero)) + (and (or (zerop y) + (equal y 1)) + (equal x (zero)))) + (equal (equal (greatest-factor x y) + 1) + (equal x 1)) + (equal (numberp (greatest-factor x y)) + (not (and (or (zerop y) + (equal y 1)) + (not (numberp x))))) + (equal (times-list (append x y)) + (times (times-list x) + (times-list y))) + (equal (prime-list (append x y)) + (and (prime-list x) + (prime-list y))) + (equal (equal z (times w z)) + (and (numberp z) + (or (equal z (zero)) + (equal w 1)))) + (equal (greatereqp x y) + (not (lessp x y))) + (equal (equal x (times x y)) + (or (equal x (zero)) + (and (numberp x) + (equal y 1)))) + (equal (remainder (times y x) + y) + (zero)) + (equal (equal (times a b) + 1) + (and (not (equal a (zero))) + (not (equal b (zero))) + (numberp a) + (numberp b) + (equal (sub1 a) + (zero)) + (equal (sub1 b) + (zero)))) + (equal (lessp (length (delete x l)) + (length l)) + (member x l)) + (equal (sort2 (delete x l)) + (delete x (sort2 l))) + (equal (dsort x) + (sort2 x)) + (equal (length (cons x1 + (cons x2 + (cons x3 (cons x4 + (cons x5 + (cons x6 x7))))))) + (plus 6 (length x7))) + (equal (difference (add1 (add1 x)) + 2) + (fix x)) + (equal (quotient (plus x (plus x y)) + 2) + (plus x (quotient y 2))) + (equal (sigma (zero) + i) + (quotient (times i (add1 i)) + 2)) + (equal (plus x (add1 y)) + (if (numberp y) + (add1 (plus x y)) + (add1 x))) + (equal (equal (difference x y) + (difference z y)) + (if (lessp x y) + (not (lessp y z)) + (if (lessp z y) + (not (lessp y x)) + (equal (fix x) + (fix z))))) + (equal (meaning (plus-tree (delete x y)) + a) + (if (member x y) + (difference (meaning (plus-tree y) + a) + (meaning x a)) + (meaning (plus-tree y) + a))) + (equal (times x (add1 y)) + (if (numberp y) + (plus x (times x y)) + (fix x))) + (equal (nth (nil) + i) + (if (zerop i) + (nil) + (zero))) + (equal (last (append a b)) + (if (listp b) + (last b) + (if (listp a) + (cons (car (last a)) + b) + b))) + (equal (equal (lessp x y) + z) + (if (lessp x y) + (equal (t) z) + (equal (f) z))) + (equal (assignment x (append a b)) + (if (assignedp x a) + (assignment x a) + (assignment x b))) + (equal (car (gopher x)) + (if (listp x) + (car (flatten x)) + (zero))) + (equal (flatten (cdr (gopher x))) + (if (listp x) + (cdr (flatten x)) + (cons (zero) + (nil)))) + (equal (quotient (times y x) + y) + (if (zerop y) + (zero) + (fix x))) + (equal (get j (set i val mem)) + (if (eqp j i) + val + (get j mem))))))) + + (define (add-lemma-lst lst) + (cond ((null? lst) + #t) + (else (add-lemma (car lst)) + (add-lemma-lst (cdr lst))))) + + (define (add-lemma term) + (cond ((and (pair? term) + (eq? (car term) + (quote equal)) + (pair? (cadr term))) + (put (car (cadr term)) + (quote lemmas) + (cons + (translate-term term) + (get (car (cadr term)) (quote lemmas))))) + (else (error "ADD-LEMMA did not like term: " term)))) + + ; Translates a term by replacing its constructor symbols by symbol-records. + + (define (translate-term term) + (cond ((not (pair? term)) + term) + (else (cons (symbol->symbol-record (car term)) + (translate-args (cdr term)))))) + + (define (translate-args lst) + (cond ((null? lst) + '()) + (else (cons (translate-term (car lst)) + (translate-args (cdr lst)))))) + + ; For debugging only, so the use of MAP does not change + ; the first-order character of the benchmark. + + (define (untranslate-term term) + (cond ((not (pair? term)) + term) + (else (cons (get-name (car term)) + (map untranslate-term (cdr term)))))) + + ; A symbol-record is represented as a vector with two fields: + ; the symbol (for debugging) and + ; the list of lemmas associated with the symbol. + + (define (put sym property value) + (put-lemmas! (symbol->symbol-record sym) value)) + + (define (get sym property) + (get-lemmas (symbol->symbol-record sym))) + + (define (symbol->symbol-record sym) + (let ((x (assq sym *symbol-records-alist*))) + (if x + (cdr x) + (let ((r (make-symbol-record sym))) + (set! *symbol-records-alist* + (cons (cons sym r) + *symbol-records-alist*)) + r)))) + + ; Association list of symbols and symbol-records. + + (define *symbol-records-alist* '()) + + ; A symbol-record is represented as a vector with two fields: + ; the symbol (for debugging) and + ; the list of lemmas associated with the symbol. + + (define (make-symbol-record sym) + (vector sym '())) + + (define (put-lemmas! symbol-record lemmas) + (vector-set! symbol-record 1 lemmas)) + + (define (get-lemmas symbol-record) + (vector-ref symbol-record 1)) + + (define (get-name symbol-record) + (vector-ref symbol-record 0)) + + (define (symbol-record-equal? r1 r2) + (eq? r1 r2)) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; + ; The second phase. + ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + (define (test n) + (let ((term + (apply-subst + (translate-alist + (quote ((x f (plus (plus a b) + (plus c (zero)))) + (y f (times (times a b) + (plus c d))) + (z f (reverse (append (append a b) + (nil)))) + (u equal (plus a b) + (difference x y)) + (w lessp (remainder a b) + (member a (length b)))))) + (translate-term + (do ((term + (quote (implies (and (implies x y) + (and (implies y z) + (and (implies z u) + (implies u w)))) + (implies x w))) + (list 'or term '(f))) + (n n (- n 1))) + ((zero? n) term)))))) + (tautp term))) + + (define (translate-alist alist) + (cond ((null? alist) + '()) + (else (cons (cons (caar alist) + (translate-term (cdar alist))) + (translate-alist (cdr alist)))))) + + (define (apply-subst alist term) + (cond ((not (pair? term)) + (let ((temp-temp (assq term alist))) + (if temp-temp + (cdr temp-temp) + term))) + (else (cons (car term) + (apply-subst-lst alist (cdr term)))))) + + (define (apply-subst-lst alist lst) + (cond ((null? lst) + '()) + (else (cons (apply-subst alist (car lst)) + (apply-subst-lst alist (cdr lst)))))) + + (define (tautp x) + (tautologyp (rewrite x) + '() '())) + + (define (tautologyp x true-lst false-lst) + (cond ((truep x true-lst) + #t) + ((falsep x false-lst) + #f) + ((not (pair? x)) + #f) + ((eq? (car x) if-constructor) + (cond ((truep (cadr x) + true-lst) + (tautologyp (caddr x) + true-lst false-lst)) + ((falsep (cadr x) + false-lst) + (tautologyp (cadddr x) + true-lst false-lst)) + (else (and (tautologyp (caddr x) + (cons (cadr x) + true-lst) + false-lst) + (tautologyp (cadddr x) + true-lst + (cons (cadr x) + false-lst)))))) + (else #f))) + + (define if-constructor '*) ; becomes (symbol->symbol-record 'if) + + (define rewrite-count 0) ; sanity check + + ; The next procedure is Henry Baker's sharing CONS, which avoids + ; allocation if the result is already in hand. + ; The REWRITE and REWRITE-ARGS procedures have been modified to + ; use SCONS instead of CONS. + + (define (scons x y original) + (if (and (eq? x (car original)) + (eq? y (cdr original))) + original + (cons x y))) + + (define (rewrite term) + (set! rewrite-count (+ rewrite-count 1)) + (cond ((not (pair? term)) + term) + (else (rewrite-with-lemmas (scons (car term) + (rewrite-args (cdr term)) + term) + (get-lemmas (car term)))))) + + (define (rewrite-args lst) + (cond ((null? lst) + '()) + (else (scons (rewrite (car lst)) + (rewrite-args (cdr lst)) + lst)))) + + (define (rewrite-with-lemmas term lst) + (cond ((null? lst) + term) + ((one-way-unify term (cadr (car lst))) + (rewrite (apply-subst unify-subst (caddr (car lst))))) + (else (rewrite-with-lemmas term (cdr lst))))) + + (define unify-subst '*) + + (define (one-way-unify term1 term2) + (begin (set! unify-subst '()) + (one-way-unify1 term1 term2))) + + (define (one-way-unify1 term1 term2) + (cond ((not (pair? term2)) + (let ((temp-temp (assq term2 unify-subst))) + (cond (temp-temp + (term-equal? term1 (cdr temp-temp))) + ((number? term2) ; This bug fix makes + (equal? term1 term2)) ; nboyer 10-25% slower! + (else + (set! unify-subst (cons (cons term2 term1) + unify-subst)) + #t)))) + ((not (pair? term1)) + #f) + ((eq? (car term1) + (car term2)) + (one-way-unify1-lst (cdr term1) + (cdr term2))) + (else #f))) + + (define (one-way-unify1-lst lst1 lst2) + (cond ((null? lst1) + (null? lst2)) + ((null? lst2) + #f) + ((one-way-unify1 (car lst1) + (car lst2)) + (one-way-unify1-lst (cdr lst1) + (cdr lst2))) + (else #f))) + + (define (falsep x lst) + (or (term-equal? x false-term) + (term-member? x lst))) + + (define (truep x lst) + (or (term-equal? x true-term) + (term-member? x lst))) + + (define false-term '*) ; becomes (translate-term '(f)) + (define true-term '*) ; becomes (translate-term '(t)) + + ; The next two procedures were in the original benchmark + ; but were never used. + + (define (trans-of-implies n) + (translate-term + (list (quote implies) + (trans-of-implies1 n) + (list (quote implies) + 0 n)))) + + (define (trans-of-implies1 n) + (cond ((equal? n 1) + (list (quote implies) + 0 1)) + (else (list (quote and) + (list (quote implies) + (- n 1) + n) + (trans-of-implies1 (- n 1)))))) + + ; Translated terms can be circular structures, which can't be + ; compared using Scheme's equal? and member procedures, so we + ; use these instead. + + (define (term-equal? x y) + (cond ((pair? x) + (and (pair? y) + (symbol-record-equal? (car x) (car y)) + (term-args-equal? (cdr x) (cdr y)))) + (else (equal? x y)))) + + (define (term-args-equal? lst1 lst2) + (cond ((null? lst1) + (null? lst2)) + ((null? lst2) + #f) + ((term-equal? (car lst1) (car lst2)) + (term-args-equal? (cdr lst1) (cdr lst2))) + (else #f))) + + (define (term-member? x lst) + (cond ((null? lst) + #f) + ((term-equal? x (car lst)) + #t) + (else (term-member? x (cdr lst))))) + + (set! setup-boyer + (lambda () + (set! *symbol-records-alist* '()) + (set! if-constructor (symbol->symbol-record 'if)) + (set! false-term (translate-term '(f))) + (set! true-term (translate-term '(t))) + (setup))) + + (set! test-boyer + (lambda (n) + (set! rewrite-count 0) + (let ((answer (test n))) + (write rewrite-count) + (display " rewrites") + (newline) + (if answer + rewrite-count + #f))))) diff --git a/tests/older-tests/benchmarks/tak.rkt b/tests/older-tests/benchmarks/tak.rkt new file mode 100644 index 0000000..a47b4f2 --- /dev/null +++ b/tests/older-tests/benchmarks/tak.rkt @@ -0,0 +1,17 @@ +#lang s-exp "../../lang/base.rkt" + +(provide tak-benchmark) +(require "run-benchmark.rkt") + + +(define (tak x y z) + (if (not (< y x)) + z + (tak (tak (- x 1) y z) + (tak (- y 1) z x) + (tak (- z 1) x y)))) + +;;; call: (tak 18 12 6) + +(define (tak-benchmark) + (run-benchmark "Tak" (lambda () (tak 18 12 6)) 10)) \ No newline at end of file diff --git a/tests/older-tests/check-coverage.rkt b/tests/older-tests/check-coverage.rkt new file mode 100644 index 0000000..4a1978e --- /dev/null +++ b/tests/older-tests/check-coverage.rkt @@ -0,0 +1,78 @@ +#lang racket/base + +(require "../private/get-wescheme-primitive-names.rkt" + racket/runtime-path + racket/path + racket/list) + +(provide print-coverage-report untouched-wescheme-primitives) + + +(define-runtime-path program-path "moby-programs") + +(define (read-module f) + (parameterize ([read-accept-reader #t]) + (let loop ([sexp + (rest (first (rest (rest (rest (read + (open-input-file f)))))))]) + sexp))) + + +(define moby-program-sources + (let loop ([files (directory-list program-path)]) + (cond + [(empty? files) + '()] + [(and (file-exists? (build-path program-path (first files))) + (bytes=? (or (filename-extension (first files)) #"") + #"rkt")) + (cons (read-module (build-path program-path (first files))) + (loop (rest files)))] + [else + (loop (rest files))]))) + +(define (sexp-symbols an-sexp) + (cond + [(symbol? an-sexp) + (list an-sexp)] + [(pair? an-sexp) + (append (sexp-symbols (car an-sexp)) + (sexp-symbols (cdr an-sexp)))] + [else + '()])) + + +;; untouched-wescheme-primitives: (listof symbol) +(define (untouched-wescheme-primitives) + (let ([ht (make-hash)]) + (for ([sym wescheme-primitive-names]) + (hash-set! ht sym #t)) + + (for ([sym (sexp-symbols moby-program-sources)]) + (hash-remove! ht sym)) + + ;; manually remove some + (hash-remove! ht '#%module-begin) + (hash-remove! ht '#%app) + (hash-remove! ht '#%datum) + (hash-remove! ht '#%top) + (hash-remove! ht '#%top-interaction) + (hash-remove! ht 'planet) + + + + (for/list ([key (in-hash-keys ht)]) + key))) + + +(define (print-coverage-report) + (let ([los (untouched-wescheme-primitives)]) + (unless (empty? los) + (printf "~a PRIMITIVES UNTOUCHED BY TESTS!!!\nList below:\n" (length los)) + (for ([sym (sort los (lambda (x y) (stringstring x) + (symbol->string y))))]) + (printf "~a\n" sym)) + (printf "\n")))) + + +(print-coverage-report) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/42.rkt b/tests/older-tests/moby-programs/42.rkt new file mode 100644 index 0000000..4896ed1 --- /dev/null +++ b/tests/older-tests/moby-programs/42.rkt @@ -0,0 +1,12 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(printf "42.rkt\n") + +(define (f x) + (* x x)) + +(check-expect (format "~s ~s ~s\n" + (f 16) + (f -5) + (f 42)) + "256 25 1764\n") diff --git a/tests/older-tests/moby-programs/all-tests.rkt b/tests/older-tests/moby-programs/all-tests.rkt new file mode 100644 index 0000000..fa577a0 --- /dev/null +++ b/tests/older-tests/moby-programs/all-tests.rkt @@ -0,0 +1,67 @@ +#lang s-exp "../../lang/base.rkt" + + +;; This module requires the majority of tests here. + + + +;; NOTE: js-input.rkt is not being tested here. Must be handled interactively. +;; NOTE: continuation-prompts.rkt is not being tested here. Must be handled interactively. +;; NOTE: continuation-prompts-3.rkt is not being tested here. Must be handled interactively. + + +(require "sleep.rkt" + "display-and-write.rkt" + "repeating-decimals.rkt" + "ffi.rkt" + "ffi-2.rkt" + "continuation-marks.rkt" + "atan.rkt" + "with-handlers-1.rkt" + "with-handlers-2.rkt" + "when-unless.rkt" + "setbang.rkt" + "require.rkt" + "quasiquote.rkt" + "permissions.rkt" + "local.rkt" + "for-each.rkt" + "letrec.rkt" + "recur.rkt" + "math.rkt" + "eof.rkt" + "js-big-bang-timer.rkt" + "images.rkt" + "image-equality.rkt" + "falling-ball.rkt" + "exercise-control.rkt" + "double-client.rkt" + "define-struct.rkt" + "continuation-prompts-2.rkt" + "case-lambda.rkt" + "begin.rkt" + "and-or.rkt" + "42.rkt" + "cycles.rkt" + "list.rkt" + "vararity.rkt" + "check-error.rkt" + "vector.rkt" + "struct.rkt" + "arity.rkt" + "apply.rkt" + "values.rkt" + "compose.rkt" + "seconds.rkt" + "random.rkt" + "identity.rkt" + "raise.rkt" + "exn.rkt" + "misc.rkt" + "jsworld.rkt" + "location.rkt" + "rotate.rkt" + "more-jsworld.ss") + + +(printf "all-tests completed\n") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/and-or.rkt b/tests/older-tests/moby-programs/and-or.rkt new file mode 100644 index 0000000..239f9c4 --- /dev/null +++ b/tests/older-tests/moby-programs/and-or.rkt @@ -0,0 +1,13 @@ +#lang s-exp "../../lang/wescheme.ss" + +(printf "and-or.rkt\n") + +(check-expect (and true "hello") "hello") +(check-expect (or #f #f "world" 'dontcomehere) + "world") + + +(check-expect (not 3) false) +(check-expect (not (not 3)) true) + +(printf "and-or.rkt end\n") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/apply.rkt b/tests/older-tests/moby-programs/apply.rkt new file mode 100644 index 0000000..6aad011 --- /dev/null +++ b/tests/older-tests/moby-programs/apply.rkt @@ -0,0 +1,18 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(require "../../lang/check-expect/test-expect.rkt") + +"apply.rkt" + +(check-expect (apply + '()) 0) +(check-expect (apply + '(1 2 3)) 6) +(check-expect (apply + 4 6 '(1 2 3)) 16) + +(define f (lambda args args)) +(check-expect (apply f 'hello 'world '()) '(hello world)) + +(let ([g (λ (x) (* x x))]) + (test-expect (apply g 3 '()) 9)) + + +"apply.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/arity.rkt b/tests/older-tests/moby-programs/arity.rkt new file mode 100644 index 0000000..0faff09 --- /dev/null +++ b/tests/older-tests/moby-programs/arity.rkt @@ -0,0 +1,31 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"arity.rkt" +(check-expect (procedure-arity (lambda () (void))) 0) +(check-expect (procedure-arity (lambda (x) (void))) 1) +(check-expect (procedure-arity (lambda (x y . z) (void))) + (make-arity-at-least 2)) + +(check-expect (arity-at-least? (make-arity-at-least 0)) + true) + +(check-expect (arity-at-least? 'not-an-arity) + false) + +(check-expect (arity-at-least-value + (make-arity-at-least 7)) + 7) + +(define f + (case-lambda [(x y) (list x y)] + [(x y z) (list x y z)])) +(check-expect (procedure-arity-includes? f 2) true) +(check-expect (procedure-arity-includes? f 3) true) +(check-expect (procedure-arity-includes? f 4) false) +(check-expect (procedure-arity-includes? f 0) false) + +(check-expect (procedure-arity-includes? (lambda (x) (* x x)) 1) true) +(check-expect (procedure-arity-includes? (lambda (x) (* x x)) 0) false) +(check-expect (procedure-arity-includes? (lambda args (void)) 0) true) + +"arity.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/atan.rkt b/tests/older-tests/moby-programs/atan.rkt new file mode 100644 index 0000000..42f4106 --- /dev/null +++ b/tests/older-tests/moby-programs/atan.rkt @@ -0,0 +1,27 @@ +#lang s-exp "../../lang/wescheme.rkt" +"atan.rkt tests" + +(define delta 0.000001) + +(check-within (atan 0.5) + 0.4636476090008061 + delta) +(check-within (atan 2 1) + 1.1071487177940904 + delta) +(check-within (atan -2 -1) + -2.0344439357957027 + delta) +(check-within (real-part (atan 1.0+5.0i)) + 1.530881333938778 + delta) + +(check-within (imag-part (atan 1.0+5.0i)) + 0.19442614214700213 + delta) + +(check-within (atan +inf.0 -inf.0) + 2.356194490192345 + delta) + +"atan.rkt tests done" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/begin.rkt b/tests/older-tests/moby-programs/begin.rkt new file mode 100644 index 0000000..7bd8538 --- /dev/null +++ b/tests/older-tests/moby-programs/begin.rkt @@ -0,0 +1,27 @@ +#lang s-exp "../../lang/wescheme.ss" + +(require "../../lang/check-expect/test-expect.rkt") + +(printf "begin.rkt\n") +(printf "You should see the string \"hello world\" immediately after this: ") + +(begin (printf "hello ") + (printf "world\n")) + + + +(let ([counter 17]) + (test-expect (begin + counter + (set! counter (add1 counter)) + counter) + 18)) + + +(let ([counter 17]) + (test-expect (begin0 counter + (set! counter (add1 counter)) + counter) + 17)) + +"begin.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/case-lambda.rkt b/tests/older-tests/moby-programs/case-lambda.rkt new file mode 100644 index 0000000..7c04dfa --- /dev/null +++ b/tests/older-tests/moby-programs/case-lambda.rkt @@ -0,0 +1,13 @@ +#lang s-exp "../../lang/wescheme.ss" + +(printf "case-lambda.rkt\n") + +(define f + (case-lambda + [(x) (list x)] + [(x y) (list y x)] + [(x y z) (list z y x)])) + +(check-expect (f 3) (list 3)) +(check-expect (f 3 4) (list 4 3)) +(check-expect (f 3 4 5) (list 5 4 3)) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/check-error.rkt b/tests/older-tests/moby-programs/check-error.rkt new file mode 100644 index 0000000..cd0472b --- /dev/null +++ b/tests/older-tests/moby-programs/check-error.rkt @@ -0,0 +1,13 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(check-error (/ 1 0) "/: division by zero") + + +#;(define-struct foo ()) +#;(check-error (make-foo 3 4) + "make-foo: expects no arguments, given 2: 3 4") + + +#;(define (f x) + (* x x)) +#;(check-error (f 3 4) "procedure f: expects 1 argument, given 2: 3 4") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/compose.rkt b/tests/older-tests/moby-programs/compose.rkt new file mode 100644 index 0000000..52dcfcc --- /dev/null +++ b/tests/older-tests/moby-programs/compose.rkt @@ -0,0 +1,18 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"compose.rkt" + +(define (f x) (* x x)) +(define (g x) (+ x x)) + +(check-expect (procedure? (compose f g)) true) +(check-expect ((compose f g) 7) + (* 14 14)) + +(check-expect ((compose) 7) + 7) + +(check-expect ((compose f) 7) + 49) + +"compose.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/continuation-marks.rkt b/tests/older-tests/moby-programs/continuation-marks.rkt new file mode 100644 index 0000000..729b8ab --- /dev/null +++ b/tests/older-tests/moby-programs/continuation-marks.rkt @@ -0,0 +1,19 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "../../lang/check-expect/test-expect.rkt") + +"continuation-marks.rkt" + +(with-continuation-mark 'x 3 + (test-expect (continuation-mark-set->list + (current-continuation-marks) + 'x) + '(3))) + +(with-continuation-mark 'x 3 + (with-continuation-mark 'x 4 + (test-expect (continuation-mark-set->list + (current-continuation-marks) + 'x) + '(4)))) + +"continuation-marks.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/continuation-prompts-2.rkt b/tests/older-tests/moby-programs/continuation-prompts-2.rkt new file mode 100644 index 0000000..aa2d2e0 --- /dev/null +++ b/tests/older-tests/moby-programs/continuation-prompts-2.rkt @@ -0,0 +1,41 @@ +#lang s-exp "../../lang/wescheme.rkt" + + +(define (escape v) + (abort-current-continuation + (default-continuation-prompt-tag) + (lambda () v))) + + +(printf "continuation-prompts-2.rkt\n") + + + +(printf "testing expected value from abort with default continuation prompt tag\n") +(check-expect + (+ 1 + (call-with-continuation-prompt + (lambda () + (+ 1 (+ 1 (+ 1 (+ 1 (+ 1 (+ 1 (escape 6)))))))) + (default-continuation-prompt-tag))) + + 7) + + +(check-expect + (+ 1 + (call-with-continuation-prompt + (lambda () + (+ 1 (+ 1 (+ 1 (+ 1 (+ 1 (+ 1 (escape 24)))))))) + (default-continuation-prompt-tag) + (lambda (thunk) + (printf "I see the escape\n") + (thunk)))) + + 25) + + + + + +(printf "continuation-prompts-2 tests done!\n") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/continuation-prompts-3.rkt b/tests/older-tests/moby-programs/continuation-prompts-3.rkt new file mode 100644 index 0000000..446c9ff --- /dev/null +++ b/tests/older-tests/moby-programs/continuation-prompts-3.rkt @@ -0,0 +1,19 @@ +#lang s-exp "../../lang/base.rkt" + + +(define n 0) +(define (f) + (call-with-continuation-prompt + (lambda () + (abort-current-continuation (default-continuation-prompt-tag) + (lambda () + (set! n (add1 n)) + (when (< n 10000) + (f))))) + (default-continuation-prompt-tag) + (lambda (thunk) + (thunk)))) + +(f) + +n \ No newline at end of file diff --git a/tests/older-tests/moby-programs/continuation-prompts.rkt b/tests/older-tests/moby-programs/continuation-prompts.rkt new file mode 100644 index 0000000..9182975 --- /dev/null +++ b/tests/older-tests/moby-programs/continuation-prompts.rkt @@ -0,0 +1,30 @@ +#lang s-exp "../../lang/base.rkt" + +(call-with-continuation-prompt + (lambda () (printf "Hello world\n") + (values 3 4 5)) + (default-continuation-prompt-tag) + (lambda (thunk) + (error))) + + + +(call-with-continuation-prompt + (lambda (a b c) (printf "~a ~a ~a\n" a b c) + (values 3 4 5)) + (default-continuation-prompt-tag) + (lambda (thunk) + (error)) + "hello" + "world" + "again") + + + +(abort-current-continuation (default-continuation-prompt-tag) + (lambda () + (printf "This is the error thunk."))) + + + +(printf "I should not see this\n") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/cycles.rkt b/tests/older-tests/moby-programs/cycles.rkt new file mode 100644 index 0000000..a72567a --- /dev/null +++ b/tests/older-tests/moby-programs/cycles.rkt @@ -0,0 +1,141 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "../../lang/check-expect/test-expect.rkt") + +"cycle tests" + + + + +(define-struct thingy (x y)) +(let ([result (shared ([y (make-thingy y y)]) + y)]) + (test-expect (thingy-x result) result) + (test-expect (thingy-y result) result)) + + + + +(define mylst (cons 1 (cons (box #f) empty))) +(set-box! (cadr mylst) mylst) + + +;; FIXME: the output format for cycles in the Javascript implementation is +;; printing out ... rather than the traditional format. +;; +;; This is a bad deviation. + +(test-expect (format "~s\n" mylst) + "(1 #&...)\n") + + +(shared ([a (cons 1 a)]) + (test-expect (format "~s\n"a) + "(1 . ...)\n")) + + +(shared ([a (vector 1 2 a)]) + (test-expect (format "~s\n" a) + "#(1 2 ...)\n")) + +(shared ([a (box a)]) + (test-expect (format "~s\n" a) + "#&...\n")) + + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define my-list (shared ([x (cons 1 (cons 2 (cons 3 y)))] + [y (cons 'a (cons 'b (cons 'c (cons 'd x))))]) + x)) +(define (take n l) + (cond + [(= n 0) + empty] + [else + (cons (first l) + (take (sub1 n) (rest l)))])) + +(test-expect (take 20 my-list) + '(1 2 3 a b c d 1 2 3 a b c d 1 2 3 a b c)) + + + + + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(test-expect (shared ([x (list 1 2)]) x) + (list 1 2)) + +(test-expect (shared ([x (vector 1 2)]) x) + #(1 2)) + +(test-expect (shared ([x (box 1)]) x) + (box 1)) + +(test-expect (shared ([x (cons 1 null)]) x) + '(1)) + + + +;;(stest (x "#1=(#1# 1)") '(shared ([x (list x 1)]) x)) +(let ([result (shared ([x (list x 1)]) x)]) + (test-expect result (car result)) + (test-expect (cdr result) '(1))) + +;(stest (x "#2=#(#2# 1)") '(shared ([x (vector x 1)]) x)) +(let ([result (shared ([x (vector x 1)]) x)]) + (test-expect (vector-ref result 0) result) + (test-expect (vector-ref result 1) 1) + (test-expect (vector-length result) 2)) + +;(stest (x "#2=#(#2# 1)") '(shared ([x (vector-immutable x 1)]) x)) +;(let ([result (shared ([x (vector-immutable x 1)]) x)]) +; (test-expect (vector-ref result 0) result) +; (test-expect (vector-ref result 1) 1) +; (test-expect (vector-length result) 2)) + + +;(stest (x "#3=##") '(shared ([x (box x)]) x)) +(let ([result (shared ([x (box x)]) x)]) + (test-expect (unbox result) result)) + +;(stest (x "#3=##") '(shared ([x (box-immutable x)]) x)) + + +;(stest (x "#4=(#4#)") '(shared ([x (cons x null)]) x)) +(let ([result (shared ([x (cons x null)]) x)]) + (test-expect (car result) result) + (test-expect (cdr result) null)) + + + +;(stest (x "#5=(1 . #5#)") '(shared ([x (cons 1 x)]) x)) +(let ([result (shared ([x (cons 1 x)]) x)]) + (test-expect (car result) 1) + (test-expect (cdr result) result)) + + +;; (stest (x "#11=(#11#)") '(shared ([x `(,x)]) x)) +(let ([result (shared ([x `(,x)]) x)]) + (test-expect (length result) 1) + (test-expect (car result) result)) + + +;; (stest (x "#11=(#11# 1)") '(shared ([x `(,x 1)]) x)) +(let ([result (shared ([x `(,x 1)]) x)]) + (test-expect (length result) 2) + (test-expect (car result) result) + (test-expect (cdr result) '(1))) + + + + + + +"cycle tests done" + diff --git a/tests/older-tests/moby-programs/define-struct.rkt b/tests/older-tests/moby-programs/define-struct.rkt new file mode 100644 index 0000000..6fed4e1 --- /dev/null +++ b/tests/older-tests/moby-programs/define-struct.rkt @@ -0,0 +1,10 @@ +#lang s-exp "../../lang/wescheme.ss" + +(printf "define-struct.rkt\n") + +(define-struct p (x y)) +"should be a structure: " (make-p 3 4) +(check-expect (p? (make-p 3 4)) + true) +(check-expect (p-x (make-p 3 4)) 3) +(check-expect (p-y (make-p 3 4)) 4) diff --git a/tests/older-tests/moby-programs/display-and-write.rkt b/tests/older-tests/moby-programs/display-and-write.rkt new file mode 100644 index 0000000..2d158a5 --- /dev/null +++ b/tests/older-tests/moby-programs/display-and-write.rkt @@ -0,0 +1,12 @@ +#lang s-exp "../../lang/wescheme.rkt" + + +(printf "should not be in quotes: ") +(display "hello world") +(newline) +(printf "should be in quotes: ") +(write "hello world") +(newline) + + +((current-print) "using current-print") diff --git a/tests/older-tests/moby-programs/double-client.rkt b/tests/older-tests/moby-programs/double-client.rkt new file mode 100644 index 0000000..488a542 --- /dev/null +++ b/tests/older-tests/moby-programs/double-client.rkt @@ -0,0 +1,8 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(require "double.rkt") + +(check-expect (double 3) 6) + +(check-expect (double (double (double 2))) 16) + diff --git a/tests/older-tests/moby-programs/double.js b/tests/older-tests/moby-programs/double.js new file mode 100644 index 0000000..0911c17 --- /dev/null +++ b/tests/older-tests/moby-programs/double.js @@ -0,0 +1,2 @@ +EXPORTS['double'] = + new types.PrimProc('double', 1, false, false, function(x) { return jsnums.multiply(x, 2)}); \ No newline at end of file diff --git a/tests/older-tests/moby-programs/double.rkt b/tests/older-tests/moby-programs/double.rkt new file mode 100644 index 0000000..f9c9af3 --- /dev/null +++ b/tests/older-tests/moby-programs/double.rkt @@ -0,0 +1,5 @@ +#lang s-exp "../../lang/js-impl/js-impl.rkt" + +(require-js "double.js") + +(provide double) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/eof.rkt b/tests/older-tests/moby-programs/eof.rkt new file mode 100644 index 0000000..79ae8ae --- /dev/null +++ b/tests/older-tests/moby-programs/eof.rkt @@ -0,0 +1,9 @@ +#lang s-exp "../../lang/wescheme.rkt" + + +"eof.rkt" + +(check-expect (eof-object? eof) true) +(check-expect (eof-object? 'eof) false) + +"eof.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/exercise-control.rkt b/tests/older-tests/moby-programs/exercise-control.rkt new file mode 100644 index 0000000..2194924 --- /dev/null +++ b/tests/older-tests/moby-programs/exercise-control.rkt @@ -0,0 +1,133 @@ +#lang s-exp "../../lang/wescheme.ss" + +(printf "exercise-control.rkt\n") + + +(check-expect (if true + 'ok + 'not-ok) + 'ok) + +(check-expect (if false + 'not-ok + 'ok) + 'ok) + +(check-expect (cond [true 'ok] + [else 'not-ok]) + 'ok) + +(check-expect (cond [false 'not-ok] + [else 'ok]) + 'ok) + +(check-expect (case 42 + [(1) 'not-ok] + [(2) 'not-ok] + [(42) 'ok]) + 'ok) + +(check-expect (case 42 + [(1) 'not-ok] + [(2) 'not-ok] + [(42) 'ok]) + 'ok) + + +;; Runtime error: we should see if the test isn't boolean +(with-handlers ([exn:fail? + (lambda (exn) + (unless (string=? "cond: question result is not true or false: 42" + (exn-message exn)) + (error 'cond-test)))]) + (cond + [42 + (error 'uh-oh)] + [else + (error 'cond-test)])) + + + +;; Test fall-through +(with-handlers ([exn:fail? + (lambda (exn) + (unless (string=? "cond: all question results were false" + (exn-message exn)) + (error 'cond-test)))]) + (cond + [false (error 'uh-oh)])) + + + +;; Runtime error: we should see if the test isn't boolean +(with-handlers ([exn:fail? + (lambda (exn) + (unless (string=? "if: question result is not true or false: \"not a boolean\"" + (exn-message exn)) + (error 'cond-test)))]) + (if "not a boolean" + (error 'uh-oh) + (error 'uh-oh))) + + +;; Check fall-though with case being an error +(with-handlers ([exn:fail? + (lambda (exn) + (unless (string=? "case: the expression matched none of the choices" + (exn-message exn)) + (error 'case-test)))]) + (case 42 + [(1) (error 'case)] + [(2) (error 'case)] + [(3) (error 'case)]) + (error 'case)) + + + +(with-handlers ([exn:fail? + (lambda (exn) + (unless (string=? "when: question result is not true or false: \"not a boolean\"" + (exn-message exn)) + (error 'when-boolean-test)))]) + (when "not a boolean" + (error 'uh-oh))) + + + +(with-handlers ([exn:fail? + (lambda (exn) + (unless (string=? "unless: question result is not true or false: \"not a boolean\"" + (exn-message exn)) + (error 'unless-boolean-test)))]) + (unless "not a boolean" + (error 'uh-oh))) + + + + +(unless (= 0 0) + (error 'huh?)) + +(when (= 0 1) + (error 'huh?)) + + + +(check-expect (let/cc return + (begin + (return 42) + (error))) + 42) + + +(check-expect (let/cc return + (begin + 'fall-through)) + 'fall-through) + + + + +(printf "exercise-control.rkt end\n") + + diff --git a/tests/older-tests/moby-programs/exn.rkt b/tests/older-tests/moby-programs/exn.rkt new file mode 100644 index 0000000..b54a2c6 --- /dev/null +++ b/tests/older-tests/moby-programs/exn.rkt @@ -0,0 +1,79 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"exn.rkt" + + +(define e0 (make-exn "blah" (current-continuation-marks))) +(define e1 (make-exn:fail "foo" (current-continuation-marks))) +(define e2 (make-exn:fail:contract "bar" (current-continuation-marks))) +(define e3 (make-exn:fail:contract:arity "baz" (current-continuation-marks))) +(define e4 (make-exn:fail:contract:divide-by-zero "blip" (current-continuation-marks))) +(define e5 (make-exn:fail:contract:variable "blop" (current-continuation-marks) 'x)) + + +(check-expect (exn? e0) true) +(check-expect (exn? e1) true) +(check-expect (exn? e2) true) +(check-expect (exn? e3) true) +(check-expect (exn? e4) true) +(check-expect (exn? e5) true) + +(check-expect (exn-message e0) "blah") +(check-expect (exn-message e1) "foo") +(check-expect (exn-message e2) "bar") +(check-expect (exn-message e3) "baz") +(check-expect (exn-message e4) "blip") +(check-expect (exn-message e5) "blop") + +(check-expect (continuation-mark-set? + (exn-continuation-marks e0)) true) +(check-expect (continuation-mark-set? + (exn-continuation-marks e1)) true) +(check-expect (continuation-mark-set? + (exn-continuation-marks e2)) true) +(check-expect (continuation-mark-set? + (exn-continuation-marks e3)) true) +(check-expect (continuation-mark-set? + (exn-continuation-marks e4)) true) +(check-expect (continuation-mark-set? + (exn-continuation-marks e5)) true) + + +(check-expect (exn:fail? e0) false) +(check-expect (exn:fail? e1) true) +(check-expect (exn:fail? e2) true) +(check-expect (exn:fail? e3) true) +(check-expect (exn:fail? e4) true) +(check-expect (exn:fail? e5) true) + +(check-expect (exn:fail:contract? e0) false) +(check-expect (exn:fail:contract? e1) false) +(check-expect (exn:fail:contract? e2) true) +(check-expect (exn:fail:contract? e3) true) +(check-expect (exn:fail:contract? e4) true) +(check-expect (exn:fail:contract? e5) true) + +(check-expect (exn:fail:contract:arity? e0) false) +(check-expect (exn:fail:contract:arity? e1) false) +(check-expect (exn:fail:contract:arity? e2) false) +(check-expect (exn:fail:contract:arity? e3) true) +(check-expect (exn:fail:contract:arity? e4) false) +(check-expect (exn:fail:contract:arity? e5) false) + +(check-expect (exn:fail:contract:variable? e0) false) +(check-expect (exn:fail:contract:variable? e1) false) +(check-expect (exn:fail:contract:variable? e2) false) +(check-expect (exn:fail:contract:variable? e3) false) +(check-expect (exn:fail:contract:variable? e4) false) +(check-expect (exn:fail:contract:variable? e5) true) + + +(check-expect (exn:fail:contract:divide-by-zero? e0) false) +(check-expect (exn:fail:contract:divide-by-zero? e1) false) +(check-expect (exn:fail:contract:divide-by-zero? e2) false) +(check-expect (exn:fail:contract:divide-by-zero? e3) false) +(check-expect (exn:fail:contract:divide-by-zero? e4) true) +(check-expect (exn:fail:contract:divide-by-zero? e5) false) + + +"exn.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/falling-ball.rkt b/tests/older-tests/moby-programs/falling-ball.rkt new file mode 100644 index 0000000..d2b6eaf --- /dev/null +++ b/tests/older-tests/moby-programs/falling-ball.rkt @@ -0,0 +1,48 @@ +#lang s-exp "../../lang/wescheme.ss" + +;; Simple falling ball example. A red ball falls down the screen +;; until hitting the bottom. + + +(printf "falling-ball.rkt\n") + +(define-struct world (radius y)) + + +;; The dimensions of the screen: +(define WIDTH 320) +(define HEIGHT 480) + +;; The radius of the red circle. +(define RADIUS 15) + +;; The world is the distance from the top of the screen. +(define INITIAL-WORLD (make-world RADIUS 0)) + +;; tick: world -> world +;; Moves the ball down. +(define (tick w) + (make-world RADIUS (+ (world-y w) 5))) + + +;; hits-floor?: world -> boolean +;; Returns true when the distance reaches the screen height. +(define (hits-floor? w) + (>= (world-y w) HEIGHT)) + +;; We have some simple test cases. +(check-expect (hits-floor? (make-world RADIUS 0)) false) +(check-expect (hits-floor? (make-world RADIUS HEIGHT)) true) + +;; render: world -> scene +;; Produces a scene with the circle at a height described by the world. +(define (render w) + (place-image (circle RADIUS "solid" "red") (/ WIDTH 2) (world-y w) + (empty-scene WIDTH HEIGHT))) + +;; Start up a big bang, 15 frames a second. +(check-expect (big-bang INITIAL-WORLD + (on-tick tick 1/15) + (to-draw render) + (stop-when hits-floor?)) + (make-world 15 480)) diff --git a/tests/older-tests/moby-programs/ffi-2.rkt b/tests/older-tests/moby-programs/ffi-2.rkt new file mode 100644 index 0000000..0ef3545 --- /dev/null +++ b/tests/older-tests/moby-programs/ffi-2.rkt @@ -0,0 +1,44 @@ +#lang s-exp "../../lang/base.rkt" +(require "../../ffi/ffi.rkt" + "../../jsworld/jsworld.rkt" + "../../lang/check-expect/check-expect.rkt") + +"my-ffi-2.rkt" + +;; Check to see that we can expression on-tick with make-world-config. + + +(define (my-on-tick world-updater) + (make-world-config + (lambda (success) + (js-call (js-get-global-value "setInterval") + #f + (procedure->void-js-fun (lambda args (js-call success #f))) + 1000)) + + (lambda (id) + (printf "shutdown with clearInterval id=~s\n" id) + (js-call (js-get-global-value "clearInterval") + #f + id)) + + (lambda (w) + (world-updater w)))) + + + + +(check-expect (big-bang 1 + + (my-on-tick + (lambda (w) + (printf "tick!\n") + (add1 w))) + + (stop-when + (lambda (n) (= n 10)))) + 10) + + +(run-tests) +"end my-ffi-2.rkt" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/ffi.rkt b/tests/older-tests/moby-programs/ffi.rkt new file mode 100644 index 0000000..85e73e6 --- /dev/null +++ b/tests/older-tests/moby-programs/ffi.rkt @@ -0,0 +1,125 @@ +#lang s-exp "../../lang/base.rkt" + + +(require "../../ffi/ffi.rkt" + "../../lang/check-expect/check-expect.rkt") + + +(define window + (js-get-global-value "window")) + +(define platform + (js-get-field window "navigator" "platform")) + +(printf "Current browser platform is ~s\n" + (prim-js->scheme platform)) + + +(check-expect (prim-js->scheme (scheme->prim-js "hello world")) + "hello world") +(check-expect (prim-js->scheme (scheme->prim-js #t)) + #t) +(check-expect (prim-js->scheme (scheme->prim-js #f)) + #f) + + +(printf "minimum and maximum js fixnums are ~a and ~a\n" + minimum-js-fixnum + maximum-js-fixnum) + + + +;; (prim-js->scheme (scheme->prim-js ...)) is not the identity, unfortunately. +;; Here are tests that show that we need to do something: + +;; Numbers that come back to us are inexact. +(check-expect (inexact->exact (prim-js->scheme (scheme->prim-js 42))) + 42) + +;; Characters are mapped to one-character strings. +(check-expect (prim-js->scheme (scheme->prim-js #\h)) + "h") + +;; Symbols are mapped to strings. +(check-expect (prim-js->scheme (scheme->prim-js 'hello)) + "hello") + +;; Note that when converting vectors, the resulting inner values are not +;; automatically transformed back. So the prim-js->scheme transformation +;; is shallow. +(check-expect (map prim-js->scheme + (vector->list (prim-js->scheme (scheme->prim-js #(1 2 3))))) + '(1.0 2.0 3.0)) + +(check-expect (map prim-js->scheme + (vector->list (prim-js->scheme + (scheme->prim-js #(1 "testing" 3))))) + '(1.0 "testing" 3.0)) + + + + + + +(check-expect (js-=== js-undefined js-undefined) true) +(check-expect (js-=== js-null js-null) true) +(check-expect (js-=== js-undefined js-null) false) +(check-expect (js-=== js-null js-undefined) false) + + +(check-expect (js-typeof (scheme->prim-js 1)) "number") +(check-expect (js-typeof (scheme->prim-js "hello")) "string") +(check-expect (js-typeof (scheme->prim-js #t)) "boolean") +(check-expect (js-typeof (scheme->prim-js #f)) "boolean") + +(check-expect (js-typeof (js-make-hash)) "object") +(check-expect (js-typeof (js-make-hash '(("name" "danny") + ("school" "wpi")))) "object") + + + + +(define a-hash (js-make-hash '(("foo" "bar") + ("baz" "blah")))) +(check-expect (prim-js->scheme (js-get-field a-hash "foo")) "bar") +(check-expect (prim-js->scheme (js-get-field a-hash "baz")) "blah") +(js-set-field! a-hash "something else" (box 3)) + + + +;; Uh oh. There's something about this that I do not understand about +;; the current design of the FFI. What's going on here? +(check-expect (js-get-field a-hash "something else") + (box 3)) + + + +(define my-escape + (let ([prim-escape (js-get-global-value "escape")]) + (lambda (s) + (prim-js->scheme (js-call prim-escape #f s))))) +(check-expect (my-escape "hello world") "hello%20world") +(check-expect (my-escape "x.mv,") "x.mv%2C") + + + + + +(let ([p (procedure->void-js-fun + (lambda () (printf "this is from scheme\n")))]) + (printf "The following should repeat 'this is from scheme'\n") + (js-call p #f)) + + +(let ([p (procedure->void-js-fun + (lambda (x y) + (printf "I see: ~s ~s\n" + (prim-js->scheme x) + (prim-js->scheme y))))]) + (printf "The following should repeat 'I see 3 \"four\"\n") + (js-call p #f 3 "four")) + + + +(run-tests) +"end of ffi tests" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/for-each.rkt b/tests/older-tests/moby-programs/for-each.rkt new file mode 100644 index 0000000..1c7f297 --- /dev/null +++ b/tests/older-tests/moby-programs/for-each.rkt @@ -0,0 +1,16 @@ +#lang s-exp "../../lang/wescheme.rkt" + + +"for-each" + +(for-each (lambda (x) (error 'nothing!)) '()) + + + +(define l1 '(hello world this is a test)) +(define l2 '(hello this test)) +(for-each (lambda (x) (set! l1 (remove x l1))) + l2) +(check-expect l1 '(world is a)) + +"for-each.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/identity.rkt b/tests/older-tests/moby-programs/identity.rkt new file mode 100644 index 0000000..6233826 --- /dev/null +++ b/tests/older-tests/moby-programs/identity.rkt @@ -0,0 +1,6 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(check-expect (identity 42) 42) + +(define p (cons 3 4)) +(check-expect (identity p) p) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/image-equality.rkt b/tests/older-tests/moby-programs/image-equality.rkt new file mode 100644 index 0000000..bdbe702 --- /dev/null +++ b/tests/older-tests/moby-programs/image-equality.rkt @@ -0,0 +1,319 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "../../image/image.rkt") + +;; Tests on images. +;; +;; An image can be a circle, star, ns:rectangle, rectangle, triangle, ellipse, line, text, place-image, overlay, underlay + +(define a-circle (circle 20 'solid 'green)) +(define a-star (star 5 20 30 'solid 'blue)) +(define a-nw-rect (nw:rectangle 20 30 'solid 'turquoise)) +(define a-rect (rectangle 50 60 'outline 'black)) +(define a-triangle (triangle 50 'solid 'magenta)) +(define a-line (line 30 40 'red)) +(define a-text (text "hello world" 20 "black")) + + +;; Let's show these at the toplevel to make sure the drawing is working +;; ok +(printf "should be a circle:") a-circle +(printf "should be a star:") a-star +(printf "should be a nw:rectangle:") a-nw-rect +(printf "should be a rectangle:") a-rect +(printf "should be a triangle:") a-triangle +(printf "should be a line:") a-line +(printf "should be a text:") a-text + + +;; check-fail-contract: (-> void) -> void +;; Make sure we fail with a contract error. +(define (check-fail-contract thunk) + (with-handlers ([exn:fail:contract? void]) + (thunk) + (raise (format "failure expected: ~s" thunk)))) + + + +;; Now do image comparisons +(printf "running image comparison tests\n") + +;; circles +(check-expect (equal? (circle 20 'solid 'green) + (circle 20 'solid 'green)) + true) +(check-expect (equal? (circle 20 'solid 'green) + (circle 21 'solid 'green)) + false) +(check-expect (equal? (circle 20 'solid 'green) + (circle 20 'solid 'blue)) + false) +(check-fail-contract (lambda () (circle 20 "foobar" "green"))) +(check-fail-contract (lambda () (circle 20 "outline" "not-a-color"))) +(check-fail-contract (lambda () (circle 20 'green 'outline))) +(check-fail-contract (lambda () (circle 'green 'outline 20))) +(check-fail-contract (lambda () (circle))) +(check-fail-contract (lambda () (circle 20))) +(check-fail-contract (lambda () (circle 20 'outline))) +(check-fail-contract (lambda () (circle 20 'outline "black" "too-many-args"))) + + +;; star +(check-expect (equal? (star 20 10 60 'solid 'purple) + (star 20 10 60 'solid 'purple)) + true) +(check-expect (equal? (star 20 9 60 'solid 'purple) + (star 20 10 60 'solid 'purple)) + false) +(check-expect (equal? (star 20 10 60 'solid 'purple) + (star 20 10 49 'solid 'purple)) + false) +(check-expect (equal? (star 20 10 60 'solid 'purple) + (star 20 10 60 'outline 'purple)) + false) +(check-expect (equal? (star 20 10 60 'solid 'purple) + (star 20 10 60 'solid 'magenta)) + false) +(check-fail-contract (lambda () (star 20 10 60 "foobar" 'green))) +(check-fail-contract (lambda () (star 20 10 60 "outline" 'not-a-color))) +(check-fail-contract (lambda () (star 20 10 60 "green" 'outline))) +(check-fail-contract (lambda () (star 10 60 "green" 'outline 20))) +(check-fail-contract (lambda () (star))) +(check-fail-contract (lambda () (star 10))) +(check-fail-contract (lambda () (star 10 60))) +(check-fail-contract (lambda () (star 10 60 50))) +(check-fail-contract (lambda () (star 10 60 50 'outline))) +(check-fail-contract (lambda () (star 10 60 50 'outline 'green 'too-many-args))) + + +;; nw:rect +(check-expect (equal? (nw:rectangle 10 20 'solid 'black) + (nw:rectangle 10 20 'solid 'black)) + true) +(check-expect (equal? (nw:rectangle 20 10 'solid 'black) + (nw:rectangle 10 20 'solid 'black)) + false) +(check-expect (equal? (nw:rectangle 10 10 'solid 'black) + (nw:rectangle 10 20 'solid 'black)) + false) +(check-expect (equal? (nw:rectangle 10 20 'solid 'black) + (nw:rectangle 10 20 'outline 'black)) + false) +(check-expect (equal? (nw:rectangle 10 20 'solid 'black) + (nw:rectangle 10 20 'outline 'white)) + false) +(check-fail-contract (lambda () (nw:rectangle 10 20 "foobar" 'green))) +(check-fail-contract (lambda () (nw:rectangle 10 20 "outline" 'not-a-color))) +(check-fail-contract (lambda () (nw:rectangle 10 20 'green 'outline))) +(check-fail-contract (lambda () (nw:rectangle 20 'green 'outline 10))) +(check-fail-contract (lambda () (nw:rectangle))) +(check-fail-contract (lambda () (nw:rectangle 10))) +(check-fail-contract (lambda () (nw:rectangle 10 20))) +(check-fail-contract (lambda () (nw:rectangle 10 20 'solid))) +(check-fail-contract + (lambda () (nw:rectangle 10 20 'solid 'green 'too-many-args))) + + +;; rect +(check-expect (equal? (rectangle 10 20 'solid 'black) + (rectangle 10 20 'solid 'black)) + true) +(check-expect (equal? (rectangle 20 10 'solid 'black) + (rectangle 10 20 'solid 'black)) + false) +(check-expect (equal? (rectangle 10 10 'solid 'black) + (rectangle 10 20 'solid 'black)) + false) +(check-expect (equal? (rectangle 10 20 'solid 'black) + (rectangle 10 20 'outline 'black)) + false) +(check-expect (equal? (rectangle 10 20 'solid 'black) + (rectangle 10 20 'outline 'white)) + false) +(check-fail-contract (lambda () (rectangle 10 20 "foobar" 'green))) +(check-fail-contract (lambda () (rectangle 10 20 "outline" 'not-a-color))) +(check-fail-contract (lambda () (rectangle 10 20 'green 'outline))) +(check-fail-contract (lambda () (rectangle 20 'green 'outline 10))) +(check-fail-contract (lambda () (rectangle))) +(check-fail-contract (lambda () (rectangle 10))) +(check-fail-contract (lambda () (rectangle 10 20))) +(check-fail-contract (lambda () (rectangle 10 20 'solid))) +(check-fail-contract (lambda () (rectangle 10 20 'solid 'green 'too-many-args))) + + + +;; triangle +(check-expect (equal? (triangle 10 'solid 'green) + (triangle 10 'solid 'green)) + true) + +(check-expect (equal? (triangle 10 'solid 'green) + (triangle 9 'solid 'green)) + false) +(check-expect (equal? (triangle 10 'solid 'green) + (triangle 10 'outline 'green)) + false) +(check-expect (equal? (triangle 10 'solid 'green) + (triangle 10 'solid 'olive)) + false) +(check-fail-contract (lambda () (triangle 10 'foobar 'green))) +(check-fail-contract (lambda () (triangle 10 'outline 'not-a-color))) +(check-fail-contract (lambda () (triangle 10 'green 'outline))) +(check-fail-contract (lambda () (triangle 'green 'outline 10))) +(check-fail-contract (lambda () (triangle))) +(check-fail-contract (lambda () (triangle 'outline))) +(check-fail-contract (lambda () (triangle 10))) +(check-fail-contract (lambda () (triangle 10 'outline))) +(check-fail-contract (lambda () (triangle 10 'outline 'green 'too-many-args))) + + +;; line +(check-expect (equal? (line 10 20 'blue) + (line 10 20 'blue)) + true) +(check-expect (equal? (line 10 20 'blue) + (line 20 10 'blue)) + false) +(check-fail-contract (lambda () (line 10 20 'not-a-color))) +(check-fail-contract (lambda () (line 'not-a-color 20 10))) +(check-fail-contract (lambda () (line))) +(check-fail-contract (lambda () (line 10))) +(check-fail-contract (lambda () (line 10 20))) +(check-fail-contract (lambda () (line 10 20 "black" "too-many-args"))) + + +;; text +(check-expect (equal? (text "hello" 20 'yellow) + (text "hello" 20 'yellow)) + true) + +(check-expect (equal? (text "hello" 20 'yellow) + (text "hi" 20 'yellow)) + false) +(check-fail-contract (lambda () (text "hello"))) +(check-fail-contract (lambda () (text "hello" 20))) +(check-fail-contract (lambda () (text "hello" 20 'yellow 'too-many-args))) +(check-fail-contract (lambda () (text 'hi 20 'yellow))) +(check-fail-contract (lambda () (text "hello" 'yellow 20))) + + + + +;; empty scenes +(check-expect (empty-scene 10 20) + (empty-scene 10 20)) +(check-expect (equal? (empty-scene 10 20) + (empty-scene 11 20)) + false) +(check-fail-contract (lambda () (empty-scene 'one 'two))) +(check-fail-contract (lambda () (empty-scene 10 20 30))) +(check-fail-contract (lambda () (empty-scene 10))) + + +;; place images +(check-fail-contract (lambda () (place-image))) +(check-fail-contract (lambda () (place-image 10))) +(check-fail-contract (lambda () (place-image (circle 20 'solid 'green)))) +(check-fail-contract (lambda () (place-image (circle 20 'solid 'green) 10))) +(check-fail-contract (lambda () (place-image (circle 20 'solid 'green) 10 20))) +(check-fail-contract + (lambda () + (place-image (circle 20 'solid 'green) 10 20 (empty-scene 3 4) + "too-many-args"))) +(check-fail-contract + (lambda () + (place-image 10 20 (circle 20 'solid 'green) (empty-scene 3 4)))) + + +(check-expect (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100)) + (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100))) + +(check-expect (equal? (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100)) + (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100))) + true) + +(check-expect (equal? (place-image (circle 9 'solid 'green) + 50 + 50 + (empty-scene 100 100)) + (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100))) + false) + + +(check-expect (equal? (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100)) + (place-image (circle 10 'solid 'green) + 40 + 50 + (empty-scene 100 100))) + false) + +(check-expect (equal? (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100)) + (place-image (circle 10 'solid 'green) + 50 + 40 + (empty-scene 100 100))) + false) + +(check-expect (equal? (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 100)) + (place-image (circle 10 'solid 'green) + 50 + 50 + (empty-scene 100 99))) + false) + + + +;; overlay +(check-fail-contract (lambda () (overlay))) + +(check-expect (overlay (rectangle 10 20 'solid 'blue) + (circle 20 'solid 'green)) + (overlay (rectangle 10 20 'solid 'blue) + (circle 20 'solid 'green))) +(check-expect (equal? (overlay (rectangle 10 20 'solid 'blue) + (circle 20 'solid 'green)) + (overlay (circle 20 'solid 'green) + (rectangle 10 20 'solid 'blue))) + false) + + + +;; underlay +(check-fail-contract (lambda () (underlay))) +(check-expect (underlay (rectangle 10 20 'solid 'blue) + (circle 20 'solid 'green)) + (underlay (rectangle 10 20 'solid 'blue) + (circle 20 'solid 'green))) +(check-expect (equal? (underlay (rectangle 10 20 'solid 'blue) + (circle 20 'solid 'green)) + (underlay (circle 20 'solid 'green) + (rectangle 10 20 'solid 'blue))) + false) + + + + +(printf "ran image comparison tests\n") diff --git a/tests/older-tests/moby-programs/images.rkt b/tests/older-tests/moby-programs/images.rkt new file mode 100644 index 0000000..02024b6 --- /dev/null +++ b/tests/older-tests/moby-programs/images.rkt @@ -0,0 +1,71 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(printf "images.rkt\n") + + +(check-expect (image? 'blue) #f) +(check-expect (image? (circle 20 "solid" "green")) #t) + +"should be a solid green circle: " (circle 20 "solid" "green") + + +(check-expect (image=? (circle 50 "solid" "blue") + (rectangle 20 30 "outline" "turquoise")) + #f) +"should be an outline turquoise rectangle: " (rectangle 20 30 "outline" "turquoise") + + +;(check-expect (color? (make-color 3 4 5))) + +(check-expect (color-red (make-color 3 4 5)) 3) +(check-expect (color-green (make-color 3 4 5)) 4) +(check-expect (color-blue (make-color 3 4 5)) 5) + +(check-expect (image? (empty-scene 20 50)) true) +(check-expect (image=? (empty-scene 20 50) (empty-scene 20 50)) true) + +(check-expect (image? (place-image (circle 50 'solid 'blue) + 50 + 50 + (empty-scene 100 100))) + true) + +"should be a blue circle in a scene with a border: " (place-image (circle 50 'solid 'blue) + 50 + 50 + (empty-scene 100 100)) + + +"should be a text:" (text "hello world" 20 'black) +"should be a text as well:" (text (string-copy "hello world") 20 'black) + + +"should be a blue ellipse" (ellipse 100 200 "solid" "blue") + +"should be an image from a url:" (image-url "http://racket-lang.org/logo.png") +"should be an image from a url:" (open-image-url "http://racket-lang.org/logo.png") + + + +(check-expect (image? + (put-pinhole (rectangle 20 20 'solid 'green) 0 0)) + true) + +"should be an overlay" +(overlay (circle 20 'solid 'green) + (rectangle 10 20 'solid 'blue)) + +"should be an overlay/xy" +(overlay/xy (circle 20 'solid 'green) + 0 0 + (rectangle 10 20 'solid 'blue)) + +"should be an underlay" +(underlay (circle 20 'solid 'green) + (rectangle 10 20 'solid 'blue)) + +"should be an underlay/xy" +(underlay/xy (circle 20 'solid 'green) + 0 0 + (rectangle 10 20 'solid 'blue)) + diff --git a/tests/older-tests/moby-programs/js-big-bang-timer.rkt b/tests/older-tests/moby-programs/js-big-bang-timer.rkt new file mode 100644 index 0000000..70630c4 --- /dev/null +++ b/tests/older-tests/moby-programs/js-big-bang-timer.rkt @@ -0,0 +1,14 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(require "../../jsworld/jsworld.rkt") + + +(printf "js-big-bang-timer.rkt\n") +(printf "number should be counting up to ten\n") +(check-expect (big-bang 1 + (on-tick (lambda (w) + (printf "~s~n" w) + (add1 w)) + 1/4) + (stop-when (lambda (w) (= w 10)))) + 10) diff --git a/tests/older-tests/moby-programs/js-input.rkt b/tests/older-tests/moby-programs/js-input.rkt new file mode 100644 index 0000000..1f6a30d --- /dev/null +++ b/tests/older-tests/moby-programs/js-input.rkt @@ -0,0 +1,35 @@ +#lang s-exp "../../lang/base.rkt" + +(require "../../jsworld/jsworld.rkt") + + +(define (make-ingredient-checkbox-sexp ingredient) + (local [(define (on-check w v) + (cond + [v + (cons ingredient w)] + [else + (remove ingredient w)]))] + (list (js-div) + (list (js-text ingredient)) + (list (js-input "checkbox" + on-check + `(("value" ,ingredient))))))) + +(define c1 (make-ingredient-checkbox-sexp "mushrooms")) +(define c2 (make-ingredient-checkbox-sexp "green peppers")) +(define c3 (make-ingredient-checkbox-sexp "olives")) + +(define (draw w) + (list (js-div) + c1 + c2 + c3 + (list (js-text (format "The world is: ~s" w))))) + +(define (draw-css w) + '()) + + +(big-bang '() + (to-draw-page draw draw-css)) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/jsworld-effects.rkt b/tests/older-tests/moby-programs/jsworld-effects.rkt new file mode 100644 index 0000000..4138ff5 --- /dev/null +++ b/tests/older-tests/moby-programs/jsworld-effects.rkt @@ -0,0 +1,19 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "../../jsworld/define-effect.rkt") + +(define-effect effect:beep () + #:impl (lambda (w) + (printf "Beep!"))) + +"This is an effect: " (make-effect:beep) + +(check-expect (effect? (make-effect:beep)) #t) +(check-expect (effect-type? (make-effect:beep)) #f) +(check-expect (effect-type? struct:effect:beep) #t) +(check-expect (effect-type? (make-effect:beep)) #f) + + + +(big-bang 0 + (initial-effect (make-effect:beep)) + (stop-when (lambda (w) true))) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/jsworld.rkt b/tests/older-tests/moby-programs/jsworld.rkt new file mode 100644 index 0000000..8282c06 --- /dev/null +++ b/tests/older-tests/moby-programs/jsworld.rkt @@ -0,0 +1,145 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(require "../../jsworld/jsworld.rkt") +;; more jsworld tests + +(printf "jsworld.rkt\n") + +(check-expect (js-big-bang 1 (stop-when (lambda (x) true))) + 1) + + +"should be an empty page" +(void (big-bang 1 + (to-draw-page (lambda (x) + (empty-page)) + (lambda (x) '())) + (stop-when (lambda (x) true)))) + + +"should be another empty page" +(void (big-bang 1 + ;; check single-arity to-draw-page + (to-draw-page (lambda (x) + (empty-page))) + (stop-when (lambda (x) true)))) + + +"at this point, something should be moving on the screen." +(void (big-bang 1 + (on-tick (lambda (x) (+ x 5))) + ;; check single-arity to-draw-page + (to-draw-page (lambda (x) + (place-on-page + (if (>= x 500) + "I'm done" + "I'm moving!") + ;(circle 100 'solid 'blue) + (modulo x 300) + (modulo x 300) + (empty-page)))) + (stop-when (lambda (x) (>= x 500))) + (on-key (lambda (w k) + 1)))) + + +(void (initial-effect '())) + + +(check-expect (image-height (circle 20 'solid 'green)) + 40) + + +(check-expect (image-width (circle 30 'solid 'green)) + 60) + + +(check-expect (effect-type? 42) false) +(check-expect (effect? 42) false) +#;(check-expect (effect? '()) true) + + +"a button" +(void (big-bang 1 + (to-draw-page (lambda (x) + (list + (js-button (lambda (x) x)) + (list (js-text "a button"))))) + (stop-when (lambda (x) true)))) +"another button" +(void (big-bang 1 + (to-draw-page (lambda (x) + (list + (js-button! (lambda (x) x) + (lambda (x) '())) + (list (js-text "another button"))))) + (stop-when (lambda (x) true)))) + +"a js-img" +(void (big-bang 1 + (to-draw-page + (lambda (x) + (list + (js-img "http://racket-lang.org/logo.png")))) + (stop-when (lambda (x) true)))) + + +"a js-p" +(void (big-bang 1 + (to-draw-page + (lambda (x) + (list + (js-p) + (list (js-text "hello world"))))) + (stop-when (lambda (x) true)))) + + +(check-expect (key=? "a" "a") true) +(check-expect (key=? "a" "b") false) + + + + +"js-select" +(let () + (define (select-house w an-option) + an-option) + + (define a-select-element + (js-select (list "" + "Gryffindor" + "Hufflepuff" + "Ravenclaw" + "Slytherin") + select-house)) + + (define (draw w) + (list (js-div) + (list a-select-element) + (list (js-text (format "House: ~a" w))))) + + (define (draw-css w) + '()) + + (big-bang "" + (to-draw-page draw draw-css) + (stop-when (lambda (x) true)))) + + +(void (on-key! (lambda (w a-key) w) + (lambda (w a-key) '()))) + + +(void (on-tick! (lambda (w) w) + (lambda (w) '()))) + +(void (stop-when! (lambda (w) true) + (lambda (w) '()))) + + + +;; we need more effects +(void (world-with-effects '() 3)) + + +"jsworld.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/letrec.rkt b/tests/older-tests/moby-programs/letrec.rkt new file mode 100644 index 0000000..5e9453f --- /dev/null +++ b/tests/older-tests/moby-programs/letrec.rkt @@ -0,0 +1,50 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "../../lang/check-expect/test-expect.rkt") + +"letrec" + +(letrec ([even? (lambda (x) + (if (= x 0) + true + (odd? (sub1 x))))] + [odd? (lambda (x) + (if (= x 0) + false + (even? (sub1 x))))]) + (test-expect (even? 1024) true) + (test-expect (even? 1023) false) + (test-expect (even? 2172) true) + (test-expect (even? 2171) false)) + + + + +(letrec-values ([(even? odd?) + (values + (lambda (x) + (if (= x 0) + true + (odd? (sub1 x)))) + (lambda (x) + (if (= x 0) + false + (even? (sub1 x)))))]) + (test-expect (even? 1024) true) + (test-expect (even? 1023) false) + (test-expect (even? 2172) true) + (test-expect (even? 2171) false)) + + + + + +(letrec ([fact (lambda (x) + (if (= x 0) + 1 + (* x (fact (sub1 x)))))]) + (test-expect (fact 3) 6) + (test-expect (fact 4) 24) + (test-expect (fact 5) 120)) + + +"letrec.rkt end" diff --git a/tests/older-tests/moby-programs/list.rkt b/tests/older-tests/moby-programs/list.rkt new file mode 100644 index 0000000..03089db --- /dev/null +++ b/tests/older-tests/moby-programs/list.rkt @@ -0,0 +1,15 @@ +#lang s-exp "../../lang/wescheme.rkt" + + +"list tests" + +(check-expect (list* 4) + 4) + +(check-expect (list* 1 2 3) + (cons 1 (cons 2 3))) + +(check-expect (list* 1 2 '(3)) + (cons 1 (cons 2 (cons 3 empty)))) + +"end list tests" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/local.rkt b/tests/older-tests/moby-programs/local.rkt new file mode 100644 index 0000000..7d31bcd --- /dev/null +++ b/tests/older-tests/moby-programs/local.rkt @@ -0,0 +1,12 @@ +#lang s-exp "../../lang/wescheme.ss" + + +(printf "local.rkt\n") + +(check-expect (local [(define (f x) + (* x x)) + (define (g x) + (* x x x))] + (f (g (g (f 3))))) + + 150094635296999121) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/location.rkt b/tests/older-tests/moby-programs/location.rkt new file mode 100644 index 0000000..7b03594 --- /dev/null +++ b/tests/older-tests/moby-programs/location.rkt @@ -0,0 +1,18 @@ +#lang s-exp "../../lang/base.rkt" + +(require "../../lang/location.rkt") +(require "../../lang/check-expect/check-expect.rkt") + +"location.rkt" + + +(check-expect (location? (make-location "location.rkt" 88 7 0 37)) + true) + +"The following should be a location " +(make-location "location.rkt" 88 7 0 37) + + + +"location.rkt end" +(run-tests) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/math.rkt b/tests/older-tests/moby-programs/math.rkt new file mode 100644 index 0000000..a549abb --- /dev/null +++ b/tests/older-tests/moby-programs/math.rkt @@ -0,0 +1,71 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"math.rkt" + +(check-expect (number? pi) true) +(check-expect (number? e) true) + +(check-within pi 22/7 0.1) +(check-within e 2.718 0.1) + +(check-expect (=~ 3 4 1) true) +(check-expect (=~ 3 4 .9) false) + + +(check-expect (< 3 4) true) +(check-expect (< 4 3) false) +(check-expect (< 3 3) false) + +(check-expect (> 3 4) false) +(check-expect (> 4 3) true) +(check-expect (> 4 4) false) + +(check-expect (<= 3 4) true) +(check-expect (<= 4 3) false) +(check-expect (<= 3 3) true) + +(check-expect (>= 3 4) false) +(check-expect (>= 4 3) true) +(check-expect (>= 4 4) true) + + +(check-expect (abs 3) 3) +(check-expect (abs -3) 3) + +(check-expect (quotient 42 2) 21) +(check-expect (remainder 42 2) 0) + +(check-expect (modulo 5 3) 2) + +(check-expect (max 3 4 5) 5) +(check-expect (max 5) 5) + +(check-expect (min 3 4 5) 3) +(check-expect (min 5) 5) + + +(check-expect (gcd 3 4) 1) +(check-expect (gcd 5 10 20) 5) + + +(check-expect (lcm 3 4) 12) +(check-expect (lcm 5 10 20) 20) + + +(check-expect (floor 3) 3) +(check-expect (ceiling 3) 3) + +(check-expect (round 3) 3) +(check-expect (round 3) 3) + +(check-expect (floor 3.5) 3.0) +(check-expect (ceiling 3.5) 4.0) + +(check-expect (floor -3.5) -4.0) +(check-expect (ceiling -3.5) -3.0) + + + + + +"math.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/misc.rkt b/tests/older-tests/moby-programs/misc.rkt new file mode 100644 index 0000000..3f1ea8e --- /dev/null +++ b/tests/older-tests/moby-programs/misc.rkt @@ -0,0 +1,1117 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(require "../../lang/check-expect/test-expect.rkt") +"misc.rkt" + +;; The tests here make sure that all of the functions +;; that we provide are at least exercised once. +;; They are not meant to be systematic. + + + +(check-expect (procedure? +) true) +(check-expect (procedure? 1432) false) + + +(check-expect (pair? 1) false) +(check-expect (pair? empty) false) +(check-expect (pair? '(hello)) true) + + +(check-expect (cons? 1) false) +(check-expect (cons? empty) false) +(check-expect (cons? '(hello)) true) + + +(check-expect (empty? 1) false) +(check-expect (empty? empty) true) +(check-expect (empty? '(hello)) false) + +(check-expect (null? 1) false) +(check-expect (null? empty) true) +(check-expect (null? '(hello)) false) + + +(check-expect (undefined? 1) false) +(check-expect (undefined? empty) false) +(check-expect (undefined? '(hello)) false) +(check-expect (undefined? (letrec ([x x]) x)) true) + + + +(check-expect (void? 1) false) +(check-expect (void? empty) false) +(check-expect (void? '(hello)) false) +(check-expect (void? (letrec ([x x]) x)) false) +(check-expect (void? (void)) true) +(check-expect (void? (void (letrec ([x x]) x))) true) + + +(check-expect (symbol? 'hello) true) +(check-expect (symbol? 3) false) +(check-expect (symbol? "a string") false) + +(check-expect (string? 'hello) false) +(check-expect (string? 3) false) +(check-expect (string? "a string") true) + + +(check-expect (char? 'hello) false) +(check-expect (char? 3) false) +(check-expect (char? "a string") false) +(check-expect (char? #\x) true) + + +(check-expect (boolean? 'hello) false) +(check-expect (boolean? 3) false) +(check-expect (boolean? "a string") false) +(check-expect (boolean? #\x) false) +(check-expect (boolean? true) true) +(check-expect (boolean? #t) true) +(check-expect (boolean? false) true) +(check-expect (boolean? false) true) + +(check-expect (vector? 'hello) false) +(check-expect (vector? 3) false) +(check-expect (vector? "a string") false) +(check-expect (vector? #\x) false) +(check-expect (vector? true) false) +(check-expect (vector? (vector 3 4)) true) +(check-expect (vector? #(hello world)) true) + + + +(define-struct my-struct ()) +(check-expect (struct? 'hello) false) +(check-expect (struct? 3) false) +(check-expect (struct? "a string") false) +(check-expect (struct? #\x) false) +(check-expect (struct? true) false) +(check-expect (struct? (vector 3 4)) false) +(check-expect (struct? (make-my-struct)) true) + + +(check-expect (immutable? '(42)) false) + + + +(check-expect (eof-object? 'hello) false) +(check-expect (eof-object? eof) true) + + + +(check-expect (bytes? 'hello) false) +(check-expect (bytes? 3) false) +(check-expect (bytes? "a string") false) +(check-expect (bytes? #\x) false) +(check-expect (bytes? true) false) +(check-expect (bytes? (vector 3 4)) false) +(check-expect (bytes? (make-my-struct)) false) +(check-expect (bytes? (bytes 1 2 3 4)) true) + + +(let loop ([i -300]) + (when (< i 300) + (begin + (test-expect (byte? i) + (and (<= 0 i) (< i 256))) + (loop (add1 i))))) + + +(check-expect (number? 'hello) false) +(check-expect (number? 3) true) +(check-expect (number? "a string") false) +(check-expect (number? #\x) false) +(check-expect (number? true) false) +(check-expect (number? (vector 3 4)) false) +(check-expect (number? (make-my-struct)) false) +(check-expect (number? (bytes 1 2 3 4)) false) + + +(check-expect (complex? 'hello) false) +(check-expect (complex? 3) true) +(check-expect (complex? "a string") false) +(check-expect (complex? #\x) false) +(check-expect (complex? true) false) +(check-expect (complex? (vector 3 4)) false) +(check-expect (complex? (make-my-struct)) false) +(check-expect (complex? (bytes 1 2 3 4)) false) + + +(check-expect (real? 'hello) false) +(check-expect (real? 3) true) +(check-expect (real? 3+0.0i) false) +(check-expect (real? "a string") false) +(check-expect (real? #\x) false) +(check-expect (real? true) false) +(check-expect (real? (vector 3 4)) false) +(check-expect (real? (make-my-struct)) false) +(check-expect (real? (bytes 1 2 3 4)) false) + + +(check-expect (rational? 'hello) false) +(check-expect (rational? 3) true) +(check-expect (rational? 3/4) true) +(check-expect (rational? 3.2) true) +(check-expect (rational? 3+0.0i) false) +(check-expect (rational? "a string") false) +(check-expect (rational? #\x) false) +(check-expect (rational? true) false) +(check-expect (rational? (vector 3 4)) false) +(check-expect (rational? (make-my-struct)) false) +(check-expect (rational? (bytes 1 2 3 4)) false) + + +(check-expect (integer? 'hello) false) +(check-expect (integer? 3) true) +(check-expect (integer? 3/4) false) +(check-expect (integer? 3.2) false) +(check-expect (integer? 3+0.0i) false) +(check-expect (integer? "a string") false) +(check-expect (integer? #\x) false) +(check-expect (integer? true) false) +(check-expect (integer? (vector 3 4)) false) +(check-expect (integer? (make-my-struct)) false) +(check-expect (integer? (bytes 1 2 3 4)) false) + + +(check-expect (exn:fail:contract? (with-handlers ([void identity]) (odd? 'hello))) + true) +(check-expect (odd? 3) true) +(check-expect (odd? 2) false) +(check-expect (exn:fail:contract? (with-handlers ([void identity]) (odd? 3/2))) + true) + + +(check-expect (exn:fail:contract? (with-handlers ([void identity]) (even? 'hello))) + true) +(check-expect (even? 3) false) +(check-expect (even? 2) true) +(check-expect (exn:fail:contract? (with-handlers ([void identity]) (even? 3/2))) + true) + + + +(check-expect (exn:fail:contract? (with-handlers ([void identity]) (zero? 'hello))) + true) +(check-expect (zero? 3) false) +(check-expect (zero? 2) false) +(check-expect (zero? 0) true) +(check-expect (zero? 0.0) true) +(check-expect (zero? 0.0+0.0i) true) +(check-expect (zero? 3/2) false) + + +(check-expect (positive? 3) true) +(check-expect (positive? 0) false) +(check-expect (positive? -3) false) + + +(check-expect (negative? 3) false) +(check-expect (negative? 0) false) +(check-expect (negative? -3) true) + + +(check-expect (box? 3) false) +(check-expect (box? (box 3)) true) + + +(check-expect (hash? 3) false) +(check-expect (hash? (make-hash)) true) + +(check-expect (eq? 'hello 'world) false) +(check-expect (eq? 'hello 'hello) true) +(check-expect (eq? (expt 2 500) (expt 2 500)) false) + + +(check-expect (eqv? 'hello 'world) false) +(check-expect (eqv? 'hello 'hello) true) +(check-expect (eqv? (expt 2 500) (expt 2 500)) true) +(check-expect (eqv? (expt 2 500) (add1 (expt 2 500))) false) + + +(check-expect (equal? "hello" "hello") true) +(check-expect (equal? "hello" 17) false) + + +(check-expect (equal~? "hello" "hello" 0.1) true) +(check-expect (equal~? 16 17 1) true) +(check-expect (equal~? 16 17 .1) false) +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) (equal~? 16 17 'foo))) + true) + + +(check-expect (false? false) true) +(check-expect (false? #f) true) +(check-expect (false? true) false) +(check-expect (false? 3) false) +(check-expect (false? "") false) +(check-expect (false? 0) false) +(check-expect (false? "false") false) + + + +(check-expect (boolean=? false true) false) +(check-expect (boolean=? false false) true) +(check-expect (boolean=? true true) true) +(check-expect (boolean=? true false) false) +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (boolean=? 3 false))) + true) + + + +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (symbol=? false 'false))) + true) +(check-expect (symbol=? 'hello 'world) false) +(check-expect (symbol=? 'hello 'hello) true) + + +(check-expect + (call-with-current-continuation + (lambda (return) + (return 42) + (error 'should-not-be-here))) + 42) + + +(check-expect + (call/cc + (lambda (return) + (return 42) + (error 'should-not-be-here))) + 42) + + + + +(check-expect (ormap even? '(1 3 5 7 9)) #f) +(check-expect (ormap even? '(1 3 5 8 9)) true) + + +(check-expect (continuation-prompt-tag? + (make-continuation-prompt-tag)) #t) + + +(check-expect (string->symbol "a-symbol") 'a-symbol) + + +(check-expect (append '(1 2 3) 4) + (cons 1 (cons 2 (cons 3 4)))) + +(check-expect (append '(1 2 3) '(4)) + (list 1 2 3 4)) + + +(check-expect (list-ref '(a e i o u) 0) 'a) +(check-expect (list-ref '(a e i o u) 1) 'e) +(check-expect (list-ref '(a e i o u) 2) 'i) +(check-expect (list-ref '(a e i o u) 3) 'o) +(check-expect (list-ref '(a e i o u) 4) 'u) +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (list-ref '(a e i o u) 5))) + true) +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (list-ref '(a e i o u) -1))) + true) + + +(check-expect (memq 2 (list 1 2 3 4)) '(2 3 4)) +(check-expect (memq 9 (list 1 2 3 4)) #f) + + +(check-expect (memv 2 (list 1 2 3 4)) + '(2 3 4)) +(check-expect (memv 9 (list 1 2 3 4)) + #f) + + +(check-expect (assoc 3 (list (list 1 2) (list 3 4) (list 5 6))) + '(3 4)) +(check-expect (assoc 9 (list (list 1 2) (list 3 4) (list 5 6))) + #f) + + +(check-expect (assv 3 (list (list 1 2) (list 3 4) (list 5 6))) + '(3 4)) + +(check-expect (cdar '((7 6 5 4 3 2 1) 8 9)) + '(6 5 4 3 2 1)) +(check-expect (cadr '((1 2) 3 4)) + 3) +(check-expect (caar '((1 2) 3 4)) + 1) + +(check-expect (cddr '(2 1)) + '()) + +(check-expect (caaar '(((6 5 4 3 2 1) 7) 8 9)) + 6) + +(check-expect (caadr '(9 (7 6 5 4 3 2 1) 8)) + 7) + +(check-expect (cadar '((7 6 5 4 3 2 1) 8 9)) + 6) +(check-expect (caddr '(3 2 1)) + 1) + +(check-expect (cdaar '(((6 5 4 3 2 1) 7) 8 9)) + '(5 4 3 2 1)) + +(check-expect (cdadr '(9 (7 6 5 4 3 2 1) 8)) + '(6 5 4 3 2 1)) + +(check-expect (cddar '((7 6 5 4 3 2 1) 8 9)) + '(5 4 3 2 1)) + +(check-expect (cdddr '(3 2 1)) + '()) +(check-expect (cadddr '(4 3 2 1)) + 1) + + +(check-expect (list? empty) true) +(check-expect (list? '(1 2)) true) +(check-expect (list? '(1 . 2)) false) + + +(let ([ht (make-hash)]) + (hash-set! ht 'name "danny") + (test-expect (hash-ref ht 'name) + "danny") + (test-expect (hash-map ht (lambda (k v) (list k v))) + '((name "danny")))) + + + +(let* ([holder (make-placeholder #f)] + [template `(hello world ,holder)]) + (test-expect (make-reader-graph template) + '(hello world #f)) + (placeholder-set! holder "test") + (test-expect (make-reader-graph template) + '(hello world "test"))) + + +(check-expect (exact? #i3.42) #f) +(check-expect (exact? 3) #t) +(check-expect (exn:fail:contract? (with-handlers ([void identity]) (exact? "not a number"))) true) + + + +(check-expect (log 1) 0) +(check-within (log 6) 1.791759469228055 0.0001) +(check-within (tan 1) 1.5574077246549023 0.0001) +(check-expect (cos 0) 1) +(check-within (cos 1) 0.5403023058681398 0.0001) +(check-expect (acos 1) 0) +(check-within (acos 0) 1.5707963267948966 0.0001) + +(check-expect (magnitude 5) 5) +(check-expect (magnitude 0+5i) 5) +(check-within (magnitude 5+5i) 7.0710678118654755 0.0001) + +(check-expect (string->int "3") 51) + + +(check-expect (string-upper-case? "hello") false) +(check-expect (string-upper-case? "Hello") false) +(check-expect (string-upper-case? "HELLO") true) + +(check-expect (string-lower-case? "hello") true) +(check-expect (string-lower-case? "Hello") false) +(check-expect (string-lower-case? "HELLO") false) + + +(check-expect (string-length "") 0) +(check-expect (string-length "abcdefghijklmnopqrstuvwxyz") 26) + + +(check-expect (string-ith "wpi" 0) "w") +(check-expect (string-ith "wpi" 1) "p") +(check-expect (string-ith "wpi" 2) "i") +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (string-ith "wpi" 3))) + true) +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (string-ith "wpi" -1))) + true) + +(let ([p (make-posn 3 4)]) + (test-expect (posn? p) true) + (test-expect (posn? 42) false) + (test-expect (posn-x p) 3) + (test-expect (posn-y p) 4) + (set-posn-x! p 17) + (test-expect (posn-x p) 17) + (test-expect p (make-posn 17 4)) + (set-posn-y! p -23) + (test-expect p (make-posn 17 -23))) + + +(check-expect (replicate 3 "hi") "hihihi") +(check-expect (replicate 0 "hi") "") + +(check-expect (number->string 42) "42") +(check-expect (number->string -42) "-42") +(check-expect (number->string -0.0) "-0.0") +(check-expect (number->string +inf.0) "+inf.0") +(check-expect (number->string -inf.0) "-inf.0") +(check-expect (number->string 3/4) "3/4") + + +(check-expect (implode '("a" "b" "c")) "abc") + + +(check-expect (string->number "42") 42) +(check-expect (string->number "-42") -42) +(check-expect (string->number "-0.0") -0.0) +(check-expect (string->number "+inf.0") +inf.0) +(check-expect (string->number "-inf.0") -inf.0) +(check-expect (string->number "3/4") 3/4) + +(check-expect (symbol->string 'hello-again) "hello-again") + + +(check-expect (list-tail '(a b c d e) 3) + '(d e)) +(check-expect (list-tail (list 1 2 3 4) 2) + '(3 4)) + + +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (list-tail (list 1 2 3 4) 20))) + true) + + +(check-expect (member 2 (list 1 2 3 4)) + #t) +(check-expect (member 9 (list 1 2 3 4)) + #f) + + +(let ([b (box-immutable 42)]) + (test-expect (unbox b) 42) + (test-expect (exn:fail:contract? + (with-handlers ([void identity]) + (set-box! b 16))) + true)) + + + +(let ([ht (make-hasheq)]) + (hash-set! ht 'name "danny") + (test-expect (hash-ref ht 'name) + "danny") + (test-expect (hash-map ht (lambda (k v) (list k v))) + '((name "danny"))) + (hash-remove! ht 'name) + (test-expect (hash-map ht (lambda (k v) (list k v))) + '())) + + + +(check-expect (inexact? 42) false) +(check-expect (inexact? 22/7) false) +(check-expect (inexact? pi) true) +(check-expect (inexact? e) true) + + +(check-expect (numerator 22/7) 22) +(check-expect (denominator 22/7) 7) + +(check-expect (numerator 234) 234) + +(check-expect (integer-sqrt 4) 2) + + +(check-expect (make-rectangular 3 4) + 3+4i) + + + +(check-within (exp 3) + #i20.08553692318767 + 0.0001) + + +(check-expect (angle 2984) 0) +(check-expect (angle #i0.0) 0) +(check-expect (angle #i0.234) 0) +(check-within (angle 1+5i) 1.373400766945016 0.00001) + + + + +(let ([ht (make-hasheq)] + [l '()]) + (hash-set! ht 'name "danny") + (test-expect (hash-ref ht 'name) + "danny") + (hash-for-each ht (lambda (k v) (set! l (cons (list k v) l)))) + (test-expect l '((name "danny")))) + +(check-expect (string-numeric? "928173419") true) +(check-expect (string-numeric? "") true) +(check-expect (string-numeric? "x") false) + + + +(check-expect (string>? "Apple" "apple") + #f) +(check-expect (string>? "apple" "Apple") + #t) +(check-expect (string>? "c" "b" "a") + #t) + +(check-expect (string>=? "Apple" "apple") + #f) +(check-expect (string>=? "apple" "Apple") + #t) +(check-expect (string>=? "c" "b" "b") + #t) + +(check-expect (string-ci=? "Apple" "apple") + #t) +(check-expect (string-ci=? "a" "a" "a") + #t) + + +(check-expect (string-ci? "Apple" "apple") + #f) +(check-expect (string-ci>? "banana" "Apple") + #t) +(check-expect (string-ci>? "c" "b" "a") + #t) + + +(check-expect (string-ci>=? "Apple" "apple") + #t) +(check-expect (string-ci>=? "apple" "Apple") + #t) +(check-expect (string-ci>=? "c" "b" "b") + #t) + + +(check-expect (string->list "Apple") + '(#\A #\p #\p #\l #\e)) +(check-expect (list->string (list #\A #\p #\p #\l #\e)) + "Apple") + + +(check-expect (build-string 5 (lambda (i) (integer->char (+ i 97)))) + "abcde") + +(check-expect (string-append "Apple" "Banana") + "AppleBanana") + +(let ([s (string #\A #\p #\p #\l #\e)]) + (string-fill! s #\q) + (test-expect s "qqqqq")) + +(check-expect (substring "Apple" 1 3) + "pp") +(check-expect (substring "Apple" 1) + "pple") + + + +(check-expect (bytes=? #"Apple" #"apple") + #f) + +(check-expect (bytes=? #"Apple" #"Apple") + #t) +(check-expect (bytes=? #"a" #"as" #"a") + #f) + +(check-expect (bytes->list #"Apple") + '(65 112 112 108 101)) + + + +(check-expect (truncate 17/4) + 4) +(check-expect (truncate -17/4) + -4) +(check-expect (truncate #i2.5) + #i2.0) +(check-expect (truncate #i-2.5) + #i-2.0) + + +(check-expect (eq? js-big-bang big-bang) #t) + +(check-expect (bytes-append #"Apple" #"Banana") + #"AppleBanana") + +(check-expect (bytes=? #"Apple" #"apple") + #f) +(check-expect (bytes=? #"a" #"as" #"a") + #f) + +(check-expect (bytes? #"Apple" #"apple") + #f) +(check-expect (bytes>? #"apple" #"Apple") + #t) +(check-expect (bytes>? #"c" #"b" #"a") + #t) + +(check-expect (bytes-length #"Apple") + 5) + +(check-expect (make-bytes 5 65) + #"AAAAA") + +(check-expect (bytes 65 112 112 108 101) + #"Apple") + + + +;; example and EXAMPLES are aliases to check-expect. +(example 3 3) +(EXAMPLE 3 3) + + +(check-expect (foldr cons '() '(1 2 3 4)) + '(1 2 3 4)) +(check-expect (foldr (lambda (v l) (cons (add1 v) l)) '() '(1 2 3 4)) + '(2 3 4 5)) + + +(check-expect (foldl cons '() '(1 2 3 4)) + '(4 3 2 1)) +(check-expect (foldl + 0 '(1 2 3 4)) + 10) +(check-expect (foldl (lambda (a b result) + (* result (- a b))) + 1 + '(1 2 3) + '(4 5 6)) + -27) + + + +(check-expect (memf (lambda (arg) + (> arg 9)) + '(7 8 9 10 11)) + '(10 11)) + + +(check-expect (build-list 10 values) + '(0 1 2 3 4 5 6 7 8 9)) +(check-expect (build-list 5 (lambda (x) (* x x))) + '(0 1 4 9 16)) + + + + + +(check-expect (char=? #\A #\a) + #t) +(check-expect (char-ci>=? #\a #\A) + #t) +(check-expect (char-ci>=? #\c #\b #\b) + #t) + +(check-expect (char=? #\a #\a) + #t) +(check-expect (char=? #\a #\A #\a) + #f) + +(check-expect (char<=? #\A #\a) + #t) +(check-expect (char<=? #\a #\A) + #f) +(check-expect (char<=? #\a #\b #\b) + #t) + + +(check-expect (char>? #\A #\a) + #f) +(check-expect (char>? #\a #\A) + #t) +(check-expect (char>? #\c #\b #\a) + #t) + + +(check-expect (char-alphabetic? #\a) true) +(check-expect (char-alphabetic? #\0) false) + +(check-expect (char-upper-case? #\a) false) +(check-expect (char-upper-case? #\A) true) +(check-expect (char-upper-case? #\0) false) + +(check-expect (char-lower-case? #\a) true) +(check-expect (char-lower-case? #\A) false) +(check-expect (char-lower-case? #\0) false) + + +(check-expect (char-ci? #\A #\a) + #f) +(check-expect (char-ci>? #\b #\A) + #t) +(check-expect (char-ci>? #\c #\b #\a) + #t) + +(check-expect (char-whitespace? #\newline) + true) +(check-expect (char-whitespace? #\a) + false) + + +(check-expect (char-numeric? #\a) + false) +(check-expect (char-numeric? #\0) + true) +(check-expect (andmap char-numeric? + '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)) + true) + + + +(check-expect (char-upcase #\a) + #\A) +(check-expect (char-upcase #\space) + #\space) + +(check-expect (char-downcase #\A) + #\a) +(check-expect (char-downcase #\space) + #\space) + +(check-expect (char->integer #\A) + 65) + +(check-expect (char-ci<=? #\A #\a) + #t) +(check-expect (char-ci<=? #\a #\A) + #t) +(check-expect (char-ci<=? #\a #\b #\b) + #t) + + +(check-expect (char>=? #\A #\a) + #f) +(check-expect (char>=? #\a #\A) + #t) +(check-expect (char>=? #\c #\b #\b) + #t) + +(check-expect (bytes->immutable-bytes (bytes 65 65 65)) + #"AAA") +(let ([b (bytes->immutable-bytes (make-bytes 5 65))]) + (test-expect (bytes->immutable-bytes b) + #"AAAAA") + (test-expect (eq? (bytes->immutable-bytes b) b) + #t)) + +(check-expect (subbytes #"Apple" 1 3) + #"pp") +(check-expect (subbytes #"Apple" 1) + #"pple") + + +(check-expect (bytes-copy #"Apple") + #"Apple") + + +(check-expect (bytes-ref #"Apple" 0) + 65) + + +(let ([s (bytes 65 112 112 108 101)]) + (bytes-set! s 4 121) + (test-expect s + #"Apply")) + + +(let ([s (bytes 65 112 112 108 101)]) + (bytes-fill! s 113) + (test-expect s + #"qqqqq")) + + + +(check-expect (argmax car '((3 pears) (1 banana) (2 apples))) + '(3 pears)) +(check-expect (argmax car '((3 pears) (3 oranges))) + '(3 pears)) + +(check-expect (argmin car '((3 pears) (1 banana) (2 apples))) + '(1 banana)) +(check-expect (argmin car '((1 banana) (1 orange))) + '(1 banana)) + + +(check-within (asin 0.25) 0.25268025514207865 0.000001) +(check-within (real-part (asin 1.0+5.0i)) + 0.1937931365549321 + 0.000001) +(check-within (imag-part (asin 1.0+5.0i)) + 2.3309746530493123 + 0.000001) + + +(check-expect (cosh 0) 1.0) +(check-within (cosh 1) 1.5430806348152437 0.000001) + + + + +(check-expect (assq 3 (list (list 1 2) (list 3 4) (list 5 6))) + '(3 4)) + + +(check-expect (conjugate 1) + 1) +(check-expect (conjugate 3+4i) + 3-4i) + + + +(let ([make-nums (lambda (n) + (do [(x n (- x 1)) (lst (list) (cons x lst))] + ((= x 0) + lst)))]) + (test-expect (make-nums 3) + '(1 2 3))) + + +(check-expect (first '(1 2 3 4 5 6 7 8 9 10)) + 1) +(check-expect (rest '(1 2 3 4 5 6 7 8 9 10)) + '(2 3 4 5 6 7 8 9 10)) +(check-expect (second '(1 2 3 4 5 6 7 8 9 10)) + 2) +(check-expect (third '(1 2 3 4 5 6 7 8 9 10)) + 3) + +(check-expect (fourth '(1 2 3 4 5 6 7 8 9 10)) + 4) + +(check-expect (fifth '(1 2 3 4 5 6 7 8 9 10)) + 5) + +(check-expect (sixth '(1 2 3 4 5 6 7 8 9 10)) + 6) +(check-expect (seventh '(1 2 3 4 5 6 7 8 9 10)) + 7) +(check-expect (eighth '(1 2 3 4 5 6 7 8 9 10)) + 8) + + + +(check-expect (sgn 10) + 1) +(check-expect (sgn #i-10.0) + #i-1.0) +(check-expect (sgn 0) + 0) + + + +(check-within (sin 3.14159) + 2.65358979335273e-06 + 0.000001) +(check-within (real-part (sin 1.0+5.0i)) + 62.44551846769653 + 0.0000001) +(check-within (imag-part (sin 1.0+5.0i)) + 40.0921657779984 + 0.0000001) + + + +(let () + (define-values (x y z) (values 3 4 5)) + (test-expect x 3) + (test-expect y 4) + (test-expect z 5)) + + + +(check-expect (exact->inexact 1) + #i1.0) +(check-expect (exact->inexact #i1.0) + #i1.0) + + +(check-expect (explode "hello") + '("h" "e" "l" "l" "o")) +(check-expect (explode "") + '()) + + +(check-expect (filter positive? '(1 -2 3 4 -5)) + '(1 3 4)) + + +(check-expect (int->string 50) + "2") + +(check-expect (let*-values ([(x y) (values + (quotient 10 3) + (remainder 10 3))] + [(z) (list y x)]) + z) + '(1 3)) + +(check-expect (list->bytes (list 65 112 112 108 101)) + #"Apple") +(check-expect (list->bytes (list)) + #"") + + +(check-within (real-part (make-polar 10 (* pi 1/2))) + #i6.123233995736766e-16 + #i0.00001) +(check-within (imag-part (make-polar 10 (* pi 1/2))) + #i10.0 + #i0.00001) + + +(check-expect (sinh 0) + 0) +(check-within (sinh 1) + #i1.1752011936438014 + 0.000001) + + +(check-expect (sort '(1 3 4 2) <) + '(1 2 3 4)) + +(check-expect (quicksort '("aardvark" "dingo" "cow" "bear") stringimmutable-string "hello") + "hello") +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (string-set! (string->immutable-string "x") + 0 + #\y))) + true) +(check-expect (exn:fail:contract? + (with-handlers ([void identity]) + (string-set! "x" + 0 + #\y))) + true) +(let ([x (string-copy "x")]) + (string-set! x 0 #\X) + (test-expect x "X")) + + + +(check-expect (make-string 5 #\z) + "zzzzz") +(check-expect (make-string 0 #\z) + "") + +(check-expect (make-vector 5 #\x) + #(#\x #\x #\x #\x #\x)) + + +(check-expect (string-alphabetic? "hello") + true) +(check-expect (string-alphabetic? "") + true) +(check-expect (string-alphabetic? "hello world") + false) + + +(check-expect (string-whitespace? "hello") + false) +(check-expect (string-whitespace? "") + true) +(check-expect (string-whitespace? " ") + true) +(check-expect (string-whitespace? " \t \n ") + true) +(check-expect (string-whitespace? "hello world") + false) + + +(check-expect (string-ref "Apple" 0) + #\A) + +(check-expect (string<=? "Apple" "apple") + #t) +(check-expect (string<=? "apple" "Apple") + #f) +(check-expect (string<=? "a" "b" "b") + #t) + + + + +(printf "Please ignore the time output (just exercising the function): ") +(time (void)) + + + +(check-expect (string-append (string-copy "hello") + (string-copy "world")) + "helloworld") +(check-expect (string-append (string-copy "hello") + (string-copy "world")) + (string-copy "helloworld")) + + + + +"misc.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/more-jsworld.ss b/tests/older-tests/moby-programs/more-jsworld.ss new file mode 100644 index 0000000..dd86367 --- /dev/null +++ b/tests/older-tests/moby-programs/more-jsworld.ss @@ -0,0 +1,118 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"more-jsworld.rkt" + +;; Fill me in with automated tests for jsworld... +;; This file is intentionally with an '.ss' suffix +;; to see if we've also fixed an issue with module names. + + +;; The tests below make sure that mutable strings pose no issue +;; to the jsworld functions. + + +;; Thanks to William Zimrin and Tiberiu-Lucian Florea +;; for this test case. +(big-bang empty + (to-draw-page + (lambda (x) + (list (js-div '(("id" "div"))) + (list (js-text (string-append "hello"))))) + (lambda (x) + `((,(string-append "div") ,(list (string-append "border") (string-append "3px black solid")))))) + (stop-when (lambda (x) true))) + + + + + + +(local [ + (define (refresh w form-val) + form-val) + + (define input-node + (js-input (string-append "text") refresh '(("id" "myname")))) + + (define (draw w) + (list (js-div) + (list (js-div) (list (js-text (format "I see: ~s~n" w)))) + (list (js-div) (list input-node)))) + + (define (draw-css w) + '())] + + (big-bang "" + (to-draw-page draw draw-css) + (stop-when (lambda (x) true)))) + + + +(define true-f (lambda (x) true)) + + +(let ([draw (lambda (w) + (list (js-img (string-append + "http://racket-lang.org/logo.png"))))]) + (big-bang 0 + (to-draw-page draw) + (stop-when true-f))) + + + + + +(local [ + (define (select-house w an-option) + an-option) + + (define a-select-element + (js-select (list (string-append "") + (string-append "Gryffindor") + "Hufflepuff" + "Ravenclaw" + (string-append "Slytherin")) + select-house)) + + (define (draw w) + (list (js-div) + (list a-select-element) + (list (js-text (format "House: ~a" w))))) + + (define (draw-css w) + '())] + + (big-bang "" + (to-draw-page draw draw-css) + (stop-when true-f))) + + + + + + + + + + +(big-bang 0 + (stop-when (lambda (x) true)) + (to-draw-page (lambda (x) + (list (js-div) + (list + (js-input "checkbox" + (lambda (x y) x) + '(("checked" true))));This checkbox is checked + (list + (js-input "checkbox" + (lambda (x y) x) + '(("checked" false))));This checkbox is checked + (list + (js-input "checkbox" + (lambda (x y) x) + '(("value" true))));This checkbox is not checked + (list + (js-input "checkbox" + (lambda (x y) x) + '(("value" false))))));This checkbox is not checked + (lambda (x) empty))) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/permissions.rkt b/tests/older-tests/moby-programs/permissions.rkt new file mode 100644 index 0000000..99ce99a --- /dev/null +++ b/tests/older-tests/moby-programs/permissions.rkt @@ -0,0 +1,10 @@ +#lang s-exp "../../lang/base.rkt" + +;; Any program that's compiled with require-permission should have +;; the permissions of the module as part of the module record. + +(printf "permissions.rkt\n") + +(require "../../permissions/require-permission.rkt") + +(require-permission "network") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/quasiquote.rkt b/tests/older-tests/moby-programs/quasiquote.rkt new file mode 100644 index 0000000..4f7a812 --- /dev/null +++ b/tests/older-tests/moby-programs/quasiquote.rkt @@ -0,0 +1,9 @@ +#lang s-exp "../../lang/wescheme.ss" + +(printf "quasiquote.rkt\n") + +(define name "danny") +(define roommates (list "guillaume" "isis" "andy")) + +(check-expect `(my name is ,name and I lived with ,@roommates) + '(my name is "danny" and I lived with "guillaume" "isis" "andy")) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/raise.rkt b/tests/older-tests/moby-programs/raise.rkt new file mode 100644 index 0000000..ba01225 --- /dev/null +++ b/tests/older-tests/moby-programs/raise.rkt @@ -0,0 +1,34 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"raise.rkt" + +(check-expect + (with-handlers ([string? identity]) + (raise "hello world") + 42) + "hello world") + + +(check-expect (exn? (with-handlers ([void identity]) + (raise (make-exn "foo" (current-continuation-marks))))) + true) + +(check-expect (exn:fail:contract:arity? (with-handlers ([void identity]) + (+ "hello" "world"))) + false) + +(check-expect (exn:fail:contract? (with-handlers ([void identity]) + (+ "hello" "world"))) + true) + +(check-expect (exn:fail:contract:arity? (with-handlers ([void identity]) + (identity "hello" "world"))) + true) + +(check-expect (exn:fail:contract:variable? (with-handlers ([void identity]) + (identity "hello" "world"))) + false) + + + +"raise.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/random.rkt b/tests/older-tests/moby-programs/random.rkt new file mode 100644 index 0000000..7ea2991 --- /dev/null +++ b/tests/older-tests/moby-programs/random.rkt @@ -0,0 +1,18 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "../../lang/check-expect/test-expect.rkt") +"random.rkt" + + +(let loop ([i 0]) + (when (< i 1000) + (begin + (test-within (random 100) 50 50) + (loop (add1 i))))) + +(let loop ([i 0]) + (when (< i 1000) + (begin + (test-within (random) 0.5 0.5) + (loop (add1 i))))) + +"random.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/recur.rkt b/tests/older-tests/moby-programs/recur.rkt new file mode 100644 index 0000000..b4d0fcd --- /dev/null +++ b/tests/older-tests/moby-programs/recur.rkt @@ -0,0 +1,13 @@ +#lang s-exp "../../lang/wescheme.rkt" + + +"recur.rkt" +(check-expect + (recur loop ([i 0]) + (cond [(= i 10) '()] + [else + (cons (* i i) + (loop (add1 i)))])) + '(0 1 4 9 16 25 36 49 64 81)) + +"recur.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/repeating-decimals.rkt b/tests/older-tests/moby-programs/repeating-decimals.rkt new file mode 100644 index 0000000..12f4b9b --- /dev/null +++ b/tests/older-tests/moby-programs/repeating-decimals.rkt @@ -0,0 +1,24 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"repeating-decimals.rkt" + + +1/3 +3227/555 +1/9 +1/3 +2/3 +9/11 +7/12 +1/81 +22/7 + +1/7 +1/17 +1/19 +1/23 +1/97 +1/29 + +"repeating-decimals.rkt end" + diff --git a/tests/older-tests/moby-programs/require.rkt b/tests/older-tests/moby-programs/require.rkt new file mode 100644 index 0000000..aedfc75 --- /dev/null +++ b/tests/older-tests/moby-programs/require.rkt @@ -0,0 +1,34 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "required.rkt") + +(require (prefix-in a-prefix: (only-in "required.rkt" f))) + +(require "required-2.rkt") + +(printf "require.rkt\n") + +(define (blah) + 'blaaargh) + +(check-expect (blah) 'blaaargh) + +(check-expect (f 42) (* 42 42)) + +(check-expect (hypo 3 4) 5) + +(check-expect (h 16) (expt 16 5)) + +(check-expect (a-prefix:f 42) (* 42 42)) + + +(check-expect (a-struct-x (make-a-struct 3 4 5)) 3) +(check-expect (a-struct? (make-a-struct 3 4 5)) true) + + +(check-expect game-name "Evolution chamber") + +;; Hopefully, all-except-out will prevent a collision +;; between this binding and the one in required-5.rkt +(define clashing-value "value with a binding in required-5.rkt") +(check-expect clashing-value + "value with a binding in required-5.rkt") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/required-2.rkt b/tests/older-tests/moby-programs/required-2.rkt new file mode 100644 index 0000000..03b29f6 --- /dev/null +++ b/tests/older-tests/moby-programs/required-2.rkt @@ -0,0 +1,15 @@ +#lang s-exp "../../lang/base.ss" + +(require "required-3.rkt") +(require "required-5.rkt") + +(provide hypo + h) + + +(define-struct a-struct (x y z)) +(provide (struct-out a-struct)) + + +(provide (except-out (all-from-out "required-5.rkt") + clashing-value)) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/required-3.rkt b/tests/older-tests/moby-programs/required-3.rkt new file mode 100644 index 0000000..b0c7b62 --- /dev/null +++ b/tests/older-tests/moby-programs/required-3.rkt @@ -0,0 +1,9 @@ +#lang s-exp "../../lang/base.ss" + +(require "required-4.rkt") + +(provide (rename-out (-hypo hypo)) h) + +(define (-hypo a b) + (sqrt (+ (sqr a) (sqr b)))) + diff --git a/tests/older-tests/moby-programs/required-4.rkt b/tests/older-tests/moby-programs/required-4.rkt new file mode 100644 index 0000000..a5bbf60 --- /dev/null +++ b/tests/older-tests/moby-programs/required-4.rkt @@ -0,0 +1,6 @@ +#lang s-exp "../../lang/base.ss" + +(provide (all-defined-out)) + +(define (h x) + (* x x x x x)) diff --git a/tests/older-tests/moby-programs/required-5.rkt b/tests/older-tests/moby-programs/required-5.rkt new file mode 100644 index 0000000..43bf4f1 --- /dev/null +++ b/tests/older-tests/moby-programs/required-5.rkt @@ -0,0 +1,8 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(provide (all-defined-out)) + +(define game-name "Evolution chamber") + + +(define clashing-value "don't look at me!") \ No newline at end of file diff --git a/tests/older-tests/moby-programs/required.rkt b/tests/older-tests/moby-programs/required.rkt new file mode 100644 index 0000000..3f379e5 --- /dev/null +++ b/tests/older-tests/moby-programs/required.rkt @@ -0,0 +1,8 @@ +#lang s-exp "../../lang/base.rkt" +(provide f) + +(define (f x) + (* x x)) + + +(define h 'something-else) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/rotate.rkt b/tests/older-tests/moby-programs/rotate.rkt new file mode 100644 index 0000000..b8c7fc8 --- /dev/null +++ b/tests/older-tests/moby-programs/rotate.rkt @@ -0,0 +1,27 @@ +#lang s-exp "../../lang/wescheme.rkt" + + +"rotate and scale" + +(printf "Three images at 30, 60, 90 degree rotation:\n") + +(rotate 30 (image-url "http://racket-lang.org/logo.png")) +(rotate 60 (image-url "http://racket-lang.org/logo.png")) +(rotate 90 (image-url "http://racket-lang.org/logo.png")) + + +(printf "scaling small and large") +(scale 1/2 (image-url "http://racket-lang.org/logo.png")) +(scale 2 (image-url "http://racket-lang.org/logo.png")) + +(scale/xy 1 2 (image-url "http://racket-lang.org/logo.png")) +(scale/xy 2 1 (image-url "http://racket-lang.org/logo.png")) + +"This should be the normal image" +(scale/xy 1 1 (image-url "http://racket-lang.org/logo.png")) + + +"Rotated, huge image" +(rotate 30 (scale 3 (image-url "http://racket-lang.org/logo.png"))) + +"rotate and scale end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/run-all-tests.rkt b/tests/older-tests/moby-programs/run-all-tests.rkt new file mode 100644 index 0000000..408e8f1 --- /dev/null +++ b/tests/older-tests/moby-programs/run-all-tests.rkt @@ -0,0 +1,3 @@ +#lang racket/base +(require "../../main.rkt") +(run-in-browser "all-tests.rkt") diff --git a/tests/older-tests/moby-programs/seconds.rkt b/tests/older-tests/moby-programs/seconds.rkt new file mode 100644 index 0000000..01c87e1 --- /dev/null +++ b/tests/older-tests/moby-programs/seconds.rkt @@ -0,0 +1,6 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(printf "current seconds: ~a\n" (current-seconds)) + +(printf "current-inexact-milliseconds: ~a\n" + (current-inexact-milliseconds)) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/setbang.rkt b/tests/older-tests/moby-programs/setbang.rkt new file mode 100644 index 0000000..43b373e --- /dev/null +++ b/tests/older-tests/moby-programs/setbang.rkt @@ -0,0 +1,128 @@ +#lang s-exp "../../lang/wescheme.ss" + + +(printf "setbang.rkt\n") + +(define some-value 16) +(check-expect (set! some-value 42) + (void)) + + +(define song '()) + +(define (bottles-of-beer) + (let ([x 100]) + (define (loop) + (if (< x 1) + (void) + (begin + (set! x (sub1 x)) + (set! song (cons (format "~a bottles of beer on the wall\n" x) + song)) + (loop)))) + (loop))) + +(bottles-of-beer) + + +(check-expect (reverse song) + (list "99 bottles of beer on the wall\n" + "98 bottles of beer on the wall\n" + "97 bottles of beer on the wall\n" + "96 bottles of beer on the wall\n" + "95 bottles of beer on the wall\n" + "94 bottles of beer on the wall\n" + "93 bottles of beer on the wall\n" + "92 bottles of beer on the wall\n" + "91 bottles of beer on the wall\n" + "90 bottles of beer on the wall\n" + "89 bottles of beer on the wall\n" + "88 bottles of beer on the wall\n" + "87 bottles of beer on the wall\n" + "86 bottles of beer on the wall\n" + "85 bottles of beer on the wall\n" + "84 bottles of beer on the wall\n" + "83 bottles of beer on the wall\n" + "82 bottles of beer on the wall\n" + "81 bottles of beer on the wall\n" + "80 bottles of beer on the wall\n" + "79 bottles of beer on the wall\n" + "78 bottles of beer on the wall\n" + "77 bottles of beer on the wall\n" + "76 bottles of beer on the wall\n" + "75 bottles of beer on the wall\n" + "74 bottles of beer on the wall\n" + "73 bottles of beer on the wall\n" + "72 bottles of beer on the wall\n" + "71 bottles of beer on the wall\n" + "70 bottles of beer on the wall\n" + "69 bottles of beer on the wall\n" + "68 bottles of beer on the wall\n" + "67 bottles of beer on the wall\n" + "66 bottles of beer on the wall\n" + "65 bottles of beer on the wall\n" + "64 bottles of beer on the wall\n" + "63 bottles of beer on the wall\n" + "62 bottles of beer on the wall\n" + "61 bottles of beer on the wall\n" + "60 bottles of beer on the wall\n" + "59 bottles of beer on the wall\n" + "58 bottles of beer on the wall\n" + "57 bottles of beer on the wall\n" + "56 bottles of beer on the wall\n" + "55 bottles of beer on the wall\n" + "54 bottles of beer on the wall\n" + "53 bottles of beer on the wall\n" + "52 bottles of beer on the wall\n" + "51 bottles of beer on the wall\n" + "50 bottles of beer on the wall\n" + "49 bottles of beer on the wall\n" + "48 bottles of beer on the wall\n" + "47 bottles of beer on the wall\n" + "46 bottles of beer on the wall\n" + "45 bottles of beer on the wall\n" + "44 bottles of beer on the wall\n" + "43 bottles of beer on the wall\n" + "42 bottles of beer on the wall\n" + "41 bottles of beer on the wall\n" + "40 bottles of beer on the wall\n" + "39 bottles of beer on the wall\n" + "38 bottles of beer on the wall\n" + "37 bottles of beer on the wall\n" + "36 bottles of beer on the wall\n" + "35 bottles of beer on the wall\n" + "34 bottles of beer on the wall\n" + "33 bottles of beer on the wall\n" + "32 bottles of beer on the wall\n" + "31 bottles of beer on the wall\n" + "30 bottles of beer on the wall\n" + "29 bottles of beer on the wall\n" + "28 bottles of beer on the wall\n" + "27 bottles of beer on the wall\n" + "26 bottles of beer on the wall\n" + "25 bottles of beer on the wall\n" + "24 bottles of beer on the wall\n" + "23 bottles of beer on the wall\n" + "22 bottles of beer on the wall\n" + "21 bottles of beer on the wall\n" + "20 bottles of beer on the wall\n" + "19 bottles of beer on the wall\n" + "18 bottles of beer on the wall\n" + "17 bottles of beer on the wall\n" + "16 bottles of beer on the wall\n" + "15 bottles of beer on the wall\n" + "14 bottles of beer on the wall\n" + "13 bottles of beer on the wall\n" + "12 bottles of beer on the wall\n" + "11 bottles of beer on the wall\n" + "10 bottles of beer on the wall\n" + "9 bottles of beer on the wall\n" + "8 bottles of beer on the wall\n" + "7 bottles of beer on the wall\n" + "6 bottles of beer on the wall\n" + "5 bottles of beer on the wall\n" + "4 bottles of beer on the wall\n" + "3 bottles of beer on the wall\n" + "2 bottles of beer on the wall\n" + "1 bottles of beer on the wall\n" + "0 bottles of beer on the wall\n")) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/sleep.rkt b/tests/older-tests/moby-programs/sleep.rkt new file mode 100644 index 0000000..98d4ec7 --- /dev/null +++ b/tests/older-tests/moby-programs/sleep.rkt @@ -0,0 +1,3 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(sleep 0) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/struct.rkt b/tests/older-tests/moby-programs/struct.rkt new file mode 100644 index 0000000..9b61091 --- /dev/null +++ b/tests/older-tests/moby-programs/struct.rkt @@ -0,0 +1,56 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(require "../../lang/check-expect/test-expect.rkt") +"struct.rkt" + +(let-values ([(a-struct-type + constructor + predicate + accessor + mutator) + (make-struct-type 'pair + #f + 2 + 0)]) + (test-expect (struct-type? a-struct-type) true) + (test-expect (struct-type? (constructor 3 4)) false) + (test-expect (predicate (constructor 3 4)) true) + (test-expect (predicate (cons 3 4)) false) + + (test-expect (struct-constructor-procedure? constructor) true) + (test-expect (struct-constructor-procedure? (lambda (x y) + (constructor x y))) + false) + + (test-expect (struct-predicate-procedure? predicate) true) + (test-expect (struct-predicate-procedure? accessor) false) + (test-expect (struct-predicate-procedure? 24) false) + (test-expect (struct-predicate-procedure? (lambda (x) true)) + false) + + (test-expect (struct-accessor-procedure? accessor) true) + (test-expect (struct-accessor-procedure? mutator) false) + (test-expect (struct-accessor-procedure? 24) false) + (test-expect (struct-accessor-procedure? (lambda (x) true)) + false) + + (test-expect (struct-mutator-procedure? mutator) true) + (test-expect (struct-mutator-procedure? accessor) false) + (test-expect (struct-mutator-procedure? 24) false) + (test-expect (struct-mutator-procedure? (lambda (x) true)) + false) + + (let ([f (make-struct-field-accessor accessor 0)] + [r (make-struct-field-accessor accessor 1)] + [set-f! (make-struct-field-mutator mutator 0)] + [set-r! (make-struct-field-mutator mutator 1)]) + (let ([p1 (constructor 17 'foo)]) + (test-expect (f p1) 17) + (test-expect (r p1) 'foo) + + (set-f! p1 'something-else) + (test-expect (f p1) 'something-else) + (set-r! p1 1024) + (test-expect (r p1) '1024)))) + +"struct.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/values.rkt b/tests/older-tests/moby-programs/values.rkt new file mode 100644 index 0000000..5f969f6 --- /dev/null +++ b/tests/older-tests/moby-programs/values.rkt @@ -0,0 +1,22 @@ +#lang s-exp "../../lang/wescheme.rkt" +(require "../../lang/check-expect/test-expect.rkt") + +"values.rkt" + +(call-with-values (lambda () (values 3 4 5)) + (lambda (x y z) + (test-expect x 3) + (test-expect y 4) + (test-expect z 5))) + +(call-with-values (lambda () (values 3 4 5)) + (lambda args + (test-expect args '(3 4 5)))) + +(call-with-values (lambda () (values)) + (lambda () + (void))) + + + +"values.rkt end" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/vararity.rkt b/tests/older-tests/moby-programs/vararity.rkt new file mode 100644 index 0000000..a788f2c --- /dev/null +++ b/tests/older-tests/moby-programs/vararity.rkt @@ -0,0 +1,8 @@ +#lang s-exp "../../lang/wescheme.rkt" + +"vararity" +(define f (lambda args args)) + +(check-expect (f) empty) +(check-expect (f 1 2) '(1 2)) +"vararity done" \ No newline at end of file diff --git a/tests/older-tests/moby-programs/vector.rkt b/tests/older-tests/moby-programs/vector.rkt new file mode 100644 index 0000000..fee27a6 --- /dev/null +++ b/tests/older-tests/moby-programs/vector.rkt @@ -0,0 +1,36 @@ +#lang s-exp "../../lang/wescheme.rkt" + +(require "../../lang/check-expect/test-expect.rkt") +(printf "vector.rkt\n") + + +(define v (build-vector 5 (lambda (a) a))) +(test-expect v #(0 1 2 3 4)) +(test-expect (vector-length v) 5) + +(test-expect (vector? v) true) +(test-expect (vector? '(not a vector)) false) + + +(define v2 (build-vector 5 (lambda (a) (* a a)))) +(test-expect v2 #(0 1 4 9 16)) + +(test-expect (vector->list #()) '()) +(test-expect (vector->list v2) '(0 1 4 9 16)) + + +(test-expect (list->vector '()) #()) +(test-expect (list->vector '(a b c)) #(a b c)) + + +(define v3 (vector 'hello 'world)) +(test-expect v3 '#(hello world)) +(vector-set! v3 0 'hola) +(test-expect v3 '#(hola world)) +(test-expect (vector-ref v3 0) 'hola) + + + + +(printf "vector.rkt end\n") + diff --git a/tests/older-tests/moby-programs/when-unless.rkt b/tests/older-tests/moby-programs/when-unless.rkt new file mode 100644 index 0000000..526a6db --- /dev/null +++ b/tests/older-tests/moby-programs/when-unless.rkt @@ -0,0 +1,12 @@ +#lang s-exp "../../lang/base.ss" + + +(printf "when-unless.rkt\n") + +(when (= (expt 2 100) + 1267650600228229401496703205376) + 'ok) + +(unless (not (= (expt 2 100) + 1/1267650600228229401496703205376)) + (error 'not-ok)) \ No newline at end of file diff --git a/tests/older-tests/moby-programs/with-handlers-1.rkt b/tests/older-tests/moby-programs/with-handlers-1.rkt new file mode 100644 index 0000000..a7d0a49 --- /dev/null +++ b/tests/older-tests/moby-programs/with-handlers-1.rkt @@ -0,0 +1,35 @@ +#lang s-exp "../../lang/base.rkt" + + +(printf "with-handlers-1.rkt\n") + +(with-handlers ([(lambda (exn) + (printf "Is the exception a failure? ~s~n" (exn:fail? exn)) + (exn:fail? exn)) + (lambda (exn) + (printf "I'm in the handler and saying ok\n") + 'ok)]) + (/ 1 0) + (error 'not-ok)) + + + +(with-handlers ([(lambda (exn) + false) + (lambda (exn) + (printf "I'm in the handler and saying ok\n") + (error 'not-ok))] + [(lambda (exn) + (printf "second test\n") + true) + (lambda (exn) + 'ok)]) + (/ 1 0) + (error 'not-ok)) + + + +(with-handlers ([void (lambda (exn) (error 'not-ok))]) + 'ok) + + diff --git a/tests/older-tests/moby-programs/with-handlers-2.rkt b/tests/older-tests/moby-programs/with-handlers-2.rkt new file mode 100644 index 0000000..a2fb82e --- /dev/null +++ b/tests/older-tests/moby-programs/with-handlers-2.rkt @@ -0,0 +1,23 @@ +#lang s-exp "../../lang/base.rkt" + + +(printf "Testing with-handlers-2.rkt\n"); + +(with-handlers ([void (lambda (exn) 'ok)]) + (with-handlers ([1 2]) + (/ 1 0) + (error "expected an error"))) + + +(with-handlers ([void (lambda (exn) 'ok)]) + (with-handlers ([void 2]) + (/ 1 0) + (error "expected an error"))) + +(with-handlers ([void (lambda (exn) + (printf "outer\n") + (error 'not-ok))]) + (with-handlers ([void (lambda (exn) + 'ok)]) + (/ 1 0) + (error "expected an error"))) \ No newline at end of file diff --git a/tests/older-tests/mz-tests/all-tests.rkt b/tests/older-tests/mz-tests/all-tests.rkt new file mode 100644 index 0000000..2a0d36e --- /dev/null +++ b/tests/older-tests/mz-tests/all-tests.rkt @@ -0,0 +1,4 @@ +#lang s-exp "../../lang/base.rkt" + +(require "basic.rkt" + #;"number.rkt") diff --git a/tests/older-tests/mz-tests/basic.rkt b/tests/older-tests/mz-tests/basic.rkt new file mode 100644 index 0000000..516479a --- /dev/null +++ b/tests/older-tests/mz-tests/basic.rkt @@ -0,0 +1,2588 @@ +#lang s-exp "../../lang/base.rkt" +(require "testing.rkt") + +(Section 'basic) + +#;(require scheme/flonum + racket/private/norm-arity) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(test '() 'null null) +(test '() 'null '()) + +(let ([f (lambda () #&7)]) + (test #t eq? (f) (f))) + +;; test that all symbol characters are supported. +'(+ - ... !.. $.+ %.- &.! *.: /:. :+. <-. =. >. ?. ~. _. ^.) + +(define disjoint-type-functions + (list boolean? char? null? number? pair? procedure? string? symbol? vector?)) +(define type-examples + (list + #t #f #\a '() 9739 '(test) record-error "test" "" 'test '#() '#(a b c) )) +(define i 1) +(for-each (lambda (x) (display (make-string i #\ )) + (set! i (+ 3 i)) + (write x) + (newline)) + disjoint-type-functions) +(define type-matrix + (map (lambda (x) + (let ((t (map (lambda (f) (f x)) disjoint-type-functions))) + (write t) + (write x) + (newline) + t)) + type-examples)) + +(test #f not #t) +(test #f not 3) +(test #f not (list 3)) +(test #t not #f) +(test #f not '()) +(test #f not (list)) +(test #f not 'nil) +(arity-test not 1 1) + +(test #t boolean? #f) +(test #t boolean? #t) +(test #f boolean? 0) +(test #f boolean? '()) +(arity-test boolean? 1 1) + +(test #t eqv? 'a 'a) +(test #f eqv? 'a 'b) +(test #t eqv? 2 2) +(test #f eqv? 2 2.0) +(test #t eqv? '() '()) +(test #t eqv? '10000 '10000) +(test #t eqv? 10000000000000000000 10000000000000000000) +(test #f eqv? 10000000000000000000 10000000000000000001) +(test #f eqv? 10000000000000000000 20000000000000000000) +(test #f eqv? (cons 1 2) (cons 1 2)) +(test #f eqv? (lambda () 1) (lambda () 2)) +(test #f eqv? #f 'nil) +(let ((p (lambda (x) x))) + (test #t eqv? p p)) +(define gen-counter + (lambda () + (let ((n 0)) + (lambda () (set! n (+ n 1)) n)))) +(let ((g (gen-counter))) (test #t eqv? g g)) +(test #f eqv? (gen-counter) (gen-counter)) +(letrec ((f (lambda () (if (eqv? f g) 'f 'both))) + (g (lambda () (if (eqv? f g) 'g 'both)))) + (test #f eqv? f g)) + +(test #t eq? 'a 'a) +(test #f eq? (list 'a) (list 'a)) +(test #t eq? '() '()) +(test #t eq? car car) +(let ((x '(a))) (test #t eq? x x)) +(let ((x '#())) (test #t eq? x x)) +(let ((x (lambda (x) x))) (test #t eq? x x)) + +(test #t equal? 'a 'a) +(test #t equal? '("a") '("a")) +(test #t equal? '(a) '(a)) +(test #t equal? '(a (b) c) '(a (b) c)) +(test #t equal? '("a" ("b") "c") '("a" ("b") "c")) +(test #t equal? "abc" "abc") +(test #t equal? 2 2) +(test #t equal? (make-vector 5 'a) (make-vector 5 'a)) +(test #t equal? (box "a") (box "a")) +(test #f equal? "" (string #\null)) + +(test #f equal? 'a "a") +(test #f equal? 'a 'b) +(test #f equal? '(a) '(b)) +(test #f equal? '(a (b) d) '(a (b) c)) +(test #f equal? '(a (b) c) '(d (b) c)) +(test #f equal? '(a (b) c) '(a (d) c)) +(test #f equal? "abc" "abcd") +(test #f equal? "abcd" "abc") +(test #f equal? 2 3) +(test #f equal? 2.0 2) +(test #f equal? (make-vector 5 'b) (make-vector 5 'a)) +(test #f equal? (box "a") (box "b")) + +(test #t equal? #\a #\a) +(test #t equal? (integer->char 1024) (integer->char 1024)) +(test #f equal? (integer->char 1024) (integer->char 1025)) + +(arity-test eq? 2 2) +(arity-test eqv? 2 2) +(arity-test equal? 2 2) + +(disable (err/rt-test (set-mcdr! (list 1 2) 4))) + +(test '(a b c d e) 'dot '(a . (b . (c . (d . (e . ())))))) +(disable (define x (mcons 'a (mcons 'b (mcons 'c null)))) + (define y x) + (set-mcdr! x 4) + (test (mcons 'a 4) 'set-mcdr! x) + (set-mcar! x 'z) + (test (mcons 'z 4) 'set-mcar! x) + (test #t eqv? x y) + (test '(a b c . d) 'dot '(a . (b . (c . d)))) + (test #f list? y) + (test #f list? (cons 'a 4)) + (arity-test list? 1 1)) + +(test #t pair? '(a . b)) +(test #t pair? '(a . 1)) +(test #t pair? '(a b c)) +(test #f pair? '()) +(test #f pair? '#(a b)) +(arity-test pair? 1 1) + +(test '(a) cons 'a '()) +(test '((a) b c d) cons '(a) '(b c d)) +(test '("a" b c) cons "a" '(b c)) +(test '(a . 3) cons 'a 3) +(test '((a b) . c) cons '(a b) 'c) +(arity-test cons 2 2) + +(test 'a car '(a b c)) +(test '(a) car '((a) b c d)) +(test 1 car '(1 . 2)) +(arity-test car 1 1) +(err/rt-test (car 1)) + +(test '(b c d) cdr '((a) b c d)) +(test 2 cdr '(1 . 2)) +(arity-test cdr 1 1) +(err/rt-test (cdr 1)) + +(test '(a 7 c) list 'a (+ 3 4) 'c) +(test '() list) + +(test 3 length '(a b c)) +(test 3 length '(a (b) (c d e))) +(test 0 length '()) +(arity-test length 1 1) +(err/rt-test (length 1)) +(err/rt-test (length '(1 . 2))) +(err/rt-test (length "a")) +; (err/rt-test (length (quote #0=(1 . #0#)))) +(disable (err/rt-test (let ([p (cons 1 (make-placeholder #f))]) + (placeholder-set! (cdr p) p) + (length (make-reader-graph p))))) +(define x (cons 4 0)) +(err/rt-test (length x)) + +(disable (arity-test set-mcar! 2 2) + (arity-test set-mcdr! 2 2) + (err/rt-test (set-mcar! 4 4)) + (err/rt-test (set-mcdr! 4 4)) + (err/rt-test (set-mcar! (cons 1 4) 4)) + (err/rt-test (set-mcdr! (cons 1 4) 4))) + +(define (box-tests box unbox box? set-box! set-box!-name unbox-name) + (define b (box 5)) + (test 5 unbox b) + (when set-box! + (set-box! b 6) + (test 6 unbox b)) + (test #t box? b) + (test #f box? 5) + (arity-test box 1 1) + (arity-test unbox 1 1) + (arity-test box? 1 1) + (when set-box! + (arity-test set-box! 2 2)) + (err/rt-test (unbox 8)) + (when set-box! + (err/rt-test (set-box! 8 8)))) +(box-tests box unbox box? set-box! 'set-box! 'unbox) +(disable (box-tests make-weak-box weak-box-value weak-box? #f #f 'weak-box-value)) + +(test '(x y) append '(x) '(y)) +(test '(a b c d) append '(a) '(b c d)) +(test '(a (b) (c)) append '(a (b)) '((c))) +(test '() append) +(test '(a b c . d) append '(a b) '(c . d)) +(test 'a append '() 'a) +(test 1 append 1) +(test '(1 . 2) append '(1) 2) +(test '(1 . 2) append '(1) 2) +(err/rt-test (append '(1 2 . 3) 1)) +(err/rt-test (append '(1 2 3) 1 '(4 5 6))) + +(define l '(1 2)) +(define l2 '(3 4 . 7)) +(define l3 (append l l2)) +(test '(1 2 3 4 . 7) 'append l3) + +(test '(c b a) reverse '(a b c)) +(test '((e (f)) d (b c) a) reverse '(a (b c) d (e (f)))) +(arity-test reverse 1 1) +(err/rt-test (reverse 1)) +(err/rt-test (reverse '(1 . 1))) + +(test 'c list-ref '(a b c d) 2) +(test 'c list-ref '(a b c . d) 2) +(arity-test list-ref 2 2) +(err/rt-test (list-ref 1 1) exn:application:mismatch?) +(err/rt-test (list-ref '(a b . c) 2) exn:application:mismatch?) +(err/rt-test (list-ref '(1 2 3) 2.0)) +(err/rt-test (list-ref '(1) '(1))) +(err/rt-test (list-ref '(1) 1) exn:application:mismatch?) +(err/rt-test (list-ref '() 0) exn:application:mismatch?) +(err/rt-test (list-ref '() 0) exn:application:mismatch?) +(err/rt-test (list-ref '(1) -1)) +(err/rt-test (list-ref '(1) 2000000000000) exn:application:mismatch?) + +(test '(c d) list-tail '(a b c d) 2) +(test '(a b c d) list-tail '(a b c d) 0) +(test '(b c . d) list-tail '(a b c . d) 1) +(test 1 list-tail 1 0) +(arity-test list-tail 2 2) +(err/rt-test (list-tail 1 1) exn:application:mismatch?) +(err/rt-test (list-tail '(1 2 3) 2.0)) +(err/rt-test (list-tail '(1) '(1))) +(err/rt-test (list-tail '(1) -1)) +(err/rt-test (list-tail '(1) 2) exn:application:mismatch?) +(err/rt-test (list-tail '(1 2 . 3) 3) exn:application:mismatch?) + +(define (test-mem memq memq-name) + (test '(a b c) memq 'a '(a b c)) + (test '(b c) memq 'b '(a b c)) + (test '(b . c) memq 'b '(a b . c)) + (test '#f memq 'a '(b c d)) + + (arity-test memq 2 2) + (err/rt-test (memq 'a 1) exn:application:mismatch?) + (err/rt-test (memq 'a '(1 . 2)) exn:application:mismatch?)) + +(test-mem memq 'memq) +(test-mem memv 'memv) +(test-mem member 'member) + +(test #f memq "apple" '("apple")) +(test #f memv "apple" '("apple")) +(test '("apple") member "apple" '("apple")) + +; (test #f memq 1/2 '(1/2)) ; rationals are immutable and we may want to optimize +(test '(1/2) memv 1/2 '(1/2)) +(test '(1/2) member 1/2 '(1/2)) + +(test '((1 2)) member '(1 2) '(1 2 (1 2))) + +(define (test-ass assq assq-name) + (define e '((a 1) (b 2) (c 3))) + (test '(a 1) assq 'a e) + (test '(b 2) assq 'b e) + (test #f assq 'd e) + (test '(a 1) assq 'a '((x 0) (a 1) b 2)) + (test '(a 1) assq 'a '((x 0) (a 1) . 0)) + (arity-test assq 2 2) + + (err/rt-test (assq 1 1) exn:application:mismatch?) + (err/rt-test (assq 1 '(1 2)) exn:application:mismatch?) + (err/rt-test (assq 1 '((0) . 2)) exn:application:mismatch?)) + +(test-ass assq 'assq) +(test-ass assv 'assv) +(test-ass assoc 'assoc) + +(test #f assq '(a) '(((a)) ((b)) ((c)))) +(test #f assv '(a) '(((a)) ((b)) ((c)))) +(test '((b) 1) assoc '(b) '(((a)) ((b) 1) ((c)))) + +; (test #f assq '1/2 '(((a)) (1/2) ((c)))) ; rationals are immutable and we may want to optimize +(test '(1/2) assv '1/2 '(((a)) (1/2) ((c)))) +(test '(1/2) assoc '1/2 '(((a)) (1/2) ((c)))) + +(test #f immutable? (cons 1 null)) +(test #f immutable? (list 1)) +(test #f immutable? (list 1 2)) +(test #f immutable? (list* 1 null)) +(test #f immutable? (list* 1 2 null)) +(test #f immutable? 1) +(test #t immutable? #(1 2 3)) +(test #f immutable? (vector 1 2 3)) +(test #f immutable? (vector)) +(test #t immutable? #()) +(test #f immutable? (string-copy "hi")) + +(test #t immutable? "hi") +(test #t immutable? (string->immutable-string "hi")) +(test #t immutable? (string->immutable-string (string-copy "hi"))) + +(disable (test #t immutable? (make-immutable-hasheq null))) +(disable (test #t immutable? (make-immutable-hasheq '((a . b))))) +(disable (test #t immutable? (make-immutable-hash '((a . b))))) +(test #f immutable? (make-hasheq)) +(disable (test #f immutable? (make-hasheqv))) +(test #f immutable? (make-hash)) +(disable (test #f immutable? (make-weak-hasheq))) +(disable (test #f immutable? (make-weak-hash))) + +(test #t symbol? 'foo) +(test #t symbol? (car '(a b))) +(test #f symbol? "bar") +(test #t symbol? 'nil) +(test #f symbol? '()) +(test #f symbol? #f) +(disable + ;;; But first, what case are symbols in? Determine the standard case: + #ci(parameterize ([read-case-sensitive #f]) + (define char-standard-case char-upcase) + (if (string=? (symbol->string 'A) "a") + (set! char-standard-case char-downcase) + (void)) + (test #t 'standard-case + (string=? (symbol->string 'a) (symbol->string 'A))) + (test #t 'standard-case + (or (string=? (symbol->string 'a) "A") + (string=? (symbol->string 'A) "a"))) + (let () + (define (str-copy s) + (let ((v (make-string (string-length s)))) + (do ((i (- (string-length v) 1) (- i 1))) + ((< i 0) v) + (string-set! v i (string-ref s i))))) + (define (string-standard-case s) + (set! s (str-copy s)) + (do ((i 0 (+ 1 i)) + (sl (string-length s))) + ((>= i sl) s) + (string-set! s i (char-standard-case (string-ref s i))))) + (test (string-standard-case "flying-fish") symbol->string 'flying-fish) + (test (string-standard-case "martin") symbol->string 'Martin) + (test "Malvina" symbol->string (string->symbol "Malvina")) + (test #t 'standard-case (eq? 'a 'A))))) + +(set! x (string #\a #\b)) +(define y (string->symbol x)) +(string-set! x 0 #\c) +(test "cb" 'string-set! x) +(test "ab" symbol->string y) +(test y string->symbol "ab") + +#ci(test #t eq? 'mISSISSIppi 'mississippi) +#ci(test #f 'string->symbol (eq? 'bitBlt (string->symbol "bitBlt"))) +#cs(test #t 'string->symbol (eq? 'bitBlt (string->symbol "bitBlt"))) +(test 'JollyWog string->symbol (symbol->string 'JollyWog)) +#ci(test 'JollyWog string->symbol (symbol->string 'JollyWog)) + +(arity-test symbol? 1 1) + +(disable (test #t keyword? '#:a) + (test #f keyword? 'a) + (test '#:apple string->keyword "apple") + (test "apple" keyword->string '#:apple) + (test #t keywordkeyword "a") (string->keyword "\uA0")) + (test #t keywordkeyword "a") (string->keyword "\uFF")) + (test #f keywordkeyword "\uA0") (string->keyword "a")) + (test #f keywordkeyword "\uFF") (string->keyword "a")) + (test #t keywordkeyword "\uA0") (string->keyword "\uFF")) + (test #f keywordkeyword "\uFF") (string->keyword "\uA0")) + (test #f keywordkeyword "\uA0") (string->keyword "\uA0")) + + (arity-test keyword? 1 1) + (arity-test keyword? #\A #\B) + (test #t char>? #\B #\A) + (test #f char>? #\A #\B #\C) + (test #f char>? #\B #\A #\C) + (test #t char>? #\C #\B #\A) + (test #f char>? #\a #\b) + (test #t char>? #\9 #\0) + (test #f char>? #\A #\A) + (test #f char>? #\370 #\370) + (test #t char>? #\371 #\370) + (test #f char>? #\370 #\371) + (arity-test char>? 2 -1) + (err/rt-test (char>? #\a 1)) + (err/rt-test (char>? #\a #\a 1)) + (err/rt-test (char>? 1 #\a)) + + (test #t char<=? #\A #\B) + (test #t char<=? #\A #\B #\C) + (test #t char<=? #\A #\A #\C) + (test #f char<=? #\A #\B #\A) + (test #f char<=? #\B #\A #\C) + (test #t char<=? #\a #\b) + (test #f char<=? #\9 #\0) + (test #t char<=? #\A #\A) + (test #t char<=? #\370 #\370) + (test #f char<=? #\371 #\370) + (test #t char<=? #\370 #\371) + (arity-test char<=? 2 -1) + (err/rt-test (char<=? #\a 1)) + (err/rt-test (char<=? #\b #\a 1)) + (err/rt-test (char<=? 1 #\a)) + + (test #f char>=? #\A #\B) + (test #f char>=? #\a #\b) + (test #t char>=? #\9 #\0) + (test #t char>=? #\A #\A) + (test #t char>=? #\370 #\370) + (test #t char>=? #\371 #\370) + (test #f char>=? #\370 #\371) + (arity-test char>=? 2 -1) + (err/rt-test (char>=? #\a 1)) + (err/rt-test (char>=? #\a #\b 1)) + (err/rt-test (char>=? 1 #\a)) + + (test #f char-ci=? #\A #\B) + (test #f char-ci=? #\A #\A #\B) + (test #f char-ci=? #\a #\B) + (test #f char-ci=? #\A #\b) + (test #f char-ci=? #\a #\b) + (test #f char-ci=? #\9 #\0) + (test #t char-ci=? #\A #\A) + (test #t char-ci=? #\A #\a) + (test #t char-ci=? #\A #\a #\A) + (test #t char-ci=? #\370 #\370) + (test #f char-ci=? #\371 #\370) + (test #f char-ci=? #\370 #\371) + (arity-test char-ci=? 2 -1) + (err/rt-test (char-ci=? #\a 1)) + (err/rt-test (char-ci=? #\a #\b 1)) + (err/rt-test (char-ci=? 1 #\a)) + + (test #t char-ci? #\A #\B) + (test #f char-ci>? #\B #\A #\C) + (test #t char-ci>? #\C #\B #\A) + (test #f char-ci>? #\a #\B) + (test #f char-ci>? #\A #\b) + (test #f char-ci>? #\a #\b) + (test #t char-ci>? #\C #\b #\A) + (test #t char-ci>? #\9 #\0) + (test #f char-ci>? #\A #\A) + (test #f char-ci>? #\A #\a) + (test #f char-ci>? #\370 #\370) + (test #t char-ci>? #\371 #\370) + (test #f char-ci>? #\370 #\371) + (arity-test char-ci>? 2 -1) + (err/rt-test (char-ci>? #\a 1)) + (err/rt-test (char-ci>? #\a #\b 1)) + (err/rt-test (char-ci>? 1 #\a)) + + (test #t char-ci<=? #\A #\B) + (test #t char-ci<=? #\a #\B) + (test #t char-ci<=? #\a #\B #\C) + (test #f char-ci<=? #\a #\b #\A) + (test #t char-ci<=? #\A #\b) + (test #t char-ci<=? #\a #\b) + (test #f char-ci<=? #\9 #\0) + (test #t char-ci<=? #\A #\A) + (test #t char-ci<=? #\A #\a) + (test #t char-ci<=? #\370 #\370) + (test #f char-ci<=? #\371 #\370) + (test #t char-ci<=? #\370 #\371) + (arity-test char-ci<=? 2 -1) + (err/rt-test (char-ci<=? #\a 1)) + (err/rt-test (char-ci<=? #\b #\a 1)) + (err/rt-test (char-ci<=? 1 #\a)) + + (test #f char-ci>=? #\A #\B) + (test #f char-ci>=? #\B #\A #\C) + (test #t char-ci>=? #\B #\B #\A) + (test #f char-ci>=? #\a #\B) + (test #f char-ci>=? #\A #\b) + (test #f char-ci>=? #\a #\b) + (test #t char-ci>=? #\9 #\0) + (test #t char-ci>=? #\A #\A) + (test #t char-ci>=? #\A #\a) + (test #t char-ci>=? #\370 #\370) + (test #t char-ci>=? #\371 #\370) + (test #f char-ci>=? #\370 #\371) + (arity-test char-ci>=? 2 -1) + (err/rt-test (char-ci>=? #\a 1)) + (err/rt-test (char-ci>=? #\a #\b 1)) + (err/rt-test (char-ci>=? 1 #\a))) + +(char-tests) + +(define (ascii-range start end) + (let ([s (or (and (number? start) start) (char->integer start))] + [e (or (and (number? end) end) (char->integer end))]) + (let loop ([n e][l (list (integer->char e))]) + (if (= n s) + l + (let ([n (sub1 n)]) + (loop n (cons (integer->char n) l))))))) + +(define uppers (ascii-range #\A #\Z)) +(define lowers (ascii-range #\a #\z)) + + +(define alphas (append uppers lowers)) +(define digits (ascii-range #\0 #\9)) +(define whites (list #\newline #\return #\space #\page #\tab #\vtab)) + +(define (test-all is-a? name members) + (let loop ([n 0]) + (unless (= n 128) + (let ([c (integer->char n)]) + (test (and (memq c members) #t) `(,is-a? (integer->char ,n)) (is-a? c)) + (loop (add1 n))))) + (arity-test is-a? 1 1) + (err/rt-test (is-a? 1))) + +(test-all char-alphabetic? 'char-alphabetic? alphas) +(test-all char-numeric? 'char-numeric? digits) +(test-all char-whitespace? 'char-whitespace? whites) +(test-all char-upper-case? 'char-upper-case? uppers) +(test-all char-lower-case? 'char-lower-case? lowers) + +(let loop ([n 0]) + (unless (= n 512) + (test n 'integer->char (char->integer (integer->char n))) + (loop (add1 n)))) + +(test 0 char->integer #\nul) +(test 10 char->integer #\newline) +(test 13 char->integer #\return) +(test 9 char->integer #\tab) +(test 8 char->integer #\backspace) +(test 12 char->integer #\page) +(test 32 char->integer #\space) +(test 127 char->integer #\rubout) +(test #\null 'null #\nul) +(test #\newline 'linefeed #\linefeed) + +(test #\. integer->char (char->integer #\.)) +(test #\A integer->char (char->integer #\A)) +(test #\a integer->char (char->integer #\a)) +(test #\371 integer->char (char->integer #\371)) +(test #\U12345 integer->char (char->integer #\U12345)) +(arity-test integer->char 1 1) +(arity-test char->integer 1 1) +(err/rt-test (integer->char 5.0)) +(err/rt-test (integer->char 'a)) +(err/rt-test (integer->char -1)) +(err/rt-test (integer->char (expt 2 32))) +(err/rt-test (integer->char 10000000000000000)) +(err/rt-test (char->integer 5)) + +(define (test-up/down case case-name members memassoc) + (let loop ([n 0]) + (unless (= n 128) + (let ([c (integer->char n)]) + (if (memq c members) + (test (cdr (assq c memassoc)) case c) + (test c case c))) + (loop (add1 n)))) + (arity-test case 1 1) + (err/rt-test (case 2))) + +(test-up/down char-upcase 'char-upcase lowers (map cons lowers uppers)) +(test-up/down char-downcase 'char-downcase uppers (map cons uppers lowers)) + +(test #t string? "The word \"recursion\\\" has many meanings.") +(test #t string? "") +(arity-test string? 1 1) +(test 3 'make-string (string-length (make-string 3))) +(test "" make-string 0) +(arity-test make-string 1 2) +(err/rt-test (make-string "hello")) +(err/rt-test (make-string 5 "hello")) +(err/rt-test (make-string 5.0 #\b)) +(err/rt-test (make-string 5.2 #\a)) +(err/rt-test (make-string -5 #\f)) +(disable (define 64-bit-machine? (eq? (expt 2 40) (eq-hash-code (expt 2 40)))) + (unless 64-bit-machine? + (err/rt-test (make-string 500000000000000 #\f) exn:fail:out-of-memory?)) ;; bignum on 32-bit machines + (err/rt-test (make-string 50000000000000000000 #\f) exn:fail:out-of-memory?) ;; bignum on 64-bit machines + ) + + +(define f (make-string 3 #\*)) +(test "?**" 'string-set! (begin (string-set! f 0 #\?) f)) +(arity-test string-set! 3 3) +(test #t immutable? "hello") +(err/rt-test (string-set! "hello" 0 #\a)) ; immutable string constant +(define hello-string (string-copy "hello")) +(err/rt-test (string-set! hello-string 'a #\a)) +(err/rt-test (string-set! 'hello 4 #\a)) +(err/rt-test (string-set! hello-string 4 'a)) +(err/rt-test (string-set! hello-string 4.0 'a)) +(err/rt-test (string-set! hello-string 5 #\a) exn:application:mismatch?) +(err/rt-test (string-set! hello-string -1 #\a)) +(err/rt-test (string-set! hello-string (expt 2 100) #\a) exn:application:mismatch?) +(test "abc" string #\a #\b #\c) +(test "" string) +(err/rt-test (string #\a 1)) +(err/rt-test (string 1 #\a)) +(err/rt-test (string 1)) +(test 3 string-length "abc") +(test 0 string-length "") +(arity-test string-length 1 1) +(err/rt-test (string-length 'apple)) +(test #\a string-ref "abc" 0) +(test #\c string-ref "abc" 2) +(arity-test string-ref 2 2) +(err/rt-test (string-ref 'apple 4)) +(err/rt-test (string-ref "apple" 4.0)) +(err/rt-test (string-ref "apple" '(4))) +(err/rt-test (string-ref "apple" 5) exn:application:mismatch?) +(err/rt-test (string-ref "" 0) exn:application:mismatch?) +(err/rt-test (string-ref "" (expt 2 100)) exn:application:mismatch?) +(err/rt-test (string-ref "apple" -1)) +(test "" substring "ab" 0 0) +(test "" substring "ab" 1 1) +(test "" substring "ab" 2 2) +(test "a" substring "ab" 0 1) +(test "b" substring "ab" 1 2) +(test "ab" substring "ab" 0 2) +(test "ab" substring "ab" 0) +(test "b" substring "ab" 1) +(test "" substring "ab" 2) +(test (string #\a #\nul #\b) substring (string #\- #\a #\nul #\b #\*) 1 4) +(arity-test substring 2 3) +(err/rt-test (substring 'hello 2 3)) +(err/rt-test (substring "hello" "2" 3)) +(err/rt-test (substring "hello" 2.0 3)) +(err/rt-test (substring "hello" 2 3.0)) +(err/rt-test (substring "hello" 2 "3")) +(err/rt-test (substring "hello" 2 7) exn:application:mismatch?) +(err/rt-test (substring "hello" -2 3)) +(err/rt-test (substring "hello" 4 3) exn:application:mismatch?) +(err/rt-test (substring "hello" (expt 2 100) 3) exn:application:mismatch?) +(err/rt-test (substring "hello" (expt 2 100) 5) exn:application:mismatch?) +(err/rt-test (substring "hello" 3 (expt 2 100)) exn:application:mismatch?) +(test "foobar" string-append "foo" "bar") +(test "foo" string-append "foo") +(test "foo" string-append "foo" "") +(test "foogoo" string-append "foo" "" "goo") +(test "foo" string-append "" "foo") +(test "" string-append) +(test (string #\a #\nul #\b #\c #\nul #\d) + string-append (string #\a #\nul #\b) (string #\c #\nul #\d)) +(err/rt-test (string-append 1)) +(err/rt-test (string-append "hello" 1)) +(err/rt-test (string-append "hello" 1 "done")) +(test "" make-string 0) +(define s (string-copy "hello")) +(define s2 (string-copy s)) +(test "hello" 'string-copy s2) +(string-set! s 2 #\x) +(test "hello" 'string-copy s2) +(test (string #\a #\nul #\b) string-copy (string #\a #\nul #\b)) +(string-fill! s #\x) +(test "xxxxx" 'string-fill! s) +(arity-test string-copy 1 1) +(arity-test string-fill! 2 2) +(err/rt-test (string-copy 'blah)) +(err/rt-test (string-fill! 'sym #\1)) +(err/rt-test (string-fill! "static" #\1)) +(err/rt-test (string-fill! (string-copy "oops") 5)) + +(disable + (let ([s (make-string 10 #\x)]) + (test (void) string-copy! s 0 "hello") + (test "helloxxxxx" values s) + (test (void) string-copy! s 3 "hello") + (test "helhelloxx" values s) + (err/rt-test (string-copy! s 6 "hello") exn:application:mismatch?) + (test (void) string-copy! s 5 "hello" 3) + (test "helhelooxx" values s) + (test (void) string-copy! s 5 "hello" 3) + (test "helhelooxx" values s) + (test (void) string-copy! s 0 "hello" 3 4) + (test "lelhelooxx" values s) + (test (void) string-copy! s 1 "hello" 3 5) + (test "llohelooxx" values s) + (err/rt-test (string-copy! s 1 "hello" 3 6) exn:application:mismatch?))) + +(disable + (arity-test string-copy! 3 5) + (let ([s (string-copy x)]) + (err/rt-test (string-copy! "x" 0 "x")) + (err/rt-test (string-copy! s "x" "x")) + (err/rt-test (string-copy! 0 0 "x")) + (err/rt-test (string-copy! s 0 "x" -1)) + (err/rt-test (string-copy! s 0 "x" 1 0) exn:application:mismatch?) + (err/rt-test (string-copy! s 2 "x" 0 1) exn:application:mismatch?))) + +(test "Hello, and how are you?" string->immutable-string "Hello, and how are you?") +(arity-test string->immutable-string 1 1) +(err/rt-test (string->immutable-string 'hello)) + +(define ax (string #\a #\nul #\370 #\x)) +(define abigx (string #\a #\nul #\370 #\X)) +(define ax2 (string #\a #\nul #\370 #\x)) +(define ay (string #\a #\nul #\371 #\x)) + +(define (string-tests) + (test #t string=? "" "") + (test #f string? "" "") + (test #t string<=? "" "") + (test #t string>=? "" "") + (test #t string-ci=? "" "") + (test #f string-ci? "" "") + (test #t string-ci<=? "" "") + (test #t string-ci>=? "" "") + + (test #f string=? "A" "B") + (test #f string=? "a" "b") + (test #f string=? "9" "0") + (test #t string=? "A" "A") + (test #f string=? "A" "AB") + (test #t string=? ax ax2) + (test #f string=? ax abigx) + (test #f string=? ax ay) + (test #f string=? ay ax) + + (test #t string? "A" "B") + (test #f string>? "a" "b") + (test #t string>? "9" "0") + (test #f string>? "A" "A") + (test #f string>? "A" "AB") + (test #t string>? "AB" "A") + (test #f string>? ax ax2) + (test #f string>? ax ay) + (test #t string>? ay ax) + + (test #t string<=? "A" "B") + (test #t string<=? "a" "b") + (test #f string<=? "9" "0") + (test #t string<=? "A" "A") + (test #t string<=? "A" "AB") + (test #f string<=? "AB" "A") + (test #t string<=? ax ax2) + (test #t string<=? ax ay) + (test #f string<=? ay ax) + + (test #f string>=? "A" "B") + (test #f string>=? "a" "b") + (test #t string>=? "9" "0") + (test #t string>=? "A" "A") + (test #f string>=? "A" "AB") + (test #t string>=? "AB" "A") + (test #t string>=? ax ax2) + (test #f string>=? ax ay) + (test #t string>=? ay ax) + + (test #f string-ci=? "A" "B") + (test #f string-ci=? "a" "B") + (test #f string-ci=? "A" "b") + (test #f string-ci=? "a" "b") + (test #f string-ci=? "9" "0") + (test #t string-ci=? "A" "A") + (test #t string-ci=? "A" "a") + (test #f string-ci=? "A" "AB") + (test #t string-ci=? ax ax2) + (test #t string-ci=? ax abigx) + (test #f string-ci=? ax ay) + (test #f string-ci=? ay ax) + (test #f string-ci=? abigx ay) + (test #f string-ci=? ay abigx) + + (test #t string-ci? "A" "B") + (test #f string-ci>? "a" "B") + (test #f string-ci>? "A" "b") + (test #f string-ci>? "a" "b") + (test #t string-ci>? "9" "0") + (test #f string-ci>? "A" "A") + (test #f string-ci>? "A" "a") + (test #f string-ci>? "A" "AB") + (test #t string-ci>? "AB" "A") + (test #f string-ci>? ax ax2) + (test #f string-ci>? ax abigx) + (test #f string-ci>? ax ay) + (test #t string-ci>? ay ax) + (test #f string-ci>? abigx ay) + (test #t string-ci>? ay abigx) + + (test #t string-ci<=? "A" "B") + (test #t string-ci<=? "a" "B") + (test #t string-ci<=? "A" "b") + (test #t string-ci<=? "a" "b") + (test #f string-ci<=? "9" "0") + (test #t string-ci<=? "A" "A") + (test #t string-ci<=? "A" "a") + (test #t string-ci<=? "A" "AB") + (test #f string-ci<=? "AB" "A") + (test #t string-ci<=? ax ax2) + (test #t string-ci<=? ax abigx) + (test #t string-ci<=? ax ay) + (test #f string-ci<=? ay ax) + (test #t string-ci<=? abigx ay) + (test #f string-ci<=? ay abigx) + + (test #f string-ci>=? "A" "B") + (test #f string-ci>=? "a" "B") + (test #f string-ci>=? "A" "b") + (test #f string-ci>=? "a" "b") + (test #t string-ci>=? "9" "0") + (test #t string-ci>=? "A" "A") + (test #t string-ci>=? "A" "a") + (test #f string-ci>=? "A" "AB") + (test #t string-ci>=? "AB" "A") + (test #t string-ci>=? ax ax2) + (test #t string-ci>=? ax abigx) + (test #f string-ci>=? ax ay) + (test #t string-ci>=? ay ax) + (test #f string-ci>=? abigx ay) + (test #t string-ci>=? ay abigx)) + +(string-tests) + +(disable (map (lambda (pred) + (arity-test pred 2 -1) + (err/rt-test (pred "a" 1)) + (err/rt-test (pred "a" "b" 5)) + (err/rt-test (pred 1 "a"))) + (list string=? + string>? + string=? + string<=? + string-ci=? + string-ci>? + string-ci=? + string-ci<=? + string-locale=? + string-locale>? + string-locale? + string-locale-ciinteger #\*))) +(test #"?**" 'bytes-set! (begin (bytes-set! f 0 (char->integer #\?)) f)) +(arity-test bytes-set! 3 3) +(err/rt-test (bytes-set! #"hello" 0 #\a)) ; immutable bytes constant +(define hello-bytes (bytes-copy #"hello")) +(err/rt-test (bytes-set! hello-bytes 'a 97)) +(err/rt-test (bytes-set! 'hello 4 97)) +(err/rt-test (bytes-set! hello-bytes 4 'a)) +(err/rt-test (bytes-set! hello-bytes 4.0 'a)) +(err/rt-test (bytes-set! hello-bytes 5 97) exn:application:mismatch?) +(err/rt-test (bytes-set! hello-bytes -1 97)) +(err/rt-test (bytes-set! hello-bytes (expt 2 100) 97) exn:application:mismatch?) +(test #"abc" bytes 97 98 99) +(test #"" bytes) +(err/rt-test (bytes #\a 1)) +(err/rt-test (bytes 1 #\a)) +(err/rt-test (bytes #\1)) +(test 3 bytes-length #"abc") +(test 0 bytes-length #"") +(arity-test bytes-length 1 1) +(err/rt-test (bytes-length 'apple)) +(test 97 bytes-ref #"abc" 0) +(test 99 bytes-ref #"abc" 2) +(arity-test bytes-ref 2 2) +(err/rt-test (bytes-ref 'apple 4)) +(err/rt-test (bytes-ref #"apple" 4.0)) +(err/rt-test (bytes-ref #"apple" '(4))) +(err/rt-test (bytes-ref #"apple" 5) exn:application:mismatch?) +(err/rt-test (bytes-ref #"" 0) exn:application:mismatch?) +(err/rt-test (bytes-ref #"" (expt 2 100)) exn:application:mismatch?) +(err/rt-test (bytes-ref #"apple" -1)) +(test #"" subbytes #"ab" 0 0) +(test #"" subbytes #"ab" 1 1) +(test #"" subbytes #"ab" 2 2) +(test #"a" subbytes #"ab" 0 1) +(test #"b" subbytes #"ab" 1 2) +(test #"ab" subbytes #"ab" 0 2) +(test #"ab" subbytes #"ab" 0) +(test #"b" subbytes #"ab" 1) +(test #"" subbytes #"ab" 2) +(test (bytes 97 0 98) subbytes (bytes 32 97 0 98 45) 1 4) +(arity-test subbytes 2 3) +(err/rt-test (subbytes 'hello 2 3)) +(err/rt-test (subbytes #"hello" #"2" 3)) +(err/rt-test (subbytes #"hello" 2.0 3)) +(err/rt-test (subbytes #"hello" 2 3.0)) +(err/rt-test (subbytes #"hello" 2 #"3")) +(err/rt-test (subbytes #"hello" 2 7) exn:application:mismatch?) +(err/rt-test (subbytes #"hello" -2 3)) +(err/rt-test (subbytes #"hello" 4 3) exn:application:mismatch?) +(err/rt-test (subbytes #"hello" (expt 2 100) 3) exn:application:mismatch?) +(err/rt-test (subbytes #"hello" (expt 2 100) 5) exn:application:mismatch?) +(err/rt-test (subbytes #"hello" 3 (expt 2 100)) exn:application:mismatch?) +(test #"foobar" bytes-append #"foo" #"bar") +(test #"foo" bytes-append #"foo") +(test #"foo" bytes-append #"foo" #"") +(test #"foogoo" bytes-append #"foo" #"" #"goo") +(test #"foo" bytes-append #"" #"foo") +(test #"" bytes-append) +(test (bytes 97 0 98 99 0 100) + bytes-append (bytes 97 0 98) (bytes 99 0 100)) +(err/rt-test (bytes-append 1)) +(err/rt-test (bytes-append #"hello" 1)) +(err/rt-test (bytes-append #"hello" 1 #"done")) +(test #"" make-bytes 0) +(set! s (bytes-copy #"hello")) +(set! s2 (bytes-copy s)) +(test #"hello" 'bytes-copy s2) +(bytes-set! s 2 (char->integer #\x)) +(test #"hello" 'bytes-copy s2) +(test (bytes 97 0 98) bytes-copy (bytes 97 0 98)) +(bytes-fill! s (char->integer #\x)) +(test #"xxxxx" 'bytes-fill! s) +(arity-test bytes-copy 1 1) +(arity-test bytes-fill! 2 2) +(err/rt-test (bytes-copy 'blah)) +(err/rt-test (bytes-fill! 'sym 1)) +(err/rt-test (bytes-fill! #"static" 1)) +(err/rt-test (bytes-fill! (bytes-copy #"oops") #\5)) + +(disable (define r (regexp "(-[0-9]*)+")) + (test '("-12--345" "-345") regexp-match r "a-12--345b") + (test '((1 . 9) (5 . 9)) regexp-match-positions r "a-12--345b") + (test '("--345" "-345") regexp-match r "a-12--345b" 2) + (test '("--34" "-34") regexp-match r "a-12--345b" 2 8) + (test '((4 . 9) (5 . 9)) regexp-match-positions r "a-12--345b" 2) + (test '((4 . 8) (5 . 8)) regexp-match-positions r "a-12--345b" 2 8) + (test '("a-b") regexp-match "a[-c]b" "a-b") + (test '("a-b") regexp-match "a[c-]b" "a-b") + (test #f regexp-match "x+" "12345") + (test "su casa" regexp-replace "mi" "mi casa" "su") + (define r2 (regexp "([Mm])i ([a-zA-Z]*)")) + (define insert "\\1y \\2") + (test "My Casa" regexp-replace r2 "Mi Casa" insert) + (test "my cerveza Mi Mi Mi" regexp-replace r2 "mi cerveza Mi Mi Mi" insert) + (test "my cerveza My Mi Mi" regexp-replace* r2 "mi cerveza Mi Mi Mi" insert) + (test "bbb" regexp-replace* "a" "aaa" "b") + (test '(#"") regexp-match "" (open-input-string "123") 3) + (test '(#"") regexp-match "$" (open-input-string "123") 3) + (test '(#"") regexp-match-peek "" (open-input-string "123") 3) + + (test "b1b2b3b" regexp-replace* "" "123" "b") + (test "1b23" regexp-replace* "(?=2)" "123" "b") + (test "xax\u03BBx" regexp-replace* "" "a\u03BB" "x") + (test "xax\u03BBxbx" regexp-replace* "" "a\u03BBb" "x") + (test #"xax\316x\273xbx" regexp-replace* #"" "a\u03BBb" #"x") + (test "==1=2===3==" regexp-replace* "2*" "123" (lambda (s) (string-append "=" s "="))) + (test "==1=2===3==4==" regexp-replace* "2*" "1234" (lambda (s) (string-append "=" s "="))) + + (test "x&b\\ab=cy&w\\aw=z" regexp-replace* #rx"a(.)" "xabcyawz" "\\&\\1\\\\&\\99=") + (test "x&cy&z" regexp-replace* #rx"a(.)" "xabcyawz" "\\&") + (test "x\\cy\\z" regexp-replace* #rx"a(.)" "xabcyawz" "\\\\") + + ;; Test sub-matches with procedure replace (second example by synx) + (test "myCERVEZA myMI Mi" + regexp-replace* "([Mm])i ([a-zA-Z]*)" "mi cerveza Mi Mi Mi" + (lambda (all one two) + (string-append (string-downcase one) "y" + (string-upcase two)))) + (test #"fox in socks, blue seal. trout in socks, blue fish!" + regexp-replace* + #rx#"([a-z]+) ([a-z]+)" + #"red fox, blue seal. red trout, blue trout!" + (lambda (total color what) + (cond + ((equal? color #"red") (bytes-append what #" in socks")) + ((equal? what #"trout") (bytes-append color #" fish")) + (else (bytes-append color #" " what))))) + + ;; Test weird port offsets: + (define (test-weird-offset regexp-match regexp-match-positions) + (test #f regexp-match "e" (open-input-string "")) + (test #f regexp-match "e" (open-input-string "") (expt 2 100)) + (test #f regexp-match "e" (open-input-string "") (expt 2 100) (expt 2 101)) + (test #f regexp-match "e" (open-input-string "") (expt 2 100) (expt 2 101)) + (test '((3 . 4)) regexp-match-positions "e" (open-input-string "eaae") 2 (expt 2 101)) + (test #f regexp-match "" (open-input-string "123") 4) + (test #f regexp-match-positions "" (open-input-string "123") 4) + (test #f regexp-match "" (open-input-string "123") 999) + (test #f regexp-match-positions "" (open-input-string "123") 999) + (test #f regexp-match "" (open-input-string "123") (expt 2 101))) + (test-weird-offset regexp-match regexp-match-positions) + (test-weird-offset regexp-match-peek regexp-match-peek-positions) + + ;; Check greedy and non-greedy operators: + (define (do-the-tests prefix suffix start end) + (define input (format "~a~a~a" prefix " " suffix)) + (define (check-greedy-stuff mk-input regexp-match regexp-match-positions) + (define (testre s-answer p-answer pattern) + (let ([p-answer (if (and p-answer start) + (list (cons (+ start (caar p-answer)) + (+ start (cdar p-answer)))) + p-answer)]) + (cond + [end + (test s-answer regexp-match pattern (mk-input) start (+ end (string-length input))) + (test p-answer regexp-match-positions pattern (mk-input) start (+ end (string-length input)))] + [start + (test s-answer regexp-match pattern (mk-input) start) + (test p-answer regexp-match-positions pattern (mk-input) start)] + [else + (test s-answer regexp-match pattern (mk-input)) + (test p-answer regexp-match-positions pattern (mk-input))]))) + (define strs + (if (string? (mk-input)) + list + (lambda l (map string->bytes/utf-8 l)))) + + (testre (strs " ") '((0 . 22)) "<.*>") + (testre (strs "") '((0 . 10)) "<.*?>") + (testre (strs " ") '((0 . 22)) "<.*?>$") + (testre (strs "") '((0 . 0)) "b*") + (testre (strs "string (reverse s))] + [plain (regexp-replace* "[()]" s "")]) + (test (cons plain (map list->string (map reverse (vector->list v)))) regexp-match s plain))] + [(or (= n mx) (< (random 10) 3)) + (if (and (positive? m) + (< (random 10) 7)) + (begin + (let loop ([p 0][m (sub1 m)]) + (if (vector-ref open p) + (if (zero? m) + (vector-set! open p #f) + (loop (add1 p) (sub1 m))) + (loop (add1 p) m))) + (loop n (sub1 m) (cons #\) s))) + + (let ([c (integer->char (+ (char->integer #\a) (random 26)))]) + (let loop ([p 0]) + (unless (= p n) + (when (vector-ref open p) + (vector-set! v p (cons c (vector-ref v p)))) + (loop (add1 p)))) + (loop n m (cons c s))))] + [else + (loop (add1 n) (add1 m) (cons #\( s))])))) + '(1 10 100 500)) + + (define (test-bad-re-args who) + (err/rt-test (who 'e "hello")) + (err/rt-test (who "e" 'hello)) + (err/rt-test (who "e" "hello" -1 5)) + (err/rt-test (who "e" "hello" (- (expt 2 100)) 5)) + (err/rt-test (who "e" (open-input-string "") (- (expt 2 100)) 5)) + (err/rt-test (who "e" "hello" 1 (- (expt 2 100)))) + (err/rt-test (who "e" (open-input-string "") 1 (- (expt 2 100)))) + (err/rt-test (who "e" "hello" 1 +inf.0)) + (err/rt-test (who "e" "" 0 1) exn:application:mismatch?) + (err/rt-test (who "e" "hello" 3 2) exn:application:mismatch?) + (err/rt-test (who "e" "hello" 3 12) exn:application:mismatch?) + (err/rt-test (who "e" "hello" (expt 2 100) 5) exn:application:mismatch?) + (err/rt-test (who "e" (open-input-string "") (expt 2 100) 5) exn:application:mismatch?) + (err/rt-test (who "e" (open-input-string "") (expt 2 100) (sub1 (expt 2 100))) exn:application:mismatch?)) + (test-bad-re-args regexp-match) + (test-bad-re-args regexp-match-positions) + + ;; Test non-capturing parens + (test '("1aaa2" "a") regexp-match #rx"1(a)*2" "01aaa23") + (test '("1aaa2") regexp-match #rx"1(?:a)*2" "01aaa23") + (test '("1akakak2" "ak") regexp-match #rx"1(ak)*2" "01akakak23") + (test '("1akakak2") regexp-match #rx"1(?:ak)*2" "01akakak23") + (test '("1akakkakkkk2" "akkkk") regexp-match #rx"1(ak*)*2" "01akakkakkkk23") + (test '("1akakkakkkk2") regexp-match #rx"1(?:ak*)*2" "01akakkakkkk23") + (test '("01akakkakkkk23" "1akakkakkkk2" "1" "a" "k" "2") + regexp-match #rx"(?:0)(((?:1))(?:(a)(?:(k))*)*((?:2)))(?:3)" "_01akakkakkkk23_") + + (test '((1 . 10) (7 . 9)) regexp-match-positions #rx"1(ak*)*2" "01akakkak23") + (test '((1 . 10)) regexp-match-positions #rx"1(?:ak*)*2" "01akakkak23") + + ;; Regexps that shouldn't work: + (err/rt-test (regexp "[a--b]") exn:fail?) + (err/rt-test (regexp "[a-b-c]") exn:fail?) + + ;; A good test of unicode-friendly ".": + (test '("load-extension: couldn't open \\\" (%s)\"") + regexp-match + (regexp "^(?:[^\\\"]|\\\\.)*\"") "load-extension: couldn't open \\\" (%s)\"") + + ;; Test bounded byte consumption on failure: + (let ([is (open-input-string "barfoo")]) + (test '(#f #\f) list (regexp-match "^foo" is 0 3) (read-char is))) + (let ([is (open-input-string "barfoo")]) + (test '(#f #\f) list (regexp-match "foo" is 0 3) (read-char is))) + + (arity-test regexp 1 1) + (arity-test regexp? 1 1) + (arity-test regexp-match 2 6) + (arity-test regexp-match-positions 2 6) + (arity-test regexp-match-peek 2 6) + (arity-test regexp-match-peek-positions 2 6) + (arity-test regexp-replace 3 4) + (arity-test regexp-replace* 3 4) + ) + +(test #t procedure? car) +(test #f procedure? 'car) +(test #t procedure? (lambda (x) (* x x))) +(test #f procedure? '(lambda (x) (* x x))) +(test #t call-with-current-continuation procedure?) +(disable (test #t call-with-escape-continuation procedure?)) +(test #t procedure? (case-lambda ((x) x) ((x y) (+ x y)))) +(arity-test procedure? 1 1) + +(test 7 apply + (list 3 4)) +(test 7 apply (lambda (a b) (+ a b)) (list 3 4)) +(test 17 apply + 10 (list 3 4)) +(test '() apply list '()) +(define compose (lambda (f g) (lambda args (f (apply g args))))) +(test 30 (compose sqrt *) 12 75) +(err/rt-test (apply) exn:application:arity?) +(err/rt-test (apply (lambda x x)) exn:application:arity?) +(err/rt-test (apply (lambda x x) 1)) +(err/rt-test (apply (lambda x x) 1 2)) +(err/rt-test (apply (lambda x x) 1 '(2 . 3))) + +(test '(b e h) map cadr '((a b) (d e) (g h))) +(test '(5 7 9) map + '(1 2 3) '(4 5 6)) +(test '#(0 1 4 9 16) 'for-each + (let ((v (make-vector 5))) + (for-each (lambda (i) (vector-set! v i (* i i))) + '(0 1 2 3 4)) + v)) + + (define (map-tests map) + (let ([size? exn:application:mismatch?] + [non-list? type?]) + (err/rt-test (map (lambda (x y) (+ x y)) '(1 2) '1)) + (err/rt-test (map (lambda (x y) (+ x y)) '2 '(1 2))) + (err/rt-test (map (lambda (x y) (+ x y)) '(1 2) '(1 2 3)) size?) + (err/rt-test (map (lambda (x y) (+ x y)) '(1 2 3) '(1 2)) size?) + (err/rt-test (map (lambda (x) (+ x)) '(1 2 . 3)) non-list?) + (err/rt-test (map (lambda (x y) (+ x y)) '(1 2 . 3) '(1 2)) non-list?) + (err/rt-test (map (lambda (x y) (+ x y)) '(1 2 . 3) '(1 2 3)) non-list?) + (err/rt-test (map (lambda (x y) (+ x y)) '(1 2) '(1 2 . 3)) non-list?) + (err/rt-test (map (lambda (x y) (+ x y)) '(1 2 3) '(1 2 . 3)) non-list?) + (err/rt-test (map) exn:application:arity?) + (err/rt-test (map (lambda (x y) (+ x y))) exn:application:arity?) + (err/rt-test (map (lambda () 10) null) exn:application:mismatch?) + (err/rt-test (map (case-lambda [() 9] [(x y) 10]) '(1 2 3)) exn:application:mismatch?) + (err/rt-test (map (lambda (x) 10) '(1 2) '(3 4)) exn:application:mismatch?))) + (map-tests map) + (map-tests for-each) + (map-tests andmap) + (map-tests ormap) + +(test-values (list (void)) (lambda () (for-each (lambda (x) (values 1 2)) '(1 2)))) +(err/rt-test (map (lambda (x) (values 1 2)) '(1 2)) arity?) + +(test #t andmap add1 null) +(test #t andmap < null null) +(test #f ormap add1 null) +(test #f ormap < null null) +(test #f andmap positive? '(1 -2 3)) +(test #t ormap positive? '(1 -2 3)) +(test #f andmap < '(1 -2 3) '(2 2 3)) +(test #t ormap < '(1 -2 3) '(0 2 4)) +(test #f andmap negative? '(1 -2 3)) +(test #t ormap negative? '(1 -2 3)) +(test #t andmap < '(1 -2 3) '(2 2 4)) +(test #f ormap < '(1 -2 3) '(0 -2 3)) +(test 4 andmap add1 '(1 2 3)) +(test 2 ormap add1 '(1 2 3)) +(test #t andmap < '(1 -2 3) '(2 2 4) '(5 6 7)) +(test #t ormap < '(1 -2 3) '(0 -2 4) '(0 0 8)) + +(err/rt-test (ormap (lambda (x) (values 1 2)) '(1 2)) arity?) +(err/rt-test (andmap (lambda (x) (values 1 2)) '(1 2)) arity?) + +(test-values '(1 2) (lambda () (ormap (lambda (x) (values 1 2)) '(1)))) +(test-values '(1 2) (lambda () (andmap (lambda (x) (values 1 2)) '(1)))) + +(test -3 call-with-current-continuation + (lambda (exit) + (for-each (lambda (x) (if (negative? x) (exit x) (void))) + '(54 0 37 -3 245 19)) + #t)) +(define list-length + (lambda (obj) + (call-with-current-continuation + (lambda (return) + (letrec ((r (lambda (obj) (cond ((null? obj) 0) + ((pair? obj) (+ (r (cdr obj)) 1)) + (else (return #f)))))) + (r obj)))))) +(test 4 list-length '(1 2 3 4)) +(test #f list-length '(a b . c)) +(test '() map cadr '()) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; exceptions + + (test 10 'exns + (with-handlers ([integer? (lambda (x) 10)]) + (raise 12))) + (test '(apple) 'exns + (with-handlers ([void (lambda (x) (list x))]) + (with-handlers ([integer? (lambda (x) 10)]) + (raise 'apple)))) + (test '((10)) 'exns + (with-handlers ([void (lambda (x) (list x))]) + (with-handlers ([integer? (lambda (x) (raise (list x)))]) + (raise 10)))) +(disable (test '((10)) 'exns + (let/ec esc + (parameterize ([uncaught-exception-handler (lambda (x) (esc (list x)))]) + (with-handlers ([integer? (lambda (x) (raise (list x)))]) + (raise 10)))))) +(disable (test '#((10)) 'exns + (let/ec esc + (with-handlers ([void (lambda (x) (vector x))]) + (parameterize ([uncaught-exception-handler (lambda (x) (esc (list x)))]) + (with-handlers ([integer? (lambda (x) (raise (list x)))]) + (raise 10))))))) + +(disable (test '(except) 'escape + (let/ec k + (call-with-exception-handler + (lambda (exn) + (k (list exn))) + (lambda () (raise 'except)))))) +(disable (test '#&except 'escape + (let/ec k + (call-with-exception-handler + (lambda (exn) + (k (list exn))) + (lambda () + (call-with-exception-handler + (lambda (exn) + (k (box exn))) + (lambda () + (raise 'except)))))))) +(disable (test '#(except) 'escape + (with-handlers ([void (lambda (x) x)]) + (values + (call-with-exception-handler + (lambda (exn) + (vector exn)) + (lambda () + (raise 'except))))))) +(disable (test '#((except)) 'escape + (with-handlers ([void (lambda (x) x)]) + (values + (call-with-exception-handler + (lambda (exn) + (vector exn)) + (lambda () + ;; (Used to replace enclosing, but not any more) + (call-with-exception-handler + (lambda (exn) + (list exn)) + (lambda () + (raise 'except))))))))) +(disable (test '#((except)) 'escape + (with-handlers ([void (lambda (x) x)]) + (values + (call-with-exception-handler + (lambda (exn) + (vector exn)) + (lambda () + (values + (call-with-exception-handler + (lambda (exn) + (list exn)) + (lambda () + (raise 'except)))))))))) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;; This tests full conformance of call-with-current-continuation. It +;;; is a separate test because some schemes do not support call/cc +;;; other than escape procedures. I am indebted to +;;; raja@copper.ucs.indiana.edu (Raja Sooriamurthi) for fixing this +;;; code. The function leaf-eq? compares the leaves of 2 arbitrary +;;; trees constructed of conses. +(define (next-leaf-generator obj eot) + (letrec ((return #f) + (cont (lambda (x) + (recurx obj) + (set! cont (lambda (x) (return eot))) + (cont #f))) + (recurx (lambda (obj) + (if (pair? obj) + (for-each recurx obj) + (call-with-current-continuation + (lambda (c) + (set! cont c) + (return obj))))))) + (lambda () (call-with-current-continuation + (lambda (ret) (set! return ret) (cont #f)))))) +(define (leaf-eq? x y) + (let* ((eot (list 'eot)) + (xf (next-leaf-generator x eot)) + (yf (next-leaf-generator y eot))) + (letrec ((loop (lambda (x y) + (cond ((not (eq? x y)) #f) + ((eq? eot x) #t) + (else (loop (xf) (yf))))))) + (loop (xf) (yf))))) +(define (test-cont) + (newline) + (display ";testing continuations; ") + (test #t leaf-eq? '(a (b (c))) '((a) b c)) + (test #f leaf-eq? '(a (b (c))) '((a) b c d)) + '(report-errs)) + +(disable + (define (test-cc-values test-call/cc) + (test '(a b c) + call-with-values + (lambda () + (test-call/cc + (lambda (k) + (dynamic-wind + void + (lambda () + (k 'a 'b 'c)) + (lambda () + (values 1 2)))))) + list) + + (test 1 dynamic-wind + (lambda () (test-call/cc void)) + (lambda () 1) + (lambda () (test-call/cc void))) + + ; Try devious jumping with pre- and post-thunks: + (test 2 test-call/cc + (lambda (exit) + (dynamic-wind + (lambda () (exit 2)) + void + void))) + (test 3 test-call/cc + (lambda (exit) + (dynamic-wind + void + void + (lambda () (exit 3))))) + + (let ([rv + (lambda (get-v) + (let ([x 0]) + (test-call/cc + (lambda (exit) + (dynamic-wind + void + (lambda () (exit)) + (lambda () (set! x (get-v)))))) + x))] + [r56 + (lambda () + (let ([x 0] + [y 1] + [c1 #f]) + (dynamic-wind + (lambda () (set! x (add1 x))) + (lambda () + (let/cc k (set! c1 k)) + (if (>= x 5) + (set! c1 #f) + (void))) + (lambda () (set! y (add1 y)))) + (when c1 (c1)) + (list x y)))] + [rx.y + (lambda (get-x get-y) + (let ([c1 #f] + [x 0] + [y 0]) + (let ([v + (dynamic-wind + (lambda () (set! y x)) + (lambda () (let/cc k (set! c1 k))) + (lambda () + (set! x (get-x)) + (when c1 + ((begin0 + c1 + (set! c1 #f)) + (get-y)))))]) + (cons y v))))] + [rv2 + (lambda (get-v) + (let ([c1 #f] + [give-up #f]) + (test-call/cc + (lambda (exit) + (dynamic-wind + (lambda () (when give-up (give-up (get-v)))) + (lambda () (let/cc k (set! c1 k))) + (lambda () (set! give-up exit) (c1)))))))] + [r10-11-12 + (lambda () + (let ([c2 #f] + [x 10] + [y 11]) + (let ([v (dynamic-wind + (lambda () (set! y (add1 y))) + (lambda () (begin0 x (set! x (add1 x)))) + (lambda () (let/cc k (set! c2 k))))]) + (when c2 ((begin0 + c2 + (set! c2 #f)))) + (list v x y))))] + [r13.14 + (lambda () + (let ([c0 #f] + [x 11] + [y 12]) + (dynamic-wind + (lambda () (let/cc k (set! c0 k))) + (lambda () (set! x (add1 x))) + (lambda () + (set! y (add1 y)) + (when c0 ((begin0 + c0 + (set! c0 #f)))))) + (cons x y)))] + [ra-b-a-b + (lambda (get-a get-b) + (let ([l null]) + (let ((k-in (test-call/cc (lambda (k1) + (dynamic-wind + (lambda () (set! l (append l (list (get-a))))) + (lambda () + (call/cc (lambda (k2) (k1 k2)))) + (lambda () (set! l (append l (list (get-b)))))))))) + (k-in (lambda (v) l)))))]) + + (test 4 rv (lambda () 4)) + (test '(5 6) r56) + + (test '(7 . 8) rx.y (lambda () 7) (lambda () 8)) + + (test 9 rv2 (lambda () 9)) + + (test '(10 11 12) r10-11-12) + + (test '(13 . 14) r13.14) + + ; !!! fixed in 50: + (test '(enter exit enter exit) + ra-b-a-b (lambda () 'enter) (lambda () 'exit)) + + (test '((13 . 14) (10 11 12) (13 . 14) (10 11 12)) + ra-b-a-b r13.14 r10-11-12) + (test '((10 11 12) (13 . 14) (10 11 12) (13 . 14)) + ra-b-a-b r10-11-12 r13.14) + + (test 10 call/cc (lambda (k) (k 10))) + + (test '((enter exit enter exit) + (exit enter exit enter) + (enter exit enter exit) + (exit enter exit enter)) + ra-b-a-b + (lambda () (ra-b-a-b (lambda () 'enter) (lambda () 'exit))) + (lambda () (ra-b-a-b (lambda () 'exit) (lambda () 'enter)))) + + (test '(enter exit enter exit) + rv (lambda () (ra-b-a-b (lambda () 'enter) (lambda () 'exit)))) + (test '(enter exit enter exit) + rv2 (lambda () (ra-b-a-b (lambda () 'enter) (lambda () 'exit)))) + + (test '(10 11 12) rv r10-11-12) + (test '(10 11 12) rv2 r10-11-12) + + (test '(13 . 14) rv r13.14) + (test '(13 . 14) rv2 r13.14) + + (test 12 'dw/ec (test-call/cc + (lambda (k0) + (test-call/cc + (lambda (k1) + (test-call/cc + (lambda (k2) + (dynamic-wind + void + (lambda () (k1 6)) + (lambda () (k2 12)))))))))) + + ;; !!! fixed in 53 (for call/ec) + (test 13 'dw/ec (test-call/cc + (lambda (k0) + (test-call/cc + (lambda (k1) + (test-call/cc + (lambda (k2) + (dynamic-wind + void + (lambda () (k1 6)) + (lambda () (k2 12))))) + (k0 13)))))) + + + ;; Interaction with exceptions: + (test 42 test-call/cc (lambda (k) + (call-with-exception-handler k (lambda () (add1 (raise 42)))))) + + )) + + + (test-cc-values call/cc) + (test-cc-values call/ec)) + + + +(disable + (test 'ok + 'ec-cc-exn-combo + (with-handlers ([void (lambda (x) 'ok)]) + (define f + (let ([k #f]) + (lambda (n) + (case n + [(0) (let/ec r (r (set! k (let/cc k k))))] + [(1) (k)])))) + (f 0) + (f 1))) + ) + +(disable + (test '(1 2 3 4 1 2 3 4) 'dyn-wind-pre/post-order + (let ([x null] + [go-back #f]) + (dynamic-wind + (lambda () (set! x (cons 4 x))) + (lambda () (dynamic-wind + (lambda () (set! x (cons 3 x))) + (lambda () (set! go-back (let/cc k k))) + (lambda () (set! x (cons 2 x))))) + (lambda () (set! x (cons 1 x)))) + (if (procedure? go-back) + (go-back 1) + x))) + ) + + +(disable + (test '(5 . 5) 'suspended-cont-escape + (let ([retry #f]) + (let ([v (let/ec exit + (dynamic-wind + void + (lambda () (exit 5)) + (lambda () + (let/ec inner-escape + (set! retry (let/cc k k)) + (inner-escape 12) + 10))))]) + (if (procedure? retry) + (retry 10) + (cons v v))))) + ) + +(disable + (test '(here) 'escape-interrupt-full-jump-up + (let ([b #f] + [v null]) + (define (f g) + (dynamic-wind + void + g + (lambda () + (set! v (cons 'here v)) + (b 10)))) + + (let/ec big + (set! b big) + (let/cc ok + (f (lambda () + (ok #f))))) + + v)) + ) + + + ;; Check interaction of map and call/cc + (let () + (define (try n m) + (let ([retries (make-vector n)] + [copy #f] + [special -1] + [in (let loop ([i n]) + (if (= i 0) + null + (cons (- n i) (loop (sub1 i)))))]) + (let ([v (apply + map + (lambda (a . rest) + (+ (let/cc k (vector-set! retries a k) 1) + a)) + (let loop ([m m]) + (if (zero? m) + null + (cons in (loop (sub1 m))))))]) + (test (map (lambda (i) + (if (= i special) + (+ i 2) + (add1 i))) + in) + `(map/cc ,n ,m) + v)) + (if copy + (when (pair? copy) + (set! special (add1 special)) + ((begin0 (car copy) (set! copy (cdr copy))) + 2)) + (begin + (set! copy (vector->list retries)) + ((vector-ref retries (random n)) 1))))) + (try 3 1) + (try 10 1) + (try 3 2) + (try 10 2) + (try 5 3) + (try 3 5) + (try 10 5)) + + +;; Make sure let doesn't allocate a mutatble cell too early: +(test 2 'let+call/cc + (let ([count 0]) + (let ([first-time? #t] + [k (call/cc values)]) + (if first-time? + (begin + (set! first-time? #f) + (set! count (+ count 1)) + (k values)) + (void))) + count)) + +;; Letrec must allocate early, though: +(test #f 'letrec+call/cc + (letrec ((x (call-with-current-continuation list))) + (if (pair? x) + ((car x) (lambda () x)) + (pair? (x))))) + +(arity-test call/cc 1 2) +(disable (arity-test call/ec 1 1)) +(err/rt-test (call/cc 4)) +(err/rt-test (call/cc (lambda () 0))) +(disable (err/rt-test (call/ec 4)) + (err/rt-test (call/ec (lambda () 0)))) + +(disable (test #t primitive? car) + (test #f primitive? leaf-eq?) + (arity-test primitive? 1 1)) + +(test 1 procedure-arity procedure-arity) +(test 2 procedure-arity cons) +(test (make-arity-at-least 2) procedure-arity >) +(disable (test (list 0 1) procedure-arity current-output-port)) +(test (list 1 3 (make-arity-at-least 5)) + procedure-arity (case-lambda [(x) 0] [(x y z) 1] [(x y z w u . rest) 2])) +;; dyoo: note: the following three tests are disabled because +;; zo-parse is actually giving us bad data on the following lambdas with rest args. +;; I've reported the bug; as soon as this is fixed, I'll re-enable the test. +(disable (test (make-arity-at-least 0) procedure-arity (lambda x 1))) +(disable (test (make-arity-at-least 0) procedure-arity (case-lambda [() 10] [x 1]))) +(disable (test (make-arity-at-least 0) procedure-arity (lambda x x))) +(arity-test procedure-arity 1 1) + +(disable + (test '() normalize-arity '()) + (test 1 normalize-arity 1) + (test 1 normalize-arity '(1)) + (test '(1 2) normalize-arity '(1 2)) + (test '(1 2) normalize-arity '(2 1)) + (test (make-arity-at-least 2) normalize-arity (list (make-arity-at-least 2) 3)) + (test (list 1 (make-arity-at-least 2)) + normalize-arity (list (make-arity-at-least 2) 1)) + (test (list 1 (make-arity-at-least 2)) + normalize-arity (list (make-arity-at-least 2) 1 3)) + (test (list 0 1 (make-arity-at-least 2)) + normalize-arity (list (make-arity-at-least 2) 1 0 3)) + (test (list 0 1 (make-arity-at-least 2)) + normalize-arity (list (make-arity-at-least 2) + (make-arity-at-least 4) 1 0 3)) + (test (list 0 1 (make-arity-at-least 2)) + normalize-arity (list (make-arity-at-least 4) + (make-arity-at-least 2) 1 0 3)) + (test (list 1 2) normalize-arity (list 1 1 2 2)) + (test 1 normalize-arity (list 1 1 1)) + (test (list 1 (make-arity-at-least 2)) + normalize-arity (list (make-arity-at-least 2) 1 1)) + (test (list 1 (make-arity-at-least 2)) + normalize-arity + (list (make-arity-at-least 2) + (make-arity-at-least 2) 1 1))) + +(disable + (let () + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; + ;; randomized testing + ;; predicate: normalize-arity produces a normalized arity + ;; + + (define (normalized-arity? a) + (or (null? a) + (arity? a) + (and (list? a) + ((length a) . >= . 2) + (andmap arity? a) + (if (arity-at-least? (last a)) + (non-empty-non-singleton-sorted-list-ending-with-arity? a) + (non-singleton-non-empty-sorted-list? a))))) + + (define (arity? a) + (or (nat? a) + (and (arity-at-least? a) + (nat? (arity-at-least-value a))))) + + (define (nat? a) + (and (number? a) + (integer? a) + (a . >= . 0))) + + ;; non-empty-non-singleton-sorted-list-ending-with-arity? : xx -> boolean + ;; know that 'a' is a list of at least 2 elements + (define (non-empty-non-singleton-sorted-list-ending-with-arity? a) + (let loop ([bound (car a)] + [lst (cdr a)]) + (cond + [(null? (cdr lst)) + (and (arity-at-least? (car lst)) + (> (arity-at-least-value (car lst)) bound))] + [else + (and (nat? (car lst)) + ((car lst) . > . bound) + (loop (car lst) + (cdr lst)))]))) + + (define (non-empty-sorted-list? a) + (and (pair? a) + (sorted-list? a))) + + (define (non-singleton-non-empty-sorted-list? a) + (and (pair? a) + (pair? (cdr a)) + (sorted-list? a))) + + (define (sorted-list? a) + (or (null? a) + (sorted/bounded-list? (cdr a) (car a)))) + + (define (sorted/bounded-list? a bound) + (or (null? a) + (and (number? (car a)) + (< bound (car a)) + (sorted/bounded-list? (cdr a) (car a))))) + + (for ((i (in-range 1 2000))) + (let* ([rand-bound (ceiling (/ i 10))] + [l (build-list (random rand-bound) + (λ (i) (if (zero? (random 5)) + (make-arity-at-least (random rand-bound)) + (random rand-bound))))] + [res (normalize-arity l)]) + (unless (normalized-arity? res) + (error 'normalize-arity-failed "input ~s; output ~s" l res)))))) + + + (test #t procedure-arity-includes? cons 2) + (test #f procedure-arity-includes? cons 0) + (test #f procedure-arity-includes? cons 3) + (test #t procedure-arity-includes? list 3) + (test #t procedure-arity-includes? list 3000) + (test #t procedure-arity-includes? (lambda () 0) 0) + (test #f procedure-arity-includes? (lambda () 0) 1) + (test #f procedure-arity-includes? cons 10000000000000000000000000000) + (test #t procedure-arity-includes? list 10000000000000000000000000000) + (test #t procedure-arity-includes? (lambda x x) 10000000000000000000000000000) + + (err/rt-test (procedure-arity-includes? cons -1)) + (err/rt-test (procedure-arity-includes? cons 1.0)) + (err/rt-test (procedure-arity-includes? 'cons 1)) + + (arity-test procedure-arity-includes? 2 2) + +(newline) +(display ";testing scheme 4 functions; ") +(test '(#\P #\space #\l) string->list "P l") +(test '() string->list "") +(test "1\\\"" list->string '(#\1 #\\ #\")) +(test "" list->string '()) +(arity-test list->string 1 1) +(arity-test string->list 1 1) +(err/rt-test (string->list 'hello)) +(err/rt-test (list->string 'hello)) +(err/rt-test (list->string '(#\h . #\e))) +(err/rt-test (list->string '(#\h 1 #\e))) + +(test '(dah dah didah) vector->list '#(dah dah didah)) +(test '() vector->list '#()) +(test '#(dididit dah) list->vector '(dididit dah)) +(test '#() list->vector '()) +(arity-test list->vector 1 1) +(arity-test vector->list 1 1) +(err/rt-test (vector->list 'hello)) +(err/rt-test (list->vector 'hello)) +(err/rt-test (list->vector '(#\h . #\e))) + + +(test-cont) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; hash tables + +(arity-test make-hash 0 1) +(arity-test make-hasheq 0 1) +(disable (arity-test make-hasheqv 0 1) + (arity-test make-weak-hash 0 1) + (arity-test make-weak-hasheq 0 1) + (arity-test make-weak-hasheqv 0 1)) + +(disable + (define (hash-tests make-hash make-hasheq make-hasheqv + make-weak-hash make-weak-hasheq make-weak-hasheqv + hash-ref hash-set! hash-ref! hash-update! hash-has-key? + hash-remove! hash-count + hash-map hash-for-each + hash-iterate-first hash-iterate-next + hash-iterate-value hash-iterate-key + hash-copy) + (define-struct ax (b c)) ; opaque + (define-struct a (b c) #:inspector (make-inspector)) + + (define save + (let ([x null]) (case-lambda [() x] [(a) (set! x (cons a x)) a]))) + (define an-ax (make-ax 1 2)) + + (define (check-hash-tables weak? reorder?) + (let ([h1 (if weak? (make-weak-hasheq) (make-hasheq))] + [l (list 1 2 3)]) + (test #t eq? (eq-hash-code l) (eq-hash-code l)) + (test #t eq? (eqv-hash-code l) (eqv-hash-code l)) + (test #t eq? (equal-hash-code l) (equal-hash-code l)) + (test #t eq? (equal-hash-code l) (equal-hash-code (list 1 2 3))) + (hash-set! h1 l 'ok) + (test 'ok hash-ref h1 l) + (test #t hash-has-key? h1 l) + (test #f hash-has-key? h1 (cdr l)) + (when hash-ref! + (test 'ok hash-ref! h1 l 'blah) + (test 'blah hash-ref! h1 (cdr l) 'blah) + (test #t hash-has-key? h1 (cdr l)) + (test 'blah hash-ref h1 (cdr l)) + (hash-remove! h1 (cdr l))) + (hash-update! h1 l (curry cons 'more)) + (test '(more . ok) hash-ref h1 l) + (hash-update! h1 l cdr) + (test 'nope hash-ref h1 (list 1 2 3) (lambda () 'nope)) + (test '(((1 2 3) . ok)) hash-map h1 (lambda (k v) (cons k v))) + (hash-remove! h1 l) + (test 'nope hash-ref h1 l (lambda () 'nope)) + (err/rt-test (hash-update! h1 l add1)) + (hash-update! h1 l add1 0) + (test 1 hash-ref h1 l) + (hash-remove! h1 l)) + + (let ([h1 (if weak? (make-weak-hasheqv) (make-hasheqv))] + [n (expt 2 500)] + [q (/ 1 2)] + [s (make-string 2 #\q)]) + (hash-set! h1 n 'power) + (hash-set! h1 q 'half) + (hash-set! h1 s 'string) + (test 'power hash-ref h1 (expt (read (open-input-string "2")) 500)) + (test 'half hash-ref h1 (/ 1 (read (open-input-string "2")))) + (test #f hash-ref h1 (make-string (read (open-input-string "2")) #\q) #f)) + + (let ([h1 (if weak? (make-weak-hash) (make-hash))] + [l (list 1 2 3)] + [v (vector 5 6 7)] + [a (make-a 1 (make-a 2 3))] + [b (box (list 1 2 3))] + [fl (flvector 1.0 +nan.0 0.0)]) + + (test 0 hash-count h1) + + ;; Fill in table. Use `puts1' and `puts2' so we can + ;; vary the order of additions. + (let ([puts1 (lambda () + (hash-set! h1 (save l) 'list) + (hash-set! h1 (save "Hello World!") 'string) + (hash-set! h1 (save 123456789123456789123456789) 'bignum) + (hash-set! h1 (save 3.45) 'flonum) + (hash-set! h1 (save 3/45) 'rational) + (hash-set! h1 (save 3+45i) 'complex) + (hash-set! h1 (save (integer->char 955)) 'char) + (hash-set! h1 (save fl) 'flvector))] + [puts2 (lambda () + (hash-set! h1 (save (list 5 7)) 'another-list) + (hash-set! h1 (save 3+0.0i) 'izi-complex) + (hash-set! h1 (save v) 'vector) + (hash-set! h1 (save a) 'struct) + (hash-set! h1 (save an-ax) 'structx) + (hash-set! h1 (save b) 'box))]) + (if reorder? + (begin + (puts2) + (test 6 hash-count h1) + (puts1)) + (begin + (puts1) + (test 8 hash-count h1) + (puts2)))) + + (when reorder? + ;; Add 1000 things and take them back out in an effort to + ;; trigger GCs that somehow affect hashing: + (let loop ([i 0.0]) + (unless (= i 1000.0) + (hash-set! h1 i #t) + (loop (add1 i)) + (hash-remove! h1 i)))) + + (test 14 hash-count h1) + (test 'list hash-ref h1 l) + (test 'list hash-ref h1 (list 1 2 3)) + (test 'another-list hash-ref h1 (list 5 7)) + (test 'string hash-ref h1 "Hello World!") + (test 'bignum hash-ref h1 123456789123456789123456789) + (test 'flonum hash-ref h1 3.45) + (test 'rational hash-ref h1 3/45) + (test 'complex hash-ref h1 3+45i) + (test 'izi-complex hash-ref h1 3+0.0i) + (test 'vector hash-ref h1 v) + (test 'vector hash-ref h1 #(5 6 7)) + (test 'struct hash-ref h1 a) + (test 'struct hash-ref h1 (make-a 1 (make-a 2 3))) + (test 'structx hash-ref h1 an-ax) + (test #f hash-ref h1 (make-ax 1 2) (lambda () #f)) + (test 'box hash-ref h1 b) + (test 'box hash-ref h1 #&(1 2 3)) + (test 'char hash-ref h1 (integer->char 955)) + (test 'flvector hash-ref h1 (flvector 1.0 +nan.0 0.0)) + (test #t + andmap + (lambda (i) + (and (member i (hash-map h1 (lambda (k v) (cons k v)))) + #t)) + `(((1 2 3) . list) + ((5 7) . another-list) + ("Hello World!" . string) + (123456789123456789123456789 . bignum) + (3.45 . flonum) + (3/45 . rational) + (3+45i . complex) + (3+0.0i . izi-complex) + (#(5 6 7) . vector) + (,(make-a 1 (make-a 2 3)) . struct) + (,an-ax . structx) + (#\u3BB . char) + (#&(1 2 3) . box) + (,(flvector 1.0 +nan.0 0.0) . flvector))) + (hash-remove! h1 (list 1 2 3)) + (test 13 hash-count h1) + (test 'not-there hash-ref h1 l (lambda () 'not-there)) + (let ([c 0]) + (hash-for-each h1 (lambda (k v) (set! c (add1 c)))) + (test 13 'count c)) + ;; return the hash table: + h1)) + + (define (check-tables-equal mode t1 t2 weak?) + (test #t equal? t1 t2) + (test (equal-hash-code t1) equal-hash-code t2) + (test #t equal? t1 (hash-copy t1)) + (let ([again (if weak? (make-weak-hash) (make-hash))]) + (let loop ([i (hash-iterate-first t1)]) + (when i + (hash-set! again + (hash-iterate-key t1 i) + (hash-iterate-value t1 i)) + (loop (hash-iterate-next t1 i)))) + (test #t equal? t1 again)) + (let ([meta-ht (make-hash)]) + (hash-set! meta-ht t1 mode) + (test mode hash-ref meta-ht t2 (lambda () #f))) + (test (hash-count t1) hash-count t2)) + + (check-tables-equal 'the-norm-table + (check-hash-tables #f #f) + (check-hash-tables #f #t) + #f) + (when make-weak-hash + (check-tables-equal 'the-weak-table + (check-hash-tables #t #f) + (check-hash-tables #t #t) + #t)) + + (save)) ; prevents gcing of the ht-registered values + + (hash-tests make-hash make-hasheq make-hasheqv + make-weak-hash make-weak-hasheq make-weak-hasheqv + hash-ref hash-set! hash-ref! hash-update! hash-has-key? + hash-remove! hash-count + hash-map hash-for-each + hash-iterate-first hash-iterate-next + hash-iterate-value hash-iterate-key + hash-copy) + (let ([ub-wrap (lambda (proc) + (lambda (ht . args) + (apply proc (unbox ht) args)))]) + (hash-tests (lambda () (box #hash())) + (lambda () (box #hasheq())) + (lambda () (box #hasheqv())) + #f #f #f + (ub-wrap hash-ref) + (lambda (ht k v) (set-box! ht (hash-set (unbox ht) k v))) + #f + (case-lambda + [(ht k u) (set-box! ht (hash-update (unbox ht) k u))] + [(ht k u def) (set-box! ht (hash-update (unbox ht) k u def))]) + (ub-wrap hash-has-key?) + (lambda (ht k) (set-box! ht (hash-remove (unbox ht) k))) + (ub-wrap hash-count) + (ub-wrap hash-map) + (ub-wrap hash-for-each) + (ub-wrap hash-iterate-first) + (ub-wrap hash-iterate-next) + (ub-wrap hash-iterate-value) + (ub-wrap hash-iterate-key) + (lambda (ht) (box (unbox ht)))))) + +(test #f hash? 5) +(test #t hash? (make-hasheq)) +(disable (test #t hash? (make-hasheqv)) + (test #t hash-eq? (make-hasheq)) + (test #f hash-eq? (make-hash)) + (test #f hash-eq? (make-hasheqv)) + (test #t hash-eq? (make-weak-hasheq)) + (test #f hash-eq? (make-weak-hash)) + (test #f hash-eq? (make-weak-hasheqv)) + (test #f hash-eqv? (make-hasheq)) + (test #f hash-eqv? (make-hash)) + (test #t hash-eqv? (make-hasheqv)) + (test #f hash-eqv? (make-weak-hasheq)) + (test #f hash-eqv? (make-weak-hash)) + (test #t hash-eqv? (make-weak-hasheqv)) + (test #f hash-weak? (make-hasheq)) + (test #f hash-weak? (make-hash)) + (test #f hash-weak? (make-hasheqv)) + (test #t hash-weak? (make-weak-hasheq)) + (test #t hash-weak? (make-weak-hash)) + (test #t hash-weak? (make-weak-hasheqv))) + +(disable + (let ([ht (make-hasheqv)] + [l (list #x03B1 #x03B2 #x03B3)] + [l2 '(1 2 3)]) + (for-each (lambda (a b) + (hash-set! ht (integer->char a) b)) + l l2) + (test '(3 2 1) + map + (lambda (a) + (hash-ref ht (integer->char a) #f)) + (reverse l)))) + +(disable (err/rt-test (hash-eq? 5))) +(disable (err/rt-test (hash-eqv? 5))) +(disable (err/rt-test (hash-weak? 5))) + +(disable + (let ([a (expt 2 500)] + [b (expt (read (open-input-string "2")) 500)]) + (test #t equal? (eqv-hash-code a) (eqv-hash-code b)) + (test #t equal? (equal-hash-code a) (equal-hash-code b)))) + +(disable + ;; Check for proper clearing of weak hash tables + ;; (internally, value should get cleared along with key): + (let ([ht (make-weak-hasheq)]) + (let loop ([n 10]) + (unless (zero? n) + (hash-set! ht (make-string 10) #f) + (loop (sub1 n)))) + (collect-garbage) + (map (lambda (i) (format "~a" i)) (hash-map ht cons)))) + +;; Double check that table are equal after deletions +(let ([test-del-eq + (lambda (mk) + (let ([ht1 (mk)] + [ht2 (mk)]) + (test #t equal? ht1 ht2) + (hash-set! ht1 'apple 1) + (hash-set! ht2 'apple 1) + (test #t equal? ht1 ht2) + (hash-set! ht2 'banana 2) + (test #f equal? ht1 ht2) + (hash-remove! ht2 'banana) + (test #t equal? ht1 ht2)))]) + (test-del-eq make-hasheq) + (test-del-eq make-hash) + (disable (test-del-eq make-weak-hasheq)) + (disable (test-del-eq make-weak-hash))) + +(disable (err/rt-test (hash-count 0))) +(err/rt-test (hash-set! 1 2 3)) +(err/rt-test (hash-ref 1 2)) +(err/rt-test (hash-remove! 1 2)) +(err/rt-test (hash-ref (make-hasheq) 2) exn:application:mismatch?) + +(let ([mk (lambda (mk) + (let ([ht (mk)]) + (hash-set! ht make-hash 2) + ht))]) + (test #t equal? (mk make-hash) (mk make-hash)) + (test #t equal? (mk make-hasheq) (mk make-hasheq)) + (disable (test #t equal? (mk make-hasheqv) (mk make-hasheqv))) + (test #f equal? (mk make-hash) (mk make-hasheq)) + (disable (test #f equal? (mk make-hash) (mk make-hasheqv))) + (disable (test #f equal? (mk make-hasheq) (mk make-hasheqv))) + (disable (test #f equal? (mk make-hash) (mk make-weak-hash))) + (disable (test #f equal? (mk make-hasheq) (mk make-weak-hasheq))) + (disable (test #f equal? (mk make-hasheqv) (mk make-weak-hasheqv)))) +(disable + (let ([mk (lambda (mk) + (mk `((1 . 2))))]) + (test #t equal? (mk make-immutable-hash) (mk make-immutable-hash)) + (test #t equal? (mk make-immutable-hasheq) (mk make-immutable-hasheq)) + (test #t equal? (mk make-immutable-hasheqv) (mk make-immutable-hasheqv)) + (test #f equal? (mk make-immutable-hash) (mk make-immutable-hasheq)) + (test #f equal? (mk make-immutable-hash) (mk make-immutable-hasheqv)) + (test #f equal? (mk make-immutable-hasheq) (mk make-immutable-hasheqv)))) + +(disable + (define im-t (make-immutable-hasheq null)) + (test #t hash? im-t) + (test #t hash-eq? im-t) + (test null hash-map im-t cons) + (err/rt-test (hash-set! im-t 1 2)) + (test #f hash-ref im-t 5 (lambda () #f)) + (set! im-t (make-immutable-hasheq '((1 . 2)))) + (test '((1 . 2)) hash-map im-t cons) + (test 2 hash-ref im-t 1) + (set! im-t (make-immutable-hasheq '(("hello" . 2)))) + (test 'none hash-ref im-t "hello" (lambda () 'none)) + (set! im-t (make-immutable-hash '(("hello" . 2)))) + (test 2 hash-ref im-t "hello" (lambda () 'none)) + (test #f hash-eq? im-t)) + +(test #f equal? #hash((x . 0)) #hash((y . 0))) +(test #t equal? #hash((y . 0)) #hash((y . 0))) + +(disable + (err/rt-test (hash-set! im-t 1 2)) + (err/rt-test (hash-remove! im-t 1)) + (err/rt-test (make-immutable-hasheq '(1))) + (err/rt-test (make-immutable-hasheq '((1 . 2) . 2))) + (err/rt-test (make-immutable-hasheq '((1 . 2) 3))) + + (define cyclic-alist (read (open-input-string "#0=((1 . 2) . #0#)"))) + (err/rt-test (make-immutable-hasheq cyclic-alist)) + (err/rt-test (make-immutable-hasheq '((1 . 2)) 'weak))) + +(disable (test 2 hash-ref (hash-copy #hasheq((1 . 2))) 1) + (test (void) hash-set! (hash-copy #hasheq((1 . 2))) 3 4)) + +(disable + (test #f hash-iterate-first (make-hasheq)) + (test #f hash-iterate-first (make-weak-hasheq)) + (err/rt-test (hash-iterate-next (make-hasheq) 0)) + (err/rt-test (hash-iterate-next (make-weak-hasheq) 0))) + +(disable + (let ([check-all-bad + (lambda (op) + (err/rt-test (op #f 0)) + (err/rt-test (op (make-hasheq) -1)) + (err/rt-test (op (make-hasheq) (- (expt 2 100)))) + (err/rt-test (op (make-hasheq) 1.0)))]) + (check-all-bad hash-iterate-next) + (check-all-bad hash-iterate-key) + (check-all-bad hash-iterate-value))) + +(disable (arity-test make-immutable-hash 1 1)) +(disable (arity-test make-immutable-hasheq 1 1)) +(disable (arity-test hash-count 1 1)) +(arity-test hash-ref 2 3) +(arity-test hash-set! 3 3) +(disable (arity-test hash-set 3 3)) +(arity-test hash-remove! 2 2) +(disable (arity-test hash-remove 2 2)) +(arity-test hash-map 2 2) +(arity-test hash-for-each 2 2) +(arity-test hash? 1 1) +(disable (arity-test hash-eq? 1 1)) +(disable (arity-test hash-weak? 1 1)) + +(disable + ;; Ensure that hash-table hashing is not sensitive to the + ;; order of key+value additions + (let () + (define ht (make-hash)) + (define ht2 (make-hash)) + (define wht (make-weak-hash)) + (define wht2 (make-weak-hash)) + (define keys (make-hash)) + + (struct a (x) #:transparent) + + (define (shuffle c l) + (if (zero? c) + l + (shuffle + (sub1 c) + (let ([n (quotient (length l) 2)]) + (let loop ([a (take l n)][b (drop l n)]) + (cond + [(null? a) b] + [(null? b) a] + [(zero? (random 2)) + (cons (car a) (loop (cdr a) b))] + [else + (cons (car b) (loop a (cdr b)))])))))) + + (define l (for/list ([i (in-range 1000)]) + i)) + + (define l2 (shuffle 7 l)) + + (define (reg v) + (hash-set! keys v #t) + v) + + (for ([i (in-list l)]) + (hash-set! ht (a i) (a (a i)))) + (for ([i (in-list l2)]) + (hash-set! ht2 (a i) (a (a i)))) + + (for ([i (in-list l)]) + (hash-set! wht (reg (a i)) (a (a i)))) + (for ([i (in-list l2)]) + (hash-set! wht2 (reg (a i)) (a (a i)))) + + (test (equal-hash-code ht) values (equal-hash-code ht2)) + (test (equal-hash-code wht) values (equal-hash-code wht2)) + (test (equal-secondary-hash-code ht) values (equal-secondary-hash-code ht2)) + + (let ([ht (for/hash ([i (in-list l)]) + (values (a i) (a (a i))))] + [ht2 (for/hash ([i (in-list l2)]) + (values (a i) (a (a i))))]) + (test (equal-hash-code ht) values (equal-hash-code ht2)) + (test (equal-secondary-hash-code ht) values (equal-secondary-hash-code ht2))))) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Misc + +(disable (test #t string? (version)) + (test #t string? (banner)) + (test #t symbol? (system-type)) + (test (system-type) system-type 'os) + (test #t string? (system-type 'machine)) + (test #t symbol? (system-type 'link)) + (test #t relative-path? (system-library-subpath)) + + (test #t 'cmdline (let ([v (current-command-line-arguments)]) + (and (vector? v) + (andmap string? (vector->list v))))) + (err/rt-test (current-command-line-arguments '("a"))) + (err/rt-test (current-command-line-arguments #("a" 1))) + + (arity-test version 0 0) + (arity-test banner 0 0) + (arity-test system-type 0 1) + (arity-test system-library-subpath 0 1) + (arity-test current-command-line-arguments 0 1)) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; procedure-closure-contents-eq? + +(disable + (for-each + (lambda (jit?) + (parameterize ([eval-jit-enabled jit?]) + (let ([f #f]) + (set! f (eval '(lambda (x) (lambda () x)))) + ((f 'c)) ; forced JIT compilation + (test #t procedure-closure-contents-eq? (f 'a) (f 'a)) + (test #f procedure-closure-contents-eq? (f 'a) (f 'b)) + (set! f (eval '(case-lambda + [(x) (lambda () 12)] + [(x y) (lambda () (list x y))]))) + ((f 'c)) ; forces JIT compilation + ((f 'c 'd)) ; forces JIT compilation + (test #t procedure-closure-contents-eq? (f 'a) (f 'a)) + (test #t procedure-closure-contents-eq? (f 'a 'b) (f 'a 'b)) + (test #f procedure-closure-contents-eq? (f 'a 'b) (f 'c 'b))))) + '(#t #f)) + (test #t procedure-closure-contents-eq? add1 add1)) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +(disable + ;; procedure-reduce-arity + (let ([check-ok + (lambda (proc ar inc not-inc) + (for-each + (lambda (proc) + (let ([a (procedure-reduce-arity proc ar)]) + (test #t procedure? a) + (test (normalize-arity ar) procedure-arity a) + (map (lambda (i) + (test #t procedure-arity-includes? a i) + (when (i . < . 100) + (test i apply a (let loop ([i i]) + (if (zero? i) + null + (cons 1 (loop (sub1 i)))))))) + inc) + (map (lambda (i) + (test #f procedure-arity-includes? a i) + (err/rt-test (procedure-reduce-arity a i)) + (err/rt-test (procedure-reduce-arity a (make-arity-at-least i))) + (err/rt-test (procedure-reduce-arity a (list 0 i))) + (err/rt-test (procedure-reduce-arity a (list 0 (make-arity-at-least i)))) + (err/rt-test (procedure-reduce-arity a (make-arity-at-least 0))) + (when (i . < . 100) + (err/rt-test (apply a (let loop ([i i]) + (if (zero? i) + null + (cons 1 (loop (sub1 i)))))) + exn:fail:contract?))) + not-inc))) + (list proc (procedure-reduce-arity proc ar))))]) + (let ([check-all-but-one + (lambda (+) + (check-ok + 0 '(0) '(1)) + (check-ok + 2 '(2) '(0 1 3 4)) + (check-ok + 10 '(10) (list 0 11 (expt 2 70))) + (check-ok + (expt 2 70) (list (expt 2 70)) (list 0 10 (add1 (expt 2 70)))) + (check-ok + (make-arity-at-least 2) (list 2 5 (expt 2 70)) (list 0 1)) + (check-ok + (list 2 4) '(2 4) '(0 3)) + (check-ok + (list 2 4) '(4 2) '(0 3)) + (check-ok + (list 0 (make-arity-at-least 2)) (list 0 2 5 (expt 2 70)) (list 1)) + (check-ok + (list 4 (make-arity-at-least 2)) '(2 3 4 10) '(0 1)) + (check-ok + (list 2 (make-arity-at-least 4)) '(2 4 10) '(0 1 3)))]) + (check-all-but-one +) + (check-all-but-one (procedure-rename + 'plus)) + (check-all-but-one (lambda args (apply + args))) + (check-all-but-one (procedure-rename (lambda args (apply + args)) 'PLUS)) + (check-all-but-one (case-lambda + [() 0] + [(a b . args) (apply + a b args)])) + (check-all-but-one (case-lambda + [(b . args) (apply + b args)] + [() 0])) + (check-all-but-one (case-lambda + [(a b c) (+ a b c)] + [(a b) (+ a b)] + [(a b c d) (+ a b c d)] + [() 0] + [(a b c d . e) (apply + a b c d e)])) + (check-all-but-one (case-lambda + [(a b) (+ a b)] + [(a b c d) (+ a b c d)] + [(a b c) (+ a b c)] + [() 0] + [(a b c d . e) (apply + a b c d e)])))) + + (test '+ object-name (procedure-reduce-arity + 3)) + (test 'plus object-name (procedure-rename + 'plus)) + (test 'again object-name (procedure-rename (procedure-rename + 'plus) 'again)) + (test 'again object-name (procedure-rename (procedure-reduce-arity + 3) 'again)) + (test 3 procedure-arity (procedure-rename (procedure-reduce-arity + 3) 'again))) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(report-errs) + +"last item in file" diff --git a/tests/older-tests/mz-tests/list.rkt b/tests/older-tests/mz-tests/list.rkt new file mode 100644 index 0000000..a0b7dc4 --- /dev/null +++ b/tests/older-tests/mz-tests/list.rkt @@ -0,0 +1,423 @@ +#lang s-exp "../../lang/base.rkt" + +(require "testing.rkt") +(require (for-syntax racket/base)) + + +(test (list 1 2 3 4) foldl cons '() (list 4 3 2 1)) +(test (list 1 2 3 4) foldr cons '() (list 1 2 3 4)) +(test (list (list 5 6) (list 3 4) (list 1 2)) + foldl (lambda (x y sofar) (cons (list x y) sofar)) + '() + (list 1 3 5) + (list 2 4 6)) +(test (list (list 1 2) (list 3 4) (list 5 6)) + foldr (lambda (x y sofar) (cons (list x y) sofar)) + '() + (list 1 3 5) + (list 2 4 6)) + +(arity-test foldl 3 -1) +(arity-test foldr 3 -1) + +(err/rt-test (foldl 'list 0 10)) +(err/rt-test (foldl list 0 10)) +(err/rt-test (foldl add1 0 '())) +(err/rt-test (foldl cons 0 '() '())) +(err/rt-test (foldl list 0 '() 10)) +(err/rt-test (foldl list 0 '() '() 10)) +(err/rt-test (let/cc k (foldl k 0 '(1 2) '(1 2 3)))) +(err/rt-test (let/cc k (foldl k 0 '(1 2) '(1 2) '(1 2 3)))) +(err/rt-test (foldr 'list 0 10)) +(err/rt-test (foldr list 0 10)) +(err/rt-test (foldr add1 0 '())) +(err/rt-test (foldr cons 0 '() '())) +(err/rt-test (foldr list 0 '() 10)) +(err/rt-test (foldr list 0 '() '() 10)) +(err/rt-test (let/cc k (foldr k 0 '(1 2) '(1 2 3)))) +(err/rt-test (let/cc k (foldr k 0 '(1 2) '(1 2) '(1 2 3)))) + +(test '(0 1 2) memf add1 '(0 1 2)) +(test '(2 (c 17)) memf number? '((a 1) (0 x) (1 w) 2 (c 17))) +(test '("ok" (2 .7) c) memf string? '((a 0) (0 a) (1 w) "ok" (2 .7) c)) +(err/rt-test (memf cons '((1) (2) (3)))) +(err/rt-test (memf string? '((1) (2) (3) . 4)) exn:application:mismatch?) + +#| dyoo: missing assf +(err/rt-test (assf add1 '(0 1 2)) exn:application:mismatch?) +(test '(0 x) assf number? '((a 1) (0 x) (1 w) (2 r) (c 17))) +(test '("ok" . 10) assf string? '((a 0) (0 a) (1 w) ("ok" . 10) (2 .7) c)) +(err/rt-test (assf cons '((1) (2) (3)))) +(err/rt-test (assf string? '((1) (2) (3) . 4)) exn:application:mismatch?) + +|# + + +#| dyoo: missing last +;; ---------- last, last-pair ---------- +(let () + (test 3 last '(1 2 3)) + (test '(3) last-pair '(1 2 3)) + (err/rt-test (last '(1 2 3 . 4))) + (test '(3 . 4) last-pair '(1 2 3 . 4)) + (err/rt-test (last '())) + (err/rt-test (last 1)) + (err/rt-test (last-pair '())) + (err/rt-test (last-pair 1))) +|# + + +;; ---------- sort ---------- +(test '("a" "b" "c" "c" "d" "e" "f") + sort + '("d" "f" "e" "c" "a" "c" "b") + stringkeyword keyword->string + +eq-hash-code + +string-copy! + +exn:fail:out-of-memory? + +regular expressions: regexp-match, regexp-match-positions, ... + +call-with-escape-continuation, dynamic-wind, let/ec, call/ec + +call-with-exception-handler, uncaught-exception-handler + +normalize-arity + +read + +make-placeholder + +version, banner, system-type, current-command-line-arguments, system-library-subpath, current-output-port + +eval, eval-jit-enabled diff --git a/tests/older-tests/mz-tests/number.rkt b/tests/older-tests/mz-tests/number.rkt new file mode 100644 index 0000000..1929df8 --- /dev/null +++ b/tests/older-tests/mz-tests/number.rkt @@ -0,0 +1,2749 @@ +#lang s-exp "../../lang/base.rkt" + +(require "testing.rkt") + +(Section 'numbers) + +(test #f number? 'a) +(test #f complex? 'a) +(test #f real? 'a) +(test #f rational? 'a) +(test #f integer? 'a) + +(test #t number? 3) +(test #t complex? 3) +(test #t real? 3) +(test #t rational? 3) +(test #t integer? 3) + +(test #t number? 3.0) +(test #t complex? 3.0) +(test #t real? 3.0) +(test #t rational? 3.0) +(test #t integer? 3.0) + +(test #t number? 3.1) +(test #t complex? 3.1) +(test #t real? 3.1) +(test #t rational? 3.1) +(test #f integer? 3.1) + +(test #t number? 3/2) +(test #t complex? 3/2) +(test #t real? 3/2) +(test #t rational? 3/2) +(test #f integer? 3/2) + +(test #t number? 3+i) +(test #t complex? 3+i) +(test #f real? 3+i) +(test #f rational? 3+i) +(test #f integer? 3+i) + +(test #t number? 3.0+0i) +(test #t complex? 3.0+0i) +(test #t real? 3.0+0i) +(test #t rational? 3.0+0i) +(test #t integer? 3.0+0i) + +(test #t number? 3.0+0.0i) +(test #t complex? 3.0+0.0i) +(test #f real? 3.0+0.0i) +(test #f rational? 3.0+0.0i) +(test #f integer? 3.0+0.0i) + +(test #t number? 3.1+0.0i) +(test #t complex? 3.1+0.0i) +(test #f real? 3.1+0.0i) +(test #f rational? 3.1+0.0i) +(test #f integer? 3.1+0.0i) + +(test #t exact? 3) +(test #t exact? 3/4) +(test #f exact? 3.0) +(test #t exact? (expt 2 100)) +(test #t exact? 3+4i) +(test #f exact? 3.0+4i) + +(test #f inexact? 3) +(test #f inexact? 3/4) +(test #t inexact? 3.0) +(test #f inexact? (expt 2 100)) +(test #f inexact? 3+4i) +(test #t inexact? 3.0+4i) +(test #t inexact? 0+4.0i) +(test #t inexact? 4+0.i) + +(test #t complex? -4.242154731064108e-5-6.865001427422244e-5i) +(test #f exact? -4.242154731064108e-5-6.865001427422244e-5i) +(test #t inexact? -4.242154731064108e-5-6.865001427422244e-5i) + +(test #t complex? -4.242154731064108f-5-6.865001427422244f-5i) +(test #f exact? -4.242154731064108f-5-6.865001427422244f-5i) +(test #t inexact? -4.242154731064108f-5-6.865001427422244f-5i) + +(test #t number? +inf.0) +(test #t complex? +inf.0) +(test #t real? +inf.0) +(test #f rational? +inf.0) +(test #f integer? +inf.0) + +(test #t number? -inf.0) +(test #t complex? -inf.0) +(test #t real? -inf.0) +(test #f rational? -inf.0) +(test #f integer? -inf.0) + +(test #t number? +nan.0) +(test #t complex? +nan.0) +(test #t real? +nan.0) +(test #f rational? +nan.0) +(test #f integer? +nan.0) + +(arity-test inexact? 1 1) +(arity-test number? 1 1) +(arity-test complex? 1 1) +(arity-test real? 1 1) +(arity-test rational? 1 1) +(arity-test integer? 1 1) +(arity-test exact? 1 1) +(arity-test inexact? 1 1) + +(err/rt-test (exact? 'a)) +(err/rt-test (inexact? 'a)) + +(test "+inf.0" number->string +inf.0) +(test "-inf.0" number->string -inf.0) +(test "+nan.0" number->string +nan.0) +(test "+nan.0" number->string +nan.0) + +(map (lambda (n) + ;; test that fresh strings are generated: + (let ([n1 (number->string n)] + [n2 (number->string n)]) + (string-set! n1 0 #\?) + (test n2 number->string n) + (test n1 string-append "?" (substring n2 1 (string-length n2))))) + '(+inf.0 -inf.0 +nan.0 -nan.0 0.0 -0.0 0 1/2 3.4 1+2i)) + +(test #t = 0.0 -0.0) +(test #f eqv? 0.0 -0.0) +(test #f equal? 0.0 -0.0) +(test #f eqv? -0.0 0.0) +(test #t eqv? 0.0 0.0) +(test #t eqv? -0.0 -0.0) + +(test #t = 22 22 22) +(test #t = 22 22) +(test #f = 34 34 35) +(test #f = 34 35) +(test #t > 3 -6246) +(test #f > 9 9 -2424) +(test #t >= 3 -4 -6246) +(test #t >= 9 9) +(test #f >= 8 9) +(test #t < -1 2 3 4 5 6 7 8) +(test #f < -1 2 3 4 4 5 6 7) +(test #t <= -1 2 3 4 5 6 7 8) +(test #t <= -1 2 3 4 4 5 6 7) +(test #f < 1 3 2) +(test #f >= 1 3 2) + +(define (test-compare lo m hi) ; all positive! + (define -lo (- lo)) + (define -m (- m)) + (define -hi (- hi)) + + (define (test-lh l h) + (test #f > l h) + (test #t < l h) + (test #f = l h) + (test #f >= l h) + (test #t <= l h)) + + (define (test-hl h l) + (test #t > h l) + (test #f < h l) + (test #f = h l) + (test #t >= h l) + (test #f <= h l)) + + (define (test-zero z) + (test-hl m z) + (test-lh -m z) + (test-hl z -m) + (test-lh z m)) + + (test-lh m hi) + (test-hl -m -hi) + + (test #f > m m) + (test #f < m m) + (test #t = m m) + (test #t >= m m) + (test #t <= m m) + + (test-hl m -m) + (test-lh -m m) + + (test-hl m lo) + (test-lh -m -lo) + + (test-zero 0) + (test-zero 0.0)) + +(test-compare 0.5 1.2 2.3) +(test-compare 2/5 1/2 2/3) +(test-compare 1/4 1/3 1/2) ; same numerator +(test-compare 3/10 7/10 9/10) ; same denominator +(test-compare 2/500000000000000000000000000 1/200000000000000000000000000 2/300000000000000000000000000) ; bignums +(test #t = 1/2 2/4) +(test #f = 2/3 2/5) +(test #f = 2/3 2/500000000000000000000000000) + +(test-compare 0.5 6/5 2.3) +(test-compare 1 11922615739/10210200 3000) +(test-compare 1.0 11922615739/10210200 3000.0) + +(err/rt-test (< 1 2.3+0.0i)) +(err/rt-test (> 1 2.3+0.0i)) +(err/rt-test (<= 1 2.3+0.0i)) +(err/rt-test (>= 1 2.3+0.0i)) +(err/rt-test (< 2.3+0.0i 1)) +(err/rt-test (> 2.3+0.0i 1)) +(err/rt-test (<= 2.3+0.0i 1)) +(err/rt-test (>= 2.3+0.0i 1)) + +(test #f > 0 (/ 1 (expt 2 400))) + +(test #t < 0.5 2/3) +(test #f < 2/3 0.5) +(test #t = 0.5 1/2) +(test #t = +0.5i +1/2i) +(test #f = +0.5i 1+1/2i) +(test #t = 1 1.0+0i) +(test #t = 1 1.0+0.0i) +(test #f eqv? 1.0 1.0+0.0i) +(test #f eqv? 1.0-0.0i 1.0+0.0i) +(test #f eqv? 1.0+0.0i 1.0-0.0i) +(test #t eqv? 1.0+0.0i 1.0+0.0i) +(test #t eqv? 1.0-0.0i 1.0-0.0i) + +(test #f = 1+2i 2+i) + +;; Test transitivity in mixed exact--inexact settings +;; (Thanks again to Aubrey Jaffer for the starting point.) +(define (test-trans expect op nop a b c) + ;; Make sure the tests check what we want to check: + (test #t = (exact->inexact a) b) + (test #t = (exact->inexact c) b) + (test #t = (exact->inexact (- a)) (- b)) + (test #t = (exact->inexact (- c)) (- b)) + ;; The real tests: + (test expect op a b) + (test expect op b c) + (test expect op a b c) + (test expect nop (- a) (- b)) + (test expect nop (- b) (- c)) + (test expect nop (- a) (- b) (- c)) + (test expect nop c b) + (test expect nop b a) + (test expect nop c b a) + (test expect op (- c) (- b)) + (test expect op (- b) (- a)) + (test expect op (- c) (- b) (- a))) +(test-trans #t < >= 1237940039285380274899124223 1.2379400392853803e+27 1237940039285380274899124225) +(test-trans #t < >= 3713820117856140824697372668/3 1.2379400392853803e+27 3713820117856140824697372676/3) +(test-trans #f > <= 1237940039285380274899124223 1.2379400392853803e+27 1237940039285380274899124225) +(test-trans #f > <= 3713820117856140824697372668/3 1.2379400392853803e+27 3713820117856140824697372676/3) +(test-trans #f = = 1237940039285380274899124223 1.2379400392853803e+27 1237940039285380274899124225) +(test-trans #f = = 3713820117856140824697372668/3 1.2379400392853803e+27 3713820117856140824697372676/3) +(test-trans #t <= > 1237940039285380274899124223 1.2379400392853803e+27 1237940039285380274899124225) +(test-trans #t <= > 3713820117856140824697372668/3 1.2379400392853803e+27 3713820117856140824697372676/3) +(test-trans #f >= < 1237940039285380274899124223 1.2379400392853803e+27 1237940039285380274899124225) +(test-trans #f >= < 3713820117856140824697372668/3 1.2379400392853803e+27 3713820117856140824697372676/3) + +(define (test-nan.0 f . args) + (apply test +nan.0 f args)) + +(define (test-i-nan.0 f . args) + (apply test (make-rectangular +nan.0 +nan.0) f args)) + +(define (test-nan c) + (test #f < +nan.0 c) + (test #f > +nan.0 c) + (test #f = +nan.0 c) + (test #f <= +nan.0 c) + (test #f >= +nan.0 c)) +(test-nan 0) +(test-nan 0.0) +(test-nan 0.3) +(test-nan +nan.0) +(test-nan +inf.0) +(test-nan -inf.0) +(test-nan (expt 2 90)) +(err/rt-test (test-nan 0.3+0.0i)) +(test #f = +nan.0 1+2i) +(test #f = +nan.0 (make-rectangular +inf.0 -inf.0)) + +(test-compare 999999999999 1000000000000 1000000000001) +(define big-num (expt 2 1500)) +(test-compare (sub1 big-num) big-num (add1 big-num)) +(test-compare 1.0 (expt 10 100) 1e200) + +(define (inf-zero-test inf rx negnot) + (let ([inf-test-x + (lambda (r v) + (test r < v inf) + (test (not r) > v inf) + (test r <= v inf) + (test (not r) >= v inf) + + (test (not r) < inf v) + (test r > inf v) + (test (not r) <= inf v) + (test r >= inf v))]) + (inf-test-x rx 5) + (inf-test-x (negnot rx) -5) + (inf-test-x rx big-num) + (inf-test-x (negnot rx) (- big-num)) + (inf-test-x rx (/ big-num 3)) + (inf-test-x (negnot rx) (/ (- big-num) 3)) + (inf-test-x rx (/ 1 big-num)) + (inf-test-x (negnot rx) (/ 1 (- big-num))))) +(inf-zero-test +inf.0 #t (lambda (x) x)) +(inf-zero-test -inf.0 #f (lambda (x) x)) +(inf-zero-test 0.0 #f not) + +(err/rt-test (= 1 'a)) +(err/rt-test (= 1 1 'a)) +(err/rt-test (= 1 2 'a)) +(err/rt-test (= 'a 1)) +(err/rt-test (> 1 'a)) +(err/rt-test (> 1 0 'a)) +(err/rt-test (> 1 2 'a)) +(err/rt-test (> 'a 1)) +(err/rt-test (> 0.5+0.1i 1)) +(err/rt-test (> 1 0.5+0.1i)) +(err/rt-test (< 1 'a)) +(err/rt-test (< 1 2 'a)) +(err/rt-test (< 1 0 'a)) +(err/rt-test (< 'a 1)) +(err/rt-test (< 0.5+0.1i 1)) +(err/rt-test (< 1 0.5+0.1i)) +(err/rt-test (>= 1 'a)) +(err/rt-test (>= 1 1 'a)) +(err/rt-test (>= 1 2 'a)) +(err/rt-test (>= 'a 1)) +(err/rt-test (>= 0.5+0.1i 1)) +(err/rt-test (>= 1 0.5+0.1i)) +(err/rt-test (<= 1 'a)) +(err/rt-test (<= 1 1 'a)) +(err/rt-test (<= 1 0 'a)) +(err/rt-test (<= 'a 1)) +(err/rt-test (<= 0.5+0.1i 1)) +(err/rt-test (<= 1 0.5+0.1i)) + +(arity-test = 2 -1) +(arity-test < 2 -1) +(arity-test > 2 -1) +(arity-test <= 2 -1) +(arity-test >= 2 -1) + +(test #t zero? 0) +(test #t zero? 0.0) +(test #t zero? +0.0i) +(test #t zero? -0.0i) +(test #t zero? 0.0+0.0i) +(test #f zero? 1.0+0.0i) +(test #f zero? 1.0+1.0i) +(test #f zero? 0.0+1.0i) +(test #t zero? 0/1) +(test #f zero? 1) +(test #f zero? -1) +(test #f zero? -100) +(test #f zero? 1.0) +(test #f zero? -1.0) +(test #f zero? 1/2) +(test #f zero? -1/2) +(test #f zero? -1/2+2i) +(test #f zero? +inf.0) +(test #f zero? -inf.0) +(test #f zero? +nan.0) +(test #f zero? (expt 2 37)) +(test #f zero? (expt -2 37)) +(test #t positive? 4) +(test #f positive? -4) +(test #f positive? 0) +(test #t positive? 4.0) +(test #f positive? -4.0) +(test #f positive? 0.0) +(test #t positive? 2/4) +(test #f positive? -2/4) +(test #f positive? 0/2) +(test #t positive? +inf.0) +(test #f positive? -inf.0) +(test #f positive? +nan.0) +(test #t positive? (expt 2 37)) +(test #f positive? (expt -2 37)) +(test #f negative? 4) +(test #t negative? -4) +(test #f negative? 0) +(test #f negative? 4.0) +(test #t negative? -4.0) +(test #f negative? 0.0) +(test #f negative? 2/4) +(test #t negative? -2/4) +(test #f negative? 0/4) +(test #f negative? (expt 2 37)) +(test #t negative? (expt -2 37)) +(test #f negative? +inf.0) +(test #t negative? -inf.0) +(test #f negative? +nan.0) +(err/rt-test (negative? 5+0.0i)) +(err/rt-test (negative? -5+0.0i)) +(test #t odd? 3) +(test #f odd? 2) +(test #f odd? -4) +(test #t odd? -1) +(err/rt-test (odd? +inf.0)) +(err/rt-test (odd? -inf.0)) +(err/rt-test (odd? 5+0.0i)) +(err/rt-test (odd? 4+0.0i)) +(test #f odd? (expt 2 37)) +(test #f odd? (expt -2 37)) +(test #t odd? (add1 (expt 2 37))) +(test #t odd? (sub1 (expt -2 37))) +(test #f even? 3) +(test #t even? 2) +(test #t even? -4) +(test #f even? -1) +(err/rt-test (even? +inf.0)) +(err/rt-test (even? -inf.0)) +(err/rt-test (even? 4+0.0i)) +(err/rt-test (even? 5+0.0i)) +(test #t even? (expt 2 37)) +(test #t even? (expt -2 37)) +(test #f even? (add1 (expt 2 37))) +(test #f even? (sub1 (expt -2 37))) + +(arity-test zero? 1 1) +(arity-test positive? 1 1) +(arity-test negative? 1 1) +(arity-test odd? 1 1) +(arity-test even? 1 1) + +(err/rt-test (positive? 5+0.0i)) +(err/rt-test (positive? -5+0.0i)) +(err/rt-test (positive? 2+i)) +(err/rt-test (negative? 2+i)) +(err/rt-test (odd? 4.1)) +(err/rt-test (odd? 4.1+0.0i)) +(err/rt-test (odd? 4+1i)) +(err/rt-test (even? 4.1)) +(err/rt-test (even? 4.1+0.0i)) +(err/rt-test (even? 4+1i)) +(err/rt-test (even? +nan.0)) + +(err/rt-test (positive? 'i)) +(err/rt-test (negative? 'i)) +(err/rt-test (odd? 'a)) +(err/rt-test (even? 'a)) +(err/rt-test (odd? 'i)) +(err/rt-test (even? 'i)) + +(test 5 max 5) +(test 5 min 5) +(test 38 max 34 5 7 38 6) +(test -24 min 3 5 5 330 4 -24) +(test 38.0 max 34 5.0 7 38 6) +(test -24.0 min 3 5 5 330 4 -24.0) +(test 2/3 max 1/2 2/3) +(test 2/3 max 2/3 1/2) +(test 2/3 max 2/3 -4/5) +(test 1/2 min 1/2 2/3) +(test 1/2 min 2/3 1/2) +(test -4/5 min 2/3 -4/5) +(test +inf.0 max +inf.0 0 -inf.0) +(test -inf.0 min +inf.0 0 -inf.0) +(test-nan.0 max +inf.0 +nan.0 0 -inf.0) +(test-nan.0 min +inf.0 0 +nan.0 -inf.0) +(err/rt-test (min 9.0+0.0i 100)) +(err/rt-test (min 9.0+0.0i 8)) +(err/rt-test (min 100 9.0+0.0i)) +(err/rt-test (min 8 9.0+0.0i)) +(err/rt-test (max 9.0+0.0i 100)) +(err/rt-test (max 9.0+0.0i 8)) +(err/rt-test (max 100 9.0+0.0i)) +(err/rt-test (max 8 9.0+0.0i)) + +(test (expt 5 27) max 9 (expt 5 27)) +(test (expt 5 29) max (expt 5 29) (expt 5 27)) +(test (expt 5 29) max (expt 5 27) (expt 5 29)) +(test (expt 5 27) max (expt 5 27) 9) +(test (expt 5 27) max (expt 5 27) (- (expt 5 29))) +(test (expt 5 27) max (- (expt 5 29)) (expt 5 27)) +(test (- (expt 5 27)) max (- (expt 5 27)) (- (expt 5 29))) +(test (- (expt 5 27)) max (- (expt 5 29)) (- (expt 5 27))) +(test 9 min 9 (expt 5 27)) +(test (expt 5 27) min (expt 5 29) (expt 5 27)) +(test (expt 5 27) min (expt 5 27) (expt 5 29)) +(test 9 min (expt 5 27) 9) +(test (- (expt 5 29)) min (expt 5 27) (- (expt 5 29))) +(test (- (expt 5 29)) min (- (expt 5 29)) (expt 5 27)) +(test (- (expt 5 29)) min (- (expt 5 27)) (- (expt 5 29))) +(test (- (expt 5 29)) min (- (expt 5 29)) (- (expt 5 27))) + +(err/rt-test (max 0 'a)) +(err/rt-test (min 0 'a)) +(err/rt-test (max 'a 0)) +(err/rt-test (min 'a 0)) +(err/rt-test (max 'a)) +(err/rt-test (min 'a)) +(err/rt-test (min 2 4+i)) +(err/rt-test (max 2 4+i)) +(err/rt-test (min 4+i)) +(err/rt-test (max 4+i)) + +(arity-test max 1 -1) +(arity-test min 1 -1) + +(test 0 +) +(test 7 + 3 4) +(test 6 + 1 2 3) +(test 7.0 + 3 4.0) +(test 6.0 + 1 2.0 3) +(test 19/12 + 1/4 1/3 1) +(test +i + +i) +(test 3/2+1i + 1 2+2i -i -3/2) +(test 3 + 3) +(test 0 +) +(test 4 * 4) +(test 16.0 * 4 4.0) +(test 1 *) +(test 6/25 * 3/5 1/5 2) +(test #i+6/25 * 3/5 1/5 2.0) +(test +6/25i * 3/5 1/5 2 +i) +(test (make-rectangular 0 #i+6/25) * 3/5 1/5 2.0 +i) +(test 18805208620685182736256260714897 + * (sub1 (expt 2 31)) + 8756857658476587568751) +(test 1073741874 + (- (expt 2 30) 50) 100) ; fixnum -> bignum for 32 bits +(test -1073741874 - (- 50 (expt 2 30)) 100) ; fixnum -> bignum for 32 bits +(test 10.0+0.0i + 9.0+0.0i 1) +(test 10.0+0.0i + 9.0+0.0i 1-0.0i) +(test 9.0+0.0i * 9.0+0.0i 1) +(test 10.0-1.0i + 9.0+0.0i 1-1.0i) +(test 0 * 0 10.0) +(test 0 * 0 +inf.0) +(test 0 * 0 +nan.0) +(test 0 / 0 0.0) +(test 0 / 0 +inf.0) +(test 0 / 0 -inf.0) +(test 0 / 0 +nan.0) +(test -0.0 + 0 -0.0) +(test -0.0 + -0.0 0) +(test -0.0 - -0.0 0) + +(test -0.0 - 0.0) +(test 0.0 - -0.0) +(test -0.0 - 0 0.0) +(test 0.0 - 0 -0.0) + +(arity-test * 0 -1) +(arity-test + 0 -1) +(arity-test - 1 -1) +(arity-test / 1 -1) + +(test 2 add1 1) +(test 0 add1 -1) +(test 2.0 add1 1.0) +(test 0.0 add1 -1.0) +(test 3/2 add1 1/2) +(test 1/2 add1 -1/2) +(test 2.0+i add1 1.0+i) +(test 0.0+i add1 -1.0+i) +(test 0.0+0.0i add1 -1+0.0i) +(test 0.0-0.0i add1 -1-0.0i) +(test 1073741824 add1 #x3FFFFFFF) ; fixnum boundary case + +(err/rt-test (add1 "a")) +(arity-test add1 1 1) + +(test 1 sub1 2) +(test -2 sub1 -1) +(test 1.0 sub1 2.0) +(test -2.0 sub1 -1.0) +(test -1/2 sub1 1/2) +(test -3/2 sub1 -1/2) +(test 1.0+i sub1 2.0+i) +(test -2.0+i sub1 -1.0+i) +(test -2.0+0.0i sub1 -1+0.0i) +(test -2.0-0.0i sub1 -1-0.0i) +(test -1073741824 sub1 -1073741823) ; fixnum boundary case + +(err/rt-test (sub1 "a")) +(arity-test sub1 1 1) + +(test 1024 expt 2 10) +(test 1/1024 expt 2 -10) +(test 1/1024 expt 1/2 10) +(test (/ 1 (expt 2 10000)) expt 1/2 10000) +(test 2 expt 4 1/2) +(test 2.0 expt 4 0.5) +(test (sqrt 5) expt 5 1/2) +(test 18446744073709551616 expt (expt 2 32) 2) +(arity-test expt 2 2) + +(test 31525197391593472 inexact->exact 31525197391593473.0) +(test 31525197391593476 inexact->exact 31525197391593476.0) +(test 31525197391593476 inexact->exact 31525197391593476.0) + +(test 0 apply + (map inexact->exact (list 3.2d+270 -2.4d+270 -8d+269))) +(test 0 apply + (map inexact->exact (list 3.2f+7 -2.4f+7 -8f+6))) + +(test #t positive? (inexact->exact 0.1)) +(test #t negative? (inexact->exact -0.1)) +(test 0 + (inexact->exact -0.1) (inexact->exact 0.1)) +(arity-test inexact->exact 1 1) +(err/rt-test (inexact->exact 'a)) +(test 1+i inexact->exact 1.0+1.0i) +(test 1 inexact->exact 1.0+0.0i) +(test 1 inexact->exact 1.0-0.0i) + +(test #t positive? (exact->inexact 1/10)) +(test #t negative? (exact->inexact -1/10)) +(test 0.0 + (exact->inexact -1/10) (exact->inexact 1/10)) +(arity-test exact->inexact 1 1) +(err/rt-test (exact->inexact 'a)) +(test 1.0+1.0i exact->inexact 1+1i) +(test 1.0+0.0i exact->inexact 1+0.0i) +(test (expt 7 30) inexact->exact (expt 7 30)) + +(err/rt-test (inexact->exact +inf.0)) +(err/rt-test (inexact->exact -inf.0)) +(err/rt-test (inexact->exact +nan.0)) + +(err/rt-test (* 'a 0)) +(err/rt-test (+ 'a 0)) +(err/rt-test (/ 'a 0)) +(err/rt-test (- 'a 0)) +(err/rt-test (+ 0 'a)) +(err/rt-test (* 0 'a)) +(err/rt-test (- 0 'a)) +(err/rt-test (/ 0 'a)) +(err/rt-test (+ 'a)) +(err/rt-test (* 'a)) +(err/rt-test (- 'a)) +(err/rt-test (/ 'a)) + +(define (test-inf-plus-times v) + (define (test+ +) + (test +inf.0 + v (+ +inf.0)) + (test -inf.0 + v (+ -inf.0)) + (test +inf.0 + (- v) (+ +inf.0)) + (test -inf.0 + (- v) (+ -inf.0)) + + (test +inf.0 + +inf.0 v) + (test -inf.0 + -inf.0 v) + (test +inf.0 + +inf.0 (- v)) + (test -inf.0 + -inf.0 (- v)) + + (test-nan.0 + +nan.0 v) + (test-nan.0 + v +nan.0)) + + (test+ +) + (test+ -) + + (test +inf.0 * +inf.0 v) + (test -inf.0 * -inf.0 v) + (test -inf.0 * +inf.0 (- v)) + (test +inf.0 * -inf.0 (- v)) + + (test +inf.0 * v +inf.0) + (test -inf.0 * v -inf.0) + (test -inf.0 * (- v) +inf.0) + (test +inf.0 * (- v) -inf.0) + + (test-nan.0 * +nan.0 v) + (test-nan.0 * v +nan.0)) + +(test-inf-plus-times 1) +(test-inf-plus-times 1.0) +(test-inf-plus-times (expt 2 100)) + +(test -inf.0 - +inf.0) +(test +inf.0 - -inf.0) +(test +inf.0 + +inf.0 +inf.0) +(test -inf.0 + -inf.0 -inf.0) +(test-nan.0 + +inf.0 -inf.0) +(test-nan.0 - +inf.0 +inf.0) +(test-nan.0 - -inf.0 -inf.0) +(test +inf.0 * +inf.0 +inf.0) +(test -inf.0 * +inf.0 -inf.0) +(test 0 * +inf.0 0) +(test-nan.0 * +inf.0 0.0) +(test-nan.0 + +nan.0 +nan.0) +(test-nan.0 - +nan.0 +nan.0) +(test-nan.0 * +nan.0 +nan.0) + +(test 1/2 / 1 2) +(test -1/3 / -1 3) +(test -1/3 / 1 -3) +(test 1/2 / 1/4 1/2) +(test 0.5 / 1 2.0) +(test 0.5 / 1.0 2) +(test 1/2+3/2i / 1+3i 2) +(test 1/5-3/5i / 2 1+3i) +(test 0.5+0.0i / 1+0.0i 2) +(test 0.25-0.0i / 1 4+0.0i) +(test 0.25+0.0i / 1+0.0i 4+0.0i) +(test 0 / 0 4+3i) +(test 0.25+0.0i / 1e300+1e300i (* 4 1e300+1e300i)) +(test 0.25+0.0i / 1e-300+1e-300i (* 4 1e-300+1e-300i)) +(test 1/2-1/2i / 1+1i) +(test 1/2+1/2i / 1-1i) +(test 1/5-2/5i / 1+2i) +(test 1/5+2/5i / 1-2i) +(test 2/5-1/5i / 2+1i) +(test 2/5+1/5i / 2-1i) +(test 0.5-0.5i / 1.0+1.0i) +(test 0.5+0.5i / 1.0-1.0i) +(test 0.2-0.4i / 1.0+2.0i) +(test 0.2+0.4i / 1.0-2.0i) +(test 0.4-0.2i / 2.0+1.0i) +(test 0.4+0.2i / 2.0-1.0i) + +(test 3 / 1 1/3) +(test -3 / 1 -1/3) +(test -3 / -1 1/3) +(test 3 / -1 -1/3) +(test 1/3 / 1 3) +(test -1/3 / 1 -3) +(test -1/3 / -1 3) +(test 1/3 / -1 -3) +(test 3/2 / 1 2/3) +(test -3/2 / 1 -2/3) +(test -3/2 / -1 2/3) +(test 3/2 / -1 -2/3) + +(test (expt 3 50) / 1 (/ 1 (expt 3 50))) +(test (- (expt 3 50)) / 1 (- (/ 1 (expt 3 50)))) +(test (- (expt 3 50)) / -1 (/ 1 (expt 3 50))) +(test (expt 3 50) / -1 (- (/ 1 (expt 3 50)))) +(test (/ 1 (expt 3 50)) / 1 (expt 3 50)) +(test (- (/ 1 (expt 3 50))) / 1 (- (expt 3 50))) +(test (- (/ 1 (expt 3 50))) / -1 (expt 3 50)) +(test (/ 1 (expt 3 50)) / -1 (- (expt 3 50))) +(test (/ (expt 3 50) (expt 2 70)) / 1 (/ (expt 2 70) (expt 3 50))) +(test (- (/ (expt 3 50) (expt 2 70))) / 1 (- (/ (expt 2 70) (expt 3 50)))) +(test (- (/ (expt 3 50) (expt 2 70))) / -1 (/ (expt 2 70) (expt 3 50))) +(test (/ (expt 3 50) (expt 2 70)) / -1 (/ (- (expt 2 70)) (expt 3 50))) + +(test (- (expt 2 30)) / (- (expt 2 30)) 1) +(test (expt 2 30) / (- (expt 2 30)) -1) +(test (expt 2 29) / (- (expt 2 30)) -2) +(test -1/1073741824 / (- (expt 2 30))) + +(test +inf.0 / 1.0 0.0) +(test -inf.0 / -1.0 0.0) +(test +inf.0 / -1.0 -0.0) +(test -inf.0 / 1.0 -0.0) + +(define (make-test-inf-zero-div zero -zero inf -inf) + (lambda (v) + (test zero / v +inf.0) + (test -zero / v -inf.0) + (test -zero / (- v) +inf.0) + (test zero / (- v) -inf.0) + + (test inf / +inf.0 v) + (test -inf / -inf.0 v) + (test -inf / +inf.0 (- v)) + (test inf / -inf.0 (- v)) + + (unless (zero? v) + (test zero / 0.0 v) + (test -zero / 0.0 (- v)) + (test -zero / -0.0 v) + (test zero / -0.0 (- v)) + + (test inf / v 0.0) + (test -inf / (- v) 0.0) + (test -inf / v -0.0) + (test inf / (- v) -0.0)) + + (test-nan.0 / +nan.0 v) + (test-nan.0 / v +nan.0))) + +(define test-inf-zero-div (make-test-inf-zero-div 0.0 -0.0 +inf.0 -inf.0)) +(define test-neg-inf-zero-div (make-test-inf-zero-div -0.0 0.0 -inf.0 +inf.0)) + +(test-inf-zero-div big-num) +(test-inf-zero-div (/ big-num 3)) +(test-inf-zero-div 0.0) + +(test-neg-inf-zero-div (- big-num)) +(test-neg-inf-zero-div (- (/ big-num 3))) +(test-neg-inf-zero-div -0.0) + +(test-nan.0 / +inf.0 +inf.0) +(test-nan.0 / +inf.0 -inf.0) +(test-nan.0 / +nan.0 -nan.0) + +(test 1.0 exact->inexact (/ big-num (add1 big-num))) + +(test 0.0 values (exact->inexact (/ (expt 2 5000) (add1 (expt 2 5000000))))) +(test -0.0 values (exact->inexact (/ (- (expt 2 5000)) (add1 (expt 2 5000000))))) +(test #t positive? (exact->inexact (* 5 (expt 10 -324)))) +(test #t negative? (exact->inexact (* -5 (expt 10 -324)))) +(test #t zero? (exact->inexact (* 5 (expt 10 -325)))) +(test #t positive? (exact->inexact (* 45 (expt 10 -325)))) + +(err/rt-test (/ 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (/ 1 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (/ 1/2 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (/ 1+2i 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (/ 1.0 0) exn:fail:contract:divide-by-zero?) + +(test -1 - 3 4) +(test -3 - 3) +(test -1.0 - 3.0 4) +(test -3.0 - 3.0) +(test 7 abs -7) +(test (expt 7 100) abs (- (expt 7 100))) +(test (expt 7 100) abs (expt 7 100)) +(test 7.0 abs -7.0) +(test 7 abs 7) +(test 0 abs 0) +(test 1/2 abs 1/2) +(test 1/2 abs -1/2) +(test +inf.0 abs +inf.0) +(test +inf.0 abs -inf.0) +(test-nan.0 abs -nan.0) +(err/rt-test (abs -4.0+0.0i)) + +(test 1073741823 abs -1073741823) +(test 1073741823 abs 1073741823) +(test 1073741824 abs -1073741824) +(test 1073741824 abs 1073741824) +(test 1073741825 abs -1073741825) +(test 1073741825 abs 1073741825) + +(arity-test abs 1 1) +(err/rt-test (-) exn:application:arity?) +(err/rt-test (abs 'a)) +(err/rt-test (abs +5i)) + +(test 5 quotient 35 7) +(test 5.0 quotient 35 7.0) +(test 5.0 quotient 36 7.0) +(test 5.0 quotient 36.0 7) +(test -5 quotient -35 7) +(test -5.0 quotient -35 7.0) +(test -5 quotient 35 -7) +(test -5.0 quotient 35 -7.0) +(test 5 quotient -35 -7) +(test 5.0 quotient -35 -7.0) +(test -5.0 quotient -36 7.0) +(test -5.0 quotient 36.0 -7) +(err/rt-test (quotient 36.0 -7+0.0i)) +(err/rt-test (quotient 36.0+0.0i -7)) +(test 0 quotient 0 5.0) +(test 0 quotient 0 -5.0) +(test (expt 2 30) quotient (- (expt 2 30)) -1) +(test 1 modulo 13 4) +(test 1 remainder 13 4) +(test 1.0 modulo 13 4.0) +(test 1.0 remainder 13 4.0) +(test 3 modulo -13 4) +(test -1 remainder -13 4) +(test 3.0 modulo -13 4.0) +(test -1.0 remainder -13 4.0) +(test -3 modulo 13 -4) +(test 1 remainder 13 -4) +(test -3.0 modulo 13.0 -4) +(test 1.0 remainder 13.0 -4) +(test -1 modulo -13 -4) +(test -1 remainder -13 -4) +(test -1.0 modulo -13 -4.0) +(test -1.0 remainder -13 -4.0) +(err/rt-test (modulo -13 -4.0+0.0i)) +(err/rt-test (remainder -13 -4.0+0.0i)) +(err/rt-test (modulo -13+0.0i -4.0)) +(err/rt-test (remainder -13+0.0i -4.0)) +(test -2 remainder -3333333332 -3) +(test -2 modulo -3333333332 -3) +(test 2 remainder 3333333332 -3) +(test -1 modulo 3333333332 -3) +(test 0 modulo 4 2) +(test 0 modulo -4 2) +(test 0 modulo 4 -2) +(test 0 modulo -4 -2) +(test 0.0 modulo 4.0 2) +(test 0.0 modulo -4.0 2) +(test 0.0 modulo 4.0 -2) +(test 0.0 modulo -4.0 -2) +(test 0 remainder 4 2) +(test 0 remainder -4 2) +(test 0 remainder 4 -2) +(test 0 remainder -4 -2) +(test 0.0 remainder 4.0 2) +(test 0.0 remainder -4.0 2) +(test 0.0 remainder 4.0 -2) +(test 0.0 remainder -4.0 -2) +(test 0 modulo 0 5.0) +(test 0 modulo 0 -5.0) +(test 0 remainder 0 5.0) +(test 0 remainder 0 -5.0) +(test 0 modulo (- (expt 2 30)) -1) +(test 0 remainder (- (expt 2 30)) -1) +(define (divtest n1 n2) + (= n1 (+ (* n2 (quotient n1 n2)) + (remainder n1 n2)))) +(test #t divtest 238 9) +(test #t divtest -238 9) +(test #t divtest 238 -9) +(test #t divtest -238 -9) + +(test 13.0 quotient 1324.0 100) + +(err/rt-test (quotient 6 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (modulo 6 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (remainder 6 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (quotient 6 0.0) exn:fail:contract:divide-by-zero?) +(err/rt-test (modulo 6 0.0) exn:fail:contract:divide-by-zero?) +(err/rt-test (remainder 6 0.0) exn:fail:contract:divide-by-zero?) +(err/rt-test (quotient 6 -0.0) exn:fail:contract:divide-by-zero?) +(err/rt-test (modulo 6 -0.0) exn:fail:contract:divide-by-zero?) +(err/rt-test (remainder 6 -0.0) exn:fail:contract:divide-by-zero?) + +(define (test-qrm-inf v) + (define iv (exact->inexact v)) + + (err/rt-test (quotient v +inf.0)) + (err/rt-test (quotient v -inf.0)) + (err/rt-test (remainder v +inf.0)) + (err/rt-test (remainder v -inf.0)) + (err/rt-test (modulo v +inf.0)) + (err/rt-test (modulo v -inf.0)) + + (err/rt-test (quotient +inf.0 v)) + (err/rt-test (quotient -inf.0 v)) + (err/rt-test (remainder +inf.0 v)) + (err/rt-test (remainder -inf.0 v)) + (err/rt-test (modulo +inf.0 v)) + (err/rt-test (modulo -inf.0 v))) + +(test-qrm-inf 9) +(test-qrm-inf 9.0) +(test-qrm-inf (expt 2 100)) +(test-qrm-inf 0.0) +(test-qrm-inf -0.0) + +;; Check 0.0 combinations +(test -0.0 quotient -0.0 2.0) +(test 0.0 quotient -0.0 -2.0) +(test 0.0 quotient 0.0 2.0) +(test -0.0 quotient 0.0 -2.0) +(test 0.0 modulo -0.0 2.0) +(test 0.0 modulo -0.0 -2.0) +(test 0.0 modulo 0.0 2.0) +(test 0.0 modulo 0.0 -2.0) +(test 0.0 remainder -0.0 2.0) +(test 0.0 remainder -0.0 -2.0) +(test 0.0 remainder 0.0 2.0) +(test 0.0 remainder 0.0 -2.0) + +(arity-test quotient 2 2) +(arity-test modulo 2 2) +(arity-test remainder 2 2) + +(err/rt-test (quotient 'a 1)) +(err/rt-test (quotient 1 'a)) +(err/rt-test (quotient 1 +nan.0)) +(err/rt-test (quotient +nan.0 1)) +(err/rt-test (modulo 'a 1)) +(err/rt-test (modulo 1 'a)) +(err/rt-test (modulo +nan.0 1)) +(err/rt-test (modulo 1 +nan.0)) +(err/rt-test (remainder 'a 1)) +(err/rt-test (remainder 1 'a)) +(err/rt-test (remainder +nan.0 1)) +(err/rt-test (remainder 1 +nan.0)) +(err/rt-test (quotient 'a 1.0)) +(err/rt-test (quotient 1.0 'a)) +(err/rt-test (modulo 'a 1.0)) +(err/rt-test (modulo 1.0 'a)) +(err/rt-test (remainder 'a 1.0)) +(err/rt-test (remainder 1.0 'a)) +(err/rt-test (quotient 1/2 1)) +(err/rt-test (remainder 1/2 1)) +(err/rt-test (modulo 1/2 1)) +(err/rt-test (quotient 2 1/2)) +(err/rt-test (remainder 2 1/2)) +(err/rt-test (modulo 2 1/2)) +(err/rt-test (quotient 12.3 1)) +(err/rt-test (remainder 12.3 1)) +(err/rt-test (modulo 12.3 1)) +(err/rt-test (quotient 2 12.3)) +(err/rt-test (remainder 2 12.3)) +(err/rt-test (modulo 2 12.3)) +(err/rt-test (quotient 1+2i 1)) +(err/rt-test (remainder 1+2i 1)) +(err/rt-test (modulo 1+2i 1)) +(err/rt-test (quotient 2 1+2i)) +(err/rt-test (remainder 2 1+2i)) +(err/rt-test (modulo 2 1+2i)) + +#| dyoo: no support for bitwise operations yet. +(test 10 bitwise-ior 10) +(test 10 bitwise-and 10) +(test 10 bitwise-xor 10) +(test 7 bitwise-ior 3 4) +(test 0 bitwise-and 3 4) +(test 7 bitwise-xor 3 4) +(test 7 bitwise-ior 3 4 1) +(test 1 bitwise-and 3 5 1) +(test 6 bitwise-xor 3 4 1) + +(test #x1ffff7777 bitwise-ior #x1aaaa5555 #x155553333) +(test #x100001111 bitwise-and #x1aaaa5555 #x155553333) +(test #x0ffff6666 bitwise-xor #x1aaaa5555 #x155553333) + +(test #x3ffff7777 bitwise-ior #x2aaaa5555 #x155553333) +(test #x000001111 bitwise-and #x2aaaa5555 #x155553333) +(test #x3ffff6666 bitwise-xor #x2aaaa5555 #x155553333) + +(test #x3ffff7777 bitwise-ior #x2aaaa5555 #x155553333) +(test #x000001111 bitwise-and #x2aaaa5555 #x155553333) +(test #x3ffff6666 bitwise-xor #x2aaaa5555 #x155553333) + +(test #xfffffffffffffe bitwise-not #x-FFFFFFFFFFFFFF) +(test #x-100000000000000 bitwise-not #xFFFFFFFFFFFFFF) + +(test (bitwise-and (bitwise-not #x-2aaaa5555) (bitwise-not #x-15555aaaa)) + bitwise-not (bitwise-ior #x-2aaaa5555 #x-15555aaaa)) +(test (bitwise-and (bitwise-not #x-2aaaa5555) (bitwise-not #x-155553333)) + bitwise-not (bitwise-ior #x-2aaaa5555 #x-155553333)) +(test (bitwise-and (bitwise-not #x-2aaaa5555) (bitwise-not #x-15555333)) + bitwise-not (bitwise-ior #x-2aaaa5555 #x-15555333)) + +(test #x-155553333 bitwise-xor #x-2aaaa5555 (bitwise-xor #x-2aaaa5555 #x-155553333)) +(test #x-15555333 bitwise-xor #x-2aaaa5555 (bitwise-xor #x-2aaaa5555 #x-15555333)) + +(test -1 bitwise-and) +(test 0 bitwise-ior) +(test 0 bitwise-xor) + +(arity-test bitwise-ior 0 -1) +(arity-test bitwise-and 0 -1) +(arity-test bitwise-xor 0 -1) +(arity-test bitwise-not 1 1) + +(define error-test-bitwise-procs + (lambda (v) + (err/rt-test (bitwise-ior v)) + (err/rt-test (bitwise-and v)) + (err/rt-test (bitwise-xor v)) + (err/rt-test (bitwise-not v)) + (err/rt-test (bitwise-ior 1 v)) + (err/rt-test (bitwise-and 1 v)) + (err/rt-test (bitwise-xor 1 v)) + (err/rt-test (bitwise-ior v 1)) + (err/rt-test (bitwise-and v 1)) + (err/rt-test (bitwise-xor v 1)))) + +(error-test-bitwise-procs 1.0) +(error-test-bitwise-procs 1/2) +(error-test-bitwise-procs 1+2i) +(error-test-bitwise-procs 1.0+0.0i) +(error-test-bitwise-procs +inf.0) +(error-test-bitwise-procs ''a) + +(test 1 arithmetic-shift 1 0) +(test 1024 arithmetic-shift 1 10) +(test 1 arithmetic-shift 1024 -10) +(test 256 arithmetic-shift 1024 -2) +(test 0 arithmetic-shift 1024 -11) +(test 0 arithmetic-shift 1024 -20) +(test 0 arithmetic-shift 1024 -40) +(test 0 arithmetic-shift 1024 -20000000000000000000) +(test 0 arithmetic-shift 0 100) +(test 0 arithmetic-shift 0 -100) +(test 0 arithmetic-shift 17 -32) + +(test (expt 2 40) arithmetic-shift (expt 2 40) 0) +(test (expt 2 50) arithmetic-shift (expt 2 40) 10) +(test (expt 2 30) arithmetic-shift (expt 2 40) -10) ; somewhere close to here is a boundary... +(test (expt 2 29) arithmetic-shift (expt 2 40) -11) +(test (expt 2 31) arithmetic-shift (expt 2 40) -9) +(test 1 arithmetic-shift (expt 2 40) -40) +(test 0 arithmetic-shift (expt 2 40) -41) +(test 0 arithmetic-shift (expt 2 40) -100) + +(test -1 arithmetic-shift -1 0) +(test -1024 arithmetic-shift -1 10) +(test -1 arithmetic-shift -1024 -10) +(test -256 arithmetic-shift -1024 -2) +(test -1 arithmetic-shift -1024 -11) +(test -1 arithmetic-shift -1024 -20) +(test -1 arithmetic-shift -1024 -20000000000000000000) + +(test (- (expt 2 40)) arithmetic-shift (- (expt 2 40)) 0) +(test (- (expt 2 50)) arithmetic-shift (- (expt 2 40)) 10) +(test (- (expt 2 30)) arithmetic-shift (- (expt 2 40)) -10) ; somewhere close to here is a boundary... +(test (- (expt 2 29)) arithmetic-shift (- (expt 2 40)) -11) +(test (- (expt 2 31)) arithmetic-shift (- (expt 2 40)) -9) +(test -1 arithmetic-shift (- (expt 2 40)) -40) +(test -1 arithmetic-shift (- (expt 2 40)) -41) +(test -1 arithmetic-shift (- (expt 2 40)) -100) + +(test 0 arithmetic-shift (sub1 (expt 2 30)) -32) +(test 0 arithmetic-shift (sub1 (expt 2 31)) -32) +(test 0 arithmetic-shift (sub1 (expt 2 32)) -32) +(test 1 arithmetic-shift (expt 2 32) -32) + +(arity-test arithmetic-shift 2 2) +(err/rt-test (arithmetic-shift "a" 1)) +(err/rt-test (arithmetic-shift 1 "a")) +(err/rt-test (arithmetic-shift 1.0 1)) +(err/rt-test (arithmetic-shift 1 1.0)) +(err/rt-test (arithmetic-shift 1 1.0+0.0i)) +(err/rt-test (arithmetic-shift 1 (expt 2 80)) exn:fail:out-of-memory?) + +(test #f bitwise-bit-set? 13 1) +(test #t bitwise-bit-set? 13 2) +(test #f bitwise-bit-set? 13 (expt 2 101)) +(test #t bitwise-bit-set? -13 (expt 2 101)) +(test #f bitwise-bit-set? (+ (expt 2 101) 13) 1) +(test #t bitwise-bit-set? (+ (expt 2 101) 13) 2) +(test #f bitwise-bit-set? (arithmetic-shift 13 101) (+ 101 1)) +(test #t bitwise-bit-set? (arithmetic-shift 13 101) (+ 101 2)) +(test #f bitwise-bit-set? (- (expt 2 101)) 0) +(test #f bitwise-bit-set? (- (expt 2 101)) 1) +(test #t bitwise-bit-set? (- (sub1 (expt 2 101))) 0) +(test #t bitwise-bit-set? (bitwise-not (expt 2 101)) 70) + +(arity-test bitwise-bit-set? 2 2) +(err/rt-test (bitwise-bit-set? "a" 1)) +(err/rt-test (bitwise-bit-set? 13 "a")) +(err/rt-test (bitwise-bit-set? 13 -1)) +(err/rt-test (bitwise-bit-set? 13 (- (expt 2 101)))) + +(test 0 bitwise-bit-field 13 0 0) +(test 1 bitwise-bit-field 13 0 1) +(test 0 bitwise-bit-field 13 1 1) +(test 0 bitwise-bit-field 13 1 2) +(test 2 bitwise-bit-field 13 1 3) +(test 0 bitwise-bit-field 13 3 3) +(test 6 bitwise-bit-field 13 1 4) +(test 6 bitwise-bit-field 13 1 10) +(test 6 bitwise-bit-field 13 1 100) +(test 3 bitwise-bit-field 13 2 10) +(test 3 bitwise-bit-field 13 2 100) +(test 0 bitwise-bit-field (arithmetic-shift 13 101) 0 0) +(test 6 bitwise-bit-field (arithmetic-shift 13 101) (+ 1 101) (+ 4 101)) +(test #t 'all-six + ;; checks boundaries of bignums + (for/and ([i (in-range 101 171)]) + (and (= 6 (bitwise-bit-field (arithmetic-shift 13 i) (+ 1 i) (+ 4 i))) + (= 6 (bitwise-bit-field (arithmetic-shift 13 i) (+ 1 i) 400))))) +(test 1 bitwise-bit-field -13 0 1) +(test 0 bitwise-bit-field -14 0 1) +(test 1 bitwise-bit-field -13 1 2) +(test 1 bitwise-bit-field -13 28 29) +(test #b111111111111 bitwise-bit-field -13 28 40) +(test #b111111111111 bitwise-bit-field -13 1028 1040) +(test 0 bitwise-bit-field (- (expt 2 101)) 0 0) +(test 1 bitwise-bit-field (- (sub1 (expt 2 101))) 0 1) +(test 1 bitwise-bit-field (bitwise-not (expt 2 101)) 70 71) +(test 7144187 bitwise-bit-field (expt 3 75) 0 24) + +(test 42 bitwise-bit-field 42 0 32) +(test (sub1 (expt 2 32)) bitwise-bit-field -1 32 64) + +(arity-test bitwise-bit-field 3 3) +(err/rt-test (bitwise-bit-field "a" 1 2)) +(err/rt-test (bitwise-bit-field 13 -1 2)) +(err/rt-test (bitwise-bit-field 13 0 -1)) +(err/rt-test (bitwise-bit-field 13 2 1)) +(err/rt-test (bitwise-bit-field 13 (expt 2 101) (sub1 (expt 2 101)))) +|# + +(test 4 gcd 0 4) +(test 4 gcd -4 0) +(test 4 gcd 4) +(test 4 gcd -4) +(test 4 gcd 32 -36) +(test 2 gcd 6 10 14) +(test 0 gcd) +(test 5 gcd 5) +(test 5.0 gcd 5.0 10) +(test 5.0 gcd -5.0 10) +(test 5.0 gcd 5.0 -10) +(test 5.0 gcd 5.0) +(test 5.0 gcd -5.0) +(test 3 gcd 0 0 3 0) +(test 3.0 gcd 0.0 0 3 0) +(test 0 gcd 0 0 0) +(err/rt-test (gcd 5.0+0.0i 10)) +(err/rt-test (gcd 5.0 10+0.0i)) +(test (expt 3 37) gcd (expt 9 35) (expt 6 37)) +(test (expt 3 37) gcd (- (expt 9 35)) (expt 6 37)) +(test (expt 3 37) gcd (expt 9 35) (- (expt 6 37))) +(test (expt 3 75) gcd (expt 3 75)) +(test (expt 3 75) gcd (- (expt 3 75))) +(test 201 gcd (* 67 (expt 3 20)) (* 67 3)) +(test 201 gcd (* 67 3) (* 67 (expt 3 20))) +(test 6 gcd (* 3 (expt 2 100)) 66) +(test 6 gcd 66 (* 3 (expt 2 100))) +(test 201.0 gcd (* 67 (expt 3 20)) (* 67. 3)) +(test 201.0 gcd (* 67. 3) (* 67 (expt 3 20))) +(test (expt 9 35) gcd (expt 9 35) 0) +(test (expt 9 35) gcd 0 (expt 9 35)) +(test 288 lcm 32 -36) +(test 12 lcm 2 3 4) +(test 1 lcm) +(test 5 lcm 5) +(test 5 lcm -5) +(test 0 lcm 123 0) +(test 0 lcm 0 0) +(test 0.0 lcm 0 0.0) +(test 0.0 lcm 0.0 0) +(test 30.0 lcm 5 6.0) +(test 6.0 lcm 6.0) +(test 6.0 lcm -6.0) +(err/rt-test (lcm 5 6.0+0.0i)) +(err/rt-test (lcm 5+0.0i 6.0)) +(test 0.0 lcm 123 0.0) +(test 0.0 lcm 123 -0.0) +(test (* (expt 2 37) (expt 9 35)) lcm (expt 9 35) (expt 6 37)) +(test (* (expt 2 37) (expt 9 35)) lcm (- (expt 9 35)) (expt 6 37)) +(test (* (expt 2 37) (expt 9 35)) lcm (expt 9 35) (- (expt 6 37))) + +(err/rt-test (gcd +nan.0)) +(err/rt-test (gcd +inf.0)) +(err/rt-test (gcd -inf.0)) +(err/rt-test (gcd 'a)) +(err/rt-test (gcd 'a 1)) +(err/rt-test (gcd 1 'a)) +(err/rt-test (lcm +nan.0)) +(err/rt-test (lcm +inf.0)) +(err/rt-test (lcm -inf.0)) +(err/rt-test (lcm 'a)) +(err/rt-test (lcm 'a 1)) +(err/rt-test (lcm 1 'a)) +(err/rt-test (gcd 1/2)) +(err/rt-test (gcd 3 1/2)) +(err/rt-test (gcd 1/2 3)) +(err/rt-test (lcm 1/2)) +(err/rt-test (lcm 3 1/2)) +(err/rt-test (lcm 1/2 3)) +(err/rt-test (gcd 1+2i)) +(err/rt-test (lcm 1+2i)) +(err/rt-test (gcd 1 1+2i)) +(err/rt-test (lcm 1 1+2i)) +(err/rt-test (gcd +nan.0 5.0)) +(err/rt-test (gcd 5.0 +nan.0)) +(err/rt-test (lcm +nan.0 5.0)) +(err/rt-test (lcm 5.0 +nan.0)) +(err/rt-test (gcd +inf.0 5.0)) +(err/rt-test (gcd 5.0 +inf.0)) +(err/rt-test (lcm +inf.0 5.0)) +(err/rt-test (lcm 5.0 +inf.0)) + +(arity-test gcd 0 -1) +(arity-test lcm 0 -1) + +(test 2 floor 5/2) +(test 3 ceiling 5/2) +(test 2 round 5/2) +(test 2 truncate 5/2) +(test -3 floor -5/2) +(test -2 ceiling -5/2) +(test -2 round -5/2) +(test -2 truncate -5/2) + +(test 1 floor 4/3) +(test 2 ceiling 4/3) +(test 1 round 4/3) +(test 1 truncate 4/3) +(test -2 floor -4/3) +(test -1 ceiling -4/3) +(test -1 round -4/3) +(test -1 truncate -4/3) + +(test 1 floor 5/3) +(test 2 ceiling 5/3) +(test 2 round 5/3) +(test 1 truncate 5/3) +(test -2 floor -5/3) +(test -1 ceiling -5/3) +(test -2 round -5/3) +(test -1 truncate -5/3) + +(test 2 floor 11/4) +(test 3 ceiling 11/4) +(test 3 round 11/4) +(test 2 truncate 11/4) +(test -3 floor -11/4) +(test -2 ceiling -11/4) +(test -3 round -11/4) +(test -2 truncate -11/4) + +(test 2 floor 9/4) +(test 3 ceiling 9/4) +(test 2 round 9/4) +(test 2 truncate 9/4) +(test -3 floor -9/4) +(test -2 ceiling -9/4) +(test -2 round -9/4) +(test -2 truncate -9/4) + +(test 2.0 floor 2.4) +(test 3.0 ceiling 2.4) +(test 2.0 round 2.4) +(test 2.0 truncate 2.4) +(test -3.0 floor -2.4) +(test -2.0 ceiling -2.4) +(test -2.0 round -2.4) +(test -2.0 truncate -2.4) + +(test 2.0 floor 2.6) +(test 3.0 ceiling 2.6) +(test 3.0 round 2.6) +(test 2.0 truncate 2.6) +(test -3.0 floor -2.6) +(test -2.0 ceiling -2.6) +(test -3.0 round -2.6) +(test -2.0 truncate -2.6) + +(test 2.0 round 2.5) +(test -2.0 round -2.5) +(test 4.0 round 3.5) +(test -4.0 round -3.5) + +(define (test-zero-ident f) + (test 0.0 f 0.0) + (test -0.0 f -0.0)) +(test-zero-ident round) +(test-zero-ident floor) +(test-zero-ident ceiling) +(test-zero-ident truncate) + +(err/rt-test (floor 2.6+0.0i)) +(err/rt-test (ceiling 2.6+0.0i)) +(err/rt-test (round 2.6+0.0i)) +(err/rt-test (truncate 2.6+0.0i)) +(test +inf.0 floor +inf.0) +(test +inf.0 ceiling +inf.0) +(test +inf.0 round +inf.0) +(test +inf.0 truncate +inf.0) +(test -inf.0 floor -inf.0) +(test -inf.0 ceiling -inf.0) +(test -inf.0 round -inf.0) +(test -inf.0 truncate -inf.0) +(test +nan.0 floor +nan.0) +(test +nan.0 ceiling +nan.0) +(test +nan.0 round +nan.0) +(test +nan.0 truncate +nan.0) + +(define (test-fcrt-int v) + (test v floor v) + (test v ceiling v) + (test v round v) + (test v truncate v)) + +(test-fcrt-int 2) +(test-fcrt-int 2.0) +(test-fcrt-int (expt 2 100)) + +(arity-test round 1 1) +(arity-test floor 1 1) +(arity-test ceiling 1 1) +(arity-test truncate 1 1) + +(err/rt-test (floor 2+i)) +(err/rt-test (ceiling 2+i)) +(err/rt-test (truncate 2+i)) +(err/rt-test (round 2+i)) + +(err/rt-test (floor "a")) +(err/rt-test (ceiling "a")) +(err/rt-test (truncate "a")) +(err/rt-test (round "a")) + +(test 5 numerator 5) +(test 5000000000000 numerator 5000000000000) +(test 5.0 numerator 5.0) +(err/rt-test (numerator 5.0+0.0i)) +(test 1 denominator 5) +(test 1 denominator 5000000000000) +(test 1.0 denominator 5.0) +(err/rt-test (denominator 5.0+0.0i)) +(test 2 numerator 2/3) +(test 3 denominator 2/3) +(test 1000.0 round (* 10000.0 (/ (numerator 0.1) (denominator 0.1)))) + +(err/rt-test (numerator +inf.0)) +(err/rt-test (numerator -inf.0)) +(err/rt-test (numerator +nan.0)) +(err/rt-test (denominator +inf.0)) +(err/rt-test (denominator -inf.0)) +(err/rt-test (denominator +nan.0)) + +(err/rt-test (numerator 'a)) +(err/rt-test (numerator 1+2i)) +(err/rt-test (denominator 'a)) +(err/rt-test (denominator 1+2i)) + +(arity-test numerator 1 1) +(arity-test denominator 1 1) + +(define (test-on-reals f filter) + (test (filter 5) f 5) + (test (filter 5.0) f 5.0) + (test (filter 1/5) f 1/5) + (test (filter (expt 2 100)) f (expt 2 100))) + +(test 1+2i make-rectangular 1 2) +(test 1.0+2.0i make-rectangular 1.0 2) +(err/rt-test (make-rectangular 1.0+0.0i 2)) +(err/rt-test (make-rectangular 1.0 2+0.0i)) +(test-nan.0 real-part (make-rectangular +nan.0 1)) +(test 1.0 imag-part (make-rectangular +nan.0 1)) +(test-nan.0 imag-part (make-rectangular 1 +nan.0)) +(test 1.0 real-part (make-rectangular 1 +nan.0)) +(test +inf.0 real-part (make-rectangular +inf.0 -inf.0)) +(test -inf.0 imag-part (make-rectangular +inf.0 -inf.0)) + +(test (make-rectangular +inf.0 -inf.0) * 1. (make-rectangular +inf.0 -inf.0)) +(test (make-rectangular +inf.0 +inf.0) * +1.0i (make-rectangular +inf.0 -inf.0)) +(test (make-rectangular -inf.0 +inf.0) * -3. (make-rectangular +inf.0 -inf.0)) +(test (make-rectangular +inf.0 -inf.0) * (make-rectangular +inf.0 -inf.0) 1.) +(test (make-rectangular +inf.0 +inf.0) * (make-rectangular +inf.0 -inf.0) +1.0i) +(test (make-rectangular -inf.0 +inf.0) * (make-rectangular +inf.0 -inf.0) -3.) +(test (make-rectangular +inf.0 -inf.0) / (make-rectangular +inf.0 -inf.0) 1.) +(test (make-rectangular -inf.0 -inf.0) / (make-rectangular +inf.0 -inf.0) +1.0i) +(test (make-rectangular -inf.0 +inf.0) / (make-rectangular +inf.0 -inf.0) -3.) + +;; Test division with exact zeros in demoniator where +;; the exact zero gets polluted to an inexact zero unless +;; it's special-cased +(test 0-0.0i / 0+1.0i -inf.0) +(test -0.0-0.0i / 1.0+1.0i -inf.0) +(test -0.0 / 0+1.0i 0-inf.0i) +(test -0.0+0.0i / 1.0+1.0i 0-inf.0i) + +(test-i-nan.0 * 1.+0.i (make-rectangular +inf.0 -inf.0)) +(test-i-nan.0 * 0.+1.0i (make-rectangular +inf.0 -inf.0)) +(test-i-nan.0 * -3.+0.i (make-rectangular +inf.0 -inf.0)) +(test-i-nan.0 * (make-rectangular +inf.0 -inf.0) 1.+0.i) +(test-i-nan.0 * (make-rectangular +inf.0 -inf.0) 0.+1.0i) +(test-i-nan.0 * (make-rectangular +inf.0 -inf.0) -3.+0.i) +(test-i-nan.0 / (make-rectangular +inf.0 -inf.0) 1.+0.i) +(test-i-nan.0 / (make-rectangular +inf.0 -inf.0) 0.+1.0i) +(test-i-nan.0 / (make-rectangular +inf.0 -inf.0) -3.+0.i) + +(test 1 magnitude 1) +(test 1 magnitude -1) +(test 1.0 magnitude 1.0) +(test 1.0 magnitude -1.0) +(test big-num magnitude big-num) +(test big-num magnitude (- big-num)) +(test 3/4 magnitude 3/4) +(test 3/4 magnitude -3/4) +(test 10.0 magnitude 10.0+0.0i) +(test 10.0 magnitude -10.0+0.0i) +(test 10.0 magnitude 0+10.0i) +(test 10 magnitude 0+10i) +(test 141421.0 round (* 1e-295 (magnitude 1e300+1e300i))) +(test 141421.0 round (* 1e+305 (magnitude 1e-300+1e-300i))) +(test +inf.0 magnitude +inf.0+inf.0i) +(test +inf.0 magnitude -inf.0-inf.0i) +(test +inf.0 magnitude 1+inf.0i) +(test +inf.0 magnitude +inf.0+1i) +(test +inf.0 magnitude +inf.0+0.0i) +(test +inf.0 magnitude 0.0+inf.0i) +(test +nan.0 magnitude +nan.0+inf.0i) +(test +nan.0 magnitude +inf.0+nan.0i) + +(test 0 angle 1) +(test 0 angle 1.0) +(test 0 angle 0.0) +(test 0 angle big-num) +(test 0 angle 3/4) +(test 0.0 angle 3+0.0i) +(test-nan.0 angle +nan.0) +(let ([pi (atan 0 -1)]) + (test pi angle -1) + (test pi angle -1.0) + (test pi angle -0.0) + (test pi angle (- big-num)) + (test pi angle -3/4) + (test pi angle -3+0.0i)) +(test -inf.0 atan 0+i) +(test -inf.0 atan 0-i) + +(err/rt-test (angle 'a)) +(err/rt-test (angle 0) exn:fail:contract:divide-by-zero?) +(err/rt-test (magnitude 'a)) +(arity-test angle 1 1) +(arity-test magnitude 1 1) + +(test 1 real-part 1+2i) +(test 1.0 real-part 1+2.0i) +(test 1.0 real-part 1+0.0i) +(test 1/5 real-part 1/5+2i) +(test-on-reals real-part (lambda (x) x)) +(test 2.0 imag-part 1+2.0i) +(test 0.0 imag-part 1+0.0i) +(test -0.0 imag-part 1-0.0i) +(test 1/5 imag-part 1+1/5i) +(test-on-reals imag-part (lambda (x) 0)) +(test-nan.0 real-part +nan.0) +(test 0 imag-part +nan.0) +(test 6@1 (lambda (x) x) 6.0@1.0) +(test 324.0 floor (* 100 (real-part 6@1))) +(test 50488.0 floor (* 10000 (imag-part 6@1))) +(test 1 make-polar 1 0) +(test 1.0+0.0i make-polar 1 0.0) +(test 1.0 make-polar 1.0 0) +(test 1.0+0.0i make-polar 1.0 0.0) +(err/rt-test (make-polar 1.0 0.0+0.0i)) +(err/rt-test (make-polar 1.0+0.0i 0.0)) +(let ([v (make-polar 1 1)]) + (test 5403.0 floor (* 10000 (real-part v))) + (test 84147.0 floor (* 100000 (imag-part v))) + (test 10000.0 round (* 10000.0 (magnitude v)))) +(let ([v (make-polar 1 2)]) + (test -416.0 ceiling (* 1000 (real-part v))) + (test 909.0 floor (* 1000 (imag-part v))) + (test 1.0 magnitude v) + (test 2.0 angle v)) +(test-nan.0 make-polar +nan.0 0) +(test-i-nan.0 make-polar +nan.0 1) +(test-i-nan.0 make-polar 1 +nan.0) +(test-i-nan.0 make-polar 1 +inf.0) +(test-i-nan.0 make-polar 1 -inf.0) +(test +inf.0 make-polar +inf.0 0) +(test -inf.0 make-polar -inf.0 0) +(test (make-rectangular +inf.0 +inf.0) make-polar +inf.0 (atan 1 1)) +(test (make-rectangular -inf.0 +inf.0) make-polar +inf.0 (atan 1 -1)) +(test (make-rectangular +inf.0 -inf.0) make-polar +inf.0 (atan -1 1)) +(test 785.0 floor (* 1000 (angle (make-rectangular 1 1)))) +(test 14142.0 floor (* 10000 (magnitude (make-rectangular 1 1)))) + +(err/rt-test (make-rectangular 1 'a)) +(err/rt-test (make-rectangular 'a 1)) +(err/rt-test (make-rectangular 1+2i 1)) +(err/rt-test (make-rectangular 1 1+2i)) +(arity-test make-rectangular 2 2) + +(err/rt-test (make-polar 1 'a)) +(err/rt-test (make-polar 'a 1)) +(err/rt-test (make-polar 1+2i 1)) +(err/rt-test (make-polar 1 1+2i)) +(arity-test make-polar 2 2) + +(err/rt-test (real-part 'a)) +(err/rt-test (imag-part 'a)) +(arity-test real-part 1 1) +(arity-test imag-part 1 1) + +(define (z-round c) (make-rectangular (round (real-part c)) (round (imag-part c)))) + +(test -1 * +i +i) +(test 1 * +i -i) +(test 2 * 1+i 1-i) +(test +2i * 1+i 1+i) +(test -3+4i - 3-4i) +(test 0.5+0.0i - (+ 0.5 +i) +i) +(test 1/2 - (+ 1/2 +i) +i) +(test 1.0+0.0i - (+ 1 +0.5i) +1/2i) + +(test 1 sqrt 1) +(test 1.0 sqrt 1.0) +(test 25 sqrt 625) +(test 3/7 sqrt 9/49) +(test 0.5 sqrt 0.25) +(test +1i sqrt -1) +(test +2/3i sqrt -4/9) +(test +1.0i sqrt -1.0) +(test 1+1i sqrt +2i) +(test 2+1i sqrt 3+4i) +(test 2.0+0.0i sqrt 4+0.0i) +(test +inf.0 sqrt +inf.0) +(test (make-rectangular 0 +inf.0) sqrt -inf.0) +(test-nan.0 sqrt +nan.0) + +;; Complex `sqrt' cases where both z and (magnitude z) are exact: +(test 1414.0 round (* 1000 (real-part (sqrt +4i)))) +(test +1414.0 round (* 1000 (imag-part (sqrt +4i)))) +(test 1414.0 round (* 1000 (real-part (sqrt -4i)))) +(test -1414.0 round (* 1000 (imag-part (sqrt -4i)))) +(test 1155.0 round (* 1000 (real-part (sqrt 1+4/3i)))) +(test +577.0 round (* 1000 (imag-part (sqrt 1+4/3i)))) +(test 1155.0 round (* 1000 (real-part (sqrt 1-4/3i)))) +(test -577.0 round (* 1000 (imag-part (sqrt 1-4/3i)))) + +(test (expt 5 13) sqrt (expt 5 26)) +(test 545915034.0 round (sqrt (expt 5 25))) +(test (make-rectangular 0 (expt 5 13)) sqrt (- (expt 5 26))) +(test (make-rectangular 0 545915034.0) z-round (sqrt (- (expt 5 25)))) + +(err/rt-test (sqrt "a")) +(arity-test sqrt 1 1) + +(test 3 integer-sqrt 10) +(test 420 integer-sqrt (expt 3 11)) +(test 97184015999 integer-sqrt (expt 2 73)) +(test 0+3i integer-sqrt -10) +(test 0+420i integer-sqrt (expt -3 11)) +(test 0+97184015999i integer-sqrt (expt -2 73)) + +(test 2.0 integer-sqrt 5.0) +(test 0+2.0i integer-sqrt -5.0) +(err/rt-test (integer-sqrt 5.0+0.0i)) +(err/rt-test (integer-sqrt -5.0+0.0i)) + +(err/rt-test (integer-sqrt "a")) +(err/rt-test (integer-sqrt 1.1)) +(err/rt-test (integer-sqrt 1+1i)) +(arity-test integer-sqrt 1 1) + +#| dyoo: no support for integer-sqrt/remainder +(test '(3 1) call-with-values (lambda () (integer-sqrt/remainder 10)) list) +(test '(420 747) call-with-values (lambda () (integer-sqrt/remainder (expt 3 11))) list) +(test '(97184015999 45402459391) call-with-values (lambda () (integer-sqrt/remainder (expt 2 73))) list) +(test '(0+3i -1) call-with-values (lambda () (integer-sqrt/remainder -10)) list) +(test '(0+420i -747) call-with-values (lambda () (integer-sqrt/remainder (expt -3 11))) list) +(test '(0+97184015999i -45402459391) call-with-values (lambda () (integer-sqrt/remainder (expt -2 73))) list) + +(test '(2.0 1.0) call-with-values (lambda () (integer-sqrt/remainder 5.0)) list) +(test '(0+2.0i -1.0) call-with-values (lambda () (integer-sqrt/remainder -5.0)) list) +(err/rt-test (integer-sqrt/remainder 5.0+0.0i)) +(err/rt-test (integer-sqrt/remainder -5.0+0.0i)) + +(err/rt-test (integer-sqrt/remainder "a")) +(err/rt-test (integer-sqrt/remainder 1.1)) +(err/rt-test (integer-sqrt/remainder 1+1i)) +(arity-test integer-sqrt/remainder 1 1) +|# + + +(test -13/64-21/16i expt -3/4+7/8i 2) +(let ([v (expt -3/4+7/8i 2+3i)]) + (test 3826.0 floor (* 10000000 (real-part v))) + (test -137.0 ceiling (* 100000 (imag-part v)))) +(test 49.0+0.0i expt 7 2+0.0i) +(test 49.0 floor (* 10 (expt 2 2.3))) +(test 189.0 floor (* 1000 (expt 2.3 -2))) +(test 1/4 expt 2 -2) +(test 1/1125899906842624 expt 2 -50) +(test 1/1024 expt 1/2 10) +(test 1024 expt 1/2 -10) +(test 707.0 floor (* 1000 (expt 1/2 1/2))) +(test 707.0 floor (* 1000 (expt 1/2 0.5))) +(test 707.0 floor (* 1000 (expt 0.5 1/2))) +(test 100.0+173.0i z-round (* 100 (expt -8 1/3))) +(test 100.0+173.0i z-round (* 100 (expt -8.0 1/3))) +(test 101.0+171.0i z-round (* 100 (expt -8 0.33))) +(test 101.0+171.0i z-round (* 100 (expt -8.0 0.33))) +(test 108.0+29.0i z-round (* 100 (expt 1+i 1/3))) +(test 25.0-43.0i z-round (* 100 (expt -8 -1/3))) + +;; This choice doesn't make sense to me, but it fits +;; with other standards and implementations: +(define INF-POWER-OF_NEGATIVE +inf.0) + +(test +inf.0 expt 2 +inf.0) +(test +inf.0 expt +inf.0 10) +(test 0.0 expt +inf.0 -2) +(test 1 expt +inf.0 0) +(test 1.0 expt +inf.0 0.) +(test +inf.0 expt +inf.0 +inf.0) +(test INF-POWER-OF_NEGATIVE expt -2 +inf.0) +(test INF-POWER-OF_NEGATIVE expt -inf.0 +inf.0) +(test 0.0 expt 2 -inf.0) +(test -inf.0 expt -inf.0 11) +(test +inf.0 expt -inf.0 10) +(test 0.0 expt -inf.0 -2) +(test -0.0 expt -inf.0 -3) +(test 1 expt -inf.0 0) +(test 1.0 expt -inf.0 0.0) +(test 0.0 expt +inf.0 -inf.0) +(test 0.0 expt -2 -inf.0) +(test 0.0 expt -inf.0 -inf.0) +(test 1 expt +nan.0 0) +(test 0 expt 0 10) +(test 0 expt 0 10.0) +(test 0 expt 0 +inf.0) +(test-nan.0 expt 0 +nan.0) +(test 1 expt 1 +inf.0) +(test 1 expt 1 -inf.0) +(test 1 expt 1 -nan.0) +(test 0.0 expt 0.0 10) +(test 0.0 expt 0.0 +inf.0) +(test +inf.0 expt 0.0 -5) +(test -inf.0 expt -0.0 -5) +(test +inf.0 expt 0.0 -4) +(test +inf.0 expt -0.0 -4) +(test +inf.0 expt 0.0 -4.3) +(test +inf.0 expt -0.0 -4.3) +(test +inf.0 expt 0.0 -inf.0) +(test-nan.0 expt 0.0 +nan.0) +(test 1 expt 0 0) +(test 1.0 expt 0 0.0) ; to match (expt 0 0) +(test 1.0 expt 0 -0.0) +(test 1.0 expt 0.0 0.0) +(test 1.0 expt 0.0 0.0) +(test 1 expt 0.0 0) +(test 1 expt -0.0 0) +(test -0.0 expt -0.0 1) +(test-nan.0 expt +nan.0 10) +(test-nan.0 expt 2 +nan.0) + +(test 0 expt 0 1+i) +(test 0 expt 0 1-i) + +(test-nan.0 expt 1.0 +inf.0) +(test-nan.0 expt 1.0 -inf.0) +(test-nan.0 expt 1.0 +nan.0) + +(test 0.0 expt 0.0 5) +(test -0.0 expt -0.0 5) +(test 0.0 expt 0.0 4) +(test 0.0 expt -0.0 4) +(test 0.0 expt 0.0 4.3) +(test 0.0 expt -0.0 4.3) + +(test 0.0 expt 0.5 +inf.0) +(test +inf.0 expt 0.5 -inf.0) +(test INF-POWER-OF_NEGATIVE expt -0.5 -inf.0) +(test +inf.0 expt 1.5 +inf.0) +(test 0.0 expt 1.5 -inf.0) +(test 0.0 expt -0.5 +inf.0) +(test +inf.0 expt -0.5 -inf.0) +(test INF-POWER-OF_NEGATIVE expt -1.5 +inf.0) +(test 0.0 expt -1.5 -inf.0) + +(err/rt-test (expt 0 -1) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 -1.0) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 -inf.0) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 -1+2i) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 -1.0+2i) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 0+2i) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 0.0+2i) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 -0.0+2i) exn:fail:contract:divide-by-zero?) +(err/rt-test (expt 0 0+0.0i) exn:fail:contract:divide-by-zero?) + +(err/rt-test (expt 'a 0)) +(err/rt-test (expt 'a 1)) +(err/rt-test (expt 'a 3)) +(err/rt-test (expt 0 'a)) +(err/rt-test (expt 1 'a)) +(err/rt-test (expt 3 'a)) + +;;;;From: fred@sce.carleton.ca (Fred J Kaudel) +;;; Modified by jaffer. +(define f3.9 (string->number "3.9")) +(define f4.0 (string->number "4.0")) +(define f-3.25 (string->number "-3.25")) +(define f.25 (string->number ".25")) +(define f4.5 (string->number "4.5")) +(define f3.5 (string->number "3.5")) +(define f0.0 (string->number "0.0")) +(define f0.8 (string->number "0.8")) +(define f1.0 (string->number "1.0")) +(newline) +(display ";testing inexact numbers; ") +(newline) +(test #t inexact? f3.9) +(test #f exact? f3.9) +(test #t 'inexact? (inexact? (max f3.9 4))) +(test f4.0 'max (max f3.9 4)) +(test f4.0 'exact->inexact (exact->inexact 4)) + +; Should at least be close... +(test 4.0 round (log (exp 4.0))) +(test 125.0 round (* 1000 (asin (sin 0.125)))) +(test 125.0d0 round (* 1000 (magnitude (asin (sin 0.125+0.0d0i))))) +(test 125.0 round (* 1000 (asin (sin 1/8)))) +(test 125.0 round (* 1000 (acos (cos 0.125)))) +(test 125.0d0-0.0i z-round (* 1000 (acos (cos 0.125+0.0d0i)))) +(test 125.0 round (* 1000 (acos (cos 1/8)))) +(test 785.0 round (* 1000 (atan 1 1))) +(test 785.0 round (* 1000 (atan 1.0 1.0))) +(err/rt-test (atan 1.0 1.0+0.0i)) +(err/rt-test (atan 1.0+0.0i 1.0)) +(test 2356.0 round (* 1000 (atan 1 -1))) +(test -785.0 round (* 1000 (atan -1 1))) +(test 785.0 round (* 1000 (atan 1))) +(test 100.0 round (* 100 (tan (atan 1)))) +(test 100.0-0.0i z-round (* 100 (tan (+ +0.0i (atan 1))))) +(test 0.0 atan 0.0 0) +(test 0 atan 0 1) +(test 0 atan 0 (expt 2 100)) +(test 0.0 atan 0 1.0) +(test 314.0 round (* 100 (atan 0 -1))) +(err/rt-test (atan 0 0) exn:fail:contract:divide-by-zero?) +(test 1024.0 round (expt 2.0 10.0)) +(test 1024.0 round (expt -2.0 10.0)) +(test -512.0 round (expt -2.0 9.0)) +(test 32.0 round (sqrt 1024.0)) +(test 32.0+0.0i z-round (sqrt 1024.0+0.0i)) +(test 1.0+1.5e-10i sqrt 1+3e-10i) + +(test 1 exp 0) +(test 1.0 exp 0.0) +(test 1.0 exp -0.0) +(test 272.0 round (* 100 (exp 1))) + +(test 0 log 1) +(test 0.0 log 1.0) +(test -inf.0 log 0.0) +(test -inf.0 log -0.0) +(test +inf.0 log +inf.0) +(test +inf.0 real-part (log -inf.0)) +(test +3142.0 round (* 1000 (imag-part (log -inf.0)))) +(test +nan.0 log +nan.0) +(err/rt-test (log 0) exn:fail:contract:divide-by-zero?) + +(test 1 cos 0) +(test 1.0 cos 0.0) +(test 0 sin 0) +(test 0.0 sin 0.0) +(test -0.0 sin -0.0) +(test 0 tan 0) +(test 0.0 tan 0.0) +(test -0.0 tan -0.0) + +(test #t >= 1 (sin 12345678901234567890123)) +(test #t >= 1 (cos 12345678901234567890123)) +(test #t <= -inf.0 (tan 12345678901234567890123) +inf.0) + +(test 0 atan 0) +(test 0.0 atan 0.0) +(test -0.0 atan -0.0) +(test 314.0 round (* 400 (atan 1))) +(test 314.0 round (* 400 (atan 1.0))) +(test 0 asin 0) +(test 0.0 asin 0.0) +(test -0.0 asin -0.0) +(test 314.0 round (* 200 (asin 1))) +(test 314.0 round (* 200 (asin 1.0))) +(test 0 acos 1) +(test 0.0 acos 1.0) +(test 314.0 round (* 200 (acos 0))) +(test 314.0 round (* 200 (acos 0.0))) +(test 314.0 round (* 200 (acos -0.0))) +(test (/ 314.0 2) round (* 100 (atan +inf.0))) +(test (/ -314.0 2) round (* 100 (atan -inf.0))) + +(test 71034.0 round (* 100 (log 312918491891666147403524564598095080760332972643192197862041633988540637438735086398143104076897116667450730097183397289314559387355872839339937813881411504027225774279272518360586167057501686099965513263132778526566297754301647311975918380842568054630540214544682491386730004162058539391336047825248736472519))) +(test 71117.0 round (* 100 (log (expt 2 1026)))) +(test 71048.0 round (* 100 (log (expt 2 1025)))) +(test 70978.0 round (* 100 (log (expt 2 1024)))) +(test 70909.0 round (* 100 (log (expt 2 1023)))) +(test 35420.0 round (* 100 (log (expt 2 511)))) +(test 35489.0 round (* 100 (log (expt 2 512)))) +(test 35558.0 round (* 100 (log (expt 2 513)))) +(test 141887.0 round (* 100 (log (expt 2 2047)))) +(test 141957.0 round (* 100 (log (expt 2 2048)))) +(test 142026.0 round (* 100 (log (expt 2 2049)))) +(test 23026.0 round (log (expt 10 10000))) +(test 23026.0 round (real-part (log (- (expt 10 10000))))) +(test 3.0 round (imag-part (log (- (expt 10 10000))))) + +(define (test-inf-bad f) + (test-nan.0 f +inf.0) + (test-nan.0 f -inf.0) + (test-nan.0 f +nan.0)) + +(test-inf-bad tan) +(test-inf-bad sin) +(test-inf-bad cos) +(test-inf-bad asin) +(test-inf-bad acos) + +#| dyoo: no support for rationalize +(test 11/7 rationalize (inexact->exact (atan +inf.0 1)) 1/100) +(test -11/7 rationalize (inexact->exact (atan -inf.0 1)) 1/100) +(test 0.0 atan 1 +inf.0) +(test 22/7 rationalize (inexact->exact (atan 1 -inf.0)) 1/100) + +; Note on the following tests with atan and inf.0: +; The IEEE standard makes this decision. I think it's a bad one, +; since (limit (atan (g x) (f x))) as x -> +inf.0 is not necessarily +; (atan 1 1) when (limit (f x)) and (limit (g x)) are +inf.0. +; Perhaps IEEE makes this choice because it's easiest to compute. +(test 7/9 rationalize (inexact->exact (atan +inf.0 +inf.0)) 1/100) +(test 26/11 rationalize (inexact->exact (atan +inf.0 -inf.0)) 1/100) +(test -7/9 rationalize (inexact->exact (atan -inf.0 +inf.0)) 1/100) +|# + +(test-nan.0 atan +nan.0) +(test-nan.0 atan 1 +nan.0) +(test-nan.0 atan +nan.0 1) + +(test -1178.+173.i z-round (* 1000 (atan -2+1i))) + +(map (lambda (f) + (err/rt-test (f "a")) + (arity-test f 1 1)) + (list log exp asin acos tan)) +(err/rt-test (atan "a" 1)) +(err/rt-test (atan 2+i 1)) +(err/rt-test (atan "a")) +(err/rt-test (atan 1 "a")) +(err/rt-test (atan 1 2+i)) +(arity-test atan 1 2) + +(test 3166.+1960.i z-round (* 1000 (sin 1+2i))) +(test -3166.-1960.i z-round (* 1000 (sin -1-2i))) +(test 0+1175.i z-round (* 1000 (sin 0+i))) +(test -642.-1069.i z-round (* 1000 (cos 2+i))) +(test -642.-1069.i z-round (* 1000 (cos -2-i))) +(test 1543. z-round (* 1000 (cos 0+i))) +(test 272-1084.i z-round (* 1000 (tan 1-i))) +(test -272+1084.i z-round (* 1000 (tan -1+i))) + +(test 693.+3142.i z-round (* 1000 (log -2))) +(test 1571.-1317.i z-round (* 1000 (asin 2))) +(test -1571.+1317.i z-round (* 1000 (asin -2))) +(test 0+3688.i z-round (* 1000 (acos 20))) +(test 3142.-3688.i z-round (* 1000 (acos -20))) + +(define (cs2 c) (+ (* (cos c) (cos c)) (* (sin c) (sin c)))) +(test 0.0 imag-part (cs2 2+3i)) +(test 1000.0 round (* 1000 (real-part (cs2 2+3i)))) +(test 0.0 imag-part (cs2 -2+3i)) +(test 1000.0 round (* 1000 (real-part (cs2 -2+3i)))) +(test 0.0 imag-part (cs2 2-3i)) +(test 1000.0 round (* 1000 (real-part (cs2 2-3i)))) + +(test #t positive? (real-part (sqrt (- 1 (* 2+3i 2+3i))))) + +(test (- f4.0) round (- f4.5)) +(test (- f4.0) round (- f3.5)) +(test (- f4.0) round (- f3.9)) +(test f0.0 round f0.0) +(test f0.0 round f.25) +(test f1.0 round f0.8) +(test f4.0 round f3.5) +(test f4.0 round f4.5) +(let ((x (string->number "4195835.0")) + (y (string->number "3145727.0"))) + (test #t 'pentium-fdiv-bug (> f1.0 (- x (* (/ x y) y))))) + +#| dyoo: no support for rationalize + +(test (exact->inexact 1/3) rationalize .3 1/10) +(test 1/3 rationalize 3/10 1/10) +(test (exact->inexact 1/3) rationalize .3 -1/10) +(test 1/3 rationalize 3/10 -1/10) +(test 0 rationalize 3/10 4/10) +(test 0.0 rationalize .3 4/10) +(err/rt-test (rationalize .3+0.0i 4/10)) +(err/rt-test (rationalize .3+0.0i 1/10)) + +(define (test-rat-inf v) + (define zero (if (exact? v) 0 0.0)) + + (test +inf.0 rationalize +inf.0 v) + (test -inf.0 rationalize -inf.0 v) + (test-nan.0 rationalize +nan.0 v) + + (test zero rationalize v +inf.0) + (test zero rationalize v -inf.0) + (test-nan.0 rationalize v +nan.0)) + +(let loop ([i 100]) + (unless (= i -100) + (test (/ i 100) rationalize (inexact->exact (/ i 100.0)) 1/100000) + (loop (sub1 i)))) + +(arity-test rationalize 2 2) +|# + +(define tb + (lambda (n1 n2) + (= n1 (+ (* n2 (quotient n1 n2)) + (remainder n1 n2))))) + + +(test -2147483648 - 2147483648) +(test 2147483648 - -2147483648) +(test #f = -2147483648 2147483648) +(test #t = -2147483648 -2147483648) +(test #t = 2147483648 2147483648) +(test 2147483647 sub1 2147483648) +(test 2147483648 add1 2147483647) +(test 2147483648 * 1 2147483648) + +(test 437893890380859375 expt 15 15) + +(test 0 modulo -2177452800 86400) +(test 0 modulo 2177452800 -86400) +(test 0 modulo 2177452800 86400) +(test 0 modulo -2177452800 -86400) + +(test 86399 modulo -2177452801 86400) +(test -1 modulo 2177452799 -86400) +(test 1 modulo 2177452801 86400) +(test -86399 modulo -2177452799 -86400) + +(test #t 'remainder (tb 281474976710655 65535)) +(test #t 'remainder (tb 281474976710654 65535)) +(test 281474976710655 string->number "281474976710655") +(test "281474976710655" number->string 281474976710655) +(test "-4" number->string -4 16) +(test "-e" number->string -14 16) +(test "0" number->string 0 16) +(test "30000000" number->string #x30000000 16) + + +(test "0" number->string 0) +(test "100" number->string 100) +(test "100" number->string 256 16) +(test 256 string->number "100" 16) +(test 15 string->number "#o17") +(test 15 string->number "#o17" 10) + +(require "numstrs.rkt") +(let loop ([l number-table]) + (unless (null? l) + (let* ([pair (car l)] + [v (car pair)] + [v (if (or (eq? v 'X) + (symbol? v) + (eof-object? v)) + #f + v)] + [s (cadr pair)]) + (test v string->number s)) + (loop (cdr l)))) + +;; Test special inexact names in complex combinations: +(let ([parts '(+inf.0 -inf.0 +nan.0 1 0 0.0 1/2)]) + (for-each + (lambda (a) + (for-each + (lambda (b) + (let ([rect (format "~a~a~ai" + a + (if (member b '(+inf.0 -inf.0 +nan.0)) + "" + "+") + b)] + [polar (format "~a@~a" a b)]) + (test (make-rectangular a b) string->number rect) + (test (make-polar a b) string->number polar))) + parts)) + parts) + + (for-each + (lambda (a) + (let ([rect1 (format "~a+1/0i" a)] + [rect2 (format "1/0~a~ai" + (if (member a '(+inf.0 -inf.0 +nan.0)) + "" + "+") + a)] + [polar1 (format "~a@1/0" a)] + [polar2 (format "1/0@~a" a)] + + ;; dyoo: currently disabled: no support for read + #;[dbz-test (lambda (s) + (test 'div 'divide-by-zero + (with-handlers ([(lambda (x) + (and (exn:fail:read? x) + (regexp-match "division by zero" + (exn-message x)))) + (lambda (x) 'div)]) + (read (open-input-string s)))))]) + (test #f string->number rect1) + (test #f string->number rect2) + (test #f string->number polar1) + (test #f string->number polar2) + ;; dyoo: no support for read + #;(dbz-test rect1) + #;(dbz-test rect2) + #;(dbz-test polar1) + #;(dbz-test polar2))) + parts)) + +(test #f string->number "88" 7) +(test #f string->number "") +(test #f string->number " 1") +(test #f string->number ".") +(test #f string->number "#4@#i5") +(test #f string->number "190888 qwerqwerq") +(test #t symbol? '1/x) +(test #t symbol? '1+ei) +(test #t symbol? '|1/0|) + +(test #t inexact? (string->number "4@5")) +(test #f inexact? (string->number "#e4@5")) +(test #f inexact? (string->number "#e4.0@5.0")) + +(arity-test string->number 1 2) +(arity-test number->string 1 2) + +(err/rt-test (number->string 'a)) +(err/rt-test (number->string 1 'a)) +(err/rt-test (number->string 'a 10)) +(err/rt-test (number->string 1.8 8) exn:application:mismatch?) +(err/rt-test (number->string 1 -1)) + +(err/rt-test (string->number 'a)) +(err/rt-test (string->number 'a 'a)) +(err/rt-test (string->number "12" -1)) +(err/rt-test (string->number "12" 17)) +(err/rt-test (string->number "1" "1")) +(err/rt-test (string->number 1 1)) + +(test #t andmap (lambda (x) (and (>= x 0) (< x 10))) (map random '(10 10 10 10))) +;; dyoo: no support for random-seed +#;(test (void) random-seed 5) +#;(test (begin (random-seed 23) (list (random 10) (random 20) (random 30))) + 'random-seed-same + (begin (random-seed 23) (list (random 10) (random 20) (random 30)))) +#;(arity-test random-seed 1 1) +(arity-test random 0 2) +#| +(err/rt-test (random-seed "apple")) +(err/rt-test (random-seed 4.5)) +(err/rt-test (random-seed -1)) +(err/rt-test (random-seed (expt 2 31))) +(err/rt-test (random-seed big-num)) +|# +(err/rt-test (random "apple")) +(err/rt-test (random 0)) +(err/rt-test (random -6)) +(err/rt-test (random 4294967088)) +(err/rt-test (random (expt 2 32))) +(err/rt-test (random big-num)) + +#| dyoo: random seed disabled for now +(random-seed 101) +(define x (list (random 10) (random 20) (random 30))) +(random-seed 101) +(parameterize ([current-pseudo-random-generator (make-pseudo-random-generator)]) + (random 10) + (random 10)) +(test x 'generator-preserved (list (random 10) (random 20) (random 30))) +(random-seed 101) +(thread-wait (thread (lambda () + (random 10) + (random 10)))) +(test #f 'generator-not-preserved (equal? x (list (random 10) (random 20) (random 30)))) +(test #t pseudo-random-generator? (make-pseudo-random-generator)) +(test #t pseudo-random-generator? (current-pseudo-random-generator)) +(test #t pseudo-random-generator? (current-evt-pseudo-random-generator)) +(test #f pseudo-random-generator? 10) +(arity-test pseudo-random-generator? 1 1) +(arity-test make-pseudo-random-generator 0 0) +(arity-test current-pseudo-random-generator 0 1) +(arity-test current-evt-pseudo-random-generator 0 1) +(err/rt-test (current-pseudo-random-generator 10)) +|# + +(test #t = 0 0) +(test #f = 0 (expt 2 32)) +(test #f = (expt 2 32) 0) +(test #f = (- (expt 2 32)) (expt 2 32)) +(test #f = (expt 2 32) (- (expt 2 32))) +(test #t = 1234567890987654321 1234567890987654321) + +(test #f < 0 0) +(test #t < 0 (expt 2 32)) +(test #f < (expt 2 32) 0) +(test #t < (- (expt 2 32)) 0) +(test #f < 0 (- (expt 2 32))) +(test #f < 1234567890987654321 1234567890987654321) +(test #t < (- (expt 3 64)) (- (expt 2 13))) +(test #f < (- (expt 2 13)) (- (expt 3 64))) +(test #t < (- 123456789876543200) 123456789876543200) +(test #f < 123456789876543200 (- 123456789876543200)) + +(test 1234567890987654321 + 1234567890987654321 0) +(test 1234567890987654321 + 0 1234567890987654321) +(test 1234567890987654321 - 1234567890987654321 0) +(test -1234567890987654321 - 0 1234567890987654321) +(test (expt 2 33) + (expt 2 32) (expt 2 32)) +(test 0 - (expt 2 32) (expt 2 32)) +(test (expt 2 31) - (expt 2 32) (expt 2 31)) +(test (- (expt 2 31)) - (expt 2 31) (expt 2 32)) +(test 18446744073709551621 + 18446744073709551615 6) +(test 18446744073709551621 + 6 18446744073709551615) +(test 0 - #xfffffffffffffffff #xfffffffffffffffff) +(test -1 - #xffffffffffffffffe #xfffffffffffffffff) +(test 1 - #xfffffffffffffffff #xffffffffffffffffe) +(test #x1000000000000000000000000 + #xffffffffffffffffffffffff 1) + +(test 0 * 1234567890987654321 0) +(test 0 * 0 1234567890987654321) +(test #x100000000000000000000 * #x100000000000 #x1000000000) +(test #x-100000000000000000000 * #x100000000000 #x-1000000000) +(test #x100000000000000000000 * #x-100000000000 #x-1000000000) +(test #x-100000000000000000000 * #x-100000000000 #x1000000000) +(test #x100000000000000000000 * #x1000000000 #x100000000000) +(test #x-100000000000000000000 * #x1000000000 #x-100000000000) +(test #x100000000000000000000 * #x-1000000000 #x-100000000000) +(test #x-100000000000000000000 * #x-1000000000 #x100000000000) +(test 4521191813415169 * #x100000000001 #x101) +(test 4521191813415169 * #x101 #x100000000001) + +(test (expt 2 35) * (expt 2 32) 8) +(test (- (expt 2 35)) * (- (expt 2 32)) 8) +(test (- (expt 2 35)) * (expt 2 32) -8) +(test (expt 2 35) * (- (expt 2 32)) -8) +(test (- (add1 (expt 2 128)) (expt 2 65)) * (sub1 (expt 2 64)) (sub1 (expt 2 64))) + +(test 4294967296 expt 2 32) +(test 3433683820292512484657849089281 expt 3 64) +(test 8192 expt 2 13) +(test 8589934592 expt 2 33) +(test 2147483648 expt 2 31) +(test 34359738368 expt 2 35) +(test 36893488147419103232 expt 2 65) +(test 18446744073709551616 expt 2 64) +(test 340282366920938463463374607431768211456 expt 2 128) +(test 340282366920938463463374607431768211456 expt -2 128) +(test 174449211009120179071170507 expt 3 55) +(test -174449211009120179071170507 expt -3 55) +(test 59768263894155949306790119265585619217025149412430681649 expt 7 66) +(test 1 expt 1234567890987654321 0) +(test 0 expt 0 1234567890987654321) +(test 1 expt 1 1234567890987654321) +(test 1234567890987654321 expt 1234567890987654321 1) +(test 828179745220145502584084235957368498016122811853894435464201864103254919330121223037770283296858019385573376 expt 953962166440690129601298432 4) + +#| dyoo: bitwise operations disabled +(test 0 bitwise-and 0 1234567890987654321) +(test 0 bitwise-and 1234567890987654321 0) +(test 0 bitwise-and -1234567890987654321 0) +(test 0 bitwise-and 0 -1234567890987654321) +(test 1234567890987654321 bitwise-and -1 1234567890987654321) +(test 1234567890987654321 bitwise-and 1234567890987654321 -1) +(test -1234567890987654321 bitwise-and -1 -1234567890987654321) +(test -1234567890987654321 bitwise-and -1234567890987654321 -1) +(test 19687594650088321058936321 bitwise-and (expt 3 55) (expt 7 66)) +(test 59768263894155949306790119265565931622375061091371745329 bitwise-and (- (expt 3 55)) (expt 7 66)) +(test 154761616359031858012234187 bitwise-and (expt 3 55) (- (expt 7 66))) +(test -59768263894155949306790119265740380833384181270442915835 bitwise-and (- (expt 3 55)) (- (expt 7 66))) +(test 19687594650088321058936321 bitwise-and (expt 7 66) (expt 3 55)) +(test 59768263894155949306790119265565931622375061091371745329 bitwise-and (expt 7 66) (- (expt 3 55))) +(test 154761616359031858012234187 bitwise-and (- (expt 7 66)) (expt 3 55)) +(test -59768263894155949306790119265740380833384181270442915835 bitwise-and (- (expt 7 66)) (- (expt 3 55))) +(test #x-10000000000000000 bitwise-and #x-100000000 #x-ffffffff00000001) +(test -9223372036854775808 bitwise-and (- (expt 2 31)) (- (expt 2 63))) +(test -57896044618658097711785492504343953926634992332820282019728792003956564819968 bitwise-and (- (expt 2 127)) (- (expt 2 255))) +(test -115792089237316195423570985008687907853269984665640564039457584007913129639936 bitwise-and (- (expt 2 128)) (- (expt 2 256))) +(test 0 bitwise-and #x10101010101010101010101010 #x1010101010101010101010101) +(test 0 bitwise-and #x10101010101010101010101010 #x101010101) +(test #xf0000000 bitwise-and #x101010101010101010f0101010 #xf1010101) + +(test 1234567890987654321 bitwise-ior 0 1234567890987654321) +(test 1234567890987654321 bitwise-ior 1234567890987654321 0) +(test -1234567890987654321 bitwise-ior -1234567890987654321 0) +(test -1234567890987654321 bitwise-ior 0 -1234567890987654321) +(test -1 bitwise-ior -1 1234567890987654321) +(test -1 bitwise-ior 1234567890987654321 -1) +(test -1 bitwise-ior -1 -1234567890987654321) +(test -1 bitwise-ior -1234567890987654321 -1) +(test -1 bitwise-ior #x-100000000 #x-ffffffff00000001) +(test 59768263894155949306790119265740380833384181270442915835 bitwise-ior (expt 3 55) (expt 7 66)) +(test -154761616359031858012234187 bitwise-ior (- (expt 3 55)) (expt 7 66)) +(test -59768263894155949306790119265565931622375061091371745329 bitwise-ior (expt 3 55) (- (expt 7 66))) +(test -19687594650088321058936321 bitwise-ior (- (expt 3 55)) (- (expt 7 66))) +(test 59768263894155949306790119265740380833384181270442915835 bitwise-ior (expt 7 66) (expt 3 55)) +(test -154761616359031858012234187 bitwise-ior (expt 7 66) (- (expt 3 55))) +(test -59768263894155949306790119265565931622375061091371745329 bitwise-ior (- (expt 7 66)) (expt 3 55)) +(test -19687594650088321058936321 bitwise-ior (- (expt 7 66)) (- (expt 3 55))) +(test 9223372039002259456 bitwise-ior (expt 2 31) (expt 2 63)) +(test #xf000000f bitwise-ior #xf0000000 #x0000000f) +(test -15 bitwise-ior #xf0000000 #x-f000000f) +(test #x-100000000 bitwise-ior #x-100000000 #x-1000000000000) +(test #x-10000000000000000 bitwise-ior #x-10000000000000000 #x-10000000000000000) +(test #x-100000000 bitwise-ior #xffff00000000 #x-1000000000000) +(test #x-ffffffff bitwise-ior #x-100000000 1) + +(test 1234567890987654321 bitwise-xor 0 1234567890987654321) +(test 1234567890987654321 bitwise-xor 1234567890987654321 0) +(test -1234567890987654321 bitwise-xor -1234567890987654321 0) +(test -1234567890987654321 bitwise-xor 0 -1234567890987654321) +(test -1234567890987654322 bitwise-xor -1 1234567890987654321) +(test -1234567890987654322 bitwise-xor 1234567890987654321 -1) +(test 1234567890987654320 bitwise-xor -1 -1234567890987654321) +(test 1234567890987654320 bitwise-xor -1234567890987654321 -1) +(test 59768263894155949306790119265720693238734092949383979514 bitwise-xor (expt 3 55) (expt 7 66)) +(test -59768263894155949306790119265720693238734092949383979516 bitwise-xor (- (expt 3 55)) (expt 7 66)) +(test -59768263894155949306790119265720693238734092949383979516 bitwise-xor (expt 3 55) (- (expt 7 66))) +(test 59768263894155949306790119265720693238734092949383979514 bitwise-xor (- (expt 3 55)) (- (expt 7 66))) +(test 59768263894155949306790119265720693238734092949383979514 bitwise-xor (expt 7 66) (expt 3 55)) +(test -59768263894155949306790119265720693238734092949383979516 bitwise-xor (expt 7 66) (- (expt 3 55))) +(test -59768263894155949306790119265720693238734092949383979516 bitwise-xor (- (expt 7 66)) (expt 3 55)) +(test 59768263894155949306790119265720693238734092949383979514 bitwise-xor (- (expt 7 66)) (- (expt 3 55))) +(test #xffffffffffffffff bitwise-xor #xf0f0f0f0f0f0f0f0 #x0f0f0f0f0f0f0f0f) +(test #x-ffffffffffffffff bitwise-xor #xf0f0f0f0f0f0f0f0 #x-0f0f0f0f0f0f0f0f) +(test #xffffffffffffffe1 bitwise-xor #x-f0f0f0f0f0f0f0f0 #x-0f0f0f0f0f0f0f0f) +(test #x-ffffffffffffffe1 bitwise-xor #x-f0f0f0f0f0f0f0f0 #x0f0f0f0f0f0f0f0f) +(test 0 bitwise-xor #xff00ff00ff00 #xff00ff00ff00) +(test 1 bitwise-xor #xff00ff00ff00 #xff00ff00ff01) + +(test -1 bitwise-not 0) +(test -2 bitwise-not 1) +(test 0 bitwise-not -1) +(test -170141183460469231731687303715884105729 bitwise-not (expt 2 127)) +(test -115792089237316195423570985008687907853269984665640564039457584007913129639937 bitwise-not (expt 2 256)) +(test 170141183460469231731687303715884105727 bitwise-not (- (expt 2 127))) +(test 115792089237316195423570985008687907853269984665640564039457584007913129639935 bitwise-not (- (expt 2 256))) +(test -6495847189879200919523571558866128178519676272281183726839381003906688615833519556218736219093975317609794137607877958572218335473711513642939050 bitwise-not (expt 13 130)) +(test 6495847189879200919523571558866128178519676272281183726839381003906688615833519556218736219093975317609794137607877958572218335473711513642939048 bitwise-not (- (expt 13 130))) +(test #x40000000 bitwise-not #x-40000001) + +(test 1234567890987654321 arithmetic-shift 1234567890987654321 0) +(test -1234567890987654321 arithmetic-shift -1234567890987654321 0) +(test (expt 2 32) arithmetic-shift (expt 2 31) 1) +(test (expt 2 256) arithmetic-shift (expt 2 128) 128) +(test (expt 2 277) arithmetic-shift (expt 2 125) 152) +(test (- (expt 2 256)) arithmetic-shift (- (expt 2 128)) 128) +(test (- (expt 2 277)) arithmetic-shift (- (expt 2 125)) 152) +(test (* (expt 13 55) (expt 2 97)) arithmetic-shift (expt 13 55) 97) +(test (* (- (expt 13 55)) (expt 2 97)) arithmetic-shift (- (expt 13 55)) 97) +(test 0 arithmetic-shift 1234567890987654321 -10000) +(test -1 arithmetic-shift -1234567890987654321 -10000) +(test (quotient (expt 13 55) (expt 2 100)) arithmetic-shift (expt 13 55) -100) +(test (quotient (expt 13 55) (expt 2 128)) arithmetic-shift (expt 13 55) -128) +(test (expt 2 13) arithmetic-shift (expt 2 256) -243) +(test (sub1 (quotient (- (expt 13 55)) (expt 2 100))) arithmetic-shift (- (expt 13 55)) -100) +(test (sub1 (quotient (- (expt 13 55)) (expt 2 128))) arithmetic-shift (- (expt 13 55)) -128) +(test (- (expt 2 13)) arithmetic-shift (- (expt 2 256)) -243) +(test #x100000000 arithmetic-shift #x200000000 -1) +(test #x200000000 arithmetic-shift #x100000000 1) + +|# + + +(test "0" number->string 0) +(test "1" number->string 1) +(test "-1" number->string -1) +(test "7284132478923046920834523467890234589203467590267382904573942345703" number->string 7284132478923046920834523467890234589203467590267382904573942345703) +(test "-7284132478923046920834523467890234589203467590267382904573942345703" number->string -7284132478923046920834523467890234589203467590267382904573942345703) +(test "1000101001010101011111011000101001011011100111110001111111010101000100010110001001011011101111011001111101000100110100010101111001111001001011111001000100111000011111110010101010110110001011011111101110000001010111111100111" number->string 7284132478923046920834523467890234589203467590267382904573942345703 2) +(test "-1000101001010101011111011000101001011011100111110001111111010101000100010110001001011011101111011001111101000100110100010101111001111001001011111001000100111000011111110010101010110110001011011111101110000001010111111100111" number->string -7284132478923046920834523467890234589203467590267382904573942345703 2) +(test "105125373051334761772504261133573175046425717113710470376252661337560127747" number->string 7284132478923046920834523467890234589203467590267382904573942345703 8) +(test "-105125373051334761772504261133573175046425717113710470376252661337560127747" number->string -7284132478923046920834523467890234589203467590267382904573942345703 8) +(test "452abec52dcf8fea88b12ddecfa268af3c97c89c3f955b16fdc0afe7" number->string 7284132478923046920834523467890234589203467590267382904573942345703 16) +(test "-452abec52dcf8fea88b12ddecfa268af3c97c89c3f955b16fdc0afe7" number->string -7284132478923046920834523467890234589203467590267382904573942345703 16) +(test "115792089237316195423570985008687907853269984665640564039457584007913129639936" number->string (expt 2 256)) +(test "115792089237316195423570985008687907853269984665640564039457584007913129639935" number->string (sub1 (expt 2 256))) +(test "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" number->string (expt 2 256) 2) +(test "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" number->string (sub1 (expt 2 256)) 2) +(test "20000000000000000000000000000000000000000000000000000000000000000000000000000000000000" number->string (expt 2 256) 8) +(test "17777777777777777777777777777777777777777777777777777777777777777777777777777777777777" number->string (sub1 (expt 2 256)) 8) +(test "10000000000000000000000000000000000000000000000000000000000000000" number->string (expt 2 256) 16) +(test "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" number->string (sub1 (expt 2 256)) 16) +(test "-115792089237316195423570985008687907853269984665640564039457584007913129639936" number->string (- (expt 2 256))) +(test "-115792089237316195423570985008687907853269984665640564039457584007913129639935" number->string (- (sub1 (expt 2 256)))) +(test "-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" number->string (- (expt 2 256)) 2) +(test "-1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" number->string (- (sub1 (expt 2 256))) 2) +(test "-20000000000000000000000000000000000000000000000000000000000000000000000000000000000000" number->string (- (expt 2 256)) 8) +(test "-17777777777777777777777777777777777777777777777777777777777777777777777777777777777777" number->string (- (sub1 (expt 2 256))) 8) +(test "-10000000000000000000000000000000000000000000000000000000000000000" number->string (- (expt 2 256)) 16) +(test "-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" number->string (- (sub1 (expt 2 256))) 16) + + +(test 0 string->number "0") +(test 1 string->number "1") +(test -1 string->number "-1") +(test 7284132478923046920834523467890234589203467590267382904573942345703 string->number "7284132478923046920834523467890234589203467590267382904573942345703") +(test -7284132478923046920834523467890234589203467590267382904573942345703 string->number "-7284132478923046920834523467890234589203467590267382904573942345703") +(test 7284132478923046920834523467890234589203467590267382904573942345703 string->number "1000101001010101011111011000101001011011100111110001111111010101000100010110001001011011101111011001111101000100110100010101111001111001001011111001000100111000011111110010101010110110001011011111101110000001010111111100111" 2) +(test -7284132478923046920834523467890234589203467590267382904573942345703 string->number "-1000101001010101011111011000101001011011100111110001111111010101000100010110001001011011101111011001111101000100110100010101111001111001001011111001000100111000011111110010101010110110001011011111101110000001010111111100111" 2) +(test 7284132478923046920834523467890234589203467590267382904573942345703 string->number "105125373051334761772504261133573175046425717113710470376252661337560127747" 8) +(test -7284132478923046920834523467890234589203467590267382904573942345703 string->number "-105125373051334761772504261133573175046425717113710470376252661337560127747" 8) +(test 7284132478923046920834523467890234589203467590267382904573942345703 string->number "452abec52dcf8fea88b12ddecfa268af3c97c89c3f955b16fdc0afe7" 16) +(test -7284132478923046920834523467890234589203467590267382904573942345703 string->number "-452abec52dcf8fea88b12ddecfa268af3c97c89c3f955b16fdc0afe7" 16) +(test (expt 2 256) string->number "115792089237316195423570985008687907853269984665640564039457584007913129639936") +(test (sub1 (expt 2 256)) string->number "115792089237316195423570985008687907853269984665640564039457584007913129639935") +(test (expt 2 256) string->number "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 2) +(test (sub1 (expt 2 256)) string->number "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" 2) +(test (expt 2 256) string->number "20000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 8) +(test (sub1 (expt 2 256)) string->number "17777777777777777777777777777777777777777777777777777777777777777777777777777777777777" 8) +(test (expt 2 256) string->number "10000000000000000000000000000000000000000000000000000000000000000" 16) +(test (sub1 (expt 2 256)) string->number "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 16) +(test (- (expt 2 256)) string->number "-115792089237316195423570985008687907853269984665640564039457584007913129639936") +(test (- (sub1 (expt 2 256))) string->number "-115792089237316195423570985008687907853269984665640564039457584007913129639935") +(test (- (expt 2 256)) string->number "-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 2) +(test (- (sub1 (expt 2 256))) string->number "-1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" 2) +(test (- (expt 2 256)) string->number "-20000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 8) +(test (- (sub1 (expt 2 256))) string->number "-17777777777777777777777777777777777777777777777777777777777777777777777777777777777777" 8) +(test (- (expt 2 256)) string->number "-10000000000000000000000000000000000000000000000000000000000000000" 16) +(test (- (sub1 (expt 2 256))) string->number "-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 16) +(test #f string->number "144r" 10) +(err/rt-test (string->number "10" 30)) + +(define (q-test quotient) + (test 0 quotient 0 12345678909876532341) + (test 0 quotient 0 -1235782934075829307) + (test 2374865902374859023745 quotient 2374865902374859023745 1) + (test -2374865902374859023745 quotient -2374865902374859023745 1) + (test 0 quotient 1 13748910785903278450) + (test 1 quotient 13748910785903278450 13748910785903278449) + (test 0 quotient 13748910785903278450 13748910785903278451) + (test -1 quotient -13748910785903278450 13748910785903278449) + (test 0 quotient -13748910785903278450 13748910785903278451) + (test -1 quotient 13748910785903278450 -13748910785903278449) + (test 0 quotient 13748910785903278450 -13748910785903278451) + (test 1 quotient -13748910785903278450 -13748910785903278449) + (test 0 quotient -13748910785903278450 -13748910785903278451) + (test 1 quotient 13748910785903278450 13748910785903278450) + (test -1 quotient -13748910785903278450 13748910785903278450) + (test -1 quotient 13748910785903278450 -13748910785903278450) + (test 1 quotient -13748910785903278450 -13748910785903278450) + (test (expt 5 64) quotient (expt 5 256) (expt 5 192)) + (test 0 quotient (expt 5 192) (expt 5 256)) + (test 8636168555094444625386351862800399571116000364436281385023703470168591803162427057971507503472288226560547293946149 quotient (expt 5 192) (expt 2 64))) +(q-test quotient) +;; dyoo: no support for quotient/remainder +#;(q-test (lambda (n1 n2) (let-values ([(q r) (quotient/remainder n1 n2)]) q))) + +(define (r-test remainder) + (test 0 remainder 0 12345678909876532341) + (test 0 remainder 0 -1235782934075829307) + (test 0 remainder 2374865902374859023745 1) + (test 0 remainder -2374865902374859023745 1) + (test 1 remainder 1 13748910785903278450) + (test 1 remainder 13748910785903278450 13748910785903278449) + (test 13748910785903278450 remainder 13748910785903278450 13748910785903278451) + (test -1 remainder -13748910785903278450 13748910785903278449) + (test -13748910785903278450 remainder -13748910785903278450 13748910785903278451) + (test 1 remainder 13748910785903278450 -13748910785903278449) + (test 13748910785903278450 remainder 13748910785903278450 -13748910785903278451) + (test -1 remainder -13748910785903278450 -13748910785903278449) + (test -13748910785903278450 remainder -13748910785903278450 -13748910785903278451) + (test 0 remainder 13748910785903278450 13748910785903278450) + (test 0 remainder -13748910785903278450 13748910785903278450) + (test 0 remainder 13748910785903278450 -13748910785903278450) + (test 0 remainder -13748910785903278450 -13748910785903278450) + (test 0 remainder (expt 5 256) (expt 5 192)) + (test (expt 5 192) remainder (expt 5 192) (expt 5 256)) + (test 12241203936672963841 remainder (expt 5 192) (expt 2 64))) +(r-test remainder) +;; dyoo: no support for quotient/remainder +#;(r-test (lambda (n1 n2) (let-values ([(q r) (quotient/remainder n1 n2)]) r))) + +(define (s-test sqrt) + (test 0 sqrt 0) + (test 1 sqrt 1) + (test 2 sqrt 4) + (test 3 sqrt 9) + (test (expt 2 64) sqrt (* (expt 2 64) (expt 2 64))) + (test (expt 13 70) sqrt (* (expt 13 70) (expt 13 70))) + (test (sub1 (expt 2 200)) sqrt (* (sub1 (expt 2 200)) (sub1 (expt 2 200)))) + (test (expt 2 25) sqrt (expt 2 50)) + (test 1 sqrt 3) + (test #xffffffff sqrt (sub1 (expt 2 64))) + (test 2876265888493261300027370452880859375 sqrt (expt 15 62)) + (test #x8f0767e50d4d0c07563bd81f530d36 sqrt (expt 15 61))) +(s-test integer-sqrt) + +;; dyoo: no support for integer-sqrt/remainder +#;(s-test (lambda (a) (let-values ([(root rem) (integer-sqrt/remainder a)]) root))) + +(define (sr-test sqrt) + (test 0 sqrt 0) + (test 0 sqrt 1) + (test 0 sqrt 4) + (test 0 sqrt 9) + (test 0 sqrt (* (expt 2 64) (expt 2 64))) + (test 0 sqrt (* (expt 13 70) (expt 13 70))) + (test 0 sqrt (* (sub1 (expt 2 200)) (sub1 (expt 2 200)))) + (test 0 sqrt (expt 2 50)) + (test 2 sqrt 3) + (test 8589934590 sqrt (sub1 (expt 2 64))) + (test 0 sqrt (expt 15 62)) + (test 1306106749204831357295958563982718571 sqrt (expt 15 61))) +;; dyoo: no support for integer-sqrt/remainder +#;(sr-test (lambda (a) (let-values ([(root rem) (integer-sqrt/remainder a)]) rem))) + +(test 1.7320508075688772 sqrt 3) +(test 4294967296.0 sqrt (sub1 (expt 2 64))) +(test 2876265888493261300027370452880859375 sqrt (expt 15 62)) +(test 7.426486590265921e+35 sqrt (expt 15 61)) + + + +(test 5.515270307539953e+71 exact->inexact (expt 15 61)) +(test -5.515270307539953e+71 exact->inexact (- (expt 15 61))) +(test 1.8446744073709552e+19 exact->inexact (expt 2 64)) +(test 1.157920892373162e+77 exact->inexact (expt 2 256)) +(test 1.157920892373162e+77 exact->inexact (sub1 (expt 2 256))) + +(test 551527030753995340375346347667240734743269800540264151034260072897183744 inexact->exact 5.515270307539953d+71) +(test (expt 2 64) inexact->exact 1.8446744073709552e+19) +(test (- (expt 2 64)) inexact->exact -1.8446744073709552e+19) +(test (expt 2 256) inexact->exact 1.157920892373162d+77) +(test 115792089237316195423570985008687907853269984665640564039457584007913129639936 inexact->exact 1.157920892373162d+77) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +#| dyoo: no support for integer-bytes->integer +(test (integer-bytes->integer #"\1\2" #f) integer-bytes->integer #"\1\2" #f (system-big-endian?)) + +(define (test-integer-bytes->integer integer-bytes->integer) + (test 0 integer-bytes->integer #"\0\0" #t) + (test -1 integer-bytes->integer #"\377\377" #t) + (test 65535 integer-bytes->integer #"\377\377" #f) + ;; + (test 0 integer-bytes->integer #"\0\0" #t #t) + (test -1 integer-bytes->integer #"\377\377" #t #t) + (test 65535 integer-bytes->integer #"\377\377" #f #t) + (test -256 integer-bytes->integer #"\377\0" #t #t) + (test -255 integer-bytes->integer #"\377\1" #t #t) + (test 511 integer-bytes->integer #"\1\377" #t #t) + (test 513 integer-bytes->integer #"\1\2" #f #f) + ;; + (test 0 integer-bytes->integer #"\0\0" #t #f) + (test -1 integer-bytes->integer #"\377\377" #t #f) + (test 65535 integer-bytes->integer #"\377\377" #f #f) + (test 511 integer-bytes->integer #"\377\1" #t #f) + (test -255 integer-bytes->integer #"\1\377" #t #f) + (test 258 integer-bytes->integer #"\1\2" #f #t) + + (test 0 integer-bytes->integer #"\0\0\0\0" #t) + (test -1 integer-bytes->integer #"\377\377\377\377" #t) + (test 4294967295 integer-bytes->integer #"\377\377\377\377" #f) + ;; + (test 0 integer-bytes->integer #"\0\0\0\0" #t #t) + (test -1 integer-bytes->integer #"\377\377\377\377" #t #t) + (test 4294967295 integer-bytes->integer #"\377\377\377\377" #f #t) + (test -16777216 integer-bytes->integer #"\377\0\0\0" #t #t) + (test 255 integer-bytes->integer #"\0\0\0\377" #t #t) + ;; + (test 0 integer-bytes->integer #"\0\0\0\0" #t #f) + (test -1 integer-bytes->integer #"\377\377\377\377" #t #f) + (test 4294967295 integer-bytes->integer #"\377\377\377\377" #f #f) + (test 16777471 integer-bytes->integer #"\377\0\0\1" #t #f) + (test -16777216 integer-bytes->integer #"\0\0\0\377" #t #f) + (test -16777215 integer-bytes->integer #"\1\0\0\377" #t #f) + + (test 1835103348 integer-bytes->integer #"matt" #t #t) + (test 1953784173 integer-bytes->integer #"matt" #t #f) + + (test 0 integer-bytes->integer #"\0\0\0\0\0\0\0\0" #t #t) + (test -1 integer-bytes->integer #"\377\377\377\377\377\377\377\377" #t #f) + (test 18446744073709551615 integer-bytes->integer #"\377\377\377\377\377\377\377\377" #f #f) + (test 4294967295 integer-bytes->integer #"\377\377\377\377\0\0\0\0" #t #f) + (test -4294967296 integer-bytes->integer #"\0\0\0\0\377\377\377\377" #t #f) + (test 8589934591 integer-bytes->integer #"\377\377\377\377\1\0\0\0" #t #f) + (test -4294967295 integer-bytes->integer #"\1\0\0\0\377\377\377\377" #t #f) + ;; + (test 0 integer-bytes->integer #"\0\0\0\0\0\0\0\0" #t #f) + (test -1 integer-bytes->integer #"\377\377\377\377\377\377\377\377" #t #f) + (test 18446744073709551615 integer-bytes->integer #"\377\377\377\377\377\377\377\377" #f #f) + (test -4294967296 integer-bytes->integer #"\377\377\377\377\0\0\0\0" #t #t) + (test 4294967295 integer-bytes->integer #"\0\0\0\0\377\377\377\377" #t #t) + (test -4294967295 integer-bytes->integer #"\377\377\377\377\0\0\0\1" #t #t) + (test 8589934591 integer-bytes->integer #"\0\0\0\1\377\377\377\377" #t #t)) + +(test-integer-bytes->integer integer-bytes->integer) +(test-integer-bytes->integer (lambda (bstr signed? [big-endian? (system-big-endian?)]) + (integer-bytes->integer (bytes-append #"xxx" bstr) + signed? + big-endian? + 3))) +(test-integer-bytes->integer (lambda (bstr signed? [big-endian? (system-big-endian?)]) + (integer-bytes->integer (bytes-append #"xxx" bstr #"x") + signed? + big-endian? + 3 + (+ 3 (bytes-length bstr))))) + +(arity-test integer-bytes->integer 2 5) +(err/rt-test (integer-bytes->integer 'ok #t)) +(err/rt-test (integer-bytes->integer #"" #t)) +(err/rt-test (integer-bytes->integer #"a" #t)) +(err/rt-test (integer-bytes->integer #"abc" #t)) +(err/rt-test (integer-bytes->integer #"abcdefghi" #t)) +(err/rt-test (integer-bytes->integer #"abcdefghi" #t #f 0 3)) +(err/rt-test (integer-bytes->integer #"abcd" #t #f 1)) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(test (integer->integer-bytes 42 2 #f) integer->integer-bytes 42 2 #f (system-big-endian?)) + +(define (test-integer->integer-bytes integer->integer-bytes) + (test #"\0\0" integer->integer-bytes 0 2 #t) + (test #"\377\377" integer->integer-bytes -1 2 #t) + (test #"\377\377" integer->integer-bytes 65535 2 #f) + ;; + (test #"\0\0" integer->integer-bytes 0 2 #t #t) + (test #"\377\377" integer->integer-bytes -1 2 #t #t) + (test #"\377\377" integer->integer-bytes 65535 2 #f #t) + (test #"\377\0" integer->integer-bytes -256 2 #t #t) + (test #"\377\1" integer->integer-bytes -255 2 #t #t) + (test #"\1\377" integer->integer-bytes 511 2 #t #t) + (test #"\1\2" integer->integer-bytes 513 2 #f #f) + ;; + (test #"\0\0" integer->integer-bytes 0 2 #t #f) + (test #"\377\377" integer->integer-bytes -1 2 #t #f) + (test #"\377\377" integer->integer-bytes 65535 2 #f #f) + (test #"\377\1" integer->integer-bytes 511 2 #t #f) + (test #"\1\377" integer->integer-bytes -255 2 #t #f) + (test #"\1\2" integer->integer-bytes 258 2 #f #t) + + (test #"\0\0\0\0" integer->integer-bytes 0 4 #t) + (test #"\377\377\377\377" integer->integer-bytes -1 4 #t) + (test #"\377\377\377\377" integer->integer-bytes 4294967295 4 #f) + ;; + (test #"\0\0\0\0" integer->integer-bytes 0 4 #t #t) + (test #"\377\377\377\377" integer->integer-bytes -1 4 #t #t) + (test #"\377\377\377\377" integer->integer-bytes 4294967295 4 #f #t) + (test #"\377\0\0\0" integer->integer-bytes -16777216 4 #t #t) + (test #"\0\0\0\377" integer->integer-bytes 255 4 #t #t) + ;; + (test #"\0\0\0\0" integer->integer-bytes 0 4 #t #f) + (test #"\377\377\377\377" integer->integer-bytes -1 4 #t #f) + (test #"\377\377\377\377" integer->integer-bytes 4294967295 4 #f #f) + (test #"\377\0\0\1" integer->integer-bytes 16777471 4 #t #f) + (test #"\0\0\0\377" integer->integer-bytes -16777216 4 #t #f) + (test #"\1\0\0\377" integer->integer-bytes -16777215 4 #t #f) + + (test #"matt" integer->integer-bytes 1835103348 4 #t #t) + (test #"matt" integer->integer-bytes 1953784173 4 #t #f) + + (test #"\0\0\0\0\0\0\0\0" integer->integer-bytes 0 8 #t #t) + (test #"\377\377\377\377\377\377\377\377" integer->integer-bytes -1 8 #t #f) + (test #"\377\377\377\377\377\377\377\377" integer->integer-bytes 18446744073709551615 8 #f #f) + (test #"\377\377\377\377\0\0\0\0" integer->integer-bytes 4294967295 8 #t #f) + (test #"\0\0\0\0\377\377\377\377" integer->integer-bytes -4294967296 8 #t #f) + (test #"\377\377\377\377\1\0\0\0" integer->integer-bytes 8589934591 8 #t #f) + (test #"\1\0\0\0\377\377\377\377" integer->integer-bytes -4294967295 8 #t #f) + ;; + (test #"\0\0\0\0\0\0\0\0" integer->integer-bytes 0 8 #t #f) + (test #"\377\377\377\377\377\377\377\377" integer->integer-bytes -1 8 #t #f) + (test #"\377\377\377\377\377\377\377\377" integer->integer-bytes 18446744073709551615 8 #f #f) + (test #"\377\377\377\377\0\0\0\0" integer->integer-bytes -4294967296 8 #t #t) + (test #"\0\0\0\0\377\377\377\377" integer->integer-bytes 4294967295 8 #t #t) + (test #"\377\377\377\377\0\0\0\1" integer->integer-bytes -4294967295 8 #t #t) + (test #"\0\0\0\1\377\377\377\377" integer->integer-bytes 8589934591 8 #t #t)) + +(test-integer->integer-bytes integer->integer-bytes) +(test-integer->integer-bytes (lambda (num sz signed? [bigend? (system-big-endian?)]) + (let ([bstr (make-bytes 11 (char->integer #\x))]) + (integer->integer-bytes num sz signed? bigend? bstr 3) + (test #"xxx" subbytes bstr 0 3) + (test (make-bytes (- 11 3 sz) (char->integer #\x)) subbytes bstr (+ 3 sz)) + (subbytes bstr 3 (+ 3 sz))))) + +(arity-test integer->integer-bytes 3 6) +(err/rt-test (integer->integer-bytes 'ack 2 #t)) +(err/rt-test (integer->integer-bytes 10 'ack #t)) +(err/rt-test (integer->integer-bytes 10 20 #t)) +(err/rt-test (integer->integer-bytes 10 2 #t #t 'ack)) +(err/rt-test (integer->integer-bytes 10 2 #t #t #"ack")) ; <-- immutable string +(err/rt-test (integer->integer-bytes 100000 2 #t) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes 65536 2 #f) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes 32768 2 #t) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes -32769 2 #t) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes (expt 2 32) 4 #f) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes (expt 2 31) 4 #t) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes (sub1 (- (expt 2 31))) 4 #t) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes (expt 2 64) 8 #f) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes (expt 2 63) 4 #t) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes (sub1 (- (expt 2 63))) 8 #t) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes 100 4 #t #t (make-bytes 3)) exn:application:mismatch?) +(err/rt-test (integer->integer-bytes 100 2 #t #t (make-bytes 3) 2) exn:application:mismatch?) + +(map (lambda (v) + (let-values ([(n size signed?) (apply values v)]) + (test n integer-bytes->integer (integer->integer-bytes n size signed? #f) signed? #f) + (test n integer-bytes->integer (integer->integer-bytes n size signed? #t) signed? #t))) + (list + (list 10 2 #t) + + (list (sub1 (expt 2 16)) 2 #f) + (list (sub1 (expt 2 15)) 2 #t) + (list (- (expt 2 15)) 2 #t) + + (list (sub1 (expt 2 32)) 4 #f) + (list (sub1 (expt 2 31)) 4 #t) + (list (- (expt 2 31)) 4 #t) + + (list (sub1 (expt 2 64)) 8 #f) + (list (sub1 (expt 2 63)) 8 #t) + (list (- (expt 2 63)) 8 #t))) + +(let ([s (make-bytes 4)] + [n (random 10000)]) + (test s integer->integer-bytes n 4 #f #f s) + (test s integer->integer-bytes n 4 #f #f)) +|# + + +#| dyoo: no support for floating-point-bytes->real +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; Used for comparison after loss of precision in 4-byte conversion +(define (close? a b) + (or (equal? a b) + (if (negative? a) + (>= (* b 0.999) a (* b 1.001)) + (<= (* b 0.999) a (* b 1.001))) + (and (= b +inf.0) + (> a 1e38)) + (and (= b -inf.0) + (< a -1e38)))) + +(map (lambda (n) + (test #t close? n (floating-point-bytes->real (real->floating-point-bytes n 4 #t) #t)) + (test #t close? n (floating-point-bytes->real (real->floating-point-bytes n 4 #f) #f)) + (test n floating-point-bytes->real (real->floating-point-bytes n 8 #t) #t) + (test n floating-point-bytes->real (real->floating-point-bytes n 8 #f) #f)) + (append + (list 0.0 + -0.0 + +inf.0 + -inf.0 + +nan.0 + 1.0 + 0.1 + 1e10) + (let loop ([n 50]) + (if (zero? n) + null + (cons (* (if (= 1 (random 2)) 1 -1) + (sqrt (/ (random 3000) 3000.0)) + (expt 2.0 (random 300))) + (loop (sub1 n))))))) + +(define (there-and-back n) + (floating-point-bytes->real (real->floating-point-bytes n 8))) + +(err/rt-test (there-and-back 1.0+0.0i)) +(err/rt-test (there-and-back 100.0+0.0i)) +(test 101.0 there-and-back 101) +(test 1e30 there-and-back 1000000000000000000000000000000) +(test 0.5 there-and-back 1/2) + +(let ([s (make-bytes 8)] + [n (expt (random 100) (- (random 100)))]) + (test s real->floating-point-bytes n 8 #f s) + (test s real->floating-point-bytes n 8 #f)) + +(err/rt-test (real->floating-point-bytes 1 -4)) +(err/rt-test (real->floating-point-bytes 1 7)) +(err/rt-test (real->floating-point-bytes 1 7000000000000000000000000)) +(err/rt-test (real->floating-point-bytes 1+2i 8)) +(err/rt-test (real->floating-point-bytes 1.0+2.0i 8)) +(err/rt-test (real->floating-point-bytes 1.0 8 #f (make-bytes 7)) exn:application:mismatch?) +|# +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(report-errs) diff --git a/tests/older-tests/mz-tests/numstrs.rkt b/tests/older-tests/mz-tests/numstrs.rkt new file mode 100644 index 0000000..4c99314 --- /dev/null +++ b/tests/older-tests/mz-tests/numstrs.rkt @@ -0,0 +1,220 @@ +#lang s-exp "../../lang/base.rkt" + + +(provide (all-defined-out)) + +;; #f means a symbol +;; X means fails (syntax forces it to be a number) +;; DBZ means fails because divide-by-zero +;; NOE means fails because no such exact + +(define number-table + `((,(+ 1/2 +i) "1/2+i") + (100 "100") + (100 "#d100") + (0.1 ".1") + (0.1 "#d.1") + (1/20000 "#e1/2e-4") + (10.0 "1e1") + (10.0 "1E1") + (10.0 "1s1") + (10.0 "1S1") + (10.0 "1f1") + (10.0 "1F1") + (10.0 "1l1") + (10.0 "1L1") + (10.0 "1d1") + (10.0 "1D1") + (0.0 "0e13") + (0.0 "#i0") + (-0.0 "#i-0") + (+inf.0 ".3e2666666666") + (+inf.0 "+INF.0") + (+nan.0 "+NaN.0") + (+inf.0 "1e500") ; Check simple overflows + (-inf.0 "-1e500") + (0.0 "1e-500") + (-0.0 "-1e-500") + (+inf.0 "1#e500") + (-inf.0 "-1#e500") + (0.0 "1#e-500") + (-0.0 "-1#e-500") + (+inf.0 "1e10000000000000000000000000000000") ; Check avoidance of extreme computations + (-inf.0 "-1e10000000000000000000000000000000") + (+inf.0 "1#e10000000000000000000000000000000") + (-inf.0 "-1#e10000000000000000000000000000000") + (+0.0 "1e-10000000000000000000000000000000") + (-0.0 "-1e-10000000000000000000000000000000") + (+0.0 "1#e-10000000000000000000000000000000") + (-0.0 "-1#e-10000000000000000000000000000000") + (10.0 "1#") + (10.0 "1#e0") + (10.0 "1####e-3") + (10.0 "1#.e0") + (10.0 "10.#e0") + (10.0 "10.e0") + (10.0 "1#.e0") + (10.0 "10.0#e0") + (10.0 "1#.##e0") + (10 "#e1#") + (10 "#e1#e0") + (10 "#e1#.e0") + (5e-5 "1/2e-4") + (5e-5 "#i1/2e-4") + (0.5 "#i1/2") + (1/2 "#e1/2") + (0.5 "#i0.5") + (1/2 "#e0.5") + (1/20 "#e0.5e-1") + (1/20 "#e0.005e1") + (1.0+0.5i "1+0.5i") + (1/2 "1/2@0") + (-1/2 "-1/2@0") + (1/2 "1/2@-0") + (0 "#o#e0") + (8 "#o#e10") + (0 "#b#e0") + (0.0 "#b#i0") + (4.0 "#b1e10") + (4 "#b#e1e10") + (1/10+1/5i "#e0.1+0.2i") + (0.0+80.0i "#i+8#i") + (521976 "#x7f6f8") + (1+8i "#b#e1+1#e10i") + (1.125 "#x1.2") + (1.1640625 "#x1.2a") + (1.1640625 "#x1.2a####") + (10.0 "#xa.") + (10.25 "#xa.4") + (160.0 "#xa#.") + (416.0 "#x1a#.") + (2816.0 "#xb##.##") + (4e62 "#i4000000000000000000000000000000000000000000000000000000000000e2") + (-0.0 "#b-0.0") + (X "#b1000000000020e1") + (#f "1.0/3") + (#f "1/3.0") + (#i10/3 "1#/3") + (#i1/300 "1/3##") + (#f "1#/#3") + (#i10/3 "#d1#/3") + (X "#d1#/#3") + (+inf.0 "1/0#") + (-inf.0 "-1/0#") + (NOE "#e+inf.0") + (NOE "#e-inf.0") + (NOE "#e+nan.0") + (NOE "#e1/0#") + (500.0 "1/2#e4") + (5000.0 "1#/2#e4") + (500000000.0 "1/2#e10") + (500000000 "#e1/2#e10") + (16140901064495857664-50176i "#e#x+e#s+e@-e#l-e") + + (#f "d") + (D "D") + (#f "i") + (I "I") + (#f "3i") + (3I "3I") + (#f "33i") + (33I "33I") + (#f "3.3i") + (3.3I "3.3I") + (#f "e") + (#f "e1") + (#f "e1") + (#f "-") + (#f "+") + (X "#e-") + (X "#e+") + (X "#i-") + (X "#i+") + (#f "+.") + (X "#e+.") + (#f "/") + (#f "+1+1") + (#f "+1/+1") + (#f "1//2") + (#f "mod//") + (#f "-1.0/2") + (#f "/2") + (#f "2..") + (#f ".2.") + (X "#e2..") + (X "#e.2.") + (#f "1#.0e4") + (#f "1#0e4") + (#f "1#0.e4") + (#f "1##.##0e4") + (#f "2i") + (#f "/2i") + (#f "2@2i") + (#f "2@@2") + (#f "-2@-+2") + (#f "1/1-e4") + (#f "1.-2") + (#f "--1") + (#f "-+1") + (#f "-1+3-4") + (#f "1\0002") + (X "#xg") + (X "#x") + (X "#xa#a") + (X "#i#j0") + (X "#x12.a#b") + (X "#e1.-2") + (X "#b#b0") + (X "#b#o0") + (X "#i#i0") + (X "#e#e0") + (X "#i8#i") + (X "#i4@#i5") + (X "#i4+#d6i") + (X "#i4+#d6") + (#f "4ef5") + (X "#e4ef5") + (X "#d1e") + (X "#b1e") + (X "#o1e") + (DBZ "1/0") + (DBZ "5+1/0i") + (DBZ "1/0+5i") + (DBZ "5@1/0") + (DBZ "1/0@5") + (DBZ "1/0e2") + (#f "1/0+hi") + (#f "x+1/0i") + (+nan.0+1i "+nan.0+1i") + (1+nan.0i "1+nan.0i") + (#f "1++nan.0i") + (0.5+nan.0i "1/2+nan.0i") + (1+inf.0i "1+inf.0i") + (1-inf.0i "1-inf.0i") + (+inf.0i "+inf.0i") + (-inf.0i "-inf.0i") + (+nan.0i "+nan.0i") + (-nan.0i "-nan.0i") + (+inf.0i "+INF.0i") + (-inf.0-nan.0i "-inf.0-nan.0i") + (#f "1++inf.0i") + (+nan.0@1 "+nan.0@1") + (+inf.0@1 "+inf.0@1") + (#f "+inf.0@1@1") + (1@+inf.0 "1@+inf.0") + (1@+inf.0 "1/1@+inf.0") + (+inf.0@1 "+inf.0@1/1") + (1.0+0.0i "1@0000.0") + (1.0 "0001.0@0") + (#f "+inf.0@3@0") + (#f "+inf.0@3+4i") + (#f "+ina.0") + (#f "1@3+4i") + (#f "@2") + (#f "+a@2") + (DBZ "1/0+inf.0i") + (DBZ "+inf.0+1/0i") + (DBZ "1/0@+inf.0") + (DBZ "+inf.0@1/0") + (#f "1e1/0") + (#f "011111122222222223333333333444444x"))) diff --git a/tests/older-tests/mz-tests/run-all-tests.rkt b/tests/older-tests/mz-tests/run-all-tests.rkt new file mode 100644 index 0000000..408e8f1 --- /dev/null +++ b/tests/older-tests/mz-tests/run-all-tests.rkt @@ -0,0 +1,3 @@ +#lang racket/base +(require "../../main.rkt") +(run-in-browser "all-tests.rkt") diff --git a/tests/older-tests/mz-tests/test-files-notes.txt b/tests/older-tests/mz-tests/test-files-notes.txt new file mode 100644 index 0000000..887d72e --- /dev/null +++ b/tests/older-tests/mz-tests/test-files-notes.txt @@ -0,0 +1,188 @@ +Looks easy to convert +--------------------- + +ztest.rktl looks good +vector.rktl +shared.rktl +shared-tests.rktl +oe.rktl +numstrs.rktl +number.rktl +nch.rktl +math.rktl +ltest.rktl +loop.rktl +list.rktl +ktest.rktl +fact.rktl +binc.rktl + + +Looks moderately hard +------------------------------------------- + +basic.rktl +syntax.rktl +structlib.rktl +struct.rktl + +string.rktl +string-mzlib.rktl + +prompt.rktl +prompt-tests.rktl + +procs.rktl +print.rktl + +mpair.rktl + +intm-adv.rktl + +htdp.rktl +htdp-test.rktl + +deep.rktl +control.rktl +contmark.rktl + +censor.rktl +advanced.rktl + + +Looks difficult to convert, or inapplicable +------------------------------------------- + +zo-marshal.rktl +will.rktl +version.rktl +unsafe.rktl +unitsig.rktl +unit.rktl +udp.rktl +trait.rktl +trace.rktl +thrport.rktl +threadlib.rktl +thread.rktl +tcp.rktl +sync.rktl +subprocess.rktl +stx.rktl + +unicode.rktl +uni-norm.rktl +unic3.rktl +unic2.rktl +unic.rktl + +stream.rktl +srfi.rktl + +set.rktl +serialize.rktl +sandbox.rktl +rx.rktl + +runflats.rktl +restart.rktl +readtable.rktl + +read.rktl +quiet.rktl + +pretty.rtkl + +portlib.rktl +port.rktl +place-channel.rktl +pconvert.rktl +pathlib.rktl +path.rktl + +param.rktl +parallel.rtkl +package.rktl +package-gen.rktl +pack.rktl +optimize.rktl +openssl.rktl +object.rktl +object-old.rktl +net.rktl + +namespac.rktl + + +name.rktl +mzq.rktl +mzlib-tests.rktl +mz-tests.rktl + +module.rktl +module-reader.rktl +modprot.rktl +moddep.rktl +makeflats.rktl +makeflat.rktl + +macrolib.rktl +macro.rktl +logger.rktl +loadtest.rktl +loadable.rktl + +kw.rktl + +intmlam-adv.rktl +intm-intml.rktl +intermediate.rktl +intermediate-lambda.rktl + + +imap.rktl +id-table-test.rktl + +htdp-image.rktl +head.rktl + + +function.rktl +foreign-test.rktl +for.rktl +fixnum.rktl +filelib.rktl +file.rktl +expand.rktl +etc.rktl +embed.rktl +embed-me4.rktl +embed-in-c.rktl +dict.rktl +date.rktl + +contract-test.rktl +contract-mzlib-test.rktl +compile.rktl + +compat.rktl +cmdline.rktl +cm.rktl +chez-module.rktl +char-set.rktl +chaperones.rktl + +cache-image-snip-test.rktl +boundmap-test.rktl + +beginner.rktl +beginner-abbr.rktl +bega-adv.rktl +beg-intml.rktl +beg-intm.rktl +beg-bega.rktl +beg-adv.rktl +awk.rktl +async-channel.rktl +all.rktl + diff --git a/tests/older-tests/mz-tests/testing.rkt b/tests/older-tests/mz-tests/testing.rkt new file mode 100644 index 0000000..1f83392 --- /dev/null +++ b/tests/older-tests/mz-tests/testing.rkt @@ -0,0 +1,193 @@ +#lang s-exp "../../lang/base.rkt" + + +(provide test test-values Section record-error arity-test err/rt-test disable + exn:application:mismatch? exn:application:type? exn:application:arity? + report-errs type? arity?) + +(require (for-syntax racket/base)) + +(define number-of-tests 0) +(define number-of-error-tests 0) + + +(define Section-prefix "") + +(define cur-section '()) + +(define errs '()) + +(define (record-error e) + (set! errs (cons (list cur-section e) errs))) + + +(define (Section . args) + (let () + (printf "~aSection~s\n" Section-prefix args) + #;(flush-output p)) + (set! cur-section args) + #t) + + +(define (report-errs) + (printf "\n\nran ~s normal tests, and ~s error-trapping tests\n" + number-of-tests number-of-error-tests) + (printf "\n\n~a errors during the run:\n" (length errs)) + (for-each (lambda (err) (printf "~s\n\n" err)) errs)) + + + +(define test + (let () + (define (test* expect fun args kws kvs) + (set! number-of-tests (add1 number-of-tests)) + (printf "~s ==> " (cons fun args)) + #;(flush-output) + (let ([res (if (procedure? fun) + (if kws + (error 'test "keywords not supported yet") + (apply fun args)) + (car args))]) + (printf "~s\n" res) + (let ([ok? (equal? expect res)]) + (unless ok? + (record-error (list res expect (cons fun args))) + (printf " BUT EXPECTED ~s\n" expect)) + ok?))) + #;(define (test/kw kws kvs expect fun . args) (test* expect fun args kws kvs)) + (define (test expect fun . args) (test* expect fun args #f #f)) + test + #;(make-keyword-procedure test/kw test))) + + + +(define (test-values l thunk) + (test l call-with-values thunk list)) + + + +(define exn:application:mismatch? exn:fail:contract?) +(define exn:application:type? exn:fail:contract?) +(define exn:application:arity? exn:fail:contract:arity?) + +(define type? exn:application:type?) +(define arity? exn:application:arity?) + + + +(define arity-test + (case-lambda + [(f min max except) + #;(void) + (letrec ([aok? + (lambda (a) + (cond + [(integer? a) (= a min max)] + [(arity-at-least? a) (and (negative? max) + (= (arity-at-least-value a) min))] + [(and (list? a) (andmap integer? a)) + (and (= min (car a)) (= max + (let loop ([l a]) + (if (null? (cdr l)) + (car l) + (loop (cdr l))))))] + [(list? a) + ;; Just check that all are consistent for now. + ;; This should be improved. + (andmap + (lambda (a) + (if (number? a) + (<= min a (if (negative? max) a max)) + (>= (arity-at-least-value a) min))) + a)] + [else #f]))] + [make-ok? + (lambda (v) + (lambda (e) + (exn:application:arity? e)))] + [do-test + (lambda (f args check?) + (set! number-of-error-tests (add1 number-of-error-tests)) + (printf "(apply ~s '~s) =e=> " f args) + + (let/cc done + (let ([v (with-handlers ([void + (lambda (exn) + (if (check? exn) + (printf " ~a\n" (if (exn? exn) + (exn-message exn) + (format "uncaught ~x" exn))) + (let ([ok-type? (exn:application:arity? exn)]) + (printf " WRONG EXN ~a: ~s\n" + (if ok-type? + "FIELD" + "TYPE") + exn) + (record-error (list exn + (if ok-type? + 'exn-field + 'exn-type) + (cons f args))))) + (done (void)))]) + (apply f args))]) + (printf "~s\n BUT EXPECTED ERROR\n" v) + (record-error (list v 'Error (cons f args))))))]) + (let loop ([n 0][l '()]) + (unless (>= n min) + (unless (memq n except) + (do-test f l (make-ok? n))) + (loop (add1 n) (cons 1 l)))) + (let loop ([n min]) + (unless (memq n except) + (test #t procedure-arity-includes? f n)) + (unless (>= n max) + (loop (add1 n)))) + (if (>= max 0) + (do-test f (let loop ([n 0][l '(1)]) + (if (= n max) + l + (loop (add1 n) (cons 1 l)))) + (make-ok? (add1 max))) + (test #t procedure-arity-includes? f 1267650600228229401496703205376 #;(arithmetic-shift 1 100))))] + [(f min max) (arity-test f min max null)])) + + + +;; err/rt-test currently a stub that doesn't do anything. +#;(define-syntax err/rt-test + (lambda (stx) + (syntax-case stx () + [(_ e exn?) + (syntax + (thunk-error-test (err:mz:lambda () e) (quote-syntax e) exn?))] + [(_ e) + (syntax + (err/rt-test e exn:application:type?))]))) + + +(define-syntax (err/rt-test stx) + (syntax-case stx () + [(_ e exn?) + (with-syntax ([stx-datum (syntax->datum #'e)]) + (syntax/loc stx + (err/rt-test-helper (lambda () e) exn? (quote stx-datum))))] + [(_ e) + (syntax/loc stx + (err/rt-test e exn:application:type?))])) + + + +(define (err/rt-test-helper thunk exn? datum) + (set! number-of-error-tests (add1 number-of-tests)) + (with-handlers ([exn? (lambda (exn) (void))]) + (thunk) + (record-error (list 'Error datum))) + #;(printf "took ~s milliseconds\n" (- (current-inexact-milliseconds) start-time))) + + + +(define-syntax (disable stx) + (syntax-case stx () + [(_ e ...) + (syntax/loc stx + (void))])) \ No newline at end of file diff --git a/tests/older-tests/require-test/m.rkt b/tests/older-tests/require-test/m.rkt new file mode 100644 index 0000000..904df2d --- /dev/null +++ b/tests/older-tests/require-test/m.rkt @@ -0,0 +1,4 @@ +#lang s-exp "../../lang/base.rkt" + +(require "m2.rkt" + "m3.rkt") \ No newline at end of file diff --git a/tests/older-tests/require-test/m1.rkt b/tests/older-tests/require-test/m1.rkt new file mode 100644 index 0000000..999b72f --- /dev/null +++ b/tests/older-tests/require-test/m1.rkt @@ -0,0 +1 @@ +#lang s-exp "../../lang/base.rkt" \ No newline at end of file diff --git a/tests/older-tests/require-test/m2.rkt b/tests/older-tests/require-test/m2.rkt new file mode 100644 index 0000000..b9b3b1b --- /dev/null +++ b/tests/older-tests/require-test/m2.rkt @@ -0,0 +1,2 @@ +#lang s-exp "../../lang/base.rkt" +(require "m1.rkt") \ No newline at end of file diff --git a/tests/older-tests/require-test/m3.rkt b/tests/older-tests/require-test/m3.rkt new file mode 100644 index 0000000..b9b3b1b --- /dev/null +++ b/tests/older-tests/require-test/m3.rkt @@ -0,0 +1,2 @@ +#lang s-exp "../../lang/base.rkt" +(require "m1.rkt") \ No newline at end of file diff --git a/tests/older-tests/require-test/test.rkt b/tests/older-tests/require-test/test.rkt new file mode 100644 index 0000000..2ddb452 --- /dev/null +++ b/tests/older-tests/require-test/test.rkt @@ -0,0 +1,40 @@ +#lang racket/base + +;; check to see that multiple invokations don't duplicate code generation. + +(require "../../private/compile-moby-module.rkt" + "../../private/module-record.rkt" + racket/runtime-path) + +(define-runtime-path m.rkt + "m.rkt" + #;"/home/dyoo/Downloads/tmp/Package/tourguide.rkt") + +(define (check-module-names-unique! module-records) + (let ([names (map module-record-name module-records)]) + (unless (unique? names) + (error 'check-module-names-unique! + "modules with non-unique names: ~s" names)))) + + +(define (unique? names) + (let ([ht (make-hash)]) + (let/ec return + (for ([n names]) + (cond [(hash-ref ht n #f) + (return #f)] + [else + (hash-set! ht n #t)]) + (return #t))))) + + + + + +(define (test) + (define modules + (compile-moby-modules m.rkt)) + (check-module-names-unique! modules)) + + +(test) \ No newline at end of file diff --git a/tests/older-tests/run-all-tests.rkt b/tests/older-tests/run-all-tests.rkt new file mode 100644 index 0000000..0083606 --- /dev/null +++ b/tests/older-tests/run-all-tests.rkt @@ -0,0 +1,25 @@ +#lang racket/base +(require racket/list + "../main.rkt" + racket/runtime-path + racket/system + "check-coverage.rkt") + +(define-runtime-path my-directory ".") + +(when (find-executable-path "node") + (printf "Running the VM internal test suite\n") + (parameterize ([current-directory my-directory]) + (system "unit-tests/run-tests") + (printf "Press Enter to continue.\n") + (void (read-line)))) + + +(printf "Checking for untouched wescheme primitives\n") +(unless (empty? (untouched-wescheme-primitives)) + (print-coverage-report) + (printf "Press Enter to continue.\n") + (void (read-line))) + +(printf "Running browser tests\n") +(run-in-browser "all-tests.rkt") diff --git a/tests/older-tests/unit-tests/browser/build-tests b/tests/older-tests/unit-tests/browser/build-tests new file mode 100755 index 0000000..bfa402a --- /dev/null +++ b/tests/older-tests/unit-tests/browser/build-tests @@ -0,0 +1,6 @@ +#!/bin/bash + +cd `dirname $0` + +../../../lib/build-test browser run-tests.js +cat ../tests.js >> run-tests.js diff --git a/tests/older-tests/unit-tests/browser/webTest.html b/tests/older-tests/unit-tests/browser/webTest.html new file mode 100644 index 0000000..c115b22 --- /dev/null +++ b/tests/older-tests/unit-tests/browser/webTest.html @@ -0,0 +1,20 @@ + + + MzScheme VM Tests + + + +

MzScheme VM Tests

+ + + + diff --git a/tests/older-tests/unit-tests/run-tests b/tests/older-tests/unit-tests/run-tests new file mode 100755 index 0000000..ec3e83d --- /dev/null +++ b/tests/older-tests/unit-tests/run-tests @@ -0,0 +1,36 @@ +#!/bin/bash + +cd `dirname $0` + +if [ -z $1 ] || [ $1 == 'unit' ] + then + srcFile='tests.js' + target='exec-tests.js' + else if [ $1 == 'struct' ] + then + srcFile='struct-tests.js' + target='exec-struct-tests.js' + else + echo $1 'is not a valid type of test' + exit + fi +fi + +#if [ -f $target ] +# then +# echo "File exec-tests.js already exists." +# echo "Please remove" $target "or use a different file." +# exit +#fi + +rm -f $target + +echo 'Building support files' +echo +../../private/lib/build-test node $target +echo + +#cat imports.js >> $target +cat $srcFile >> $target +node $target +#rm -f $target diff --git a/tests/older-tests/unit-tests/struct-tests.js b/tests/older-tests/unit-tests/struct-tests.js new file mode 100644 index 0000000..9bc03b4 --- /dev/null +++ b/tests/older-tests/unit-tests/struct-tests.js @@ -0,0 +1,84 @@ + +var parent = types.makeStructureType('parent', false, 1, 0, false, function(args, name, k) { return k(args); }); +var child1 = types.makeStructureType('child1', parent, 1, 1, 'auto1', + function(args, name, k) { return k([args[0]+'-g1a', args[1]+'-g1b']); }); +var child2 = types.makeStructureType('child2', parent, 2, 1, 'auto2', false); + +var subchild1 = types.makeStructureType('subchild1', child1, 0, 0, false, + function(args, name, k) { return k([args[0]+'-g2a', args[1]+'-g2b']); }); +// function(arg1, arg2, name) { return new types.ValuesWrapper([arg1+'-g2a', arg2+'-g2b']); }); +var subchild2 = types.makeStructureType('subchild2', child2, 2, 2, 'auto2b', false); + + + +// Constructors +var parentInstance = parent.constructor('a'); +var child1Instance = child1.constructor('b', '1'); +var child2Instance = child2.constructor('c', '2', '3'); +var subchild1Instance = subchild1.constructor('d', '4'); +var subchild2Instance = subchild2.constructor('e', '5', '6', 7, 8); + +sys.print(sys.inspect(parentInstance) + '\n'); +sys.print(sys.inspect(child1Instance) + '\n'); +sys.print(sys.inspect(child2Instance) + '\n'); +sys.print(sys.inspect(subchild1Instance) + '\n'); +sys.print(sys.inspect(subchild2Instance) + '\n'); + + +// Predicates +assert.ok( parent.predicate(parentInstance) ); +assert.ok( parent.predicate(child1Instance) ); +assert.ok( parent.predicate(child2Instance) ); +assert.ok( parent.predicate(subchild1Instance) ); +assert.ok( parent.predicate(subchild2Instance) ); + +assert.ok( !child1.predicate(parentInstance) ); +assert.ok( child1.predicate(child1Instance) ); +assert.ok( !child1.predicate(child2Instance) ); +assert.ok( child1.predicate(subchild1Instance) ); +assert.ok( !child1.predicate(subchild2Instance) ); + +assert.ok( !child2.predicate(parentInstance) ); +assert.ok( !child2.predicate(child1Instance) ); +assert.ok( child2.predicate(child2Instance) ); +assert.ok( !child2.predicate(subchild1Instance) ); +assert.ok( child2.predicate(subchild2Instance) ); + +assert.ok( !subchild1.predicate(parentInstance) ); +assert.ok( !subchild1.predicate(child1Instance) ); +assert.ok( !subchild1.predicate(child2Instance) ); +assert.ok( subchild1.predicate(subchild1Instance) ); +assert.ok( !subchild1.predicate(subchild2Instance) ); + +assert.ok( !subchild2.predicate(parentInstance) ); +assert.ok( !subchild2.predicate(child1Instance) ); +assert.ok( !subchild2.predicate(child2Instance) ); +assert.ok( !subchild2.predicate(subchild1Instance) ); +assert.ok( subchild2.predicate(subchild2Instance) ); + + +// Accessors +assert.deepEqual(parent.accessor(parentInstance, 0), 'a'); +assert.deepEqual(parent.accessor(child1Instance, 0), 'b-g1a'); +assert.deepEqual(parent.accessor(child2Instance, 0), 'c'); +assert.deepEqual(parent.accessor(subchild1Instance, 0), 'd-g2a-g1a'); +assert.deepEqual(parent.accessor(subchild2Instance, 0), 'e'); + +assert.deepEqual(child1.accessor(child1Instance, 0), '1-g1b'); +assert.deepEqual(child1.accessor(child1Instance, 1), 'auto1'); +assert.deepEqual(child1.accessor(subchild1Instance, 0), '4-g2b-g1b'); +assert.deepEqual(child1.accessor(subchild1Instance, 1), 'auto1'); + +assert.deepEqual(child2.accessor(child2Instance, 0), '2'); +assert.deepEqual(child2.accessor(child2Instance, 1), '3'); +assert.deepEqual(child2.accessor(child2Instance, 2), 'auto2'); +assert.deepEqual(child2.accessor(subchild2Instance, 0), '5'); +assert.deepEqual(child2.accessor(subchild2Instance, 1), '6'); +assert.deepEqual(child2.accessor(subchild2Instance, 2), 'auto2'); + +assert.deepEqual(subchild2.accessor(subchild2Instance, 0), 7); +assert.deepEqual(subchild2.accessor(subchild2Instance, 1), 8); +assert.deepEqual(subchild2.accessor(subchild2Instance, 2), 'auto2b'); +assert.deepEqual(subchild2.accessor(subchild2Instance, 3), 'auto2b'); + +sys.print('All tests passed!!\n'); diff --git a/tests/older-tests/unit-tests/tests.js b/tests/older-tests/unit-tests/tests.js new file mode 100644 index 0000000..fb44412 --- /dev/null +++ b/tests/older-tests/unit-tests/tests.js @@ -0,0 +1,3462 @@ +////////////////////////////////////////////////////////////////////// + + +var run = function(state) { + while (!state.isStuck()) { + interpret.step(state); + } + return state.v; +} + +var step = interpret.step; + + +////////////////////////////////////////////////////////////////////// + +var EXIT_ON_FIRST_ERROR = true; + + +////////////////////////////////////////////////////////////////////// + + +var StateModule = state; + + +var makeStateWithConstant = function(c) { + var s = new StateModule.State(); + s.v = c; + return s; +}; + + +var makePrefix = function(n) { + var arr = []; + for (var i = 0; i < n; i++) { + arr.push(false); + } + return new control.Prefix({numLifts: 0, + toplevels: arr }); +}; + +var makeMod = function(prefix, body) { + return new control.ModControl(prefix, [], body); +}; + +var makeConstant = function(c) { + return new control.ConstantControl(c); +}; + +var makeBranch = function(x, y, z) { + return new control.BranchControl(x, y, z); +}; + +var makeSeq = function() { + return new control.SeqControl(arguments); +}; + +var makeBeg0 = function() { + return new control.Beg0Control(arguments); +}; + +var makeToplevel = function(depth, pos) { + return new control.ToplevelControl(depth, pos); +}; + + +var makeDefValues = function(ids, body) { + return new control.DefValuesControl(ids, body); +}; + + +var makeLam = function(arity, closureMap, body) { + var aClosureMap = []; + var aClosureTypes = []; + var aParamTypes = []; + for (var i = 0; i < closureMap.length; i++) { + aClosureMap.push(closureMap[i]); + aClosureTypes.push("val/ref"); + } + for (var i = 0; i < arity; i++) { + aParamTypes.push("val"); + } + + return new control.LamControl({'numParams': arity, + 'paramTypes': aParamTypes, + 'isRest': false, + 'closureMap' : aClosureMap, + 'closureTypes' : aClosureTypes, + 'body': body}); +}; + + +var makeLamWithRest = function(arity, closureMap, body) { + var aClosureMap = []; + var aClosureTypes = []; + var aParamTypes = []; + for (var i = 0; i < closureMap.length; i++) { + aClosureMap.push(closureMap[i]); + aClosureTypes.push("val/ref"); + } + for (var i = 0; i < arity; i++) { + aParamTypes.push("val"); + } + + return new control.LamControl({'numParams': arity, + 'paramTypes': aParamTypes, + 'isRest': true, + 'closureMap' : aClosureMap, + 'closureTypes' : aClosureTypes, + 'body': body}); +}; + + + + + + +var makePrimval = function(name) { + return new control.PrimvalControl(name); +}; + + +var makeApplication = function(rator, rands) { + assert.ok(typeof(rands) === 'object' && rands.length !== undefined); + return new control.ApplicationControl(rator, rands); +}; + + +var makeLocalRef = function(n) { + return new control.LocalrefControl(n); +}; + + +var makeApplyValues = function(proc, argsExpr) { + return new control.ApplyValuesControl(proc, argsExpr); +}; + + +var makeLet1 = function(rhs, body) { + return new control.LetOneControl(rhs, body); +}; + + +var makeLetVoid = function(count, isBoxes, body) { + return new control.LetVoidControl({count: count, + isBoxes : isBoxes, + body : body}); +}; + +var makeBoxenv = function(pos, body) { + return new control.BoxenvControl(pos, body); +}; + + +var makeInstallValue = function(count, pos, isBoxes, rhs, body) { + return new control.InstallValueControl({count: count, + pos: pos, + isBoxes: isBoxes, + rhs: rhs, + body: body}); + +}; + + +var makeWithContMark = function(key, val, body) { + return new control.WithContMarkControl(key, val, body); +}; + + +var makeAssign = function(id, rhs, isUndefOk) { + return new control.AssignControl({id: id, + rhs: rhs, + isUndefOk: isUndefOk}); +}; + + +var makeVarref = function(aToplevel) { + return new control.VarrefControl(aToplevel); +}; + + +var makeClosure = function(genId) { + return new control.ClosureControl(genId); +}; + + +var makeCaseLam = function(name, clauses) { + assert.ok(typeof(clauses) === 'object' && clauses.length !== undefined); + return new control.CaseLamControl(name, clauses); +}; + + +var makeLetrec = function(procs, body) { + return new control.LetRecControl(procs, body); +}; + + +///////////////////////////////////////////////////////////////////// + + +var testPrim = function(funName, f, baseArgs, expectedValue) { + var state = new StateModule.State(); + var args = []; + for (var i = 0; i < baseArgs.length; i++) { + args.push(makeConstant(f(baseArgs[i]))); + } + state.pushControl(makeApplication(makePrimval(funName), args)); + assert.ok(types.isEqual(run(state), + expectedValue)); +}; + +var testPrimF = function(funName, f, baseArgs, expectedValue, transform) { + var state = new StateModule.State(); + var args = []; + for (var i = 0; i < baseArgs.length; i++) { + args.push(makeConstant(f(baseArgs[i]))); + } + state.pushControl(makeApplication(makePrimval(funName), args)); + assert.deepEqual(transform(run(state)), + expectedValue); +} + +var listToStringArray = function(lst) { + var ret = []; + while ( !lst.isEmpty() ) { + ret.push( lst.first().toString() ); + lst = lst.rest(); + } + return ret; +} + +var id = function(x) {return x;}; + + + +////////////////////////////////////////////////////////////////////// + +var runTest = function(name, thunk) { + sys.print("running " + name + "... "); + try { + thunk(); + } catch(e) { + sys.print(" FAIL\n"); + sys.print(e); + if (EXIT_ON_FIRST_ERROR) { + if (typeof(console) !== 'undefined' && console.log && e.stack) { + console.log(e.stack); + } +// if (typeof(console) !== 'undefined' && console.log && e.stack) { +// console.log(e.stack); +// } +// sys.print(sys.inspect(e) + '\n'); + throw e; + } + } + sys.print(" ok\n") + +}; + +////////////////////////////////////////////////////////////////////// + + +sys.print("START TESTS\n\n"); + +runTest("simple empty state", + // Simple running should just terminate, and always be at the "stuck" state. + function() { + var state = new StateModule.State(); + assert.ok(state.isStuck()); + run(state); + assert.ok(state.isStuck()); + }); + + + +// Numeric constants should just evaluate through. +runTest("Numeric constant", + function() { + var state = new StateModule.State(); + state.pushControl(makeConstant(42)); + var result = run(state); + assert.deepEqual(result, + 42); + + assert.deepEqual(state, makeStateWithConstant(42)); + }); + + + +// String constant. +runTest("String constant", + function() { + var state = new StateModule.State(); + state.pushControl(makeConstant("hello world")); + var result = run(state); + assert.deepEqual(result, + "hello world"); + + assert.deepEqual(state, makeStateWithConstant("hello world")); + }); + + +// boolean constant. +runTest("Boolean constant", + function() { + var state = new StateModule.State(); + state.pushControl(makeConstant(true)); + var result = run(state); + assert.deepEqual(result, true); + + assert.deepEqual(state, makeStateWithConstant(true)); + }); + + + +runTest("external call", + function() { + var state = new StateModule.State(); + interpret.call(state, + primitive.getPrimitive("*"), + [2, 3], + function(v) { assert.equal(v, 6) }); + }); + + + +// Simple branch to true +runTest("Simple boolean branch to true", + function() { + var state = new StateModule.State(); + state.pushControl(makeBranch(makeConstant(true), + makeConstant(true), + makeConstant(false))); + var result = run(state); + assert.deepEqual(result, true); + }); + + +// Simple branch to false +runTest("Simple boolean branch to false", + function() { + var state = new StateModule.State(); + state.pushControl(makeBranch(makeConstant(false), + makeConstant(false), + makeConstant(true))); + var result = run(state); + assert.deepEqual(result, + true); + + assert.deepEqual(state, makeStateWithConstant(true)); + }); + + + +// (if (if true false true) "apple" "pie") --> "pie" +runTest("nested booleans", + function() { + var state = new StateModule.State(); + state.pushControl(makeBranch(makeBranch(makeConstant(true), makeConstant(false), makeConstant(true)), + makeConstant("apple"), + makeConstant("pie"))); + var result = run(state); + assert.deepEqual(result, "pie"); + + assert.deepEqual(state, makeStateWithConstant("pie")); + }); + + + +// Sequences +runTest("Sequences", + function() { + var state1 = new StateModule.State(); + state1.pushControl(makeSeq(makeConstant(3), + makeConstant(4), + makeConstant(5))); + step(state1); + step(state1); + assert.ok(!state1.isStuck()); + assert.deepEqual(state1.v, 3); + step(state1); + assert.deepEqual(state1.v, 4); + var result = run(state1); + assert.deepEqual(result, 5); + + assert.deepEqual(state1, makeStateWithConstant(5)); + }); + + + +// Module prefix +runTest("module prefix", + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(3), + [])); + run(state); + assert.equal(1, state.vstack.length); + assert.ok(state.vstack[0] instanceof types.PrefixValue); + assert.equal(state.vstack[0].length(), 3); + }); + + +runTest("toplevel lookup", + // toplevel lookup + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(3), + [])); + run(state); + + state.vstack[0].set(0, "zero"); + state.vstack[0].set(1, "one"); + state.vstack[0].set(2, "two"); + + state.pushControl(makeToplevel(0, 0)); + assert.equal(run(state), "zero"); + + state.pushControl(makeToplevel(0, 1)); + assert.equal(run(state), "one"); + + state.pushControl(makeToplevel(0, 2)); + assert.equal(run(state), "two"); + }); + + + +runTest("define-values", + // define-values + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(3), [])); + run(state); + state.pushControl(makeDefValues([makeToplevel(0, 0)], + makeConstant("try it"))); + run(state); + + var expectedState = new StateModule.State(); + expectedState.pushControl(makeMod(makePrefix(3), + [])); + run(expectedState); + expectedState.v = "try it"; + expectedState.vstack[0].set(0, "try it"); + assert.deepEqual(state, expectedState); + }); + + +runTest("lambda", + // lambda + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(3), [])); + run(state); + state.pushControl(makeDefValues([makeToplevel(0, 0)], + makeConstant("Some toplevel value"))); + + run(state); + state.pushControl(makeLam(3, [0], makeConstant("I'm a body"))); + + var result = run(state); + + // result should be a lambda. + assert.ok(result instanceof types.ClosureValue); + assert.equal(result.closureVals.length, 1); + assert.ok(result.closureVals[0] instanceof types.PrefixValue); + assert.deepEqual(result.body, makeConstant("I'm a body")); + assert.equal(result.numParams, 3); + }); + + + +runTest("primval (current-print)", + // primval + function() { + var state = new StateModule.State(); + state.pushControl(makePrimval("current-print")); + var result = run(state); + assert.ok(result instanceof types.PrimProc); + }); + + +runTest("primval on bad primitive should throw error", + // primval on unknowns should throw error + function() { + var state = new StateModule.State(); + state.pushControl(makePrimval("foobar")); + assert.throws(function() { run(state); }); + }); + + +runTest("Primval on *", + // primval on * + // primval + function() { + var state = new StateModule.State(); + state.pushControl(makePrimval("*")); + var result = run(state); + assert.ok(result instanceof types.PrimProc); + }); + + +runTest("My own list function", + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makeLamWithRest(0, [], makeLocalRef(0)), + [makeConstant("one"), + makeConstant("two"), + makeConstant("three")])) + var result = run(state); + assert.deepEqual(result, + types.list(["one", "two", "three"])); + }); + + +runTest("primitive application", + // primitive application. + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval("*"), + [makeConstant(types.rational(3)), + makeConstant(types.rational(5))])); + var result = run(state); + assert.deepEqual(result, types.rational(15)); + assert.equal(state.vstack.length, 0); + }); + + +runTest("primitive application, no arguments", + // primitive application with no arguments. + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval("*"), + [])); + var result = run(state); + assert.deepEqual(result, types.rational(1)); + assert.equal(state.vstack.length, 0); + }); + + +runTest("primitive application, nested application", + // primitive application, with nesting + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("*"), + [makeApplication( + makePrimval("*"), + [makeConstant(types.rational(3)), + makeConstant(types.rational(5))]), + makeConstant(types.rational(7))])); + var result = run(state); + assert.deepEqual(result, types.rational(105)); + assert.equal(state.vstack.length, 0); + }); + + +runTest("primitive appliation, nesting, testing non-commutativity", + // primitive application, with nesting, testing order + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("string-append"), + [makeApplication( + makePrimval("string-append"), + [makeConstant(types.string("hello")), + makeConstant(types.string("world"))]), + makeConstant(types.string("testing"))])); + var result = run(state); + assert.deepEqual(result, types.string("helloworldtesting")); + assert.equal(state.vstack.length, 0); + }); + +runTest("primitive application, subtraction", + // subtraction + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("-"), + [makeApplication( + makePrimval("-"), + [makeConstant(types.rational(3)), + makeConstant(types.rational(4))]), + makeConstant(types.rational(15))])); + var result = run(state); + assert.deepEqual(result, types.rational(-16)); + assert.equal(state.vstack.length, 0); + }); + +runTest("primitive application, unary subtraction (negation)", + // Checking negation. + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("-"), + [makeConstant(types.rational(1024))])); + var result = run(state); + assert.deepEqual(result, types.rational(-1024)); + assert.equal(state.vstack.length, 0); + }); + + +runTest("closure application", + // Closure application + // lambda will just return a constant value + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(1), [])); + run(state); + assert.equal(state.vstack.length, 1); + + state.pushControl(makeDefValues([makeToplevel(0, 0)], + makeLam(1, [], + makeConstant("I'm a body")))); + run(state); + state.pushControl(makeApplication(makeToplevel(1, 0), [makeConstant("boo")])); + var result = run(state); + assert.equal(result, "I'm a body"); + + assert.equal(state.vstack.length, 1); + }); + + +runTest("closure application, defining square", + // Closure application + // lambda will square its argument + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(1), [])); + run(state); + assert.equal(state.vstack.length, 1); + + state.pushControl(makeDefValues([makeToplevel(0, 0)], + makeLam(1, [], + makeApplication(makePrimval("*"), + [makeLocalRef(2), + makeLocalRef(2)])))); + run(state); + state.pushControl(makeApplication(makeToplevel(1, 0), + [makeConstant(types.rational(4))])); + var result = run(state); + assert.deepEqual(result, types.rational(16)); + assert.equal(state.vstack.length, 1); + }); + + + +runTest("closure application, testing tail calls", + // Checking tail calling behavior + // The standard infinite loop should consume bounded control stack. + // (define (f) (f)) (begin (f)) --> infinite loop, but with bounded control stack. + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(1), [])); + run(state); + assert.equal(state.vstack.length, 1); + + state.pushControl(makeDefValues([makeToplevel(0, 0)], + makeLam(0, [0], + makeApplication(makeToplevel(0, 0), + [])))); + run(state); + state.pushControl(makeApplication(makeToplevel(0, 0), [])); + var MAXIMUM_BOUND = 5; + var ITERATIONS = 1000000; + for (var i = 0; i < ITERATIONS; i++) { + step(state); + assert.ok(state.cstack.length < MAXIMUM_BOUND); + } + }); + + + +runTest("closure application, testing tail calls with even/odd", + // Checking tail calling behavior + // The standard infinite loop should consume bounded control stack. + // (define (even? x) (if (zero? x) true (odd? (sub1 x)))) + // (define (odd? x) (if (zero? x) false (even? (sub1 x)))) + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(2), [])); + run(state); + assert.equal(state.vstack.length, 1); + state.pushControl(makeDefValues + ([makeToplevel(0, 0)], + makeLam(1, [0], + makeBranch( + makeApplication(makePrimval("zero?"), + [makeLocalRef(2)]), + makeConstant(true), + makeApplication(makeToplevel(1, 1), + [makeApplication( + makePrimval("sub1"), + [makeLocalRef(3)])]))))); + state.pushControl(makeDefValues + ([makeToplevel(0, 1)], + makeLam(1, [0], + makeBranch( + makeApplication(makePrimval("zero?"), + [makeLocalRef(2)]), + makeConstant(false), + makeApplication(makeToplevel(1, 0), + [makeApplication( + makePrimval("sub1"), + [makeLocalRef(3)])]))))); + + run(state); + + var even = function(n) { + state.pushControl(makeApplication(makeToplevel(1, 0), + [makeConstant(types.rational(n))])); + var MAXIMUM_BOUND = 10; + while (!state.isStuck()) { + step(state); + assert.ok(state.cstack.length < MAXIMUM_BOUND); + //sys.print(state.cstack.length + "\n"); + } + return state.v; + } + assert.equal(even(0), true); + assert.equal(even(1), false); + assert.equal(even(50), true); + assert.equal(even(51), false); + assert.equal(even(501), false); + assert.equal(even(1001), false); + assert.equal(even(10000), true); + assert.equal(even(10001), false); + }); + + +runTest("factorial", + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(1), [])); + run(state); + assert.equal(state.vstack.length, 1); + + state.pushControl(makeDefValues( + [makeToplevel(0, 0)], + makeLam(1, [0], + makeBranch( + makeApplication(makePrimval("zero?"), + [makeLocalRef(2)]), + makeConstant(types.rational(1)), + makeApplication(makePrimval("*"), + [makeLocalRef(3), + makeApplication( + makeToplevel(3, 0), + [makeApplication(makePrimval("sub1"), + [makeLocalRef(5)])])]))))); + + run(state); + + var fact = function(n) { + state.pushControl(makeApplication(makeToplevel(1, 0), + [makeConstant(types.rational(n))])); + return run(state); + } + + assert.equal(fact(0), 1); + assert.equal(fact(1), 1); + assert.equal(fact(2), 2); + assert.equal(fact(3), 6); + assert.equal(fact(4), 24); + assert.equal(fact(5), 120); + assert.equal(fact(6), 720); + assert.equal(fact(10), 3628800); + assert.equal(fact(11), 39916800); + assert.equal(fact(12), 479001600); + }); + + + +runTest("apply on a primitive *", + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("apply"), + [makePrimval("*"), + makeConstant( + types.list([types.rational(3), + types.rational(9)]))])); + assert.deepEqual(run(state), + 27); + assert.equal(state.vstack.length, 0); + }); + + + +runTest("apply on a primitive -", + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("apply"), + [makePrimval("-"), + makeConstant( + types.list([types.rational(3), + types.rational(9)]))])); + assert.deepEqual(run(state), + -6); + assert.equal(state.vstack.length, 0); + }); + +runTest("apply on a primitive -, three arguments", + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("apply"), + [makePrimval("-"), + makeConstant( + types.list([types.rational(3), + types.rational(9), + types.rational(12)]))])); + assert.deepEqual(run(state), + -18); + assert.equal(state.vstack.length, 0); + }); + + +runTest("values", + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("values"), + [makePrimval("*"), + makeConstant( + types.list([types.rational(3), + types.rational(9), + types.rational(12)]))])); + var result = run(state); + assert.equal(state.vstack.length, 0); + assert.ok(result instanceof types.ValuesWrapper); + assert.equal(result.elts.length, 2); + }); + + + +runTest("values with no arguments", + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication( + makePrimval("values"),[])); + var result = run(state); + assert.equal(state.vstack.length, 0); + assert.ok(result instanceof types.ValuesWrapper); + assert.equal(result.elts.length, 0); + }); + + + + +runTest("current-inexact-milliseconds", + function() { + var state = new StateModule.State(); + for (var i = 0; i < 2000; i++) { + state.pushControl(makeApplication( + makePrimval("current-inexact-milliseconds"),[])); + var result1 = run(state); + + + state.pushControl(makeApplication( + makePrimval("current-inexact-milliseconds"),[])); + var result2 = run(state); + assert.ok(jsnums.lessThanOrEqual(result1, result2)); + } + }); + + + + +runTest("values with def-values", + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(2), [])); + run(state); + assert.equal(state.vstack.length, 1); + + state.pushControl(makeDefValues( + [makeToplevel(0, 0), + makeToplevel(0, 1)], + makeApplication(makePrimval("values"), + [makeConstant("hello"), + makeConstant("world")]))); + run(state); + assert.equal(state.vstack.length, 1); + assert.ok(state.vstack[0] instanceof types.PrefixValue); + assert.equal(state.vstack[0].ref(0), "hello"); + assert.equal(state.vstack[0].ref(1), "world"); + }); + + + +runTest("apply-values", + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(2), [])); + run(state); + state.pushControl(makeDefValues( + [makeToplevel(0, 0), + makeToplevel(0, 1)], + makeApplication(makePrimval("values"), + [makeConstant(types.string("hello")), + makeConstant(types.string("world"))]))); + run(state); + + state.pushControl(makeApplyValues( + makeLam(2, [], makeApplication(makePrimval("string-append"), + [makeLocalRef(2), + makeLocalRef(3)])), + makeApplication(makePrimval("values"), + [makeToplevel(2, 0), + makeToplevel(2, 1)]))); + assert.deepEqual(run(state), types.string("helloworld")); + }); + + + +runTest("apply-values, testing no stack usage", + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(2), [])); + run(state); + state.pushControl(makeDefValues( + [makeToplevel(0, 0), + makeToplevel(0, 1)], + makeApplication(makePrimval("values"), + [makePrimval("zero?"), + makeConstant(types.rational(0))]))); + run(state); + + state.pushControl(makeApplyValues( + makeToplevel(0, 0), + makeToplevel(0, 1))); + assert.equal(run(state), true); + assert.equal(state.vstack.length, 1); + }); + +runTest("let-one, trivial", + function() { + var state = new StateModule.State(); + assert.equal(state.vstack.length, 0); + var body = makeLocalRef(0); + state.pushControl(makeLet1(makeConstant("someValue"), + body)); + while (state.cstack[state.cstack.length - 1] !== body) { + step(state); + } + assert.equal(state.vstack.length, 1); + assert.equal(state.vstack[0], "someValue"); + var result = run(state); + assert.equal(state.vstack.length, 0); + assert.deepEqual(result, "someValue"); + }); + + +runTest("let-one, different body", + function() { + var state = new StateModule.State(); + assert.equal(state.vstack.length, 0); + var body = makeConstant("something else"); + state.pushControl(makeLet1(makeConstant("someValue"), + body)); + while (state.cstack[state.cstack.length - 1] !== body) { + step(state); + } + assert.equal(state.vstack.length, 1); + assert.equal(state.vstack[0], "someValue"); + var result = run(state); + assert.equal(state.vstack.length, 0); + assert.deepEqual(result, "something else"); + }); + + +runTest("let-void, no boxes", + function() { + var state = new StateModule.State(); + var body = makeConstant("blah"); + state.pushControl(makeLetVoid(2, false, body)); + while (state.cstack[state.cstack.length - 1] !== body) { + step(state); + } + assert.equal(state.vstack.length, 2); + for(var i = 0; i < state.vstack.length; i++) { + assert.ok(state.vstack[i] === types.UNDEFINED); + } + var result = run(state); + assert.equal(result, "blah"); + assert.equal(state.vstack.length, 0); + }); + + +runTest("let-void, with boxes", + function() { + var state = new StateModule.State(); + var body = makeConstant("blah"); + state.pushControl(makeLetVoid(2, true, body)); + while (state.cstack[state.cstack.length - 1] !== body) { + step(state); + } + assert.equal(state.vstack.length, 2); + for(var i = 0; i < state.vstack.length; i++) { + assert.ok( types.isBox(state.vstack[i]) ); + } + var result = run(state); + assert.equal(result, "blah"); + assert.equal(state.vstack.length, 0); + }); + + +runTest("beg0 with just one argument should immediately reduce to its argument", + function() { + var state = new StateModule.State(); + state.pushControl(makeBeg0(makeConstant("first post"))); + step(state); + assert.equal(state.cstack.length, 1); + assert.deepEqual(state.cstack[0], + makeConstant("first post")); + var result = run(state); + assert.equal(result, "first post"); + }); + + + +runTest("beg0, more general", + function() { + var state = new StateModule.State(); + state.pushControl(makeBeg0(makeConstant("first post"), + makeConstant("second post"), + makeConstant("third post"), + makeConstant("fourth post"))); + step(state); + + // By this point, there should be two elements + // in the control stack, the evaluation of the first + // argument, and a control to continue the + // rest of the sequence evaluation. + assert.equal(state.cstack.length, 2); + var result = run(state); + assert.equal(result, "first post"); + }); + + + +runTest("boxenv", + function() { + var state = new StateModule.State(); + state.pushControl(makeLet1(makeConstant("foo"), + makeBoxenv(0, + makeLocalRef(0)))); + var result = run(state); + assert.ok( types.isBox(result) ); + assert.deepEqual(result, types.box("foo")); + }); + + +runTest("install-value, without boxes", + function() { + var state = new StateModule.State(); + var aBody = makeConstant("peep"); + state.pushControl + (makeLetVoid + (4, + false, + makeInstallValue + (3, 1, false, + makeApplication(makePrimval("values"), + [makeConstant("3"), + makeConstant("1"), + makeConstant("4")]), + aBody))); + while (state.cstack[state.cstack.length - 1] !== aBody) { + step(state); + } + assert.equal(state.vstack.length, 4); + assert.equal(state.vstack[0], "4"); + assert.equal(state.vstack[1], "1"); + assert.equal(state.vstack[2], "3"); + var result = run(state); + assert.equal(result, "peep"); + assert.equal(state.vstack.length, 0); + }); + + + +runTest("install-value, with boxes", + function() { + var state = new StateModule.State(); + var aBody = makeConstant("peep"); + state.pushControl + (makeLetVoid + (4, + true, + makeInstallValue + (3, 1, true, + makeApplication(makePrimval("values"), + [makeConstant("3"), + makeConstant("1"), + makeConstant("4")]), + aBody))); + while (state.cstack[state.cstack.length - 1] !== aBody) { + step(state); + } + assert.equal(state.vstack.length, 4); + assert.deepEqual(state.vstack[0], types.box("4")); + assert.deepEqual(state.vstack[1], types.box("1")); + assert.deepEqual(state.vstack[2], types.box("3")); + var result = run(state); + assert.equal(result, "peep"); + assert.equal(state.vstack.length, 0); + }); + + +runTest("assign", + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(1), + [makeAssign(makeToplevel(0, 0), + makeConstant("some value"), + true)])); + run(state); + assert.equal(state.vstack.length, 1); + assert.equal(state.vstack[0].ref(0), "some value"); + }); + + +runTest("varref", + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(2), + [makeSeq(makeAssign(makeToplevel(0, 0), + makeConstant("a toplevel value"), + true), + makeAssign( + makeToplevel(0, 1), + makeVarref(makeToplevel(0, 0))))])); + var prefixValue = run(state); + // WARNING: breaking abstractions. + // Let's look directly at the representation structures + // and make sure we are dealing with a variable reference. + var result = prefixValue.slots[1]; + assert.ok(result instanceof types.VariableReference); + assert.equal(result.ref(), "a toplevel value"); + result.set("something else!"); + assert.equal(state.vstack.length, 1); + assert.equal(state.vstack[0].ref(0), "something else!"); + }); + + +runTest("closure", + function() { + var state = new StateModule.State(); + state.heap['some-closure'] = 42; + state.pushControl(makeClosure('some-closure')); + // The way we process closures in bytecode-compiler + // should make this a direct heap lookup. + assert.equal(run(state), 42); + }); + + +runTest("with-cont-mark", + function() { + var state = new StateModule.State(); + var aBody = makeConstant("peep"); + state.pushControl + (makeWithContMark(makeConstant + (types.symbol("x")), + makeConstant("42"), + aBody)); + while (state.cstack[state.cstack.length -1] !== aBody) { + step(state); + } + assert.equal(state.cstack.length, 2); + assert.ok( types.isContMarkRecordControl(state.cstack[0]) ); + assert.equal(state.cstack[0].dict.get(types.symbol('x')), + "42"); + var result = run(state); + assert.equal(result, "peep"); + }); + + + + +runTest("closure application, testing tail calls in the presence of continuation marks", + // Checking tail calling behavior + // The standard infinite loop should consume bounded control stack. + // (define (f) (call-with-continuation-marks 'x 1 (f))) (begin (f)) --> infinite loop, but with bounded control stack. + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(1), [])); + run(state); + assert.equal(state.vstack.length, 1); + + state.pushControl(makeDefValues([makeToplevel(0, 0)], + makeLam(0, [0], + (makeWithContMark + (makeConstant(types.symbol("x")), + makeConstant(types.rational(1)), + + makeApplication(makeToplevel(0, 0), + [])))))); + run(state); + state.pushControl(makeApplication(makeToplevel(0, 0), [])); + var MAXIMUM_BOUND = 6; + var ITERATIONS = 1000000; + for (var i = 0; i < ITERATIONS; i++) { + step(state); + assert.ok(state.cstack.length < MAXIMUM_BOUND); + } + }); + + +runTest("case-lambda, with a function that consumes one or two values", + function() { + var state = new StateModule.State(); + state.pushControl + (makeMod(makePrefix(1), + [makeDefValues + ([makeToplevel(0, 0)], + makeCaseLam(types.symbol("last"), + [makeLam(1, [], makeLocalRef(0)), + makeLam(2, [], makeLocalRef(1))]))])); + run(state); + state.pushControl(makeApplication(makeToplevel(1, 0), + [makeConstant(types.rational(5))])); + var result = run(state); + assert.deepEqual(result, types.rational(5)); + + state.pushControl(makeApplication(makeToplevel(2, 0), + [makeConstant(types.rational(7)), + makeConstant(types.rational(42))])); + result = run(state); + assert.deepEqual(result, types.rational(42)); + }); + + + +// runTest("factorial again, testing the accumulation of continuation marks", +// // +// // (define marks #f) +// // (define (f x) +// // (with-continuation-marks 'x x +// // (if (= x 0) +// // (begin (set! marks (current-continuation-marks)) +// // 1) +// // (* x (f (sub1 x)))))) +// function() { + +// }); + + +runTest("let-rec", + function() { + var state = new StateModule.State(); + state.pushControl(makeLetVoid(2, + false, + makeLetrec([makeLam(1, [1], + makeBranch + (makeApplication(makePrimval("zero?"), + [makeLocalRef(2)]), + makeConstant(true), + makeApplication(makeLocalRef(1), + [makeApplication + (makePrimval("sub1"), + [makeLocalRef(3)])]))), + makeLam(1, [0], + makeBranch + (makeApplication(makePrimval("zero?"), + [makeLocalRef(2)]), + makeConstant(false), + makeApplication(makeLocalRef(1), + [makeApplication + (makePrimval("sub1"), + [makeLocalRef(3)])])))], + makeLocalRef(0)))); + var evenValue = run(state); + var e = function(x) { + state.pushControl(makeApplication(makeConstant(evenValue), + [makeConstant(types.rational(x))])); + return run(state); + } + assert.equal(state.vstack.length, 0); + + assert.equal(e(0), true); + assert.equal(e(1), false); + assert.equal(e(2), true); + assert.equal(e(3), false); + assert.equal(e(100), true); + assert.equal(e(101), false); + assert.equal(e(10000), true); + assert.equal(e(10001), false); + }); + + +/*************************************** + *** Primitive String Function Tests *** + ***************************************/ + +runTest('symbol?', + function() { + testPrim('symbol?', types.symbol, ['hi'], true); + testPrim('symbol?', types.rational, [1], false); + }); + +runTest('symbol=?', + function() { + testPrim('symbol=?', types.symbol, ['abc', 'abd'], false); + testPrim('symbol=?', types.symbol, ['cdf', 'cdf'], true); + }); + +runTest('string->symbol', + function() { + testPrim('string->symbol', id, ['hello!'], types.symbol('hello!')); + testPrim('string->symbol', types.string, [' world'], types.symbol(' world')); + }); + + +runTest('symbol->string', + function() { + testPrim('symbol->string', types.symbol, ['hello!'], types.string('hello!')); + }); + + +runTest('number->string', + function() { + testPrim('number->string', types.rational, [5], types.string('5')); + testPrim('number->string', id, [types.complex(0, 2)], types.string('0+2i')); + testPrim('number->string', id, [types.rational(5, 3)], types.string('5/3')); + }); + + +runTest('stinrg->number', + function() { + testPrim('string->number', types.string, ['abc'], false); + testPrim('string->number', id, ['123'], 123); + testPrim('string->number', types.string, ['0+3i'], types.complex(0, 3)); + }); + + +runTest('string?', + function() { + testPrim('string?', id, [types.symbol('hello!')], false); + testPrim('string?', id, ['string'], true); + testPrim('string?', types.string, ['world'], true); + }); + + +runTest('make-string', + function() { + testPrim('make-string', id, [0, types.char('A')], types.string("")); + testPrim('make-string', id, [types.rational(3), types.char('b')], types.string('bbb')); + }); + + +runTest('string', + function() { + testPrim('string', id, [], types.string('')); + testPrim('string', types.char, ['a', 'b'], types.string('ab')); + }); + +runTest('string-length', + function() { + testPrim('string-length', types.string, [''], 0); + testPrim('string-length', id, ['5'], 1); + testPrim('string-length', types.string, ['antidisestablishmentarianism'], 28); + }); + +runTest('string-ref', + function() { + testPrim('string-ref', id, ['world', 3], types.char('l')); + testPrim('string-ref', id, [types.string('abcd'), 1], types.char('b')); + testPrim('string-ref', id, [types.string('asdfasdf'), 4], types.char('a')); + }); + +runTest('string=?', + function() { + testPrim('string=?', id, ['asdf', 'Asdf'], false); + testPrim('string=?', id, ['asdf', types.string('asdf')], true); + testPrim('string=?', types.string, ['asdf', 'asdf', 'Asdf'], false); + testPrim('string=?', types.string, ['far', 'fAr'], false); + testPrim('string=?', id, ['', ''], true); + testPrim('string=?', types.string, ['as', 'as', 'as'], true); + testPrim('string=?', types.string, ['1', '1', '2'], false); + }); + +runTest('string-ci=?', + function() { + testPrim('string-ci=?', id, ['asdf', 'Asdf'], true); + testPrim('string-ci=?', id, ['asdf', types.string('asdf')], true); + testPrim('string-ci=?', types.string, ['asdf', 'asdf', 'Asdf'], true); + testPrim('string-ci=?', types.string, ['far', 'fAr'], true); + testPrim('string-ci=?', id, ['', ''], true); + testPrim('string-ci=?', types.string, ['as', 'as', 'as'], true); + testPrim('string-ci=?', types.string, ['1', '1', '2'], false); + }); + +runTest('string?', + function() { + testPrim('string>?', id, ["", "a"], false); + testPrim('string>?', types.string, ['abc', 'ab'], true); + testPrim('string>?', id, [types.string('abc'), 'abc'], false); + testPrim('string>?', types.string, ['abc', 'def', 'cde'], false); + testPrim('string>?', id, ['a', types.string(']'), 'A'], true); + testPrim('string>?', types.string, ['e', 'd', 'cc', 'c', 'b', 'a'], true); + }); + +runTest('string<=?', + function() { + testPrim('string<=?', id, ["", "a"], true); + testPrim('string<=?', types.string, ['abc', 'ab'], false); + testPrim('string<=?', id, [types.string('abc'), 'abc'], true); + testPrim('string<=?', types.string, ['abc', 'aBc'], false); + testPrim('string<=?', types.string, ['abc', 'def', 'cde'], false); + testPrim('string<=?', id, ['A', types.string(']'), 'a'], true); + testPrim('string<=?', types.string, ['a', 'b', 'b', 'd', 'dd', 'e'], true); + }); + +runTest('string>=?', + function() { + testPrim('string>=?', id, ["", "a"], false); + testPrim('string>=?', types.string, ['abc', 'ab'], true); + testPrim('string>=?', id, [types.string('abc'), 'abc'], true); + testPrim('string>=?', types.string, ['aBc', 'abc'], false); + testPrim('string>=?', types.string, ['abc', 'def', 'cde'], false); + testPrim('string>=?', id, ['a', types.string(']'), 'A'], true); + testPrim('string>=?', types.string, ['e', 'e', 'cc', 'c', 'b', 'a'], true); + }); + +runTest('string-ci?', + function() { + testPrim('string-ci>?', id, ["", "a"], false); + testPrim('string-ci>?', id, [types.string('Abc'), 'ab'], true); + testPrim('string-ci>?', types.string, ['abc', 'abc'], false); + testPrim('string-ci>?', types.string, ['def', 'abc', 'cde'], false); + testPrim('string-ci>?', types.string, ['e', 'D', 'cc', 'c', 'b', 'a'], true); + }); + +runTest('string-ci<=?', + function() { + testPrim('string-ci<=?', id, ["", "a"], true); + testPrim('string-ci<=?', types.string, ['Abc', 'ab'], false); + testPrim('string-ci<=?', id, [types.string('abc'), 'abc'], true); + testPrim('string-ci<=?', types.string, ['abc', 'aBc'], true); + testPrim('string-ci<=?', types.string, ['abc', 'def', 'cde'], false); + testPrim('string-ci<=?', types.string, ['a', 'b', 'b', 'D', 'dd', 'e'], true); + }); + +runTest('string-ci>=?', + function() { + testPrim('string-ci>=?', id, ["", "a"], false); + testPrim('string-ci>=?', types.string, ['Abc', 'ab'], true); + testPrim('string-ci>=?', id, [types.string('abc'), 'abc'], true); + testPrim('string-ci>=?', types.string, ['aBc', 'abc'], true); + testPrim('string-ci>=?', types.string, ['def', 'abc', 'cde'], false); + testPrim('string-ci>=?', types.string, ['e', 'e', 'cc', 'C', 'b', 'a'], true); + }); + + +runTest('substring', + function() { + testPrim('substring', id, ['abc', 1], types.string('bc')); + testPrim('substring', id, [types.string('abc'), 0], types.string('abc')); + testPrim('substring', id, ['abcdefgh', 2, 4], types.string('cd')); + testPrim('substring', id, [types.string('abc'), 3], types.string('')); + testPrim('substring', id, [types.string('abcd'), 2, 2], types.string('')); + }); + + +runTest('string-append', + function() { + testPrim('string-append', types.string, [], types.string('')); + testPrim('string-append', id, ['a', types.string('b'), 'c'], types.string('abc')); + testPrim('string-append', types.string, ['a', '', 'b', ' world'], types.string('ab world')); + }); + + +runTest('string->list', + function() { + testPrim('string->list', types.string, [''], types.EMPTY); + testPrim('string->list', id, ['one'], types.list([types.char('o'), types.char('n'), types.char('e')])); + testPrim('string->list', types.string, ['two'], types.list([types.char('t'), + types.char('w'), + types.char('o')])); + }); + +runTest('list->string', + function() { + testPrim('list->string', id, [types.EMPTY], types.string('')); + testPrim('list->string', id, + [types.list([types.char('H'), + types.char('e'), + types.char('l'), + types.char('l'), + types.char('o')])], + types.string('Hello')); + }); + + +runTest('string-copy', + function() { + testPrim('string-copy', types.string, [''], types.string('')); + testPrim('string-copy', id, ['had'], types.string('had')); + testPrim('string-copy', types.string, ['hello'], types.string('hello')); + + var state = new StateModule.State(); + var str = types.string('hello'); + state.pushControl(makeApplication(makePrimval('string-copy'), [makeConstant(str)])); + var result = run(state); + assert.deepEqual(result, str); + assert.ok(result !== str); + }); + + +runTest('format', + function() { + testPrim('format', types.string, ['hello'], types.string('hello')); + testPrim('format', id, ['hello~n'], types.string('hello\n')); + testPrim('format', id, [types.string('Test: ~a~nTest2: ~A~%'), + types.char('A'), + types.list([1, 2, 3])], + types.string('Test: A\nTest2: (1 2 3)\n')); + testPrim('format', id, ['~s ~S ~a', + types.char('b'), + types.complex(0, 2), + types.char('b')], + types.string('#\\b 0+2i b')); + + testPrim('format', id, ['~s ~a', primitive.getPrimitive('+'), primitive.getPrimitive('format')], + types.string('# #')); + + var box1 = types.box('junk'); + var box2 = types.box(box1); + box1.set(box2); + testPrim('format', id, ['~s', box1], types.string('#&#&...')); + + var box3 = types.box('junk'); + box3.set(box3); + testPrim('format', id, ['~a', box3], types.string('#&...')); + }); + + +runTest('explode', + function() { + testPrim('explode', id, [''], types.EMPTY); + testPrim('explode', types.string, ['hello'], types.list([types.string('h'), + types.string('e'), + types.string('l'), + types.string('l'), + types.string('o')])); + }); + + +runTest('implode', + function() { + testPrim('implode', id, [types.EMPTY], types.string('')); + testPrim('implode', types.list, [[types.string('h'), + types.string('e'), + types.string('l'), + types.string('l'), + types.string('o')]], + types.string('hello')); + }); + + +runTest('string->int', + function() { + testPrim('string->int', types.string, ['0'], 48); + testPrim('string->int', types.string, ['\n'], 10); + }); + + +runTest('int->string', + function() { + testPrim('int->string', id, [50], types.string('2')); + testPrim('int->string', id, [10], types.string('\n')); + }); + + +runTest('string-alphabetic?', + function() { + testPrim('string-alphabetic?', id, ['abcd'], true); + testPrim('string-alphabetic?', types.string, ['AbCZ'], true); + testPrim('string-alphabetic?', id, ['a b c'], false); + testPrim('string-alphabetic?', types.string, ['1243!'], false); + }); + + +runTest('string-ith', + function() { + testPrim('string-ith', id, ['abcde', 2], types.string('c')); + testPrim('string-ith', id, [types.string('12345'), 0], types.string('1')); + }); + + +runTest('string-lower-case?', + function() { + testPrim('string-lower-case?', types.string, ['abcd'], true); + testPrim('string-lower-case?', id, ['abc1'], false); + testPrim('string-lower-case?', types.string, ['Abc'], false); + }); + + +runTest('string-numeric?', + function() { + testPrim('string-numeric?', id, ['1234'], true); + testPrim('string-numeric?', types.string, ['5432'], true); + testPrim('string-numeric?', types.string, ['0+2i'], false); + testPrim('string-numeric?', types.string, ['03()'], false); + }); + + +runTest('string-upper-case?', + function() { + testPrim('string-upper-case?', id, ['ABCD'], true); + testPrim('string-upper-case?', types.string, ['ADF'], true); + testPrim('string-upper-case?', types.string, ['AbZ'], false); + testPrim('string-upper-case?', types.string, ['05AB'], false); + }); + + +runTest('string-whitespace?', + function() { + testPrim('string-whitespace?', types.string, ['a b c'], false); + testPrim('string-whitespace?', id, [' \n '], true); + testPrim('string-whitespace?', types.string, ['\t\r\n '], true); + }); + + +runTest('replicate', + function() { + testPrim('replicate', id, [3, types.string('ab')], types.string('ababab')) + testPrim('replicate', id, [0, 'hi'], types.string('')); + testPrim('replicate', id, [50, types.string('')], types.string('')); + }); + + +runTest('string->immutable-string', + function() { + testPrim('string->immutable-string', id, ['hello'], 'hello'); + testPrim('string->immutable-string', types.string, ['world'], 'world'); + }); + + +runTest('string-set!', + function() { + var str1 = types.string('hello'); + testPrim('string-set!', id, [str1, 2, types.char('w')], types.VOID); + assert.deepEqual(str1, types.string('hewlo')); + + var str2 = types.string('no'); + testPrim('string-set!', id, [str2, 1, types.char('!')], types.VOID); + assert.deepEqual(str2, types.string('n!')); + }); + + +runTest('string-fill!', + function() { + var str1 = types.string('lawl'); + testPrim('string-fill!', id, [str1, types.char('q')], types.VOID); + assert.deepEqual(str1, types.string('qqqq')); + + var str2 = types.string(''); + testPrim('string-fill!', id, [str2, types.char(' ')], types.VOID); + assert.deepEqual(str2, types.string('')); + }); + + + +/************************************* + *** Primitive Math Function Tests *** + *************************************/ + + +runTest("zero?", + function() { + testPrim('zero?', types.rational, [0], true); + testPrim('zero?', types.rational, [1], false); + testPrim('zero?', id, [types.complex(0, 1)], false); + }); + + + +runTest("sub1", + function() { + testPrim('sub1', types.rational, [25], types.rational(24)); + testPrim('sub1', id, [types.complex(3, 5)], types.complex(2, 5)); + }); + + +runTest("add1", + function() { + testPrim('add1', types.rational, [25], types.rational(26)); + testPrim('add1', id, [types.complex(3, 5)], types.complex(4, 5)); + }); + + +runTest("+", + function() { + testPrim('+', types.rational, [], types.rational(0)); + testPrim('+', types.rational, [2], types.rational(2)); + testPrim('+', types.rational, [1, 2], types.rational(3)); + testPrim('+', types.rational, [1, 2, 3, 4], types.rational(10)); + }); + + +runTest("-", + function() { + testPrim('-', types.rational, [2], types.rational(-2)); + testPrim('-', types.rational, [1, 2], types.rational(-1)); + testPrim('-', types.rational, [1, 2, 3, 4], types.rational(-8)); + }); + + +runTest("*", + function() { + testPrim('*', types.rational, [], types.rational(1)); + testPrim('*', types.rational, [2], types.rational(2)); + testPrim('*', types.rational, [1, 2], types.rational(2)); + testPrim('*', types.rational, [1, 2, 3, 4], types.rational(24)); + }); + + +runTest("/", + function() { + testPrim('/', types.rational, [2], types.rational(1, 2)); + testPrim('/', types.rational, [1, 3], types.rational(1, 3)); + testPrim('/', types.rational, [18, 2, 3, 4], types.rational(3, 4)); + }); + + +runTest('abs', + function() { + testPrim('abs', types.rational, [2], types.rational(2)); + testPrim('abs', types.rational, [0], types.rational(0)); + testPrim('abs', types.rational, [-2], types.rational(2)); + }); + + +runTest('quotient', + function() { + testPrim('quotient', types.rational, [5, 3], types.rational(1)); + }); + + +runTest('remainder', + function() { + testPrim('remainder', types.rational, [5, 3], types.rational(2)); + }); + + +runTest('modulo', + function() { + testPrim('modulo', types.rational, [-5, 3], types.rational(1)); + }); + + +runTest('=', + function() { + testPrim('=', types.rational, [2, 3], false); + testPrim('=', types.rational, [2, 2, 2, 2], true); + testPrim('=', types.rational, [2, 2, 3, 3], false); + }); + + +runTest('<', + function() { + testPrim('<', types.rational, [1, 2], true); + testPrim('<', types.rational, [2, 2], false); + testPrim('<', types.rational, [3, 2], false); + testPrim('<', types.rational, [1, 2, 3, 4], true); + testPrim('<', types.rational, [1, 2, 2, 3], false); + testPrim('<', types.rational, [1, 3, 5, 4], false); + }); + + +runTest('>', + function() { + testPrim('>', types.rational, [1, 2], false); + testPrim('>', types.rational, [2, 2], false); + testPrim('>', types.rational, [3, 2], true); + testPrim('>', types.rational, [4, 3, 2, 1], true); + testPrim('>', types.rational, [4, 3, 3, 2], false); + testPrim('>', types.rational, [4, 3, 5, 2], false); + }); + + +runTest('<=', + function() { + testPrim('<=', types.rational, [1, 2], true); + testPrim('<=', types.rational, [2, 2], true); + testPrim('<=', types.rational, [3, 2], false); + testPrim('<=', types.rational, [1, 2, 3, 4], true); + testPrim('<=', types.rational, [2, 3, 3, 3], true); + testPrim('<=', types.rational, [1, 3, 5, 4], false); + }); + + +runTest('>=', + function() { + testPrim('>=', types.rational, [1, 2], false); + testPrim('>=', types.rational, [2, 2], true); + testPrim('>=', types.rational, [3, 2], true); + testPrim('>=', types.rational, [4, 3, 2, 1], true); + testPrim('>=', types.rational, [4, 3, 3, 2], true); + testPrim('>=', types.rational, [5, 3, 5, 4], false); + }); + + +runTest('positive?', + function() { + testPrim('positive?', types.rational, [-1], false); + testPrim('positive?', types.rational, [0], false); + testPrim('positive?', types.rational, [1], true); + }); + + +runTest('negative?', + function() { + testPrim('negative?', types.rational, [-1], true); + testPrim('negative?', types.rational, [0], false); + testPrim('negative?', types.rational, [1], false); + }); + + +runTest('max', + function() { + testPrim('max', types.rational, [1], types.rational(1)); + testPrim('max', types.rational, [1, 2], types.rational(2)); + testPrim('max', types.rational, [2, 1, 4, 3, 6, 2], types.rational(6)); + }); + + +runTest('min', + function() { + testPrim('min', types.rational, [1], types.rational(1)); + testPrim('min', types.rational, [1, 2], types.rational(1)); + testPrim('min', types.rational, [2, 1, 4, 3, 6, 2], types.rational(1)); + }); + + +runTest('=~', + function() { + testPrim('=~', id, [1, 2, 2], true); + testPrim('=~', id, [1, 2, types.float(0.5)], false); + testPrim('=~', types.rational, [5, 3, 1], false); + testPrim('=~', types.rational, [5, 3, 4], true); + }); + + +runTest('conjugate', + function() { + testPrim('conjugate', id, [1], 1); + testPrim('conjugate', id, [types.complex(3, 3)], types.complex(3, -3)); + }); + + +runTest('magnitude', + function() { + testPrim('magnitude', id, [4], 4); + testPrim('magnitude', id, [types.complex(3, 4)], 5); + testPrim('magnitude', id, [types.float(3.5)], types.float(3.5)); + testPrim('magnitude', id, [types.rational(3, 5)], types.rational(3, 5)); + testPrim('magnitude', id, [types.complex(12, 5)], 13); + }); + + +runTest('number?', + function() { + testPrim('number?', id, [5], true); + testPrim('number?', types.rational, [10], true); + testPrim('number?', id, [types.rational(10, 3)], true); + testPrim('number?', types.float, [10.5], true); + testPrim('number?', id, [types.complex(5, 3)], true); + testPrim('number?', id, ['string'], false); + }); + + +runTest('complex?', + function() { + testPrim('complex?', id, [5], true); + testPrim('complex?', types.rational, [10], true); + testPrim('complex?', id, [types.rational(10, 3)], true); + testPrim('complex?', types.float, [10.5], true); + testPrim('complex?', id, [types.complex(5, 3)], true); + testPrim('complex?', id, ['string'], false); + }); + + +runTest('real?', + function() { + testPrim('real?', id, [5], true); + testPrim('real?', types.rational, [10], true); + testPrim('real?', id, [types.rational(10, 3)], true); + testPrim('real?', types.float, [10.5], true); + testPrim('real?', id, [types.complex(5, 3)], false); + testPrim('real?', id, ['string'], false); + }); + + +runTest('rational?', + function() { + testPrim('rational?', id, [5], true); + testPrim('rational?', types.rational, [10], true); + testPrim('rational?', id, [types.rational(10, 3)], true); + testPrim('rational?', types.float, [10.5], true); + testPrim('rational?', types.float, [Math.sqrt(2)], true); + testPrim('rational?', id, [types.complex(5, 3)], false); + testPrim('rational?', id, ['string'], false); + }); + + +runTest('integer?', + function() { + testPrim('integer?', id, [5], true); + testPrim('integer?', types.rational, [10], true); + testPrim('integer?', id, [types.complex(5, 0)], true); + testPrim('integer?', id, [types.rational(10, 3)], false); + testPrim('integer?', types.float, [10.5], false); + testPrim('integer?', id, [types.complex(5, 3)], false); + testPrim('integer?', id, ['string'], false); + }); + + +runTest('exact?', + function() { + testPrim('exact?', id, [5], true); + testPrim('exact?', id, [types.rational(4, 3)], true); + testPrim('exact?', types.float, [10.0], false); + testPrim('exact?', id, [types.complex(5, 2)], true); + testPrim('exact?', id, [types.complex(types.float(5.2), types.float(0.1))], false); + }); + + +runTest('inexact?', + function() { + testPrim('inexact?', id, [5], false); + testPrim('inexact?', id, [types.rational(4, 3)], false); + testPrim('inexact?', types.float, [10.0], true); + testPrim('inexact?', id, [types.complex(5, 2)], false); + testPrim('inexact?', id, [types.complex(types.float(5.2), types.float(0.1))], true); + }); + + +runTest('odd? and even?', + function() { + testPrim('odd?', id, [5], true); + testPrim('odd?', types.float, [10.0], false); + testPrim('even?', id, [15], false); + testPrim('even?', types.float, [13.0], false); + }); + + +runTest('gcd and lcm', + function() { + testPrim('gcd', id, [1001, 98], 7); + testPrim('gcd', id, [6, 10, 15], 1); + testPrim('lcm', id, [91, 77], 1001); + testPrim('lcm', id, [6, 10, 15], 30); + }); + + +runTest('floor, ceiling, and round', + function() { + testPrim('floor', id, [14], 14); + testPrim('floor', types.float, [12.56], types.float(12)); + testPrim('ceiling', id, [13], 13); + testPrim('ceiling', types.float, [12.23], types.float(13)); + testPrim('ceiling', types.float, [12.00], types.float(12)); + testPrim('round', id, [124], 124); + testPrim('round', types.float, [12.432], types.float(12)); + testPrim('round', types.float, [12.543], types.float(13)); + }); + + +runTest('numerator and denominator', + function() { + testPrim('numerator', id, [30], 30); + testPrim('numerator', id, [types.rational(10, -2)], -5); + testPrim('numerator', types.float, [10.5], types.float(21)); + testPrim('numerator', types.float, [-2.53], types.float(-253)); + testPrim('denominator', id, [43], 1); + testPrim('denominator', id, [types.rational(12, 4)], 1); + testPrim('denominator', id, [types.rational(23, -5)], 5); + testPrim('denominator', types.float, [12.125], types.float(8)); + testPrim('denominator', types.float, [-2.53], types.float(100)); + }); + + +runTest('exp and log', + function() { + testPrim('exp', id, [0], 1); + testPrim('exp', types.float, [0], types.float(1)); + testPrim('exp', id, [3], types.float(Math.exp(3))); + testPrim('log', id, [1], 0); + testPrim('log', types.float, [1], types.float(0)); + testPrim('log', id, [primitive.getPrimitive('e')], types.float(1)); + }); + + +runTest('sin, cos, tan, asin, acos, atan', + function() { + testPrim('sin', id, [20], types.float(Math.sin(20))); + testPrim('sin', id, [0], 0); + testPrim('cos', id, [0], 1); + testPrim('cos', types.float, [43], types.float(Math.cos(43))); + testPrim('tan', types.float, [0], types.float(0)); + testPrim('tan', id, [-30], types.float(Math.tan(-30))); + + testPrim('asin', types.float, [-0.5], types.float(Math.asin(-0.5))); + testPrim('acos', types.float, [0.53], types.float(Math.acos(0.53))); + testPrim('atan', types.float, [-543], types.float(Math.atan(-543))); + }); + + +runTest('sqrt, integer-sqrt, and expt', + function() { + testPrim('sqrt', id, [25], 5); + testPrim('sqrt', types.float, [1.44], types.float(1.2)); + testPrim('sqrt', id, [-1], types.complex(0, 1)); + testPrim('sqrt', id, [types.complex(0, 2)], types.complex(1, 1)); + testPrim('sqrt', id, [types.complex(types.float(0), types.float(-2))], + types.complex(types.float(1), types.float(-1))); + + testPrim('integer-sqrt', id, [15], 3); + testPrim('integer-sqrt', id, [88], 9); + + testPrim('expt', id, [2, 20], 1048576); + testPrim('expt', id, [3, 3], 27); + testPrim('expt', types.float, [12.4, 5.43], types.float(Math.pow(12.4, 5.43))); + }); + + +runTest('make-rectangular, make-polar, real-part, imag-part, angle', + function() { + testPrim('make-rectangular', id, [5, 3], types.complex(5, 3)); + testPrim('make-rectangular', id, [5, types.float(4)], + types.complex(types.float(5), types.float(4))); + + testPrim('make-polar', id, [1, 0], types.complex(1, 0)); + testPrimF('make-polar', types.float, [5, Math.PI/2], true, + function(res) { + return (jsnums.isInexact(res) && + Math.abs(jsnums.toFixnum(jsnums.realPart(res))) < 0.000001 && + Math.abs(jsnums.toFixnum(jsnums.imaginaryPart(res)) - 5) < 0.0000001); + }); + + testPrim('real-part', id, [14], 14); + testPrim('real-part', types.float, [4], types.float(4)); + testPrim('real-part', id, [types.complex(0, 1)], 0); + testPrim('real-part', id, [types.complex(types.float(1.44), types.float(5))], types.float(1.44)); + + testPrim('imag-part', id, [14], 0); + testPrim('imag-part', types.float, [4], 0); + testPrim('imag-part', id, [types.complex(0, 1)], 1); + testPrim('imag-part', id, [types.complex(types.float(1.44), types.float(5))], types.float(5)); + + testPrim('angle', id, [types.complex(3, 0)], 0); + testPrim('angle', types.float, [4.46], 0); + testPrim('angle', id, [-54], types.float(Math.PI)); + testPrimF('angle', id, [types.complex(1, 1)], true, + function(res) { + return (jsnums.isInexact(res) && + Math.abs(jsnums.toFixnum(res) - Math.PI/4) < 0.0000001); + }); + }); + + +runTest('exact->inexact and inexact->exact', + function() { + testPrim('exact->inexact', id, [5], types.float(5)); + testPrim('exact->inexact', types.float, [5.2], types.float(5.2)); + testPrim('exact->inexact', id, [types.rational(2, 3)], types.float(2/3)); + testPrim('exact->inexact', id, [types.complex(3, 5)], types.complex(types.float(3), types.float(5))); + + testPrim('inexact->exact', types.float, [0], 0); + testPrim('inexact->exact', types.float, [1.25], types.rational(5, 4)); + testPrim('inexact->exact', id, [5], 5); + testPrim('inexact->exact', id, [types.complex(5, 3)], types.complex(5, 3)); + testPrim('inexact->exact', id, [types.complex(types.float(5.2), types.float(4))], + types.complex(types.rational(26, 5), 4)); + }); + + +runTest('first, second, third, fourth, fifth, sixth, seventh, eighth', + function() { + var testList1 = types.list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + var testList2 = types.list([types.list([1, 2]), + types.list([3, 4]), + types.list([5, 6]), + types.list([7, 8]), + types.list([9, 10]), + types.list([11, 12]), + types.list([13, 14]), + types.list([15, 16]), + types.list([17, 18]), + types.list([19, 20])]); + testPrim('first', id, [testList1], 1); + testPrim('first', id, [testList2], types.list([1, 2])); + + testPrim('second', id, [testList1], 2); + testPrim('second', id, [testList2], types.list([3, 4])); + + testPrim('third', id, [testList1], 3); + testPrim('third', id, [testList2], types.list([5, 6])); + + testPrim('fourth', id, [testList1], 4); + testPrim('fourth', id, [testList2], types.list([7, 8])); + + testPrim('fifth', id, [testList1], 5); + testPrim('fifth', id, [testList2], types.list([9, 10])); + + testPrim('sixth', id, [testList1], 6); + testPrim('sixth', id, [testList2], types.list([11, 12])); + + testPrim('seventh', id, [testList1], 7); + testPrim('seventh', id, [testList2], types.list([13, 14])); + + testPrim('eighth', id, [testList1], 8); + testPrim('eighth', id, [testList2], types.list([15, 16])); + }); + + + + +/************************************* + *** Primitive List Function Tests *** + *************************************/ + + +runTest('cons, car, and cdr', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('car'), + [makeApplication(makePrimval('cons'), + [makeConstant(types.rational(1)), + makeConstant(types.EMPTY)])])); + assert.deepEqual(run(state), types.rational(1)); + + state.pushControl(makeApplication(makePrimval('cdr'), + [makeApplication(makePrimval('cons'), + [makeConstant(types.rational(1)), + makeConstant(types.EMPTY)])])); + assert.deepEqual(run(state), types.EMPTY); + + state.pushControl(makeApplication(makePrimval('cdr'), + [makeApplication(makePrimval('cons'), + [makeConstant(types.rational(1)), + makeApplication(makePrimval('cons'), + [makeConstant(types.rational(2)), + makeConstant(types.EMPTY)])])])); + assert.deepEqual(run(state), types.pair(2, types.EMPTY)); + }); + + +runTest('list?', + function() { + testPrim('list?', id, [types.EMPTY], true); + testPrim('list?', id, [types.pair(1, types.EMPTY)], true); + testPrim('list?', id, [types.list([1, 2, 0, 3, 2])], true); + testPrim('list?', id, [types.pair(1, 4)], false); + testPrim('list?', id, [types.complex(0, 2)], false); + }); + + +runTest('list', + function() { + testPrim('list', types.rational, [], types.EMPTY); + testPrim('list', types.rational, [1], types.pair(types.rational(1), types.EMPTY)); + testPrim('list', types.rational, [1, 5, 3], types.list([types.rational(1), + types.rational(5), + types.rational(3)])); + }); + + +runTest('list*', + function() { + testPrim('list*', id, [types.EMPTY], types.EMPTY); + testPrim('list*', id, [types.rational(1), types.pair(types.rational(2), types.EMPTY)], + types.list([types.rational(1), types.rational(2)])); + testPrim('list*', id, [1, 2, 3, types.list([4, 5])], types.list([1, 2, 3, 4, 5])); + }); + + +runTest('length', + function() { + testPrim('length', id, [types.EMPTY], 0); + testPrim('length', types.list, [[1]], 1); + testPrim('length', types.list, [[1, 2, 3, 4]], 4); + }); + + +runTest('append', + function() { + testPrim('append', types.list, [], types.EMPTY); + testPrim('append', types.list, [[1]], types.list([1])); + testPrim('append', types.list, [[], [1, 2, 3], [1, 2]], + types.list([1, 2, 3, 1, 2])); + testPrim('append', id, [types.list([1, 2]), types.list([3]), 4], + types.pair(1, types.pair(2, types.pair(3, 4)))); + testPrim('append', id, [5], 5); + testPrim('append', id, [types.EMPTY, 3], 3); + }); + + +runTest('reverse', + function() { + testPrim('reverse', id, [types.EMPTY], types.EMPTY); + testPrim('reverse', id, [types.list([1])], types.list([1])); + testPrim('reverse', id, [types.list([1, 2, 3, 4, 5])], types.list([5, 4, 3, 2, 1])); + }); + + +runTest('list-ref', + function() { + var testList = types.list([types.rational(1), + types.rational(1), + types.rational(2), + types.rational(3), + types.rational(5), + types.rational(8), + types.rational(11)]); + testPrim('list-ref', id, [testList, types.rational(0)], types.rational(1)); + testPrim('list-ref', id, [testList, types.rational(5)], types.rational(8)); + }); + + +runTest('memq', + function() { + testPrim('memq', id, [0, types.list([1, 2, 3])], false); + testPrim('memq', id, [2, types.list([1, 2, 3])], types.list([2, 3])); + testPrim('memq', id, [types.complex(2, 2), + types.list([types.complex(1, 1), + types.complex(2, 2), + types.complex(3, 3)])], + false); + testPrim('memq', id, [types.char('a'), + types.list([types.char('c'), + types.char('b'), + types.char('a')])], + types.list([types.char('a')])); + testPrim('memq', id, [types.string('a'), + types.list([types.string('c'), + types.string('b'), + types.string('a')])], + false); + + var str = types.string('hi'); + testPrim('memq', id, [str, types.list([types.string('Yo'), + types.string(', '), + str])], + types.list([str])); + }); + + +runTest('memv', + function() { + testPrim('memv', id, [0, types.list([1, 2, 3])], false); + testPrim('memv', id, [2, types.list([1, 2, 3])], types.list([2, 3])); + testPrim('memv', id, [types.complex(2, 2), + types.list([types.complex(1, 1), + types.complex(2, 2), + types.complex(3, 3)])], + types.list([types.complex(2, 2), types.complex(3, 3)])); + testPrim('memv', id, [types.char('a'), + types.list([types.char('c'), + types.char('b'), + types.char('a')])], + types.list([types.char('a')])); + testPrim('memv', id, [types.string('a'), + types.list([types.string('c'), + types.string('b'), + types.string('a')])], + false); + + var str = types.string('hi'); + testPrim('memv', id, [str, types.list([types.string('Yo'), + types.string(', '), + str])], + types.list([str])); + }); + + +runTest('member', + function() { + testPrim('member', id, [0, types.list([1, 2, 3])], false); + testPrim('member', id, [2, types.list([1, 2, 3])], types.list([2, 3])); + testPrim('member', id, [types.complex(2, 2), + types.list([types.complex(1, 1), + types.complex(2, 2), + types.complex(3, 3)])], + types.list([types.complex(2, 2), types.complex(3, 3)])); + testPrimF('member', id, [types.char('b'), + types.list([types.char('c'), + types.char('b'), + types.char('a')])], + ['#\\b', '#\\a'], listToStringArray); + testPrimF('member', id, [types.string('a'), + types.list([types.string('c'), + types.string('b'), + types.string('a')])], + ['a'], listToStringArray); + + var str = types.string('hi'); + testPrim('member', id, [str, types.list([types.string('Yo'), + types.string(', '), + str])], + types.list([str])); + }); + + +runTest('remove', + function() { + testPrim('remove', id, [3, types.list([1, 2, 3, 4, 5])], types.list([1, 2, 4, 5])); + testPrim('remove', id, [1, types.list([1, 2, 1, 2])], types.list([2, 1, 2])); + testPrim('remove', id, [10, types.list([1, 2, 3, 4])], types.list([1,2,3,4])); + testPrimF('remove', id, [types.string('a'), types.list([types.string('b'), + types.string('a'), + types.string('c'), + types.string('a')])], + ['b', 'c', 'a'], listToStringArray); + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('remove'), + [makeConstant(types.string('a')), + makeConstant(types.list([types.string('b'), + types.string('a'), + types.string('c'), + types.string('a')]))])); + var res = run(state); + assert.deepEqual(res.first().toString(), 'b'); + assert.deepEqual(res.rest().first().toString(), 'c'); + assert.deepEqual(res.rest().rest().first().toString(), 'a'); + assert.deepEqual(res.rest().rest().rest(), types.EMPTY); + }); + + + +runTest('map', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('map'), + [makePrimval('add1'), + makeConstant(types.list([1, 2, 3]))])); + assert.deepEqual(run(state), types.list([2, 3, 4])); + }); + +runTest('filter', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('filter'), + [makePrimval('even?'), + makeConstant(types.list([1, 2, 3, 4, 5, 6]))])); + assert.deepEqual(run(state), types.list([2, 4, 6])); + + state.pushControl(makeApplication(makePrimval('filter'), + [makeLam(1, [], makeConstant(false)), + makeConstant(types.list([1, 2, 3, 4]))])); + assert.deepEqual(run(state), types.EMPTY); + + state.pushControl(makeApplication(makePrimval('filter'), + [makeLam(1, [], makeConstant(true)), + makeConstant(types.list([1, 2, 3, 4]))])); + assert.deepEqual(run(state), types.list([1, 2, 3, 4])); + }); + + +runTest('foldl', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('foldl'), + [makePrimval('-'), + makeConstant(2), + makeConstant(types.list([1, 2, 3, 4]))])); + assert.deepEqual(run(state), 4); + + state.pushControl(makeApplication(makePrimval('foldl'), + [makePrimval('cons'), + makeConstant(types.list([1, 2])), + makeConstant(types.list([3, 4, 5, 6]))])); + assert.deepEqual(run(state), types.list([6, 5, 4, 3, 1, 2])); + }); + + +runTest('foldr', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('foldr'), + [makePrimval('-'), + makeConstant(2), + makeConstant(types.list([1, 2, 3, 4]))])); + assert.deepEqual(run(state), 0); + + state.pushControl(makeApplication(makePrimval('foldr'), + [makePrimval('cons'), + makeConstant(types.list([1, 2])), + makeConstant(types.list([3, 4, 5, 6]))])); + assert.deepEqual(run(state), types.list([3, 4, 5, 6, 1, 2])); + }); + + + +runTest('build-list', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('build-list'), + [makeConstant(5), makePrimval('add1')])); + assert.deepEqual(run(state), types.list([1, 2, 3, 4, 5])); + + state.pushControl(makeApplication(makePrimval('build-list'), + [makeConstant(5), makePrimval('number->string')])); + assert.deepEqual(run(state), types.list([types.string('0'), + types.string('1'), + types.string('2'), + types.string('3'), + types.string('4')])); + }); + + +runTest('argmax', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('argmax'), + [makePrimval('car'), + makeConstant(types.list([types.pair(1, 2), + types.list([1, 2, 3]), + types.pair(3, 5), + types.pair(2, 13)]))])); + assert.deepEqual(run(state), types.pair(3, 5)); + + state.pushControl(makeApplication(makePrimval('argmax'), + [makePrimval('-'), + makeConstant(types.list([1, 3, 5, 2, 4]))])); + assert.deepEqual(run(state), 1); + }); + + +runTest('argmin', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('argmin'), + [makePrimval('car'), + makeConstant(types.list([types.pair(1, 2), + types.list([1, 2, 3]), + types.pair(3, 5), + types.pair(2, 13)]))])); + assert.deepEqual(run(state), types.pair(1, 2)); + + state.pushControl(makeApplication(makePrimval('argmin'), + [makePrimval('-'), + makeConstant(types.list([1, 3, 5, 2, 4]))])); + assert.deepEqual(run(state), 5); + }); + + +runTest('quicksort', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('quicksort'), + [makeConstant(types.list([4, 3, 6, 8, 2, 9])), + makePrimval('<')])); + var result = run(state); + assert.ok(types.isEqual(result, types.list([2, 3, 4, 6, 8, 9]))); + + state.pushControl(makeApplication(makePrimval('quicksort'), + [makeConstant(types.list([types.char('k'), + types.char('o'), + types.char('c'), + types.char('g')])), + makePrimval('char>?')])); + assert.ok(types.isEqual(run(state), types.list([types.char('o'), + types.char('k'), + types.char('g'), + types.char('c')]))); + }); + + +runTest('compose', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makeApplication(makePrimval('compose'), + [makePrimval('magnitude'), + makePrimval('+'), + makePrimval('values')]), + [makeConstant(2), + makeConstant(3), + makeConstant(2), + makeConstant(types.complex(-4, 4))])); + assert.deepEqual(run(state), types.rational(5)); + + var composed = makeApplication(makePrimval('compose'), + [makePrimval('even?'), + makePrimval('*'), + makePrimval('values')]); + state.pushControl(makeApplication(composed, [makeConstant(3), makeConstant(5)])); + assert.deepEqual(run(state), false); + state.pushControl(makeApplication(composed, [makeConstant(2), makeConstant(4), makeConstant(15)])); + assert.deepEqual(run(state), true); + }); + + +runTest('caar, cadr, cdar, cddr, etc.', + function() { + var deepArrayToList = function(a) { + if ( !(a instanceof Array) ) { + return a; + } + return types.list( helpers.map(deepArrayToList, a) ); + } + + testPrim('car', types.list, [[1, 2, 3]], 1); + testPrim('caar', deepArrayToList, [[[1, 2], [3, 4], []]], 1); + testPrim('caar', deepArrayToList, [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], types.list([1, 2])); + testPrim('caar', types.list, [[types.pair(1, types.pair(2, 3))]], 1); + + testPrim('cadr', types.list, [[1, 2, 3]], 2); + testPrim('cadr', deepArrayToList, [[[1, 2], [3, 4]]], types.list([3, 4])); + + testPrim('cdar', deepArrayToList, [[[1, 2], [3, 4], []]], types.list([2])); + testPrim('cdar', types.list, [[types.pair(1, 2)]], 2); + + testPrim('cddr', types.list, [[1, 2, 3, 4]], types.list([3, 4])); + testPrim('cddr', deepArrayToList, [[[], [1], [1, 2], [1, 2, 3]]], deepArrayToList([[1, 2], [1, 2, 3]])); + testPrim('cddr', id, [types.pair(1, types.pair(2, 3))], 3); + + testPrim('caaar', deepArrayToList, [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 1); + testPrim('caaar', deepArrayToList, [[[types.pair(0, 1)]]], 0); + + testPrim('caadr', deepArrayToList, [[[1, 2], [3, 4], []]], 3); + testPrim('caadr', deepArrayToList, [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], types.list([5, 6])); + + testPrim('cadar', deepArrayToList, [[[1, 2], [3, 4], []]], 2); + testPrim('cadar', deepArrayToList, [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], types.list([3, 4])); + + testPrim('cdaar', deepArrayToList, [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], types.list([2])); + testPrim('cdaar', deepArrayToList, [[[types.pair(0, 1)]]], 1); + + testPrim('cdadr', deepArrayToList, [[[1, 2], [3, 4], []]], types.list([4])); + testPrim('cdadr', deepArrayToList, [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], deepArrayToList([[7, 8]])); + testPrim('cdadr', deepArrayToList, [[types.pair(1, 2), types.pair(3, 4)]], 4); + + testPrim('cddar', deepArrayToList, [[[1, 2], [3, 4], []]], types.EMPTY); + testPrim('cddar', deepArrayToList, [[types.pair(1, types.pair(2, 3))]], 3); + + testPrim('caddr', types.list, [[1, 2, 3, 4]], 3); + testPrim('caddr', deepArrayToList, [[[1, 2], [3, 4], []]], types.EMPTY); + + testPrim('cdddr', types.list, [[1, 2, 3, 4]], types.list([4])); + testPrim('cdddr', id, [types.pair(1, types.pair(2, types.pair(3, 4)))], 4); + + testPrim('cadddr', types.list, [[1, 2, 3, 4]], 4); + testPrim('cadddr', deepArrayToList, [[[1, 2], [3, 4], [5, 6], [7, 8]]], types.list([7, 8])); + }); + + + + +/*************************** + *** Box Primitive Tests *** + ***************************/ + + +runTest('box', + function() { + testPrim('box', id, [1], types.box(1)); + testPrim('box', types.string, ['abc'], types.box(types.string('abc'))); + }); + + +runTest('box?', + function() { + testPrim('box?', types.box, [1], true); + testPrim('box?', types.char, ['a'], false); + testPrim('box?', id, [15], false); + }); + + +runTest('unbox', + function() { + testPrim('unbox', types.box, [2], 2); + testPrim('unbox', types.box, [types.char('a')], types.char('a')); + }); + + +runTest('set-box!', + function() { + var testBox1 = types.box(1); + var testBox2 = types.box(types.string('hello')); + testPrim('set-box!', id, [testBox1, 15], types.VOID); + testPrim('set-box!', id, [testBox2, types.string('world')], types.VOID); + + assert.deepEqual(testBox1, types.box(15)); + assert.deepEqual(testBox2, types.box(types.string('world'))); + }); + + + + +/**************************** + *** Hash Primitive Tests *** + ****************************/ + + +runTest('hash?', + function() { + testPrim('hash?', id, [1], false); + testPrim('hash?', types.vector, [[1, 2, 3]], false); + testPrim('hash?', types.hash, [types.EMPTY], true); + testPrim('hash?', types.hashEq, [types.EMPTY], true); + testPrim('hash?', types.hash, [types.list([types.pair(1, 2)])], true); + testPrim('hash?', types.hashEq, [types.list([types.pair(1, 2)])], true); + }); + + +runTest('str', + function() { + assert.equal(typeof(types.string('a')), 'object'); + }); + + +runTest('make-hash', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('make-hash'), [])); + var res = run(state); + assert.ok(types.isHash(res)); + assert.ok(res.hash.isEmpty()); + + + state.pushControl(makeApplication(makePrimval('make-hash'), + [makeConstant(types.list([types.pair(1, 2), + types.pair(3, 4), + types.pair(5, 6)]))])); + var res2 = run(state); + assert.ok(types.isHash(res2)); + assert.ok( !res2.hash.isEmpty() ); + assert.ok(res2.hash.containsKey(1)); + assert.ok(res2.hash.containsKey(3)); + assert.ok(res2.hash.containsKey(5)); + assert.deepEqual(res2.hash.get(1), 2); + assert.deepEqual(res2.hash.get(3), 4); + assert.deepEqual(res2.hash.get(5), 6); + + state.pushControl(makeApplication(makePrimval('make-hash'), + [makeConstant(types.list( + [types.pair(types.string('a'), + 2)]))])); + var res3 = run(state); + assert.deepEqual(res3.hash.get(types.string('a')), 2); + }); + + +runTest('make-hasheq', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('make-hasheq'), [])); + var res = run(state); + assert.ok(types.isHash(res)); + assert.ok(res.hash.isEmpty()); + + + state.pushControl(makeApplication(makePrimval('make-hasheq'), + [makeConstant(types.list([types.pair(1, 2), + types.pair(3, 4), + types.pair(5, 6)]))])); + var res2 = run(state); + assert.ok(types.isHash(res2)); + assert.ok( !res2.hash.isEmpty() ); + assert.ok(res2.hash.containsKey(1)); + assert.ok(res2.hash.containsKey(3)); + assert.ok(res2.hash.containsKey(5)); + assert.deepEqual(res2.hash.get(1), 2); + assert.deepEqual(res2.hash.get(3), 4); + assert.deepEqual(res2.hash.get(5), 6); + + var str1 = types.string('a'); + var str2 = types.string('a'); + state.pushControl(makeApplication(makePrimval('make-hasheq'), + [makeConstant(types.list( + [types.pair(str1, 1), + types.pair(str2, 2)]))])); + var res3 = run(state); + assert.ok( !res3.hash.containsKey(types.string('a')) ); + assert.deepEqual(res3.hash.get(str1), 1); + assert.deepEqual(res3.hash.get(str2), 2); + }); + + +runTest('hash-set!', + function() { + var testHash = types.hash(types.list([types.pair(1, 1), types.pair(2, 3)])); + +// sys.print('\ntestHash = ' + sys.inspect(testHash) + "\n"); +// sys.print('testHash.hash = ' + sys.inspect(testHash.hash) + '\n'); + + assert.deepEqual(testHash.hash.get(1), 1); + assert.deepEqual(testHash.hash.containsKey(5), false); + + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('hash-set!'), + [makeConstant(testHash), makeConstant(5), makeConstant(8)])); + var result = run(state); + assert.deepEqual(result, types.VOID); + assert.deepEqual(testHash.hash.get(5), 8); + + state.pushControl(makeApplication(makePrimval('hash-set!'), + [makeConstant(testHash), makeConstant(1), makeConstant(0)])); + assert.deepEqual(run(state), types.VOID); + assert.deepEqual(testHash.hash.get(1), 0); + }); + + +runTest('hash-ref', + function() { + var hash1 = types.hash(types.list([types.pair(1, 2), + types.pair(types.string('hello'), + types.string('world')), + types.pair(types.string('hello'), + types.string('world2'))])); + + testPrim('hash-ref', id, [hash1, types.string('hello')], types.string('world2')); + testPrim('hash-ref', id, [hash1, 1, false], 2); + testPrim('hash-ref', id, [hash1, 2, false], false); + + var str1 = types.string('hello'); + var str2 = str1.copy(); + var hash2 = types.hashEq(types.list([types.pair(str1, types.string('world')), + types.pair(str2, types.string('world2')), + types.pair(1, 2), + types.pair(3, 4)])); + testPrim('hash-ref', id, [hash2, types.string('hello'), false], false); + testPrim('hash-ref', id, [hash2, str1], types.string('world')); + testPrim('hash-ref', id, [hash2, types.string('a'), 2], 2); + + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('hash-ref'), + [makeConstant(hash1), + makeConstant(2), + makeLam(0, [], makeConstant(15))])); + assert.deepEqual(run(state), 15); + + state.pushControl(makeApplication(makePrimval('hash-ref'), + [makeConstant(hash2), + makeConstant(types.string('hello')), + makeLam(0, [], makeConstant(true))])); + assert.deepEqual(run(state), true); + }); + + +runTest('hash-remove!', + function() { + var hash1 = types.hash(types.list([types.pair(1, 2), + types.pair(2, 3), + types.pair(3, 4), + types.pair(4, 5)])); + assert.ok(hash1.hash.containsKey(1)); + testPrim('hash-remove!', id, [hash1, 1], types.VOID); + assert.ok( !hash1.hash.containsKey(1) ); + + var str1 = types.string('a'); + var str2 = types.string('b'); + var hash2 = types.hashEq(types.list([types.pair(str1, 5), + types.pair(str2, 3)])); + testPrim('hash-remove!', id, [hash2, types.string('a')], types.VOID); + assert.ok(hash2.hash.containsKey(str1)); + testPrim('hash-remove!', id, [hash2, str2], types.VOID); + assert.ok( !hash2.hash.containsKey(str2) ); + }); + + +runTest('hash-map', + function() { + var str1 = types.string('hello'); + var str2 = str1.copy(); + var str3 = str1.copy(); + var hash1 = types.hash(types.list([types.pair(str1, types.string('a')), + types.pair(str2, types.string('b')), + types.pair(str3, types.string('c'))])); + + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('hash-map'), + [makeConstant(hash1), makePrimval('string-append')])); + assert.ok( hash1.hash.containsKey(types.string('hello')) ); + assert.deepEqual(run(state), types.list([types.string('helloc')])); + + var hash2 = types.hashEq(types.list([types.pair(str1, types.string('a')), + types.pair(str2, types.string('b')), + types.pair(str3, types.string('c'))])); + + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('hash-map'), + [makeConstant(hash2), makePrimval('string-append')])); + assert.deepEqual(run(state), types.list([types.string('helloc'), + types.string('hellob'), + types.string('helloa')])); + }); + + +runTest('hash-for-each', + function() { + var hash1 = types.hash(types.list([types.pair(1, 2), + types.pair(2, 3), + types.pair(3, 4), + types.pair(4, 5)])); + var state = new StateModule.State(); + var ret = []; + state.pushControl(makeApplication(makePrimval('hash-for-each'), + [makeConstant(hash1), + makeConstant(new types.PrimProc('', 2, false, false, + function(key, val) { + ret.push( helpers.format('~s - ~s!~n', [key, val]) ); + }))])); + assert.deepEqual(run(state), types.VOID); + assert.deepEqual(ret, ['1 - 2!\n', '2 - 3!\n', '3 - 4!\n', '4 - 5!\n']); + }); + + + + + +/****************************** + *** Vector Primitive Tests *** + ******************************/ + + +runTest('vector?', + function() { + testPrim('vector?', id, [1], false); + testPrim('vector?', types.list, [[1, 2, 3]], false); + testPrim('vector?', types.vector, [[1, 2, 3]], true); + }); + + +runTest('make-vector', + function() { + testPrim('make-vector', id, [0, types.char('a')], types.vector([])); + testPrim('make-vector', id, [3, 5], types.vector([5, 5, 5])); + }); + + +runTest('vector', + function() { + testPrim('vector', id, [1, 2, 3, 4], types.vector([1, 2, 3, 4])); + testPrim('vector', id, [], types.vector([])); + }); + + +runTest('vector-length', + function() { + testPrim('vector-length', types.vector, [[]], 0); + testPrim('vector-length', types.vector, [[1, 2, 3]], 3); + }); + + +runTest('vector-ref', + function() { + testPrim('vector-ref', id, [types.vector([1, 2]), 1], 2); + testPrim('vector-ref', id, [types.vector([3, 2, 1]), 0], 3); + }); + + +runTest('vector-set!', + function() { + testPrim('vector-set!', id, [types.vector([1, 2, 3]), 0, types.char('a')], types.VOID); + + var testVec = types.vector([1, 2, 3, 4]); + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('vector-set!'), + [makeConstant(testVec), + makeConstant(2), + makeConstant(5)])); + var result = run(state); + assert.deepEqual(result, types.VOID); + assert.deepEqual(testVec, types.vector([1, 2, 5, 4])); + + var testVec2 = types.vector([types.char('a'), + types.char('b'), + types.char('c')]); + state.pushControl(makeApplication(makePrimval('vector-set!'), + [makeConstant(testVec2), + makeConstant(1), + makeConstant(types.char('B'))])); + run(state); + assert.deepEqual(testVec2, types.vector([types.char('a'), + types.char('B'), + types.char('c')])); + }); + + +runTest('vector->list', + function() { + testPrim('vector->list', types.vector, [[]], types.EMPTY); + testPrim('vector->list', types.vector, [[1, 2, 3]], types.list([1, 2, 3])); + }); + + + +/**************************** + *** Char Primitive Tests *** + ****************************/ + + + + +runTest('char?', + function() { + testPrim('char?', id, [types.symbol('hello!')], false); + testPrim('char?', types.string, ['string'], false); + testPrim('char?', types.char, ['w'], true); + }); + + +runTest('char=?', + function() { + testPrim('char=?', types.char, ['a', 's', 'D'], false); + testPrim('char=?', types.char, ['f', 'F'], false); + testPrim('char=?', types.char, ['a', 'a', 'a'], true); + testPrim('char=?', types.char, ['1', '1', '2'], false); + }); + +runTest('char-ci=?', + function() { + testPrim('char-ci=?', types.char, ['a', 's', 'D'], false); + testPrim('char-ci=?', types.char, ['f', 'F'], true); + testPrim('char-ci=?', types.char, ['a', 'a', 'a'], true); + testPrim('char-ci=?', types.char, ['1', '1', '2'], false); + }); + +runTest('char?', + function() { + testPrim('char>?', types.char, ['A', 'a'], false); + testPrim('char>?', types.char, ['a', 'b'], false); + testPrim('char>?', types.char, ['b', 'a'], true); + testPrim('char>?', types.char, ['f', 'd', 'e'], false); + testPrim('char>?', types.char, ['e', 'd', 'c', 'c', 'a'], false); + testPrim('char>?', types.char, ['e', 'd', 'c', 'b', 'a'], true); + }); + +runTest('char<=?', + function() { + testPrim('char<=?', types.char, ['A', 'a'], true); + testPrim('char<=?', types.char, ['a', 'b'], true); + testPrim('char<=?', types.char, ['b', 'a'], false); + testPrim('char<=?', types.char, ['a', 'd', 'c'], false); + testPrim('char<=?', types.char, ['a', 'b', 'b', 'd'], true); + testPrim('char<=?', types.char, ['a', 'b', 'c', 'd', 'e'], true); + }); + +runTest('char>=?', + function() { + testPrim('char>=?', types.char, ['A', 'a'], false); + testPrim('char>=?', types.char, ['a', 'b'], false); + testPrim('char>=?', types.char, ['b', 'a'], true); + testPrim('char>=?', types.char, ['f', 'd', 'e'], false); + testPrim('char>=?', types.char, ['e', 'd', 'c', 'c', 'a'], true); + testPrim('char>=?', types.char, ['e', 'd', 'c', 'b', 'a'], true); + }); + +runTest('char-ci?', + function() { + testPrim('char-ci>?', types.char, ['a', 'A'], false); + testPrim('char-ci>?', types.char, ['a', 'b'], false); + testPrim('char-ci>?', types.char, ['b', 'A'], true); + testPrim('char-ci>?', types.char, ['f', 'd', 'e'], false); + testPrim('char-ci>?', types.char, ['e', 'd', 'c', 'c', 'a'], false); + testPrim('char-ci>?', types.char, ['e', 'd', 'C', 'b', 'a'], true); + }); + +runTest('char-ci<=?', + function() { + testPrim('char-ci<=?', types.char, ['a', 'A'], true); + testPrim('char-ci<=?', types.char, ['a', 'B'], true); + testPrim('char-ci<=?', types.char, ['b', 'a'], false); + testPrim('char-ci<=?', types.char, ['a', 'd', 'c'], false); + testPrim('char-ci<=?', types.char, ['a', 'b', 'B', 'd'], true); + testPrim('char-ci<=?', types.char, ['a', 'b', 'C', 'd', 'e'], true); + }); + +runTest('char-ci>=?', + function() { + testPrim('char-ci>=?', types.char, ['A', 'a'], true); + testPrim('char-ci>=?', types.char, ['a', 'b'], false); + testPrim('char-ci>=?', types.char, ['B', 'a'], true); + testPrim('char-ci>=?', types.char, ['f', 'd', 'e'], false); + testPrim('char-ci>=?', types.char, ['e', 'd', 'C', 'c', 'a'], true); + testPrim('char-ci>=?', types.char, ['e', 'd', 'c', 'B', 'a'], true); + }); + + +runTest('char-alphabetic?', + function() { + testPrim('char-alphabetic?', types.char, ['a'], true); + testPrim('char-alphabetic?', types.char, ['Z'], true); + testPrim('char-alphabetic?', types.char, ['3'], false); + testPrim('char-alphabetic?', types.char, [' '], false); + testPrim('char-alphabetic?', types.char, ['!'], false); + testPrim('char-alphabetic?', types.char, ['\n'], false); + }); + + +runTest('char-numeric?', + function() { + testPrim('char-numeric?', types.char, ['a'], false); + testPrim('char-numeric?', types.char, ['Z'], false); + testPrim('char-numeric?', types.char, ['3'], true); + testPrim('char-numeric?', types.char, [' '], false); + testPrim('char-numeric?', types.char, ['!'], false); + testPrim('char-numeric?', types.char, ['\n'], false); + }); + + +runTest('char-whitespace?', + function() { + testPrim('char-whitespace?', types.char, ['a'], false); + testPrim('char-whitespace?', types.char, ['Z'], false); + testPrim('char-whitespace?', types.char, ['3'], false); + testPrim('char-whitespace?', types.char, [' '], true); + testPrim('char-whitespace?', types.char, ['!'], false); + testPrim('char-whitespace?', types.char, ['\n'], true); + testPrim('char-whitespace?', types.char, ['\t'], true); + }); + + +runTest('char-upper-case?', + function() { + testPrim('char-upper-case?', types.char, ['a'], false); + testPrim('char-upper-case?', types.char, ['Z'], true); + testPrim('char-upper-case?', types.char, ['3'], false); + testPrim('char-upper-case?', types.char, [' '], false); + testPrim('char-upper-case?', types.char, ['!'], false); + testPrim('char-upper-case?', types.char, ['\n'], false); + }); + + +runTest('char-lower-case?', + function() { + testPrim('char-lower-case?', types.char, ['a'], true); + testPrim('char-lower-case?', types.char, ['Z'], false); + testPrim('char-lower-case?', types.char, ['3'], false); + testPrim('char-lower-case?', types.char, [' '], false); + testPrim('char-lower-case?', types.char, ['!'], false); + testPrim('char-lower-case?', types.char, ['\n'], false); + }); + + +runTest('char->integer', + function() { + testPrim('char->integer', types.char, ['0'], 48); + testPrim('char->integer', types.char, ['\n'], 10); + }); + + +runTest('integer->char', + function() { + testPrim('integer->char', id, [48], types.char('0')); + testPrim('integer->char', id, [65], types.char('A')); + }); + + +runTest('char-upcase', + function() { + testPrim('char-upcase', types.char, ['a'], types.char('A')); + testPrim('char-upcase', types.char, ['B'], types.char('B')); + testPrim('char-upcase', types.char, ['2'], types.char('2')); + testPrim('char-upcase', types.char, ['~'], types.char('~')); + }); + + +runTest('char-downcase', + function() { + testPrim('char-downcase', types.char, ['a'], types.char('a')); + testPrim('char-downcase', types.char, ['B'], types.char('b')); + testPrim('char-downcase', types.char, ['2'], types.char('2')); + testPrim('char-downcase', types.char, ['~'], types.char('~')); + }); + + +runTest('char print formatting', + function() { + testPrim('format', id, ['~s', types.char('\n')], types.string('#\\newline')); + testPrim('format', id, ['~s', types.char('\0')], types.string('#\\nul')); + testPrim('format', id, ['~a', types.char('b')], types.string('b')); + testPrim('format', id, ['~s', types.char('b')], types.string('#\\b')); + + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('format'), + [makeConstant('~s'), + makeApplication(makePrimval('integer->char'), + [makeConstant(24)])])); + assert.deepEqual(run(state), types.string('#\\u0018')); + + state.pushControl(makeApplication(makePrimval('format'), + [makeConstant('~s'), + makeApplication(makePrimval('integer->char'), + [makeConstant(127)])])); + assert.deepEqual(run(state), types.string('#\\rubout')); + + state.pushControl(makeApplication(makePrimval('format'), + [makeConstant('~s'), + makeApplication(makePrimval('integer->char'), + [makeConstant(955)])])); + assert.deepEqual(run(state), types.string('#\\u03BB')); + }); + + +/////////////////////////////////////////////////////////////////////// + + +runTest('values', + function() { + testPrim('values', id, [], new types.ValuesWrapper([])); + testPrim('values', id, [1, 2, 3, 4], new types.ValuesWrapper([1, 2, 3, 4])); + testPrim('values', id, [1], 1); + }); + +runTest('call-with-values', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('call-with-values'), + [makePrimval('values'), + makePrimval('+')])); + assert.deepEqual(run(state), 0); + + state.pushControl(makeApplication(makePrimval('call-with-values'), + [makeLam(0, [], makeConstant(1)), + makePrimval('+')])); + assert.deepEqual(run(state), 1); + + state.pushControl(makeApplication(makePrimval('call-with-values'), + [makeLam(0, [], makeApplication(makePrimval('values'), + [makeConstant(1), + makeConstant(2), + makeConstant(3)])), + makePrimval('+')])); + assert.deepEqual(run(state), 6); + }); + + +runTest('not', + function() { + testPrim('not', id, [false], true); + testPrim('not', id, [0], false); + testPrim('not', id, [1], false); + testPrim('not', types.char, ['0'], false); + }); + + +runTest('boolean?', + function() { + testPrim('boolean?', id, [false], true); + testPrim('boolean?', id, [true], true); + testPrim('boolean?', types.string, ['false'], false); + testPrim('boolean?', id, [0], false); + testPrim('boolean?', id, [1], false); + }); + + +runTest('eq?', + function() { + var testStr = types.string('hello'); + var testChar = types.char('H'); + testPrim('eq?', id, [1, 1], true); + testPrim('eq?', id, [1, 2], false); + testPrim('eq?', id, [types.rational(1, 3), types.rational(1, 3)], false); + testPrim('eq?', types.symbol, ['a', 'a'], true); + testPrim('eq?', types.string, ['a', 'a'], false); + testPrim('eq?', id, [testStr, testStr], true); + testPrim('eq?', id, [testChar, testChar], true); + testPrim('eq?', id, [testChar, types.char('H')], true); + }); + + +runTest('eqv?', + function() { + var testStr = types.string('hello'); + var testChar = types.char('H'); + testPrim('eqv?', id, [1, 1], true); + testPrim('eqv?', id, [1, 2], false); + testPrim('eqv?', id, [types.rational(1, 3), types.rational(1, 3)], true); + testPrim('eqv?', types.symbol, ['a', 'a'], true); + testPrim('eqv?', types.string, ['a', 'a'], false); + testPrim('eqv?', id, [testStr, testStr], true); + testPrim('eqv?', id, [testChar, testChar], true); + testPrim('eqv?', id, [testChar, types.char('H')], true); + }); + + +runTest('equal?', + function() { + var testStr = types.string('hello'); + var testChar = types.char('H'); + testPrim('equal?', id, [1, 1], true); + testPrim('equal?', id, [1, 2], false); + testPrim('equal?', id, [types.rational(1, 3), types.rational(1, 3)], true); + testPrim('equal?', types.symbol, ['a', 'a'], true); + testPrim('equal?', types.string, ['a', 'a'], true); + testPrim('equal?', id, [testStr, testStr], true); + testPrim('equal?', id, [testChar, testChar], true); + testPrim('equal?', id, [testChar, types.char('H')], true); + }); + + +runTest('equal~?', + function() { + testPrim('equal~?', id, [types.string('h'), types.string('h'), 5], true); + testPrim('equal~?', id, [5, 4, 0], false); + testPrim('equal~?', id, [types.char('a'), types.char('b'), 3], false); + testPrim('equal~?', id, [5, 3, 3], true); + testPrim('equal~?', types.float, [5.4, 4.9, 0.5], true); + }); + + +runTest('struct?', + function() { + testPrim('struct?', types.string, ['a'], false); + testPrim('struct?', id, [1], false); + testPrim('struct?', id, [types.EMPTY], false); + testPrim('struct?', types.box, [2], false); + + var PosnType = types.makeStructureType( + 'posn', false, 2, 0, false, false); + testPrim('struct?', id, [PosnType.constructor(2, 4)], true); + }); + + +runTest('procedure-arity', + function() { + var state = new StateModule.State(); + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makePrimval('+')])); + assert.deepEqual(run(state), types.arityAtLeast(0)); + + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makePrimval('-')])); + assert.deepEqual(run(state), types.arityAtLeast(1)); + + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makePrimval('equal?')])); + assert.deepEqual(run(state), 2); + + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makePrimval('random')])); + assert.deepEqual(run(state), types.list([0, 1])); + + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makePrimval('hash-ref')])); + assert.deepEqual(run(state), types.list([2, 3])); + + var testProc = new types.CaseLambdaValue('', + [new types.PrimProc('', 1, false, false, function() {}), + new types.PrimProc('', 2, true, false, function() {})]); + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makeConstant(testProc)])); + assert.deepEqual(run(state), types.list([1, types.arityAtLeast(2)])); + + var testProc2 = new types.CaseLambdaValue('', + [new types.PrimProc('', 1, false, false, function() {}), + new types.PrimProc('', 0, true, false, function() {})]); + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makeConstant(testProc2)])); + assert.deepEqual(run(state), types.arityAtLeast(0)); + + var testProc3 = new types.CaseLambdaValue('', + [new types.PrimProc('', 1, false, false, function() {}), + new types.PrimProc('', 4, true, false, function() {}), + new types.PrimProc('', 0, false, false, function() {}), + new types.PrimProc('', 3, true, false, function() {}), + new types.PrimProc('', 3, false, false, function() {})]); + state.pushControl(makeApplication(makePrimval('procedure-arity'), [makeConstant(testProc3)])); + assert.deepEqual(run(state), types.list([0, 1, types.arityAtLeast(3)])); + }); + + +runTest('identity', + function() { + testPrim('identity', id, [5], 5); + testPrim('identity', types.string, ['hello'], types.string('hello')); + }); + + +// runTest('make-posn', +// function() { +// testPrim('make-posn', id, [4, 5], types.posn(4, 5)); +// testPrim('make-posn', types.char, ['a', 'B'], types.posn(types.char('a'), types.char('B'))); +// }); + +// runTest('posn?', +// function() { +// testPrim('posn?', id, [4], false); +// testPrim('posn?', types.box, [4], false); +// testPrim('posn?', id, [types.posn(5, 4)], true); +// }); + +// runTest('posn-x', +// function() { +// testPrim('posn-x', id, [types.posn(5, 4)], 5); +// testPrim('posn-x', id, [types.posn(types.char('a'), types.char('b'))], types.char('a')); +// }); + +// runTest('posn-y', +// function() { +// testPrim('posn-y', id, [types.posn(5, 4)], 4); +// testPrim('posn-y', id, [types.posn(types.char('a'), types.char('b'))], types.char('b')); +// }); + + +runTest('structure equality', + function() { + var ParentType = types.makeStructureType('parent', false, 2, 0, false, false); + var makeParent = ParentType.constructor; + var ChildType = types.makeStructureType('child', ParentType, 0, 0, false, false); + var makeChild = ChildType.constructor; + + testPrim('equal?', id, [makeParent('a', 5), makeParent('a', 5)], true); + testPrim('equal?', id, [makeParent('a', 5), makeParent('b', 5)], false); + testPrim('equal?', id, [makeParent('a', 5), makeChild('a', 5)], false); + testPrim('equal?', id, [makeChild('a', 5), makeParent('a', 5)], false); + testPrim('equal?', id, [makeParent('a', 5), types.color(4, 3, 6)], false); + }); + + +/*************************** + *** FFI Primitive Tests *** + ***************************/ + + +/* +runTest('get-js-object', + function() { + testPrim('get-js-object', id, ['setInterval'], types.jsObject('setInterval', setInterval)); + testPrim('get-js-object', id, [types.jsObject('types', types), 'box'], + types.jsObject('types.box', types.box)); + testPrim('get-js-object', types.string, ['types', 'cons'], types.jsObject('types.cons', types.cons)); + testPrim('get-js-object', id, ['world', types.string('Kernel'), 'ellipseImage'], + types.jsObject('world.Kernel.ellipseImage', world.Kernel.ellipseImage)); + testPrim('get-js-object', id, [types.jsObject('world', world), 'Kernel', 'isColor'], + types.jsObject('world.Kernel.isColor', world.Kernel.isColor)); + testPrim('get-js-object', id, [types.jsObject('world.config', world.config), 'Kernel', 'getNoneEffect'], + types.jsObject('world.config.Kernel.getNoneEffect', world.config.Kernel.getNoneEffect)); + testPrim('get-js-object', id, ['junk'], types.jsObject('junk', undefined)); + + try { + testPrim('get-js-object', id, ['world', 'junk', 'something'], false); + } catch(e) { + assert.deepEqual(e, types.schemeError( + types.exnFailContract('get-js-object: tried to access field something of world.junk, ' + + 'but world.junk was undefined'), + false)); + } + }); + + +runTest('js-call', + function() { + testPrim('js-call', id, [types.jsObject('jsnums.greaterThan', jsnums.greaterThan), 4, types.rational(3, 2)], true); + testPrim('js-call', id, [types.jsObject('types.hash', types.hash), types.EMPTY], types.hash(types.EMPTY)); + + var state = new StateModule.State(); + var results = []; + state.pushControl(makeApplication(makePrimval('js-call'), + [makeConstant(types.jsObject('setInterval', setInterval)), + makeConstant(function() { results.push('tick'); }), + makeConstant(500)])); + var watchId = run(state); + setTimeout(function() { + clearInterval(watchId); + assert.deepEqual(results, ['tick', 'tick', 'tick', 'tick', 'tick']); + }, 2600); + }); +*/ + + + + + + +runTest("topsyntax", + function() { + sys.print("!Not implemented yet! "); + }); + + + + +runTest("Error structure hierarchy", + function() { + assert.ok(types.isExnFail(types.exnFail("hello", types.continuationMarkSet()))); + assert.ok(types.isExnFail(types.exnFailContract("hello", types.continuationMarkSet()))); + assert.ok(types.isExnFail(types.exnFailContractDivisionByZero("hello", types.continuationMarkSet()))); + }); + + + + + + + + + + +/** +This next test is special and should be last. It'll run an infinite loop, and +schedule a break. + +Only after the interpreter breaks do we print "END TESTS". +*/ +runTest("closure application, testing break", + // (define (f) (f)) (begin (f)) --> infinite loop, but with bounded control stack. + function() { + var state = new StateModule.State(); + state.pushControl(makeMod(makePrefix(1), [])); + run(state); + state.pushControl(makeApplication(makeToplevel(0, 0), [])); + state.pushControl(makeDefValues([makeToplevel(0, 0)], + makeLam(0, [0], + makeApplication(makeToplevel(0, 0), + [])))); + var isTerminated = false; + state.onFail = function(e) { + assert.ok(types.isSchemeError(e)); + assert.ok(types.isExnBreak(e.val)); + isTerminated = true; + }; + interpret.run(state); + var waitTillBreak = function() { + if (isTerminated) { + sys.print("\nEND TESTS\n") + return; + } else { + state.breakRequested = true; + setTimeout(waitTillBreak, 10); + } + }; + waitTillBreak(); + });