Test-based programming Ask: “What should this software do?” Write a test first “Does this...
-
Upload
dennis-strickland -
Category
Documents
-
view
215 -
download
3
Transcript of Test-based programming Ask: “What should this software do?” Write a test first “Does this...
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
Designing a ‘Simple’ Computational Program
Static Beam Deflection
Exaggerated beam deflection
Desired Output
Prediction of shape of beam deformed under static load More specific:
Necessary Inputs
Necessary Mathematics
Math is what will connect the inputs and outputs
Mathematical Steps
Translate inputs into mathematical terms (boundary conditions, loads)Solve the differential equation (numerically)Parse the numerical output to get user-desired output
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)
Generality in Beam Problem
Beam Structure/Supports
Mathematical Solving Technique
Implement first for cantilevered beams Initial conditions are
Beam Structure/Supports
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
Designing the softwareNeed user input, mathematical formulation, solving,and expressing user outputWill code in object oriented format, with beam beingan object
Designing the software II
Necessary Functions
Where to test
Remember, it’s good practice to think of the test before the code!
Where to test
Remember, it’s good practice to think of the test before the code!
What are the tests?
Input/Output for beam
Integration Module
Test code vs. Functional Code
Implementation in Java
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.
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!
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/