Functional Problem Solving (CSC 151 2016S) : Outlines
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [Remote] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2016S)] [Davis (2013F)] [Rebelsky (2015F)] [Weinman (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Held: Monday, 15 February 2016
Back to Outline 12 - Testing Your Procedures. On to Outline 14 - Drawings as Values.
Summary
We continue our exploration of testing.
Related Pages
Overview
Administrivia
The following notes are from a previous version of the course. They are preserved for posterity.
center-atcenter-atThe following notes are from a previous offering.
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.