cs31 lecture 2

X but be consistent always use the same x only the 3

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: algorithms x There is no unique syntax: find your own! x But be consistent: always use the same x Only the 3-section principle is ‘mandatory’ x Principle: it can be read and understood by someone else, Principle: years later years x You can adapt your algorithm writing to be more or less You close to a given programming language close 15 Testing MilesToRefuel x Step 3: test the algorithm with multiple inputs x Test set 1: m = 100, g = 10, c = 20 Run the algorithm, its output is 100 x Test set 2: m = 300, g = 10, c = 15 Run the algorithm, its output is 150 16 Testing MilesToRefuel x Test set 3: m = 0, g = 0.001, c = 15 Test engine started, no driving Run the algorithm, its output is 0 (is it ok?) x Test set 4: m = 1, g = 0, c = 15 Hybrid car, drove electric for the first mile Hybrid Run the algorithm, division by 0! Error! x Test set 5: m = -1, g = 10, c = 15 Error in sensor data (-1 miles) Run the algorithm, its output is -1.5 (is it ok?) 17 Observations from testing x The current algorithm is not valid for any possible inputs x But it is valid for some inputs x Many scenarios are not taken into account Engine on but no driving Driving electric Sensor problem x We need to refi...
View Full Document

This note was uploaded on 04/03/2014 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Ask a homework question - tutors are online