Triangle Exercise { Triangle Classification [ Myers] [ M ] A - - PDF document

triangle exercise
SMART_READER_LITE
LIVE PREVIEW

Triangle Exercise { Triangle Classification [ Myers] [ M ] A - - PDF document

{bnielsen@cs.aau.dk} } Brian Nielsen Triangle Exercise { Triangle Classification [ Myers] [ M ] A program reads three integer values. The A d th i t l Th three values are interpreted as representing the lengths of the sides


slide-1
SLIDE 1

Triangle Exercise

Brian Nielsen {bnielsen@cs.aau.dk} { }

slide-2
SLIDE 2

Triangle Classification [ M ] [ Myers]

“A d th i t l Th

 “A program reads three integer values. The

three values are interpreted as representing the lengths of the sides of a triangle. The g g program prints a message that states whether the triangle is scalene, isosceles, or equilateral ” equilateral.

 Write a set of test cases to test this

program

Input Expected Input data Expected

  • utput

5,5,5 equilateral CISS , , q …

slide-3
SLIDE 3

Triangle Classification g [ Myers]

Test cases for:

1 lid l t i l ? 9.

  • ne side larger than sum of

1. valid scalene triangle ? 2. valid equilateral triangle ?

  • 3. valid isosceles triangle ?
  • thers ?
  • 10. 3 permutations of previous ?
  • 11. all sides = 0 ?
  • 4. 3 permutations of previous ?

5. side = 0 ? 6 negative side ?

  • 12. non-integer input ?
  • 13. wrong number of values ?

14 for each test case: is 6. negative side ? 7.

  • ne side is sum of others ?

8. 3 permutations of previous ?

  • 14. for each test case: is

expected output specified ?

  • 15. check behaviour after

t t d d ?

  • utput was produced ?

CISS

slide-4
SLIDE 4

TDD E i TDD Exercise

 Develop a program that classifies

triangles according to the given specification using TDD, i.e.

 TEST FI RST+ xUnit Testing  Get started with supplied skeleton

CISS

slide-5
SLIDE 5

N R i t New Requirem ent

 Don’t peek: complete the former step

first!!

 The program must also be able to classify

The program must also be able to classify “Rectangular” triangles

CISS

slide-6
SLIDE 6

N R i t New Requirem ent

D ’t k l t th f t fi t!!

 Don’t peek: complete the former step first!!  The program must print out meaningful error  The program must print out meaningful error

messages why a given input is invalid.

 “The sides (a= 1,b= 2,c= 9) is not a valid triangle

( , , ) g because c is greater that the sum of a and b”

 The program must print out meaningful

explanations why a given triangle is a particular explanations why a given triangle is a particular type

 “The sides (a= 5,b= 13,c= 12) is a rectangular triangle

b d l d l b d” because a squared plus c squared equals b squared”

CISS