Agile Development & Companies

Slides:



Advertisements
Similar presentations
Introduction to C++ Templates Speaker: Bill Chapman, C++ developer, financial company in Mid-Manhattan. Can be reached via: ' This.
Advertisements

C Language.
PART 6 Programming 1.Decomposition 2.Three Constructs 3.Counting Example 4.Debugging.
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
1 C++ Syntax and Semantics The Development Process.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Writing and Testing Programs Drivers and Stubs Supplement to text.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Computer Science 1620 Programming & Problem Solving.
Chapter 6: Functions.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Introduction to Python
16&17-2 Grasp the concept of top-down programming Identify Function Headers and Prototypes Understand when and where prototypes used Understand how arguments.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Testing Michael Ernst CSE 140 University of Washington.
Testing CSE 140 University of Washington 1. Testing Programming to analyze data is powerful It’s useless if the results are not correct Correctness is.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Creating your first C++ program
Recursion Textbook chapter Recursive Function Call a recursive call is a function call in which the called function is the same as the one making.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Beginning C++ Through Game Programming, Second Edition
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
1 Chapter 9 Additional Control Structures Dale/Weems.
1 Additional Control Structures. 2 Chapter 9 Topics  Switch Statement for Multi-way Branching  Do-While Statement for Looping  For Statement for Looping.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
C++ Classes and Data Structures Jeffrey S. Childs
C++ Basics L KEDIGH. Objectives 1. basic components of a c++ program using proper terminology and programming conventions adopted for this class. 2. List.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
C++ Basics L KEDIGH. Objectives 1. basic components of a c++ program using proper terminology and programming conventions adopted for this class. 2. List.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
1 Brief Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Compiler Directives. The C Preprocessor u The C preprocessor (cpp) changes your source code based on instructions, or preprocessor directives, embedded.
4.3 Functions. Functions Last class we talked about the idea and organization of a function. Today we talk about how to program them.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Introduction to Computing Systems and Programming Programming.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Bill Tucker Austin Community College COSC 1315
User-Written Functions
Agile Development & Companies
Chapter 6: User-Defined Functions I
Chapter 1.2 Introduction to C++ Programming
The Selection Structure
Variables, Expressions, and IO
Basic operations in Matlab
Functions CIS 40 – Introduction to Programming in Python
One-Dimensional Array Introduction Lesson xx
Additional Control Structures
Chapter 7 Additional Control Structures
Coding Concepts (Basics)
Testing (Continued).
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Chapter 6: User-Defined Functions I
CS150 Introduction to Computer Science 1
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Agile Development & Companies Harvard Business Review: “Why the lean start-up changes everything” Agile development applied to entire business of start-ups Simplest possible prototype! Iterate! Image: leadnet.org

Testing Vaughn Betz ECE 297

Testing Philosophy “If you didn’t test it, it doesn’t work” Assume all code broken until proven otherwise Look at what the program does not what it is supposed to do Scientist: you are testing hypotheses about program Think of every case your program should handle  cover them all

Testing Time Develop tests as or before you code Test-driven development Prototype Refine Test & Evaluate

Test-Driven Development The tests are the detailed specification And now can be executed, not just read More tests Less specification document

Types of Tests End-to-end (system) tests Test entire system (like end user would) Hard to debug a failure  problem could be anywhere! Fragile: often test some exact user input would produce some exact output text / file End to End Tests Unit Tests Test small pieces of system (single classes / functions) Much easier to debug a failure  start with that class / function Don’t check user interface (I/O): check API / class does what it should with code (testfixture) Unit Tests

Types of Tests End to End Tests Integration Tests Bigger unit tests Work the same way But now test multiple classes / bigger functionality Moderate difficulty to debug Integration Tests Unit Tests

Testing Automation You will re-test often System tests: save in files Every time you change the program How to speed up? System tests: save in files Use file redirection prog.exe < in.txt > out.txt diff out.txt out_good.txt // matched known good result? Less fragile Write validity checker instead of checking exact output match Write scripts to run all tests and check results

Unit Tests Want: No! To test individual classes / functions How? Carefully chosen user input? Output ... No! struct Point { float x; float y; t_point& operator*=(float rhs); . . .

Unit Tests Write new code To put class in right state To directly send it some input / make some calls To immediately check the responses Test driver

Unit Tests myCode.cpp struct Point { float x; float y; t_point& operator*=(float rhs); . . . tester.cpp int test1 () { Point testme (1, 2); testme *= 3; if (testme != Point (3, 6)) { cout << “uh – oh” << endl; return (1); } return (0); test_main.cpp g++ myCode.cpp main.cpp –o prog.exe int main () { int error = 0; error += test1(); . . . // Lots more tests g++ myCode.cpp tester.cpp test_main.cpp –o test.exe

Unit Test Frameworks Lots of repetitive code to create test drivers Set up the test Check if the test passed Run all the tests Output appropriate messages Collect statistics Unit Test Frameworks Useful macros (#defines) and functions to simplify coding We are using UnitTest++ Powerful, but easy to learn ECE 297 Unit Test Quick Start Guide TEST(..) or TESTFIXTURE (…) CHECK(..) RunAllTests() Automatic Automatic

“Test the Seams” Overlapping tests good Therac-25 Your code + partner’s code Both unit tested Make sure there’s an integration test Therac-25

Testing Tools What tools? Debugger Memory checker Use to debug when a test fails Use to verify new code Step through it and watch execution Memory checker Program seg faults? Program behaving very strangely? Maybe you are accessing memory you shouldn’t be! Run valgrind

Testing Tools 3. Code coverage Tools that can track what lines of your programs have executed over all your tests MyCode.cpp int someFunc (int input) { if (input == 0) return (3); else return (7); } main.cpp int main () { int j = someFunc (8); // Wow I’m bad at testing! }

Testing Tools 3. Code coverage Tools that can track what lines of your programs have executed over all your tests MyCode.cpp int someFunc (int input) { if (input == 0) return (3); else return (7); } No test reaches this line. Code coverage: 6 out of 7 lines or 86% main.cpp int main () { int j = someFunc (8); // Wow I’m bad at testing! }

Google: Testing so Important, Tutorials in the Bathroom

“Testing on the Toilet”

Good Coding Style

1. Use White Space White space: show code organization int sumVec (int vec[], int nElem) { int i, result = 0; for (i = 0; i < nElem; i++) { result += vec[i]; } return (result); void nextFunc (int i) { … int sumVec (int vec[], int nElem) { int i, result = 0; for (i = 0; i < nElem; i++) { result += vec[i]; } return (result); void nextFunc (int i) { White space: show code organization Indent properly (3 or 4 spaces) per { }. Leave blank lines between functions / key blocks

float di (float a, float b) { float val, d, x, x2, y; d = 1 float di (float a, float b) { float val, d, x, x2, y; d = 1.e-4; val = 0; for (x = a; x < b; x += d) { x2 = x + d; if (x2 > b) x2 = b; y = 0.5 * ((1. / x) + (1. / x2)); val += y * (x2 - x); } return (val); What does this do?

float definite_integral (float x_left, float x_right) { float integral, step_size, x1, x2, y_average; step_size = 1.e-4; integral = 0; for (x1 = x_left; x1 < x_right; x1 += step_size) { x2 = x1 + step_size; if (x2 > x_right) x2 = x_right; y_average = 0.5 * ((1. / x1) + (1. / x2)); integral += y_average * (x2 – x1); } return (integral); What does this do?

2. Descriptive Variable Names Use descriptive names Variables, functions, structs/types, … get_file_name ( ); // Use _ to separate getFileName (); // Or use upper case to mark words Types: start with a capital letter Variables: start with lowercase class MyClass { … MyClass oneVar;

float definite_integral (float x_left, float x_right) { float integral, step_size, x1, x2, y_average; step_size = 1.e-4; integral = 0; for (x1 = x_left; x1 < x_right; x1 += step_size) { x2 = x1 + step_size; if (x2 > x_right) x2 = x_right; y_average = 0.5 * ((1. / x1) + (1. / x2)); integral += y_average * (x2 – x1); } return (integral); What does this do?

Comment what whole function does // Compute the definite integral of 1/x between x_left and x_right via the // trapezoidal method. Smaller values of step_size improve accuracy, but // increase computation time. float definite_integral_of_one_over_x (float x_left, float x_right) { float integral, step_size, x1, x2, y_average; step_size = 1e-4; integral = 0.; for (x1 = x_left; x1 < x_right; x1 += step_size) { x2 = x1 + step_size; if (x2 > x_right) // in case (x_right – x_left) is not a multiple of step_size x2 = x_right; y_average = 0.5 * ((1. / x1) + (1. / x2)); // average of y(x1) and y(x2) integral += y_average * (x2 – x1); } return (integral); Comment what whole function does Comment any tricky bits of code

Comments: Usefulness? trans_sim.cpp /* Functions to simulate transistors. * We model transistors as nonlinear elements, * by looking up the source-drain current for each V … */ StudentRecord.h /* Main data structure used to store all information * about a U of T student. Linked list. */ struct StudentRecord { int nClassesCurrent; // Number of classes enrolled in. int nClassesComplete; // Number of completed classes, // not including currently enrolled ones StudentRecord *next; // Pointer to next (linked list) record program.cpp // Compute the sum of the array, over all its elements int sum = 0; for (int i = 0; i < nElem; i++) sum += array[i];

3. “High-Level” Comments Most important comments: give the big picture Documentation should be in the comments Not a separate document  will get out of date Top of files // Functions to simulate transistors. We proceed in 6 stages … Class / data structure definitions Understand the data  can understand the program! Start of functions Tricky code Not very useful comments: Translate C++ to English Most important Least important

Thoughts on This Code? Using a “magic number”: 20 int checkWeights (int weights[20]) { for (int i = 0; i < 20; i++) { if (weights[i] < 0) return (-1); if (weights[i] == 0) return (0); } return (1); Using a “magic number”: 20 Change array size: must find and change all 20’s Returning magic numbers: -1, 0, 1 Must read code carefully to see what each means

4. Use Named Constants const int NUM_WEIGHTS = 20; // 1. Constant variable #define WEIGHT_ZERO 0 // 2. Pre-processor constant enum WtReturn {HAS_NEG = -1, HAS_ZERO = 0, ALL_POS = 1}; // 3. make an “enumeration” (list) of int constants int checkWeights (int weights[NUM_WEIGHTS]) { for (int i = 0; i < NUM_WEIGHTS; i++) { if (weights[i] < 0) return (HAS_NEG); if (weights[i] == 0) return (HAS_ZERO); } return (ALL_POS); Three ways to make constants  use any way you like Name: ALL CAPITALS (convention)