Writing a unit test in Elm

Series: Snake in Elm, Elm makes me happy, Elm Basics, Elm Unit Test

I’ve been having fun with Elm programming recently. Elm is a replacement for JavaScript that is pure functional and highly practical.

Here’s how to go from nothing installed at all to writing a unit test that passes, in just over 10 minutes.

The source code is here: github.com/andybalaam/elm-unit-test-example

Code for detecting when you leave an Android app

Further to Detecting whether an Android app is stopping (or starting), I implemented code to decide when you are leaving or entering my game Rabbit Escape.

The relevant class is called Lifecycle2SoundEvents. (Yes, it’s a terrible name. Yes, I spent a long time trying to name it, and this is the best I came up with.)

And the tests, which are in TestLifecycle2SoundEvents, look like this:

public void Press_the_home_button_api10_causes_pause()
    Tester t = new Tester( activity1 );

    t.in.onSaveInstanceState( activity1 );
    t.in.onPause( activity1 );
    t.in.onStop( activity1 );

    // When we press home, we must at least pause (really we stop)

which I was reasonably pleased with, because they match my original blog post Order of Android Activity lifecycle events fairly well, without too much noise.

Mocks are Bad, Layers are Bad

In which I argue that mocks are a code smell, and layers lead to increased coupling:

Mocks are Bad, Layers are Bad (in ACCU‘s Overload Journal issue 127)

I also suggest some ways to avoid both mocks and layers, including Classical TDD, Selfish Object, Refactor to Functional and, of course, the Unix Philosophy. I work through a code example to demonstrate some of these things.

I also suggest that frameworks and inheritance hierarchies are bad, but the title was getting too long already.

You can also get the PDF of Overload 127.

Rabbit Escape (a bit like Lemmings) v0.1 released for Linux, Windows and Mac

Today I am releasing the first version of my new game, Rabbit Escape.

It’s an arcade puzzle game inspired by Lemmings and Pingus, but intended to be simpler and easier to control on a mobile device.

Your task is to guide a party of rabbits from the entrance to the exit by dropping tokens in front of them that give them special abilities such as building bridges or climbing walls.

Here’s what it looks like:

Rabbit Escape

An Android version will be coming soon, but for now I’m releasing the desktop version for Linux, Windows and Mac.

There are 60 levels, and I’m hoping people will be sending me lots more soon!

I plan to write a level editor, but for now you can create your own levels by editing text files.

The game is Free Software under GPL v2, and the graphics, levels etc. are released under the non-commercial Creative Commons BY-NC-SA licence. The choice of a non-commercial license for these parts is intended to prevent people copying the game wholesale onto an app store and making money from it. If you want to use it under a different license, please contact me.

I plan to charge the minimum price on the Android store, and offer the desktop version for free (providing an opportunity for donations).

Please try it out and let me know how you get on. It’s a bit rough around the edges, but the game mechanics work, and it seems like it might be fun.

If you’d like to contribute, I’d be very excited! You can find the code at github.com/andybalaam/rabbit-escape.