Functional Problem Solving (CSC 151 2014F) : Outlines
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Held: Friday, 19 September 2014
Back to Outline 12 - Raster Graphics and RGB Colors. On to Outline 14 - Transforming Colors.
Summary
We continue our exploration of testing.
Related Pages
Overview
Administrivia
classify-triangle
procedure is correct?We consider its formal definition.
;;; Procedure:
;;; classify-triangle
;;; Parameters:
;;; side1, a rational number [unverified]
;;; side2, a rational number [unverified]
;;; side3, a rational number [unverified]
;;; Purpose:
;;; Determine the kind of triangle the three sides describe.
;;; Produces:
;;; classification, a string
;;; Preconditions:
;;; side1, side2, and side3 together describe a triangle [verified]
;;; Postconditions:
;;; If all three sides are equal, classification is "equilateral".
;;; If exactly two sides are equal, classification is "isosceles".
;;; If no two sides are equal, classification is "scalene".
We start with some simple tests.
(require triangles/tri-0000)
(define triangle-tests
(test-suite
"Testing classify-triangle"
(test-case "unit side length equilateral triangle"
(check-equal? (classify-triangle 1 1 1) "equilateral"))))
(run-tests triangle-tests)
That's one test. What are some others?
We should check for isoceles triangles.
(test-case "simple isosceles triangle"
(check-equal? (classify-triangle 2 2 3) "isosceles"))
Is that the only way to write an isosceles triangle? Does it matter? Let's try another.
(test-case "simple isosceles triangle"
(check-equal? (classify-triangle 2 2 3) "isosceles"))
(test-case "simple isosceles triangle"
(check-equal? (classify-triangle 3 2 2) "isosceles"))
Rather than copying and pasting the same three lines over and over again, I might write a helper procedure.
(define isosceles-tests
(lambda (message same other)
(test-suite
message
(check-equal? (classify-triangle same same other) "isosceles")
(check-equal? (classify-triangle same other same) "isosceles")
(check-equal? (classify-triangle other same same) "isosceles"))))
Now in my main suite, I can write
(isosceles-tests "isosceles: same 2, other 3" 2 3)
(isosceles-tests "isosceles: same 3, other 2" 3 2)
(isosceles-tests "isosceles: same 10, other 15" 10 15)
(isosceles-tests "isosceles: same 1/2, other 1/3" 1/2 1/3)
You'll see this approach on the exam.