I’ve been playing around with doing some testing of my Android apps, and it turns out to be a little bit more difficult than I’d hoped, but with the aid of some tools it can be brought back under control. Given Android apps are basically just Java, the usual choice would be JUnit. Android needs a bunch of extra classes that aren’t part of the standard Java setup, but given the SDK provides an android.jar it should just be a matter of plugging that into your test stage, right?
Ok, it’s not quite that simple. Doing this gets you “java.lang.RuntimeException: Stub!” rather rapidly. As it turns out, the major purpose of the android.jar is to provide something to compile against, but the actual implementation of the classes is missing, as it’s assumed you’re going to run the app on your device or emulator. Interfacing with either of these is going to be a bit slow and fiddly for unit testing purposes (my netbook for example is perfectly good for Android dev provided you don’t need the emulator…), so that’s out. Something could possibly be worked out using the x86 Android port, but that’s likely to get very complicated very fast, so let’s skip that as well.
The zipper is a purely functional data structure which is useful when manipulating immutable data structures (see the original paper here by Gerard Huet). Haskell and Clojure both have implementations of the zipper, but I have been unable to find one for use with F#. The original implementation is written in OCAML so is relatively easy to port to F# so this post will briefly walk through the code and give an example of its use.
Here I have defined three types:
The location type is a pointer into the tree structure, by manipulating the location we can traverse the tree.
We use two additional functions to create locations and extract the tree from a location.
We also need functions that will actually manipulate the zipper, these differ from Huet’s OCAML in that the parameters have been swapped so that they can be used with the F#
pipe forward (|>) operator.
Now, we have that we can try it out using FSI:
The pipe forward operator combined with the navigation and modification functions produces a nicely readable line of code that traverses and produces an altered tree. The original tree is also unmodified as this is purely functional code.
Soon after I started learning Smalltalk, I found my brain broken. Smalltalk doesn’t have control structures. No ifs, no whiles, no for loops. All these structures are instead patterns of message
Version 1.1 of mercurial-server is now available. This permits one repository to be in a subdirectory of another, which makes subrepositories more convenient, as well as improvements to logging and documentation. I’ve also included the collection of scripts I use for testing under the “dev” subdirectory in the main repository, though I’d want to clean these up somewhat before including them in the release tarballs.
The Debian version also includes fixes for all the outstanding bugs against it in Debian; I’ve sent the files off to the sponsor, so hopefully that’ll enter Debian testing soon.
You are currently browsing the LShift Ltd. blog archives for December, 2010.