21
Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working until the test runs successfully

Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Embed Size (px)

Citation preview

Page 1: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Test-based programming

Ask: “What should this software do?”Write a test first “Does this software do X correctly?”Fill in the code, and keep working until the test runs successfully

Page 2: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Designing a ‘Simple’ Computational Program

Static Beam Deflection

Exaggerated beam deflection

Page 3: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Desired Output

Prediction of shape of beam deformed under static load More specific:

Page 4: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Necessary Inputs

Page 5: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Necessary Mathematics

Math is what will connect the inputs and outputs

Page 6: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Mathematical Steps

Translate inputs into mathematical terms (boundary conditions, loads)Solve the differential equation (numerically)Parse the numerical output to get user-desired output

Page 7: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

GeneralityHardest part of starting numerical code is finding the right level of generalization to start coding with too general means it takes too long to get

going too specific can mean substantial investment in

risky re-engineering laterRule of thumb: structure for the most common range of cases first, and get it running Re-engineering may never happen (false cost) may be easier after your experience (inflated

cost) will have test cases (makes re-writing more

reliable)

Page 8: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Generality in Beam Problem

Beam Structure/Supports

Mathematical Solving Technique

Page 9: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Implement first for cantilevered beams Initial conditions are

Beam Structure/Supports

Page 10: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Loads are difficult to input as functions hard to input as a list of points with

forces harder to integrate numerically with

point forces

For a first run, we’ll assume q(x) is uniform (constant)

Range of Loads

Page 11: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Designing the softwareNeed user input, mathematical formulation, solving,and expressing user outputWill code in object oriented format, with beam beingan object

Page 12: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Designing the software II

Page 13: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Necessary Functions

Page 14: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Where to test

Remember, it’s good practice to think of the test before the code!

Page 15: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Where to test

Remember, it’s good practice to think of the test before the code!

Page 16: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

What are the tests?

Input/Output for beam

Integration Module

Page 17: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Test code vs. Functional Code

Page 18: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Implementation in Java

Page 19: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Getting Started with Java

Download the Java Development Kit (JDK) (not the run-time environment, which just lets you run programs, not

write them)

Follow the tutorials to get a “Hello, world” program runningRead up on the fundamentals of object-oriented programming

http://java.sun.com/docs/books/tutorial/java/concepts/

Keep in mind: Once you get into programming, you don’t need to

understand every line of someone else’s code imitation (also known as cut and paste) is the sincerest form

of flattery. If appropriate, simply cite the source.

Page 20: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

For next class

Get Java running on a machine you can useGet a working program runningGet the scaffold for a ‘beam’ class, which has inputs for the cantilevered case No internals need to be written yet

Read the JUnit descriptions (as much as makes sense to you) Come with questions!

Page 21: Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working

Resources

Beam deflection http://www.geom.uiuc.edu/education/calc-init/static-beam/

Java Tutorials http://java.sun.com/docs/books/tutorial/

JUnit http://junit.sourceforge.net/#Documentation http://www.junit.org/