An array example: the transpose A 2-D array corresponds to a mathematical matrix: 111213 212223 313233 One simple matrix operation transposes the matrix.

Slides:



Advertisements
Similar presentations
Chapter 5 Errors Bjarne Stroustrup
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Recursion CS 367 – Introduction to Data Structures.
1 CS101 Introduction to Computing Lecture 17 Algorithms II.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Debugging Introduction to Computing Science and Programming I.
Computer Science 1620 Loops.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
16-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Chapter 8 Arrays and Strings
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Introduction to Methods. How do we use Methods in Java? Let us start by creating one which displays “hello” on Dos Prompt.
Programming Arrays. Question Write a program that reads 3 numbers from the user and print them in ascending order. How many variables do we need to store.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
Lists in Python.
Reading and Writing Mathematical Proofs
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Chapter 8 Arrays and Strings
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Testing Testing Techniques to Design Tests. Testing:Example Problem: Find a mode and its frequency given an ordered list (array) of with one or more integer.
Working with arrays (we will use an array of double as example)
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Built-in Data Structures in Python An Introduction.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,
Looping and Counting Lecture 3 Hartmut Kaiser
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft RAM Allocation Chapter 3.
Research Topics in Computational Science. Agenda Survey Overview.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
INTRODUCTION TO DATABASE USING MICROSOFT ACCESS 2013 Part 5.2 November 16, 2014.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
The median again The steps of our algorithm: Read the size of the list, N. Declare and instantiate an array of integers, "list". Read the elements of list.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
CompSci 100E 18.1 Testing and Debugging Robert A Wagner.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Introducing Arrays. Too Many Variables?  Remember, a variable is a data structure that can hold a single value at any given time.  What if I want to.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Data Structures Arrays and Lists Part 2 More List Operations.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
Pseudo-code. Pseudo-code Task 1 Preparation Use the following code to declare, initialise and populate an array in a new VB.NET console application:
CS 115 Lecture 5 Math library; building a project Taken from notes by Dr. Neil Moore.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
GetFamilyName( ) with one "name" field We will assume these specifications for the "name" field: The name field consists of these parts, in this order:
Chapter 7 Part 1 Edited by JJ Shepherd
Suppose I want to add all the even integers from 1 to 100 (inclusive)
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Linked Lists and Loops based on slides by Ethan Apter
slides created by Ethan Apter
Class code for pythonroom.com cchsp2cs
Testing Slides adopted from John Jannotti, Brown University
Presentation transcript:

An array example: the transpose A 2-D array corresponds to a mathematical matrix: One simple matrix operation transposes the matrix elements:

Our first solution for (int i = 0; i < A.length; i++) for (int j = 0; j < A[0].length; j++) { // Swap A[i][j] and A[j][i]. int temp = A[i][j]; A[i][j] = A[j][i]; A[j][i] = temp; } What's wrong?

Fixed for (int i = 0; i < A.length; i++) i for (int j = 0; j < i; j++) { // Swap A[i][j] and A[j][i]. int temp = A[i][j]; A[i][j] = A[j][i]; A[j][i] = temp; } Does it work if you write " j <= i "?

Testing Remember the family-name problem. Suppose we have a solution: String parseFamilyName (String name) Imagine we've tested it, with these results: namereturn valueOK? Clarke JimClarkeyes Chan MaryChanyes MacDonald JohnMacDonaldyes O'Shaughnessy PatO'Shaughnessyyes DuMaurier DianeDuMaurieryes Thant UThantyes Hammarskjold DagHammarskjoldyes Tryggve LieTryggveyes

Is it OK? Is our testing convincing? a very short name: length 1, 2 given name missing given name missing but still a pair of blanks after the family name given name missing but a single blank after the family name a blank within the family name a blank after the given name a pair of given names a given name containing a double blank

Bad data Should we test these cases? a blank at the beginning two blanks at the beginning the empty string a single blank They're not covered by the specifications – but should they be?

Testing is hard It's boring, too – but you have to think about it from the start.

Testing rules Design test cases first, before coding. Use testing tools to help prepare test cases. Don't test your own work. What if you're the only programmer?

Test all the cases? Testing integer multiplication: 2 32 integers 2 32  2 32 = 2 64  different products at 1 nanosecond per test, = seconds, or about 100,000 years And first, someone made a table of the right answers.

So, how to test? You can't test all cases, but you can try for two kinds of completeness: Complete coverage of the kinds of data positive, 0, negative –other boundary values: blank character, empty string, empty list small (0, 1, 2) and large –or short and long extremes: selected value found at beginning or end of list duplicates –median of list with pairs, triples, or all the same special sets –sorted, reverse-sorted, all the same

Another kind of completeness Complete coverage of your code Your test cases should cause every line of your program to be executed. –Test tools can help here. For example: both branches of an "if" statement. Each loop should be executed each of 0 times, 1 time, and >1 times. And if it's not possible to exercise a line, what's it doing in your program? The two kinds of completeness interact. While checking code coverage, you'll think of things to add to the data coverage.

More testing homilies Justify your test cases. If there isn't a reason for a test case, discard it. Test early. Design your test cases before you write your code. (But look at them again after you code.)

Built-in testing Make it easier to test your code. Write toString( ) methods. Include print statements in your code. –Guard them with "if (testing)" so you can control the output. Write a main( ) method for each class.

Don't trust yourself Get an enemy to test your code. (Why? If you don't understand the problem when you write your code, you can't test it either.)