Errata for Pragmatic Unit Testing in Java with JUnit
We try to keep our books accurate, but sometimes mistakes creep
in. This page lists the errors submitted by our astute readers.
If you've found a new error, please
submit it.
The latest version of the book is P7.0,
released over 3 years ago.
If you've bought a PDF of the book and would like to upgrade
it to this version (for free), visit your
home page.
| PDF |
Paper |
Description |
Found in |
Fixed in |
| 1 |
|
#43541: "prepared exclusively for Ren" misses the mark - I do not know Ren.--Rene V. Jansen
|
P7.0
03-Jun-10
|
|
| 29 |
|
#46421: ...don't want TO TO include that...--denis clot
|
P7.0
19-Feb-11
|
|
|
53 |
#46928: In the description of the invariant for the MyStack class the authors write "However we manipulate the index variable next_index, one thing is supposed to be always true: (next_index >= 0 && next_index < stack.length)."
The upper bound of this condition is off by one, the condition should be: (... && next_index <= stack.length).
next_index is 0 when the stack is empty and is one larger than the index of the top element otherwise (its value could be used to represent the number of items on the stack). When the stack has 99 elements in it, next_index is 99. When the client pushes another element on to the stack, "stack[next_index++] = aString;" puts the 100th value at index 99 and increments next_index to 100 (stack.length). This is a valid state for the stack to be in, and it should be allowed by the invariant. In this example, however, the authors' invariant fails.
The same correction should be made to implementation of the checkInvariant method in the text, as well as in the MyStack.java file in code on the web site.
The following code sample illustrates the error:
public class Driver {
public static void main(String[] args) throws InvariantException {
MyStack s = new MyStack();
for (int i = 0; i < 100; ++i) {
s.push(Integer.toString(i));
s.checkInvariant();
}
}
}
The code produces:
Exception in thread "main" InvariantException: next_index out of range: 100 for stack length 100
at MyStack.checkInvariant(MyStack.java:38)
at Driver.main(Driver.java:7)--Andrew R. Dalton #46928: In the description of the invariant for the MyStack class the authors write "However we manipulate the index variable next_index, one thing is ...more...
|
P7.0
23-Apr-11
|
|
| 2009 |
eBQmv |
#48809: I have that photo but I want to share it with those who live in U.S. only. Please send me your soacil security number, name and address with mother maiden name. I will send it out when I get 10 persons with requested information. sincerely yours, Ali Barbar Was this answer helpful? --GUiKCiDE #48809: I have that photo but I want to share it with those who live in U.S. only. Please send me your soacil security number, name and address wit ...more...
|
P7.0
26-Feb-12
|
|
Stuff To Be Considered in the Next Edition
| PDF |
Paper |
Description |
Found in |
Fixed in |
|
76 |
#25897: I was doing exercize 7 on page 76 and found that the tests do not cover pause. In fact, I left pause unimplemented and the tests pass. I suggest adding
assertFalse(mp3.isPlaying());
after line 69 in the test suite to ensure pause does what it ought to.--Tim Hennekey #25897: I was doing exercize 7 on page 76 and found that the tests do not cover pause. In fact, I left pause unimplemented and the tests pass. I sugge ...more...
|
P4.0
12-Sep-06
|
|