I couldn’t go on for much longer in Io without somehow testing my code. I’m okay with printing out results for a little while, but as soon as i come to refactoring my code i feel the need to assert somehow the results i’m expecting.
I had a nice chat with Matt Pep about it and tried a few things before i came to the idea of adding a shouldEqual slot on Object so that anything can assert equality.
Object shouldEqual := method(expected, if(self == expected, "." print, ("Expected " .. self .. " to equal " .. expected) println ) )
This means i can do a few things like this:
myList := List2d clone myList dim(3, 5) myList items size shouldEqual(5)
And things like this:
myList set(2, 3, "Middle") myList get(2, 3) shouldEqual("Middle")
The only question i have now is: how do i take that assertEqual slot definition out of this file and into a file of its own that i can include everywhere from now on?
I’d like to do something like:
How would you do such a thing in Io?
I’m afraid i still haven’t finished Day 2’s exercises yet! I must move on to Day 3 tomorrow …! :)
Susan Potter has found the answer! I will try this later: Io’s “require”