Many more tests
parent
1129e1e2d9
commit
bc0d17e58f
|
@ -1,2 +1,6 @@
|
|||
/target
|
||||
*.scm~
|
||||
|
||||
# dr racket
|
||||
*.scm~
|
||||
*.scm#*
|
||||
.#*.scm
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
source: src/tests.rs
|
||||
assertion_line: 45
|
||||
expression: run-pass fib.scm
|
||||
|
||||
---
|
||||
10.0
|
||||
89.0
|
||||
|
||||
9.0
|
||||
55.0
|
||||
|
||||
8.0
|
||||
34.0
|
||||
|
||||
7.0
|
||||
21.0
|
||||
|
||||
6.0
|
||||
13.0
|
||||
|
||||
5.0
|
||||
8.0
|
||||
|
||||
4.0
|
||||
5.0
|
||||
|
||||
3.0
|
||||
3.0
|
||||
|
||||
2.0
|
||||
2.0
|
||||
|
||||
1.0
|
||||
1.0
|
||||
|
||||
0.0
|
||||
1.0
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: src/tests.rs
|
||||
assertion_line: 45
|
||||
expression: run-pass multi.scm
|
||||
|
||||
---
|
||||
3.0
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: src/tests.rs
|
||||
assertion_line: 41
|
||||
expression: run-pass nested-defs.scm
|
||||
|
||||
---
|
||||
1.4142156862745097
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: src/tests.rs
|
||||
assertion_line: 41
|
||||
expression: run-pass sqrt.scm
|
||||
|
||||
---
|
||||
1.4142156862745097
|
|
@ -0,0 +1,21 @@
|
|||
#lang scheme
|
||||
|
||||
(define (displayln x) (display x) (newline))
|
||||
|
||||
(define (my-or a b) (if a #t b)) ; Test was written before we had `or`
|
||||
|
||||
|
||||
(define (fib-base? n) (my-or (= n 1) (= n 0)))
|
||||
|
||||
(define (fib n)
|
||||
(if (fib-base? n) 1
|
||||
(+ (fib (- n 1)) (fib (- n 2)))))
|
||||
|
||||
|
||||
(define (pfib n) (displayln n) (displayln (fib n)) (newline))
|
||||
|
||||
(define (pfibs n)
|
||||
(if (= n (- 1)) 0 ; Hack
|
||||
((lambda () (pfib n) (pfibs (- n 1)))))) ; Hack
|
||||
|
||||
(pfibs 10)
|
|
@ -0,0 +1,5 @@
|
|||
#lang scheme
|
||||
|
||||
(define (multi) 1 2 3)
|
||||
|
||||
(display (multi))
|
|
@ -0,0 +1,20 @@
|
|||
#lang scheme
|
||||
|
||||
; We dont have closures at the time of writing, but each func gets its own env
|
||||
; http://sarabander.github.io/sicp/html/1_002e1.xhtml#g_t1_002e1_002e7
|
||||
|
||||
(define (sqrt x)
|
||||
(define (sqrt-iter guess x)
|
||||
(define (good-enough? guess x)
|
||||
(define (square x) (* x x))
|
||||
(< (abs (- (square guess) x)) 0.001))
|
||||
(define (improve guess x)
|
||||
(define (average x y)
|
||||
(/ (+ x y) 2))
|
||||
(average guess (/ x guess)))
|
||||
(if (good-enough? guess x)
|
||||
guess
|
||||
(sqrt-iter (improve guess x) x)))
|
||||
(sqrt-iter 1.0 x))
|
||||
|
||||
(display (sqrt 2))
|
|
@ -0,0 +1,25 @@
|
|||
#lang scheme
|
||||
|
||||
; We dont have closures at the time of writing, but each func gets its own env
|
||||
; http://sarabander.github.io/sicp/html/1_002e1.xhtml#g_t1_002e1_002e7
|
||||
|
||||
(define (sqrt-iter guess x)
|
||||
(if (good-enough? guess x)
|
||||
guess
|
||||
(sqrt-iter (improve guess x) x)))
|
||||
|
||||
(define (improve guess x)
|
||||
(average guess (/ x guess)))
|
||||
|
||||
(define (average x y)
|
||||
(/ (+ x y) 2))
|
||||
|
||||
(define (square x) (* x x))
|
||||
|
||||
(define (good-enough? guess x)
|
||||
(< (abs (- (square guess) x)) 0.001))
|
||||
|
||||
(define (sqrt x)
|
||||
(sqrt-iter 1.0 x))
|
||||
|
||||
(display (sqrt 2))
|
|
@ -33,10 +33,6 @@ fn run_pass() {
|
|||
.assert()
|
||||
.success();
|
||||
|
||||
dbg!(&p, p.components().collect::<Vec<_>>());
|
||||
|
||||
dbg!(&p, manifest_dir);
|
||||
|
||||
let p = p.strip_prefix(manifest_dir).unwrap();
|
||||
let p = p.strip_prefix("src/test/run-pass").unwrap();
|
||||
let p = p.to_str().unwrap();
|
||||
|
|
Loading…
Reference in New Issue