Permalink
Browse files

First set of exercises

  • Loading branch information...
0 parents commit 382625bdd6718044ca50cb2edaf3eca30a05665d @edendevelopment edendevelopment committed May 19, 2010
@@ -0,0 +1,8 @@
+require 'rake'
+
+task :default => :test
+
+desc 'Run the tests for the project'
+task :test do
+ sh %Q{mit-scheme --batch-mode --eval "(set! load/suppress-loading-message? #t)" --load all-tests.scm --eval "(%exit (run-registered-tests))"}
+end
@@ -0,0 +1,10 @@
+; Testing template for running the tests (aka. suite)
+;
+; author: Enrique Comba Riepenhausen
+; ecomba.github.com
+;
+(load "lib/test-manager/load.scm")
+;
+; To test add the test classes below
+;
+(load "ex1.8-test.scm")
@@ -0,0 +1,12 @@
+(load "ex1.8.scm")
+
+(define (assert-close actual expected)
+ (assert-true (close? actual expected)))
+
+(in-test-group exercise-1-8-cube-root
+ (define-each-test
+ (assert-close (cube-root 27) 3)))
+
+(in-test-group exercise-1-8-sqrt
+ (define-each-test
+ (assert-close (square-root 9) 3)))
@@ -0,0 +1,28 @@
+(define (close? x y)
+ (< (abs (- x y)) 0.001))
+
+(define (approximate radicand check improve)
+ (define (good-enough? guess)
+ (close? (check guess) radicand))
+ (define (iterate-with guess)
+ (if (good-enough? guess)
+ guess
+ (iterate-with (improve radicand guess))))
+ (iterate-with 1.0))
+
+(define (square-root x)
+ (define (improve x guess)
+ (define (average x y)
+ (/ (+ x y) 2))
+ (average guess (/ x guess)))
+ (define (check x)
+ (square x))
+ (approximate x check improve))
+
+(define (cube-root x)
+ (define (check x)
+ (* x x x))
+ (define (improve x guess)
+ (/ (+ (/ x (square guess)) (* 2 guess)) 3.0))
+ (approximate x check improve))
+
Oops, something went wrong.
@@ -0,0 +1,62 @@
+### ----------------------------------------------------------------------
+### Copyright 2007-2008 Alexey Radul.
+### ----------------------------------------------------------------------
+### This file is part of Test Manager.
+###
+### Test Manager is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation, either version 3 of the License, or
+### (at your option) any later version.
+###
+### Test Manager is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with Test Manager. If not, see <http://www.gnu.org/licenses/>.
+### ----------------------------------------------------------------------
+
+# -*- ruby-mode -*-
+
+require 'rake'
+
+task :default => :test
+
+desc "Run the full test suite in MIT Scheme and Guile"
+task :test => [ :mit_scheme_test, :guile_test ]
+
+desc "Run the full test suite in MIT Scheme"
+task :mit_scheme_test do
+ sh %Q{mit-scheme --batch-mode --eval "(set! load/suppress-loading-message? #t)" --load load.scm --load all-tests.scm --eval "(%exit (run-registered-tests))"}
+end
+
+desc "Run the full test suite in Guile"
+task :guile_test do
+ sh %Q{guile -l load.scm -l all-tests.scm -c "(exit (run-registered-tests))"}
+end
+
+desc "Run a demonstration test suite to show off failure reports in MIT Scheme"
+task :demo do
+ sh %Q{mit-scheme --batch-mode --eval "(set! load/suppress-loading-message? #t)" --load load.scm --load failure-report-demo.scm --eval "(%exit 0)"}
+end
+
+desc "Run a demonstration test suite to show off failure reports in Guile"
+task :guile_demo do
+ sh %Q{guile -l load.scm -l failure-report-demo.scm -c "(exit 0)"}
+end
+
+desc "Generate html documentation"
+task :doc do
+ sh "cd #{File.dirname(__FILE__)}/doc/; cat testing.pod | pod2html > testing.html"
+end
+
+desc "Delete random temporary files that arise as one works"
+task :clean do
+ sh "cd #{File.dirname(__FILE__)}; find . -name '*~' | xargs rm -f; find . -name 'actions.log' | xargs rm -f; find . -name 'pod2htm*.tmp' | xargs rm -f; "
+end
+
+desc "Prepare a release tarball"
+task :release => [:doc, :clean] do
+ sh "cd #{File.dirname(__FILE__)}; " + %Q{tar --create --verbose --file ../test-manager-1.2.tar --directory .. --exclude="*.svn*" --exclude=.commitmail --exclude=todo.txt test-manager/}
+end
Oops, something went wrong.

0 comments on commit 382625b

Please sign in to comment.