The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

341781 (5) [Avatar] Offline
#1
Listing 4.16 Counting word frequency with maps in the Groovy in Action Second Edition assertion is false. If you change teh assertion line to "print statistics" you get:

necessities: 4
bare: 4
the: 3
your: 2
life: 1

Which is the same as what is being asserted. So why does the assert fail with this?

Caught: Assertion failed:

assert statistic == """ necessities: 4 bare: 4 the: 3 your: 2 life: 1 """
| |
| false

necessities: 4
bare: 4
the: 3
your: 2
life: 1


Mittie (397) [Avatar] Offline
#2
Hi,

I can only assume that when you copied the source (or typed it in manually) you
accidentally added non-LF characters at the end of the the "statistics" lines, i.e. the difference is in whitespace.

cheers
Dierk
341781 (5) [Avatar] Offline
#3
No whitespace.

assert statistic == """
necessities: 4
bare: 4
the: 3
your: 2
life: 1
"""
341781 (5) [Avatar] Offline
#4
Okay, I added the whitespace in and the assert works. Picky.

I've attached the good code.
Mittie (397) [Avatar] Offline
#5
Yeah, the assertion reads nice but needs very careful handling smilie

Glad it works now for you.

keep groovin'
Dierk