Auxiliary_Slides

Auxiliary_Slides - CS134 Auxiliary Slide I CS134 Auxiliary...

This preview shows pages 1–3. Sign up to view the full content.

CS134 Auxiliary Slide I Assertions Example int examMark = in.nextInt(); int examTotal = 65; // ASSERT: double examAvg = (1.0*examMark) / examTotal; // ASSERT: CS134 Auxiliary Slide II Pre- and Post-Condition Examples public static double sqrt(double x) public static void sort(int[] grades) public class Date { private int year; private int month; private int day; // lots omitted public boolean before(Date other) // pre: // post: public int age(Date today) // pre: // post: public void nextDay() // pre: // post: }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS134 Auxiliary Slide III Enlarging an Array public void add(int index, Object item) { // pre: 1 <= index <= size() + 1 // post: Items from index to size have their index increased by // one, item is inserted at index. assert 1 <= index && index <= this.size() + 1; ensureCapacity(); for (int i=numItems; i>=index; i--) { this.set(i + 1, this.get(i)); } this.set(index, item); this.numItems++; } private void ensureCapacity() { // post: this.items has enough space to store one more item. if (items.length == numItems) { int newLength = items.length*2 + 1; Object newItems[ ] = new Object[newLength]; // copy values into the new array for (int i = 0; i < numItems; i++) { newItems[i] = items[i]; } items = newItems; //N.B. the old array is garbage } } CS134 Auxiliary Slide IV Challenges of Software Testing: Specifications clear? Large (infinite?) number of test-cases
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2010 for the course CS CS134 taught by Professor Cl during the Fall '07 term at Waterloo.

Page1 / 5

Auxiliary_Slides - CS134 Auxiliary Slide I CS134 Auxiliary...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online