Course&updates& Tes=ng& Ariane&5&rocket& Mars&Polar&Lander& Therac[25&radia=on&therapy&machine& 4/3/17& Real%programmers%need%no%tes/ng!

Size: px
Start display at page:

Download "Course&updates& Tes=ng& Ariane&5&rocket& Mars&Polar&Lander& Therac[25&radia=on&therapy&machine& 4/3/17& Real%programmers%need%no%tes/ng!"

Transcription

1 4/3/17 Courseupdates LiteraturereviewfeedbackonMoodle Allpresenta=onsgraded ProjectplanassignmentdueApril11 Tes=ng Midtermnextweek,April13 We llstartreviewthisthursday,finishnexttuesday HW1,2,and3solu=onsonMoodle Allpresenta=onslidesonclasswebpage Homework4extendedun=lApril20,9AMEDT Real%programmers%need%no%tes/ng! 5)Iwanttogetthisdonefast,tes=ngisgoingtoslowmedown. 4)IstartedprogrammingwhenIwas2.Don tinsultmebytes=ngmy perfectcode! 3)Tes=ngisforincompetentprogrammerswhocannothack. 2)WearenotNotreDamestudents,ourcodeactuallyworks! 1) Mostofthefunc=onsinGraph.java,asimplemented,areoneor twolinefunc=onsthatrelysolelyuponfunc=onsinhashmapor HashSet.Iamassumingthatthesefunc=onsworkperfectly,andthus thereisreallynoneedtotestthem. an#excerpt#from#a#student s#e1mail Ariane5rocket Therocketself[destructed37secondsa\erlaunch Reason:Acontrolso\warebugthatwentundetected Conversionfrom64[bitfloa=ngpointto16[bitsignedintegervaluehad causedanexcep=on Thefloa=ngpointnumberwaslargerthan32767(max16[bitsignedinteger) Efficiencyconsidera=onshadledtothedisablingoftheexcep=onhandler. Programcrashed!rocketcrashed TotalCost:over$1billion Therac[25radia=ontherapymachine Causedexcessiveradia=on,killingpa=entsfrom radia=onpoisoning Whathappened? Updateddesignhadremovedhardwareinterlocksthat preventtheelectron[beamfromopera=nginitshigh[energy mode.nowallthesafetychecksaredoneintheso\ware. Theso\waresetaflagvariablebyincremen=ngit. Occasionallyanarithme=coverflowoccurred,causingthe so\waretobypasssafetychecks. Theequipmentcontroltaskdidnotproperlysynchronize withtheoperatorinterfacetask,sothatracecondi=ons occurrediftheoperatorchangedthesetuptooquickly. Thiswasevidentlymissedduringtes=ng,sinceittooksome prac=cebeforeoperatorswereabletoworkquicklyenough fortheproblemtooccur. MarsPolarLander Sensorsignalfalselyindicatedthatthecra\hadtoucheddown whenitwas130[feetabovethesurface. thedescentenginestoshutdownprematurely Theerrorwastracedtoasinglebadlineofso\warecode. NASAinves=ga=onpanelsblameforthelander sfailure, "arewellknownasdifficultpartsoftheso\ware[engineering process, 1

2 4/3/17 Tes=ngisforeverysystem Examplesshowedpar=cularlycostlyerrors Buteverylikleerroraddsup Insufficientso\waretes=ngcosts $22[60billionperyearintheU.S. [NISTPlanningReport02[3,2002] Ifyourso\wareisworthwri=ng, it sworthwri=ngright Buildingqualityso\ware WhatImpactstheSo\wareQuality? External Correctness Does#it#do#what#it#suppose#to#do?# Reliability Does#it#do#it#accurately#all#the#:me?# Efficiency Does#it#do#with#minimum#use#of#resources?# Integrity Is#it#secure?# Internal Portability Can#I#use#it#under#different#condi:ons?# Maintainability Can#I#fix#it?# Flexibility Can#I#change#it#or#extend#it#or#reuse#it?# QualityAssurance Theprocessofuncoveringproblemsandimprovingthequalityofso\ware. Tes=ngisamajorpartofQA. Thephasesoftes=ng UnitTes=ng Iseachmoduledoeswhatitsupposetodo? Integra=onTes=ng Doyougettheexpectedresultswhentheparts areputtogether? Valida=onTes=ng Doestheprogramsa=sfytherequirements SystemTes=ng Doesitworkwithintheoverallsystem UnitTes=ng Atestisatthelevelofamethod/class/interface Checkthattheimplementa=onmatchesthe specifica=on. Blackboxtes=ng Choosetestdatawithout#lookingatimplementa=on Glassbox(whitebox)tes=ng Choosetestdatawith#knowledgeofimplementa=on Howistes=ngdone? Basicstepsofatest 1)Chooseinputdata/configura=on 2)Definetheexpectedoutcome 3)Runprogram/methodagainsttheinput andrecordtheresults 4)Examineresultsagainsttheexpected outcome What ssohardabouttes=ng? "justtryitandseeifitworks..." int proc1(int x, int y, int z) // requires: 1 <= x,y,z <= 1000 // effects: computes some f(x,y,z) Exhaus=vetes=ngwouldrequire1billionruns! Soundstotallyimprac=cal CouldseehowinputsetsizewouldgetMUCHbigger Keyproblem:choosingtestsuite(setofpar==onsofinputs) Smallenoughtofinishquickly Largeenoughtovalidatetheprogram 2

3 4/3/17 Approach:par==ontheinputspace Inputspaceverylarge,programsmall "behavioristhe same forsetsofinputs Idealtestsuite: Iden=fysetswithsamebehavior Tryoneinputfromeachset Twoproblems 1.No=onofthesamebehaviorissubtle Naiveapproach:execu=onequivalence Bekerapproach:revealingsubdomains 2.Discoveringthesetsrequiresperfectknowledge Useheuris=cstoapproximatecheaply Naiveapproach:execu=onequivalence int abs(int x) { // returns: x < 0 => returns -x // otherwise => returns x if (x < 0) return -x; else return x; All x < 0 are execution equivalent: program takes same sequence of steps for any x < 0 All x >= 0 are execution equivalent Suggests that {-3, 3, for example, is a good test suite Whyexecu=onequivalencedoesn twork Considerthefollowingbuggycode: int abs(int x) { // returns: x < 0 => returns -x // otherwise => returns x if (x < -2) return -x; else return x; {[3,3doesnotrevealtheerror! Two$executions:.!x#<#%2#!!x#>=#%2! Three$behaviors:$..!x#<#%2#(OK)!x#=#%2#or#%1#(bad)!#x#>=#0#(OK)! Revealingsubdomainapproach Same behaviordependsonspecifica=on Saythatprogramhas samebehavior ontwoinputsif 1)givescorrectresultonboth,or 2)givesincorrectresultonboth Subdomainisasubsetofpossibleinputs Subdomainisrevealingforanerror,E,if 1) Eachelementhassamebehavior 2) IfprogramhaserrorE,itisrevealedbytest Trickistodividepossibleinputsintosetsofrevealing subdomainsforvariouserrors Example Forbuggyabs,whatarerevealingsubdomains? int abs(int x) { if (x < -2) return -x; else return x; { 1 { 2 { 2, 1 { 3, 2, 1 { 2, 1 Whichisbest? % Heuris=csfordesigningtestsuites Agoodheuris=cgives: fewsubdomains errorseinsomeclassoferrorse, highprobabilitythatsomesubdomainis revealingfore Differentheuris=cstargetdifferentclassesoferrors Inprac=ce,combinemul=pleheuris=cs 3

4 4/3/17 Black[boxtes=ng Heuris=c:explorealternatepathsthroughspecifica=on theinterfaceisablackbox;internalsarehidden Example int max(int a, int b) // effects: a > b => returns a // a < b => returns b // a = b => returns a 3paths,so3testcases: (4,3)=>4(i.e.,#any#input#in#the#subdomain#a#>#b) (3,4)=>4(i.e.,#any#input#in#the#subdomain#a#<#b)# (3,3)=>3(i.e.,#any#input#in#the#subdomain#a#=#b) Black[boxtes=ng:advantages Processnotinfluencedbycomponentbeing tested Assump=onsembodiedincodenotpropagatedtotest data. Robustwithrespecttochangesinimplementa=on Testdataneednotbechangedwhencodeischanged Allowsforindependenttesters Testersneednotbefamiliarwithcode Amorecomplexexample Writetestcasesbasedonpathsthroughthe specifica=on int find(int[] a, int value) throws Missing // returns: the smallest i such // that a[i] == value // throws: Missing if value not in a[] Twoobvioustests: ([4,5,6],5) =>1 ([4,5,6],7) =>throwmissing HaveIcapturedallthepaths? ( [4, 5, 5], 5 ) => 1 Musthuntformul=plecasesineffectsorrequires Heuris=c:boundarytes=ng Createtestsattheedgesofsubdomains Whydothis? off[by[onebugs forgettohandleemptycontainer overflowerrorsinarithme=c programdoesnothandlealiasingofobjects Smallsubdomainsattheedgesofthe main subdomainshaveahighprobabilityof revealingthesecommonerrors Boundarytes=ng Todefineboundary,mustdefineadjacentpoints Oneapproach: Iden=fybasicopera=onsoninputpoints Twopointsareadjacentifonebasicopera=onaway Apointisisolatedifcan tapplyabasicopera=on Example:listofintegers Basicopera=ons:create,append,remove Adjacentpoints:<[2,3],[2,3,3]>,<[2,3],[2]> Isolatedpoint:[](can tapplyremoveinteger) Pointisonaboundaryifeither Thereexistsanadjacentpointindifferentsubdomain Pointisisolated Commonboundarycases Arithme=c Smallest/largestvalues Zero Objects Null Circular Sameobjectpassedtomul=plearguments (aliasing) 4

5 4/3/17 Boundarycases:arithme=coverflow public int abs(int x) // returns: x Testsforabs whataresomevaluesorrangesofxthatmightbeworthprobing? x#<0(flipssign)orx# #0(returnsunchanged) aroundx#=0(boundarycondi=on) Specific#tests:#say#x#=#11,#0,#1# How#about # int x = ; // this is Integer.MIN_VALUE System.out.println(x<0); // true System.out.println(Math.abs(x)<0); // also true! FromJavadocforMath.abs: NotethatiftheargumentisequaltothevalueofInteger.MIN_VALUE,the mostnega=verepresentableintvalue,theresultisthatsamevalue, whichisnega=ve# Boundarycases:duplicatesandaliases <E> void appendlist(list<e> src, List<E> dest) { // modifies: src, dest // effects: removes all elements of src and // appends them in reverse order to // the end of dest while (src.size()>0) { E elt = src.remove(src.size()-1); dest.add(elt) Whathappensifsrcanddestrefertothesamething? Aliasing(sharedreferences)iso\enforgoken Clear(glass,white)[boxtes=ng Goals: Ensuretestsuitecovers(executes)alloftheprogram Measurequalityoftestsuitewith%coverage Assump=on: Highcoverage! (noerrorsintestoutput!fewmistakesinprogram) Focus:featuresnotdescribedbyspecifica=on Control[flowdetails Performanceop=miza=ons Alternatealgorithmsfordifferentcases Glass[boxmo=va=on Therearesomesubdomainsthatblack[boxtes=ngwon'tcatch: boolean[] primetable = new boolean[cache_size]; boolean isprime(int x) { if (x>cache_size) { for (int i=2; i<x/2; i++) { if (x%i==0) return false; return true; else { return primetable[x]; Importanttransi=onaroundx=CACHE_SIZE Glass[boxtes=ng:advantages Insightintotestcases Whicharelikelytoyieldnewinforma=on Findsanimportantclassofboundaries ConsiderCACHE_SIZEinisPrimeexample Needtochecknumbersoneachsideof CACHE_SIZE CACHE_SIZE-1,CACHE_SIZE,CACHE_SIZE+1 If CACHE_SIZEismutable,wemayneedtotest withdifferentcache_size s Glass[boxchallenges Defini=onofalloftheprogram Whatneedstobecovered? Op=ons: Statementcoverage Decisioncoverage Loopcoverage Condi=on/Decisioncoverage Path[completecoverage 100%coveragenotalwaysreasonabletarget 100% may be unattainable (dead code) High cost to approach the limit increasing number of cases (more or less) 5

6 4/3/17 Regressiontes=ng Wheneveryoufindabug Reproduceit(beforeyoufixit!) Storeinputthatelicitedthatbug Storecorrectoutput Putintotestsuite Then,fixitandverifythefix Whyisthisagoodidea? Helpstopopulatetestsuitewithgoodtests Protectsagainstregressionsthatreintroducebug Ithappenedonce,soitmightagain RulesofTes=ng Firstruleoftes=ng:Do#it#early#and#do#it#o-en# Besttocatchbugssoon,beforetheyhaveachancetohide. Automatetheprocessifyoucan Regressiontes=ngwillsave=me. Secondruleoftes=ng:Be#systema1c Ifyourandomlythrash,bugswillhideinthecornerun=lyou're gone Wri=ngtestsisagoodwaytounderstandthespec Thinkaboutrevealingdomainsandboundarycases Ifthespecisconfusing!writemoretests Speccanbebuggytoo Incorrect,incomplete,ambiguous,andmissingcornercases Whenyoufindabug!fixitfirstandthenwriteatestforit Tes=ngsummary Tes=ngmakers Youneedtoconvinceothersthatmoduleworks Catchproblemsearlier Bugsbecomeobscurebeyondtheunittheyoccurin Don'tconfusevolumewithqualityoftestdata Canloserelevantcasesinmassofirrelevantones Lookforrevealingsubdomains( characteris=c tests ) Choosetestdatatocover Specifica=on(blackboxtes=ng) Code(glassboxtes=ng) Tes=ngcan'tgenerallyproveabsenceofbugs Butitcanincreasequalityandconfidence 6

Who is our rival? Upcoming. Testing. Ariane 5 rocket (1996) Ariane 5 rocket 3/8/18. Real programmers need no testing!

Who is our rival? Upcoming. Testing. Ariane 5 rocket (1996) Ariane 5 rocket 3/8/18. Real programmers need no testing! Upcoming Homework 3 posted; due March 22 Literature review due March 20 Testing Paper presentation instructions posted: http://people.cs.umass.edu/~brun/class/2018spring/cs621/paperpresentation/paperpresentation.pdf

More information

5) I want to get this done fast, testing is going to slow me down.

5) I want to get this done fast, testing is going to slow me down. Testing Real Programmers need no Testing! The Top Five List 5) I want to get this done fast, testing is going to slow me down. 4) I started programming when I was 2. Don t insult me by testing my perfect

More information

Exceptions and Testing Michael Ernst Saman Amarasinghe

Exceptions and Testing Michael Ernst Saman Amarasinghe Exceptions and Testing 6.170 Michael Ernst Saman Amarasinghe Generic Types Bugfix to the last lecture public class List { private T lst[]; public void add(int, T) { } public T get(int) { } } List

More information

Therac-25 radiation therapy machine

Therac-25 radiation therapy machine Testing CSE 331 Ariane 5 rocket The rocket self-destructed 37 seconds after launch Reason: A control software bug that went undetected Conversion from 64-bit floating point to 16-bit signed integer value

More information

Testing. CSE 331 University of Washington. Michael Ernst

Testing. CSE 331 University of Washington. Michael Ernst Testing CSE 331 University of Washington Michael Ernst Ariane 5 rocket The rocket self-destructed 37 seconds after launch Reason: A control software bug that went undetected Conversion from 64-bit floating

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Fall 2017 Testing (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) How do we ensure correctness? Best practice:

More information

Beta. Team Assessment. Exam. Exam stats. Things to remember. TesAng 3/23/15

Beta. Team Assessment. Exam. Exam stats. Things to remember. TesAng 3/23/15 Beta Beta is due April 1, at noon That s 1 week from Wednesday! Beta includes presentaaons 15 minutes per group at least 2 students per group pracace pracace pracace Team Assessment Due Wed, March 25,

More information

CSE 403: Software Engineering, Fall courses.cs.washington.edu/courses/cse403/16au/ Unit Testing. Emina Torlak

CSE 403: Software Engineering, Fall courses.cs.washington.edu/courses/cse403/16au/ Unit Testing. Emina Torlak CSE 403: Software Engineering, Fall 2016 courses.cs.washington.edu/courses/cse403/16au/ Unit Testing Emina Torlak emina@cs.washington.edu Outline Software quality control Effective unit testing Coverage

More information

Announcements. Testing. Announcements. Announcements

Announcements. Testing. Announcements. Announcements Announcements Testing HW0, HW1, and HW2 are graded Grades and feedback in Submitty Email us at csci2600@cs.lists.rpi.edu Use Submitty discussion board! HW0, HW1, and HW2, Quiz 1 and 2 Grades in Submitty

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Testing 1 Administrivia 1 HW4 due Thursday night Gotta implement things as specified Watch the late days: some people have used 3 of 4 as

More information

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12

CS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12 CS 151 Linked Lists, Recursively Implemented 1 2 Linked Lists, Revisited Recall that a linked list is a structure that represents a sequence of elements that are stored non-contiguously in memory. We can

More information

CS159. Nathan Sprague. September 30, 2015

CS159. Nathan Sprague. September 30, 2015 CS159 Nathan Sprague September 30, 2015 Testing Happens at Multiple Levels Unit Testing - Test individual classes in isolation. Focus is on making sure that each method works according to specification.

More information

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated 1. What are the 2 types of short circuit operators. 1. Short circuit AND (&&) = if first condition is false then the second is never evaluated because true and false gives you false only. 2. Short circuit

More information

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi

COL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi Stack and Queue How do we implement a Queue using Array? : A collection of nodes with linear ordering defined on them. Each node holds an element and points to the next node in the order. The first node

More information

Linked Lists. Linked List Nodes. Walls and Mirrors Chapter 5 10/25/12. A linked list is a collection of Nodes: item next -3.

Linked Lists. Linked List Nodes. Walls and Mirrors Chapter 5 10/25/12. A linked list is a collection of Nodes: item next -3. Linked Lists Walls and Mirrors Chapter 5 Linked List Nodes public class Node { private int item; private Node next; public Node(int item) { this(item,null); public Node(int item, Node next) { setitem(item);

More information

Violations of the contract are exceptions, and are usually handled by special language constructs. Design by contract

Violations of the contract are exceptions, and are usually handled by special language constructs. Design by contract Specification and validation [L&G Ch. 9] Design patterns are a useful way to describe program structure. They provide a guide as to how a program fits together. Another dimension is the responsibilities

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018 Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment

More information

Introduction to Computer Science II CS S-18 Linked Lists

Introduction to Computer Science II CS S-18 Linked Lists Introduction to Computer Science II CS112-2012S-18 Linked Lists David Galles Department of Computer Science University of San Francisco 18-0: Linked Lists Linked List node Data Pointer to the next element

More information

Java Identifiers, Data Types & Variables

Java Identifiers, Data Types & Variables Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char

More information

CS 3 Introduction to Software Engineering. 5: Iterators

CS 3 Introduction to Software Engineering. 5: Iterators CS 3 Introduction to Software Engineering 5: Iterators Questions? 2 PS1 Discussion Question You are to choose between two procedures, both of which compute the minimum value in an array of integers. One

More information

CISC327 - So*ware Quality Assurance. Lecture 13 Black Box Unit

CISC327 - So*ware Quality Assurance. Lecture 13 Black Box Unit CISC327 - So*ware Quality Assurance Lecture 13 Black Box Unit Tes@ng Black Box Unit Tes@ng Black box method tes@ng Test harnesses Role of code- level specifica@ons (asser@ons) Automa@ng black box unit

More information

Specifications. CSE 331 Spring 2010

Specifications. CSE 331 Spring 2010 Specifications CSE 331 Spring 2010 The challenge of scaling software Small programs are simple and malleable easy to write easy to change Big programs are (often) complex and inflexible hard to write hard

More information

LECTURE 11 TEST DESIGN TECHNIQUES IV

LECTURE 11 TEST DESIGN TECHNIQUES IV Code Coverage Testing 1. Statement coverage testing 2. Branch coverage testing 3. Conditional coverage testing LECTURE 11 TEST DESIGN TECHNIQUES IV Code Complexity Testing 1. Cyclomatic Complexity s V

More information

(Func&onal (Programming (in (Scheme)))) Jianguo Lu

(Func&onal (Programming (in (Scheme)))) Jianguo Lu (Func&onal (Programming (in (Scheme)))) Jianguo Lu 1 Programming paradigms Func&onal No assignment statement No side effect Use recursion Logic OOP AOP 2 What is func&onal programming It is NOT what you

More information

Assertions, pre/postconditions

Assertions, pre/postconditions Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What

More information

Data Structures and Object-Oriented Design VIII. Spring 2014 Carola Wenk

Data Structures and Object-Oriented Design VIII. Spring 2014 Carola Wenk Data Structures and Object-Oriented Design VIII Spring 2014 Carola Wenk Collections and Maps The Collection interface is for storage and access, while a Map interface is geared towards associating keys

More information

CSE431 Translation of Computer Languages

CSE431 Translation of Computer Languages CSE431 Translation of Computer Languages Semantic Analysis Doug Shook Control Structure Analysis Three major phases for Java: Type Checking How might this apply to control structures? Reachability Analysis

More information

Your data structure should implement all operations in logarithmic time (or better) as a function of the size of the queue.

Your data structure should implement all operations in logarithmic time (or better) as a function of the size of the queue. 1. Write a method isbst(node t) that checks that the binary subtree at t is a binary search tree. The method should return true if t is the root of a binary search tree and false otherwise. Assume Node

More information

CS18000: Problem Solving and Object-Oriented Programming

CS18000: Problem Solving and Object-Oriented Programming CS18000: Problem Solving and Object-Oriented Programming Recursion 28 March 2011 Prof. Chris Clifton Recursion Idea: break a problem down into small, similar sub-problems Write a method to solve first

More information

Solutions Manual. Data Structures and Algorithms in Java, 5th edition International Student Version. M. T. Goodrich and R.

Solutions Manual. Data Structures and Algorithms in Java, 5th edition International Student Version. M. T. Goodrich and R. Solutions Manual Data Structures and Algorithms in Java, 5th edition International Student Version M. T. Goodrich and R. Tamassia Chapter 1 Reinforcement Solution R-1.1 Since, after the clone, A[4] and

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures ITEC2620 Introduction to Data Structures Lecture 10a Grammars II Review Three main problems Derive a sentence from a grammar Develop a grammar for a language Given a grammar, determine if an input is valid

More information

Lecture 4 Specifications

Lecture 4 Specifications CSE 331 Software Design and Implementation Administrivia Next assignments posted tonight HW2: Written problems on loops Lecture 4 Specifications Readings posted as well! Quizzes coming soon J Zach Tatlock

More information

User-defined Functions. Conditional Expressions in Scheme

User-defined Functions. Conditional Expressions in Scheme User-defined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment

More information

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle.

Stacks. Stacks. Main stack operations. The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle. Stacks 1 Stacks The ADT Stack stores arbitrary objects. Insertions and deletions follow the last-in first-out (LIFO) principle. 2 Main stack operations Insertion and removal are defined by: push(e): inserts

More information

Programming Basics. Digital Urban Visualization. People as Flows. ia

Programming Basics.  Digital Urban Visualization. People as Flows. ia Programming Basics Digital Urban Visualization. People as Flows. 28.09.2015 ia zuend@arch.ethz.ch treyer@arch.ethz.ch Programming? Programming is the interaction between the programmer and the computer.

More information

(Not Quite) Minijava

(Not Quite) Minijava (Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures 9//07 ITEC60 Introduction to Data Structures Lecture 7a ADTs and Stacks Abstract Data Types A way to specify the functionality of an entity without worrying about its implementation Similar to a JAVA interface

More information

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Test 2 Question Max Mark Internal

More information

Sorting. Task Description. Selection Sort. Should we worry about speed?

Sorting. Task Description. Selection Sort. Should we worry about speed? Sorting Should we worry about speed? Task Description We have an array of n values in any order We need to have the array sorted in ascending or descending order of values 2 Selection Sort Select the smallest

More information

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

More information

2018/2/5 话费券企业客户接入文档 语雀

2018/2/5 话费券企业客户接入文档 语雀 1 2 2 1 2 1 1 138999999999 2 1 2 https:lark.alipay.com/kaidi.hwf/hsz6gg/ppesyh#2.4-%e4%bc%81%e4%b8%9a%e5%ae%a2%e6%88%b7%e6%8e%a5%e6%94%b6%e5%85%85%e5 1/8 2 1 3 static IAcsClient client = null; public static

More information

CSL 201 Data Structures Mid-Semester Exam minutes

CSL 201 Data Structures Mid-Semester Exam minutes CL 201 Data tructures Mid-emester Exam - 120 minutes Name: Roll Number: Please read the following instructions carefully This is a closed book, closed notes exam. Calculators are allowed. However laptops

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Dynamic Data Structures 12 April 2010 Prof. Chris Clifton More on Dynamic Data Structures Difficulties with Dynamic Data Structures: Removing self Solution 1: Violate Encapsulation

More information

Introduc)on to tes)ng with JUnit. Workshop 3

Introduc)on to tes)ng with JUnit. Workshop 3 Introduc)on to tes)ng with JUnit Workshop 3 We have to deal with errors Early errors are usually syntax errors. The compiler will spot these. Later errors are usually logic errors. The compiler cannot

More information

Introduction to Computer Science II CS S-20 Linked Lists III

Introduction to Computer Science II CS S-20 Linked Lists III Introduction to Computer Science II CS112-2012S-20 Linked Lists III David Galles Department of Computer Science University of San Francisco 20-0: Linked List Previous Practical Example: removeat(int index)

More information

CSE 331 Software Design and Implementation. Lecture 4 Specifications

CSE 331 Software Design and Implementation. Lecture 4 Specifications CSE 331 Software Design and Implementation Lecture 4 Specifications Leah Perlmutter / Summer 2018 Announcements Announcements HW1 Due tonight Looking ahead: HW2 and HW3 both due next week Quiz2 to be posted

More information

CS32 Discussion Week 3

CS32 Discussion Week 3 CS32 Discussion Week 3 Muhao Chen muhaochen@ucla.edu http://yellowstone.cs.ucla.edu/~muhao/ 1 Outline Doubly Linked List Sorted Linked List Reverse a Linked List 2 Doubly Linked List A linked list where

More information

Study Guide for Test 2

Study Guide for Test 2 Study Guide for Test 2 Topics: decisions, loops, arrays, c-strings, linux Material Selected from: Chapters 4, 5, 6, 7, 10.1, 10.2, 10.3, 10.4 Examples 14 33 Assignments 4 8 Any syntax errors are unintentional

More information

1 Quickies String s1 = "Hello World"; String s2 = "Hello "; s2 = s2 + "World"; Point a = new Point(3, 4); Point b = new Point(3, 4);

1 Quickies String s1 = Hello World; String s2 = Hello ; s2 = s2 + World; Point a = new Point(3, 4); Point b = new Point(3, 4); 1 Quickies Please explain what the output for each code segment will be (Compile Time Error, Run Time Error, Output) and why. Assume that each code segment is in a main function and the necessary library

More information

Automatic Test Generation. Galeotti/Gorla/Rau Saarland University

Automatic Test Generation. Galeotti/Gorla/Rau Saarland University Automatic Test Generation Galeotti/Gorla/Rau Saarland University Testing : Find inputs that make the program fail Debugging : The process of finding the cause of a failure. Test Case Values/Test Input/Test

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 21 March 17, 2014 Connec@ng OCaml to Java Announcements No Weirich OH today - > Wed 1-3PM instead Read Chapters 19-22 of the lecture notes HW07 available

More information

Searching & Sorting in Java Bubble Sort

Searching & Sorting in Java Bubble Sort With the bubble sort, the basic idea is to compare adjacent values and exchange them if they are not in order. Consider the following example which shows the first pass through the algorithm. 1. Compare

More information

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Spring Written Exam 1 COS 126 General Computer Science Spring 2017 Written Exam 1 This exam has 9 questions (including question 0) worth a total of 70 points. You have 50 minutes. Write all answers inside the designated spaces.

More information

Sorting Algorithms part 1

Sorting Algorithms part 1 Sorting Algorithms part 1 1. Bubble sort Description Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the array to be sorted, comparing two items at a time, swapping these

More information

CS S-20 Linked Lists III 1. We can then use the next pointer of the previous node to do removal (example on board)

CS S-20 Linked Lists III 1. We can then use the next pointer of the previous node to do removal (example on board) CS112-2012S-20 Linked Lists III 1 20-0: Linked List ious Practical Example: removeat(int index) remove( o) 20-1: removeat First need to get to node before the one we want to remove We can then use the

More information

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Section 003 Fall CS 170 Exam 2. Name (print): Instructions: CS 170 Exam 2 Section 003 Fall 2012 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

Chapter 11 Paper Practice

Chapter 11 Paper Practice Chapter 11 Paper Practice Scrambled Code For each method, rearrange the lines of code in order to build the functionality required by the specification and tests. To accomplish this, you are given three

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

Computer Science and Software Engineering SEMESTER 1, 2016 EXAMINATIONS. CITS1001 Object-oriented Programming and Software Engineering

Computer Science and Software Engineering SEMESTER 1, 2016 EXAMINATIONS. CITS1001 Object-oriented Programming and Software Engineering Computer Science and Software Engineering SEMESTER 1, 2016 EXAMINATIONS CITS1001 Object-oriented Programming and Software Engineering FAMILY NAME: GIVEN NAMES: STUDENT ID: SIGNATURE: This Paper Contains:

More information

Linked List. ape hen dog cat fox. tail. head. count 5

Linked List. ape hen dog cat fox. tail. head. count 5 Linked Lists Linked List L tail head count 5 ape hen dog cat fox Collection of nodes with a linear ordering Has pointers to the beginning and end nodes Each node points to the next node Final node points

More information

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID: CMPS 12A - Winter 2002 Midterm 2 March 5, 2002 Name: ID: This is a closed note, closed book exam. Any place where you are asked to write code, you must declare all variables that you use. However, I just

More information

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0 6 Statements 43 6 Statements The statements of C# do not differ very much from those of other programming languages. In addition to assignments and method calls there are various sorts of selections and

More information

Java Review Outline. basics exceptions variables arrays modulo operator if statements, booleans, comparisons loops: while and for

Java Review Outline. basics exceptions variables arrays modulo operator if statements, booleans, comparisons loops: while and for Java Review Outline basics exceptions variables arrays modulo operator if statements, booleans, comparisons loops: while and for Java basics write a simple program, e.g. hello world http://www2.hawaii.edu/~esb/2017fall.ics211/helloworl

More information

Blox. September 28, 2016 Programming Languages and Translators Stephen A. Edwards. Naeem Bhatti bnb2115 Language Guru

Blox. September 28, 2016 Programming Languages and Translators Stephen A. Edwards. Naeem Bhatti bnb2115 Language Guru Blox September 28, 2016 Programming Languages and Translators Stephen A. Edwards Team Members Name UNI Role Paul Czopowik pc2550 Manager Naeem Bhatti bnb2115 Language Guru Tyrone Wilkinson trw2119 System

More information

Inf1-OOP. Arrays 1. Perdita Stevens, adapting earlier version by Ewan Klein. January 11, School of Informatics

Inf1-OOP. Arrays 1. Perdita Stevens, adapting earlier version by Ewan Klein. January 11, School of Informatics Inf1-OOP Arrays 1 Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics January 11, 2015 1 Thanks to Sedgewick&Wayne for much of this content Arrays Introduction to Arrays Arrays

More information

Exceptions, Case Study-Exception handling in C++.

Exceptions, Case Study-Exception handling in C++. PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case

More information

CS 139 Practice Midterm Questions #2

CS 139 Practice Midterm Questions #2 CS 139 Practice Midterm Questions #2 Spring 2016 Name: 1. Write Java statements to accomplish each of the following. (a) Declares numbers to be an array of int s. (b) Initializes numbers to contain a reference

More information

Some Sample AP Computer Science A Questions - Solutions

Some Sample AP Computer Science A Questions - Solutions Some Sample AP Computer Science A Questions - s Note: These aren't from actual AP tests. I've created these questions based on looking at actual AP tests. Also, in cases where it's not necessary to have

More information

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified. The Stack ADT Stacks Set of objects in which the location an item is inserted and deleted is prespecified Stacks! Insert in order! Delete most recent item inserted! LIFO - last in, first out Stacks 2 The

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Lecture 5 Specifications (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Reminders HW2 is due

More information

CMPS 11 Introduction to Programming Midterm 1 Review Problems

CMPS 11 Introduction to Programming Midterm 1 Review Problems CMPS 11 Introduction to Programming Midterm 1 Review Problems Note: The necessary material for some of these problems may not have been covered by end of class on Monday, the lecture before the exam. If

More information

! A data structure representing a list. ! A series of dynamically allocated nodes. ! A separate pointer (the head) points to the first

! A data structure representing a list. ! A series of dynamically allocated nodes. ! A separate pointer (the head) points to the first Linked Lists Introduction to Linked Lists A data structure representing a Week 8 Gaddis: Chapter 17 CS 5301 Spring 2014 Jill Seaman A series of dynamically allocated nodes chained together in sequence

More information

Inf1-OOP. Arrays. Many Variables of the Same Type. Arrays Introduction to Arrays Arrays in Java Shuffling a Deck Multidimensional Arrays Summary/Admin

Inf1-OOP. Arrays. Many Variables of the Same Type. Arrays Introduction to Arrays Arrays in Java Shuffling a Deck Multidimensional Arrays Summary/Admin Inf1-OOP Arrays 1 Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics Arrays Introduction to Arrays Arrays in Java Shuffling a Deck Multidimensional Arrays Summary/Admin January

More information

CS180. Exam 1 Review

CS180. Exam 1 Review CS180 Exam 1 Review What is the output to the following code? System.out.println("2 + 2 = " + (2 + 2)); System.out.println("2 + 2 = " + 2 + 2); What is the output to the following code? System.out.println(String.valueOf(15+20));

More information

CIS November 14, 2017

CIS November 14, 2017 CIS 1068 November 14, 2017 Administrative Stuff Netflix Challenge New assignment posted soon Lab grades Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the

More information

CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017

CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017 Administrative Stuff CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017 Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 26 Mar 21, 2012 EncapsulaBon & Queues CIS120 / Spring 2012 EncapsulaBon Object encapsulabon EncapsulaBon preserves invariants about the state of the

More information

Fun facts about recursion

Fun facts about recursion Outline examples of recursion principles of recursion review: recursive linked list methods binary search more examples of recursion problem solving using recursion 1 Fun facts about recursion every loop

More information

Tutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays:

Tutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays: College of Computer and Information Sciences CSC111 Computer Programming I Exercise 1: Tutorial 11 Arrays: A. Write a code snippet to define the following arrays: 1. An int array named nums of size 10.

More information

Basic Data Structures

Basic Data Structures Basic Data Structures Some Java Preliminaries Generics (aka parametrized types) is a Java mechanism that enables the implementation of collection ADTs that can store any type of data Stack s1

More information

Ch 7 Designing Java Classes & Class structure

Ch 7 Designing Java Classes & Class structure Ch 7 Designing Java Classes & Class structure Classes comprise fields and methods Fields: Things that describe the class or describe instances (i.e. objects) e.g. student number, first name, last name,

More information

CIS 265 Summer 2015 Exam 1 First Name Last Name

CIS 265 Summer 2015 Exam 1 First Name Last Name CIS 265 Summer 2015 Exam 1 First Name Last Name ID MULTIPLE CHOICE. (30pts - 3 pts each) Choose the one alternative that best completes the statement or answers the question. 1) Which of the following

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Priority Queues. 04/10/03 Lecture 22 1

Priority Queues. 04/10/03 Lecture 22 1 Priority Queues It is a variant of queues Each item has an associated priority value. When inserting an item in the queue, the priority value is also provided for it. The data structure provides a method

More information

CPSC 211. SOLUTIONS to PRACTICE EXERCISES II

CPSC 211. SOLUTIONS to PRACTICE EXERCISES II CPSC 211 SOLUTIONS to PRACTICE EXERCISES II Recursion 1. The output of cheers(3) is: Hip Hip Hurrah 2. public static void cheers(int n) { if ( n

More information

AP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50

AP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50 AP COMPUTER SCIENCE A DIAGNOSTIC EXAM Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50 Directions: Determine the answer to each of the following

More information

DO NOT REPRODUCE. CS61B, Fall 2008 Test #3 (revised) P. N. Hilfinger

DO NOT REPRODUCE. CS61B, Fall 2008 Test #3 (revised) P. N. Hilfinger CS6B, Fall 2008 Test #3 (revised) P. N. Hilfinger. [7 points] Please give short answers to the following, giving reasons where called for. Unless a question says otherwise, time estimates refer to asymptotic

More information

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009 CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009 What is your name?: There are two sections: I. True/False..................... 60 points; ( 30 questions, 2 points each) II.

More information

Specification tips and pitfalls

Specification tips and pitfalls Specification tips and pitfalls David Cok, Joe Kiniry, and Erik Poll Eastman Kodak Company, University College Dublin, and Radboud University Nijmegen David Cok, Joe Kiniry & Erik Poll - ESC/Java2 & JML

More information

Basic Data Structures 1 / 24

Basic Data Structures 1 / 24 Basic Data Structures 1 / 24 Outline 1 Some Java Preliminaries 2 Linked Lists 3 Bags 4 Queues 5 Stacks 6 Performance Characteristics 2 / 24 Some Java Preliminaries Generics (aka parametrized types) is

More information

Inf1-OP. Arrays 1. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. February 26, School of Informatics

Inf1-OP. Arrays 1. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. February 26, School of Informatics Inf1-OP Arrays 1 Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics February 26, 2018 1 Thanks to Sedgewick&Wayne for much of this content Arrays Arrays Arrays:

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

Testing and Debugging

Testing and Debugging Testing and Debugging Comp-303 : Programming Techniques Lecture 14 Alexandre Denault Computer Science McGill University Winter 2004 March 1, 2004 Lecture 14 Comp 303 : Testing and Debugging Page 1 Announcements...

More information

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops. Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8 Handout 5 Loops. Loops implement repetitive computation, a k a iteration. Java loop statements: while do-while for 1. Start with the while-loop.

More information

8.1. Chapter 8: Introduction to Search Algorithms. Linear Search. Linear Search. Linear Search - Example 8/23/2014. Introduction to Search Algorithms

8.1. Chapter 8: Introduction to Search Algorithms. Linear Search. Linear Search. Linear Search - Example 8/23/2014. Introduction to Search Algorithms Chapter 8: Searching and Sorting Arrays 8.1 Introduction to Search Algorithms Introduction to Search Algorithms Search: locate an item in a list of information Two algorithms we will examine: Linear search

More information

int[] a; a = new int[8]; a[0] = 1; a[1] = 1; for (int i = 2; i < 8; i++) a[i] = a[i-1] - a[i-2];

int[] a; a = new int[8]; a[0] = 1; a[1] = 1; for (int i = 2; i < 8; i++) a[i] = a[i-1] - a[i-2]; 1. The source code for a class (a) must explicitly define exactly one constructor. (b) can explicitly define zero, one or more constructors. (c) must explicitly define at least one constructor. (d) can

More information

CS S-20 Linked Lists IV 1

CS S-20 Linked Lists IV 1 CS112-2012S-20 Linked Lists IV 1 20-0: Doubly Linked List Deleting from (and inserting into!) a linked can be challenging because you need to find the node before the node you are looking for Once you

More information

What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one

What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one Iterators What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one 9-2 2-2 What is an Iterator? An iterator is an abstract data

More information