The Artima Developer Community


Errata for Programming in Scala, 2nd Edition
Chapter 14: Assertions and Unit Testing
Return to errata index.

Page 256 (PDF page 296):
Similarly to page 206,

var right = ...

should be

val right = ...
Page 257 (PDF page 297):
Listing 14.3, and all applicable listings below it in the chapter.

"import org.stairwaybook.layout.Element" needs to be added above "import
Element.elem" in order for the class to compile.

-- snip --
import org.scalatest.Suite
// import org.stairwaybook.layout.Element  // Errata, added
import Element.elem
-- snip --

A simple test in the scala REPL to verify this:

scala> import org.scalatest.Suite
import org.scalatest.Suite

scala> import Element.elem
<console>:8: error: not found: value Element
       import Element.elem
              ^

scala> import org.stairwaybook.layout.Element  // Errata, added
import layout.Element

scala> import Element.elem // now Element can be found
import Element.elem
Page 257 (PDF page 297):
"Assertions can be enabled and disabled using the JVM's -ea and -da
command-line flags."

This does not work. Assertions may be disabled at compile time using the
"-Xdisable-assertions" scalac option. But this is different from the
JVM's -ea and -da runtime option.
Page 263 (PDF page 303):
pg 303 pdf (chapter 14)

Output of "(new ElementSpec).execute()" near the bottom of the page:

"- should throw an IAE if passed a negative width" should read:

- should throw an IAE if passed a negative width *** FAILED ***
  Expected exception java.lang.IllegalArgumentException to be thrown, but
no exception was thrown. 

Spiral.scala will compile with "def verticalBar = elem('|', -2,
sp.height)". However, the spiral will then be missing some sides. This is
actually a good example of a test that reveals a bug in the code.

Page number: Book type: Paperback book PDF eBook
Book version: (Or build date. Found on back of title page.)
Your feedback:
Your name: (optional)
Your email address: (optional) (will not be published)

Copyright © 2021 Artima, Inc. All rights reserved.