small medium large xlarge

06 Jun 2017, 16:34
Dan McHarness (7 posts)

I’m attempting to write a Doctest for IslandsEngine.Guesses, recreating the iex session from page 17 of the latest book release.

I’ve figured out how to represent an empty MapSet in a doctest as:

%IslandsEngine.Guesses{hits: %MapSet{}, misses: %MapSet{}}

However, I cannot figure out how to represent a MapSet that contains an IslandsEngine.Coordinate.

From the book I’m attempting to convert the example MapSet (which doctest does not like):

hits: #MapSet<[%IslandsEngine.Coordinate{col: 1, row: 1}]>,
misses: #MapSet<[]>

To the following MapSet:

hits: %MapSet{%IslandsEngine.Coordinate{col: 1, row: 1}},
misses: %MapSet{}

Doctest accepts the empty MapSet (misses: %MapSet{}) portion, but doesn’t like hits: that contains the Coordinate, reporting a: ‘syntax error before: ‘}’ ??

Any ideas anyone?


09 Jul 2017, 15:03
Derrick Zhang (1 post)

Hi Dan, I came across the same question as yours. And after a few attempts, I found the doctest can be written like this:

%Guesses{hits:[]), misses:[])}

Looks like the expected result of the doctest is not the string presentation of the value, it is an express which reduce the same value, like the normal ExUnit assertions.

So if you have a doctest like this:

iex> 1 + 1
3 - 1

It will also pass.

You must be logged in to comment