Cs2220: Engineering Software Class 5: Validation Fall 2010 University of Virginia David Evans.

Slides:



Advertisements
Similar presentations
Cs2220: Engineering Software Class 10: Generic Datatypes Fall 2010 University of Virginia David Evans.
Advertisements

David Evans CS201j: Engineering Software? University of Virginia Computer Science Lecture 2: Java Semantics, Validation.
Java Review Interface, Casting, Generics, Iterator.
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 6: Reasoning about Data Abstractions.
Written by: Dr. JJ Shepherd
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Loops Notes adapted from Dr. Flores. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while”
Terms and Rules Professor Evan Korth New York University (All rights reserved)
CS Collection and Input/Output Classes CS 3331 Fall 2009.
Cs205: engineering software university of virginia fall 2006 Semantics and Specifying Procedures David Evans
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
Cs205: engineering software university of virginia fall 2006 Validation David Evans
Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.
Cs2220: Engineering Software Class 8: Implementing Data Abstractions Fall 2010 University of Virginia David Evans.
DIRC Workshop on Software Quality and the Legal System 13 February 2004, Gray's Inn, London LEGAL ASPECTS OF SOFTWARE PROCUREMENT Jos Dumortier University.
Cs3102: Theory of Computation Class 18: Proving Undecidability Spring 2010 University of Virginia David Evans.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
CSC 480 Software Engineering Lecture 14 Oct 16, 2002.
Cs205: engineering software university of virginia fall 2006 Data Abstraction David Evans
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
EECE 310: Software Engineering Testing / Validation.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Cs2220: Engineering Software Class 6: Defensive Programming Fall 2010 University of Virginia David Evans.
David Evans These slides: Introduction to Static Analysis.
Grouping objects Collections and iterators Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
David Evans CS551/651: Dependable Computing University of Virginia Computer Science Static Analysis.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 3: Levels of Abstraction
CSC Programming I Lecture 6 September 4, 2002.
“Education is a Treasure that follows you everywhere.” – Chines Proverb Methods and Functions.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
Iterators ITI 1121 N. El Kadri. Motivation Given a (singly) linked-list implementation of the interface List, defined as follows, public interface List.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 9: Designing Exceptionally.
Cs2220: Engineering Software Class 12: Substitution Principle Fall 2010 University of Virginia David Evans.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Cs205: engineering software university of virginia fall 2006 Programming Exceptionally David Evans
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
JAVA GENERICS Lecture 16 CS2110 – Spring 2016 Photo credit: Andrew Kennedy.
Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:
Object Oriented Programming Lecture 2: BallWorld.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
Testing Recap Testing can find problems, but cannot prove your program works Since exhaustive testing is impossible, select test cases with maximum likelihood.
null, true, and false are also reserved.
An Introduction to Java – Part I, language basics
Data Abstraction David Evans cs205: engineering software
Units with – James tedder
Lecture 4: Data Abstraction CS201j: Engineering Software
LCC 6310 Computation as an Expressive Medium
Reasoning about Data Abstractions
Lecture 2: Java Semantics, Validation CS201j: Engineering Software?
Presentation transcript:

cs2220: Engineering Software Class 5: Validation Fall 2010 University of Virginia David Evans

Menu PS2 Questions ArrayList Software Validation

List Datatype Lists in Scheme: What are the elements of a List? Either (1) null or (2) a Pair whose second part is a List Either (1) null or (2) a Pair whose second part is a List

Statically-Typed Lists In Java, every variable must have a statically- declared type: the elements in a list can’t just be “anything”, we need to declare what type they are. java.util.ArrayList is a Parameterized Type ArrayList a = new ArrayList (); a.add(“Hello”); String hello = a.get(0);

import java.util.ArrayList; public class TypesExample { public static void main(String[] args) { ArrayList as = new ArrayList (); ArrayList ao = new ArrayList (); ArrayList > aas = new ArrayList >(); aas.add(as); aas.add(ao); as.add("Hello"); ao.add("Hello"); String el = as.get(0); el = ao.get(0); el = aas.get(0).get(0); System.out.println(el); }

Java Collection Types java.util.List java.util.ArrayList Closest to Scheme and Python lists java.util.Set java.util.TreeSet java.util.HashMap Similar to Python Dictionary type

Using HashMap package ps2; import java.util.HashMap; import java.util.Set; /** * TallyTable provides an abstraction that maps a String to an integer value. * Initially, the count associated with every string is 0. */ public class TallyTable { private HashMap map; public TallyTable() { map = new HashMap (); } public void tally(String w) { map.put(w, getTally(w) + 1); } public int getTally(String w) { if (map.containsKey(w)) { return map.get(w); } else { return 0; } } … }

Validation

Dictionary Definition val·i·date 1.To declare or make legally valid. 2.To mark with an indication of official sanction. 3.To establish the soundness of; corroborate. Can we do any of these with software?

Java’s License READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED SUPPLEMENTAL LICENSE TERMS (COLLECTIVELY "AGREEMENT") CAREFULLY BEFORE OPENING THE SOFTWARE MEDIA PACKAGE. BY OPENING THE SOFTWARE MEDIA PACKAGE, YOU AGREE TO THE TERMS OF THIS AGREEMENT. IF YOU ARE ACCESSING THE SOFTWARE ELECTRONICALLY, INDICATE YOUR ACCEPTANCE OF THESE TERMS BY SELECTING THE "ACCEPT" BUTTON AT THE END OF THIS AGREEMENT. IF YOU DO NOT AGREE TO ALL THESE TERMS, PROMPTLY RETURN THE UNUSED SOFTWARE TO YOUR PLACE OF PURCHASE FOR A REFUND OR, IF THE SOFTWARE IS ACCESSED ELECTRONICALLY, SELECT THE "DECLINE" BUTTON AT THE END OF THIS AGREEMENT.

Java’s License 5. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. …

Java’s License 2. RESTRICTIONS. … Unless enforcement is prohibited by applicable law, you may not modify, decompile, or reverse engineer Software. You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. Sun disclaims any express or implied warranty of fitness for such uses.

Software Validation Process designed to increase our confidence that a program works as intended For complex programs, guarantees are very unusual This is why typical software licenses don’t make any claims about their program working

Increasing Confidence Testing Run the program on set of inputs and check the results Verification Argue formally or informally that the program always works as intended Analysis Poor programmer’s verification: examine the source code to increase confidence that it works as intended

Testing and Fishing Using some successful tests to conclude that a program has no bugs, is like concluding there are no fish in the lake because you didn’t catch one! flickr cc: gsankary

Exhaustive Testing Test all possible inputs PS1: void accelerateSong(String tune, int repeats, int tempo, double rate) How many inputs? How many possible strings? Integer.MAX_VALUE = Number of different characters (1 byte) = 2 8 Number of possible strings:

Selective Testing We can’t test everything, pick test cases with high probability of finding flaws Black-Box Testing: design tests looking only at specification Glass-Box Testing: design tests looking at code Path-complete: at least one test to exercise each path through code

Black-Box Testing Test all paths through the specification public void insert(String word) REQUIRES: word does not contain a '/' character (this is necessary because currentWindow uses '/' to separate words in its result. MODIFIES: this EFFECTS: If word is non-null and non-empty, adds word as the newest element in this. If this already has size elements, removes the oldest element in this. If word is null or empty, does nothing. from WordWindow

Black-Box Testing Test all paths through the specification public void insert(String word) REQUIRES: word does not contain a '/' character (this is necessary because currentWindow uses '/' to separate words in its result. MODIFIES: this EFFECTS: If word is non-null and non-empty, adds word as the newest element in this. If this already has size elements, removes the oldest element in this. If word is null or empty, does nothing. 1.Word is non-null and non-empty, this has size elements. 2.Word is non-null and non-empty, this has fewer than size elements. 3.Word is null. 4.Word is empty.

Black-Box Testing Test all paths through the specification public void insert(String word) REQUIRES: word does not contain a '/' character (this is necessary because currentWindow uses '/' to separate words in its result. MODIFIES: this EFFECTS: If word is non-null and non-empty, adds word as the newest element in this. If this already has size elements, removes the oldest element in this. If word is null or empty, does nothing. 1.Word is non-null and non-empty, this has size elements. 2.Word is non-null and non-empty, this has fewer than size elements. 3.Word is null. 4.Word is empty. Test boundary cases 1.this is empty

Glass-Box Testing public void insert(String word) { if (word == null || word.length() == 0) { return; } assert !word.contains("/"); words[index++] = word; if (index == words.length) index = 0; // System.out.println("Insert: " + word + " ==> " + currentWindow()); } How many paths are there through this code? How many paths are there through this code? public void insert(String word) REQUIRES: word does not contain a '/' character (this is necessary because currentWindow uses '/' to separate words in its result. MODIFIES: this EFFECTS: If word is non-null and non-empty, adds word as the newest element in this. If this already has size elements, removes the oldest element in this. If word is null or empty, does nothing. Glass-Box Testing: determine test strategy and test cases based on examining the implementation code

Glass-Box Testing public void insert(String word) { if (word == null || word.length() == 0) { return; } assert !word.contains("/"); words[index++] = word; if (index == words.length) index = 0; // System.out.println("Insert: " + word + " ==> " + currentWindow()); } How many paths are there through this code? Note: there is no shame in using println statements to debug your code! Unless it is too much clutter, leave them in the code as comments.

WordWindow Representation public class WordWindow { // To avoid moving elements, we maintain an index into a fixed array, and // cycle through the array with each new element. private String words[]; // Array of the current words in the queue private int index; // Index of the last element // INVARIANT: 0 <= i < words.length public void insert(String word) { if (word == null || word.length() == 0) { return; } assert !word.contains("/"); words[index++] = word; if (index == words.length) index = 0; // System.out.println("Insert: " + word + " ==> " + currentWindow()); }

Example: currentWindow public String currentWindow() EFFECTS: Returns a single String representation of the currentWindow which is the concatenation of all the words in order from oldest to newest, separated by '/’ characters. What would be good Black-Box test cases?

Example: currentWindow public String currentWindow() { String res = ""; boolean first = true; for (int i = index; i < index + words.length; i++) { if (first) { first = false; } else { res = res + "/"; } String word = words[i % words.length]; if (word != null) { // no word, just leave "/"s res = res + word; } return res; } How paths tmany hrough this code?

Charge PS2: Due Thursday – My office hours: Wednesday, noon-1pm; Thursday, 11am-noon – Robbie’s help hours: Wednesday, 2-3:30pm; 5-6:30pm For PS2, you should think about how to test your program (but it is not an explicit question for PS2) For PS3, you will need to describe a testing strategy Next class: Is it really hopeless?