Someone must have really been looking forward to work today…

…4.4/5 stars.

Snow day :)

Snow day :)


JUnit 3 & 4 on Ubuntu 8.10

One of the things which I want to start dong more using automated testing for my web applications. jsUnit is the most widely-used testing framework for Ajax applications. jsUnit, along with many other unit-testing frameworks are based off of the Java framework JUnit. Since I’ve been meaning to try out JUnit anyways, I figured now would be as good a time as any. Although the usual way to use JUnit is through Eclipse or an Ant task, I like to do things manually first. Once you can do it from the command-line, testing through Eclipse should be easy.

There seem to be two different versions of JUnit which are widely used: 3.x and 4.x. They are quite different from one another and require different approaches. I’m going to give a simple example of both, starting with version 3.x.

JUnit 3
1. Install JUnit:

$ sudo aptitude install junit

To find out where JUnit was installed to you can use the Debian package management tool, dpkg:

$ dpkg -L junit | grep junit.jar

The “-L” lists the locations of all of the files installed by a particular package. I used grep to have it only show the junit.jar files.

2. Next, set the CLASSPATH environmental variable to point to the JUnit jar file:

$ CLASSPATH=.:/usr/share/java/junit.jar

Don’t forget to include the working directory (the period just after the equals sign) in the classpath, otherwise you will get a “Class not found” error when you try to run the tests.
Also, using the above will only set the variable for your current shell session. To make it stick, edit the .bashrc file in your home directory and add the line:

export CLASSPATH=.:/usr/share/java/junit.jar

3. Test the installation to make sure everything is working:

$ java junit.textui.TestRunner
Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class

Nothing exciting going on here, but at least it seems to be working. This is the same we will initiate the actual testing once we have set some tests up.

4. Create a file called “MyTest1.java”. We will do two tests, one of which should pass and the other should fail.

import junit.framework.*;

public class MyTest1 extends TestCase {

	// Normally you would be testing some function's output, and not some variable you set...
	public void testOne() {
		int a = 2;
		int b = 2;
		int sum = a + b;
		int expected = 4;
		assertEquals(sum, expected); // 2 + 2 = 4?
	//This test should fail...
	public void testTwo() {
		int a = 2;
		int b = 2;
		int sum = a + b +1; // Just pretend that "+1" was a mistake you overlooked
		int expected = 4;
		assertEquals(sum, expected); // 2 + 2 = 5?

5. Compile it and run the tests:

$ javac MyTest1.java 
$ java junit.textui.TestRunner MyTest1
Time: 0.004
There was 1 failure:
1) testTwo(MyTest1)junit.framework.AssertionFailedError: expected: but was:
	at MyTest1.testTwo(MyTest1.java:20)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Tests run: 2,  Failures: 1,  Errors: 0

Notice at the bottom it says that two tests were run, one of which failed. This was just as we expected! Now lets try something similar with JUnit 4.

JUnit 4
JUnit4 should be installed to the same place as JUnit3. Don’t forget to update the CLASSPATH though so that it points to “junit4.jar” instead of “junit3.jar”. The format of the tests is pretty similar but the imports are different and you also have to use the @TEST tag above your test functions (although the functions themselves no longer have to be named “test…”). Also, pay attention to the command used to run the tests: is different from that command used in JUnit 3.

$ sudo aptitude install junit4
$ CLASSPATH=.:/usr/share/java/junit4.jar
$ java org.junit.runner.JUnitCore
JUnit version 4.3.1

Time: 0.001

OK (0 tests)


import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class MyTest2{

	public void testOne() {
		int a = 2;
		int b = 2;
		int sum = a + b;
		int expected = 4;
		assertEquals(sum, expected); // 2 + 2 = 4?

	public void testTwo() {
		int a = 2;
		int b = 2;
		int sum = a + b +1;
		int expected = 4;
		assertEquals(sum, expected); // 2 + 2 = 5?

Compile & Run:

$ javac MyTest2.java 
$ java org.junit.runner.JUnitCore MyTest2
JUnit version 4.3.1
Time: 0.019
There was 1 failure:
1) testTwo(MyTest2)
java.lang.AssertionError: expected: but was:
	at org.junit.Assert.fail(Assert.java:71)
	at org.junit.Assert.failNotEquals(Assert.java:451)
	at org.junit.Assert.assertEquals(Assert.java:99)
	at org.junit.Assert.assertEquals(Assert.java:116)
	at MyTest2.testTwo(MyTest2.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
	at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
	at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
	at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
	at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
	at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at org.junit.internal.runners.CompositeRunner.run(CompositeRunner.java:29)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:109)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:100)
	at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81)
	at org.junit.runner.JUnitCore.main(JUnitCore.java:44)

Tests run: 2,  Failures: 1

Got it! Next up: JSUnit.


For more JUnit info, here are some resources which may be helpful:

JUnit 3 Resources:
[1] http://www.jaredrichardson.net/articles/junit-tutorial.html
[2] http://junit.sourceforge.net/doc/testinfected/testing.htm
[3] http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/junit/junit.html
[4] http://clarkware.com/articles/JUnitPrimer.html
[5] http://en.wikipedia.org/wiki/JUnit

JUnit 4 Resources:
[1] http://pub.admc.com/howtos/junit4x/
[2] http://junit.sourceforge.net/doc/faq/faq.htm
[3] http://junit.sourceforge.net/doc/cookbook/cookbook.htm
[4] http://today.java.net/pub/a/today/2006/12/07/junit-reloaded.html
[5] http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/
[6] http://www.ibm.com/developerworks/edu/j-dw-java-junit4.html


A Simple Quicksort Implementation in Ruby

I’ve recently start playing around with Rails. In the past I’ve used mostly PHP for the server-side. My first impressions of Rails are pretty positive though. Of course, since I haven’t used Ruby before either, I’m going to need to pick up some Ruby programming skills along the way.

I decided to start with something pretty basic: Quicksort. Here is a very simple implementation based entirely off of the algorithm from Cormen, Leiserson, Rivest, and Stein’s book.

# quicksort.rb

def quicksort(list, p, r)
    if p < r then
        q = partition(list, p, r)
        quicksort(list, p, q-1)
        quicksort(list, q+1, r)

def partition(list, p, r)
    pivot = list[r]
    i = p - 1
    p.upto(r-1) do |j|
        if list[j] <= pivot
            i = i+1
            list[i], list[j] = list[j],list[i]
    list[i+1],list[r] = list[r],list[i+1]
    return i + 1

# Testing it out
a = [9,4,10,12,3,5,10,3,2,25,6,21,33,23,19,13,38,26,12,3]
quicksort(a, 0, a.length-1)
puts a

You can do a whole lot better than this of course. Check out


Update on life

It’s been over a couple months now since I’ve written so I thought I’d update people on what has been going on in my life. I hope to resume posting regularly starting this week so check back soon.

As some of you may know, I graduated last December from The University of Maryland, Baltimore County with a B.S. in Bioinformatics and Computational Biology, and a B.S. in Psychology (yes,yes, laugh all you want… It was fun!) The next month or so I spent job hunting and interviewing at various places. I had originally expected that I would end up working somewhere like JCVI, however before I was ever able to get in touch with people there I was offered a really cool job working at the NASA Goddard Space Flight Center in Greenbelt, Maryland.

I’m now working with Solar Physicists there as a web developer. Although in the days to come I will be working on several different projects including a Virtual Solar Observatory, the project I’m currently focused on is called “HelioViewer.” The goals of HelioViewer are to produce something similar to Google Maps, but using solar data. The project is still in it’s infancy, and has a long way to go, but there already a working prototype which includes some basically functionality like loading images, layering, and zooming.

This is what it looks like:

HelioViewer Screenshot

The application is written primarily in Javascript and PHP, and uses the Prototype and Script.aculo.us Javascript Frameworks.

I’ve been developing web applications for a pretty long time now, but up until recently I stuck mostly to server-side languages and have avoided Javascript like the plague. The whole idea of client-side scripting seemed like a dead-end: browser support was variable and the only really interesting applications of Javascript to come out at the time (aside from, of course, blinking text) were browser exploits. Recently, however, with the availability of the XMLHttpRequest object, which is the life-force behind the now-ubiquitous Ajax applications we have come to know and love (think gmail), things are changing for Javascript.

Javascript 2.0, based off ECMAScript version 4, will boast a number of improvements including better OOP support and is (I believe) slated for release at the end of 2008. That’s grand and all but already the web-development community has gotten together and made some extraordinary progress on the Javascript front in the form of Javascript “frameworks.” These frameworks, which include Prototype, Jquery, YUI and Ext JS, make writing full-scale Javascript applications a highly respectable task. I will talk more about these later, but for now, let’s just say I’m a Javascript convert.

Let me step aside for one moment and point out that, while Ajax has become hugely popular for web application/RIA development, it is not the only contender in the arena. Another technology I wrote about a while back, Flex, is also a very able contestant in my opinion. Just this past week it reached a new milestone with the release of the Flex 3. Flex and Ajax applications have their own advantages and weaknesses, and both are worth considering. I also plan to write more about this in the future, but if you are interested in learning more about Flex in the meantime, there are a number of excellent blogs worth checking out including Ted On Flex, Flex Examples, EverythingFlex, InsideRIA.

Finally, as I mentioned above, I graduated with a degree in Bioinformatics. I still love bioinformatics, and am doing my best to keep up with current research in the field. From time to time I will try to post interesting advances in the field, and maybe even write some posts which combine topics in bioinformatics some of the web development technologies I’m working with at the moment. It should be a lot of fun :) If you would like to see what I’m reading in the meantime, feel free to subscribe to my Google Reader Shared items feed. I should warn you though, I am presently subscribed to over 300 feeds on topics ranging from bioinformatics to cute annotated pictures of cats, so be prepared for an interesting mix of items.


Have a merry x-mas… compiz style

One of the cooler, lesser-known plugins for Compiz, xglsnow, was sadly left in the dust with the inclusion of Compiz Fusion into Ubuntu 7.10. That doesn’t mean, however, you can’t still get it working in time for the holiday season! Check out the video below to see the plugin in action.

Here is a screenshot of what it looks like on my machine:

screenshot of xglsnow running on my desktop

Note: This tutorial assumes that you have Compiz or Compiz fusion setup already. If you don’t, however, try searching the forums– there is a huge number of guides floating around on getting Compiz running for different graphics cards.

Ready? Here goes…

I. Installing xglsnow

First, you need to install the necessary packages to build the plugin. Open up a console (alt+F2 -> “gnome-terminal”),
and type:

sudo apt-get install compiz-bcop compiz-dev build-essential libxcomposite-dev libpng12-dev libsm-dev libxrandr-dev libxdamage-dev libxinerama-dev libstartup-notification0-dev libgconf2-dev librsvg2-dev libdbus-1-dev libdbus-glib-1-dev libgnome-desktop-dev x11proto-scrnsaver-dev libxss-dev libxslt1-dev libtool

Create a directory in your home folder to install the plugin to:

mkdir -p ~/compiz/

Download xglsnow and extract it to the directory you just created:

Finally, navigate to the directory, compile and install:

cd ~/compiz/snow

make install

Now you just need to install some textures, configure xgl, and you’re done! :)

*The above steps are based off a tutorial by Scott at the Compiz Fusion forums. Thanks!

II. Adding textures

The above tarball doesn’t include any snow textures, so by default all you would see are some floating white blocks… not very pretty… The package from the xglsnow homepage, however, includes a texture which looks pretty nice. To set it up, go to the xglsnow project homepage and download xglsnow-0.2.0.tar.gz. Extract the files, and copy the file “snowflake2.png” to any location you would like, e.g. ~/.compiz/images or /usr/share/images:

tar -xf xglsnow-0.2.0.tar.gz

cd xglsnow-0.2.0/

mkdir ~/.compiz/images

mv snowflake2.png ~/.compiz/images

If you haven’t already, restart Compiz to load the new plugin (alt+F2 -> “compiz –replace”) and run the Compiz settings manager: alt+F2 -> “ccsm”. Find the “Snow” plugin and check the box to the left of it to enable it.

Compiz settings manager

Now click on the plugin’s name to modify its settings. Next go to “Textures” -> “add” -> “browse” (click the folder icon). Navigate to the location where you saved the texture from above and hit “okay.”

Compiz settings manager (snow configuration)

All done!

Press “Super + F3″ to start xgl snow. If you don’t see anything, check to make sure the the PNG plugin for compiz is enabled, and that the hotkey for xglsnow is in fact “super + F3.”

If you want to install some different snow textures, try the Snowflakes pack on Gnome-look.

III. Wallpapers

Finally, if you want to find some wintry wallpapers to go along with your new snow-covered desktop, take a look at Blue Christmas
from digital blasphemy (that is the one in the screenshot above). Gnome-art has a nice picture of a winter landscape in Alsace, France You can also find some winter wallpapers at Gnome-look and Kde-look.
Try searching for “winter” or “snow.”

That’s all!

Feel free to write any suggestions, or a link to a screenshot of your own holiday desktop :)


Intro Data Mining Webinar (December 13, 2007)

Salford Systems is hosting a free Introductory Data Mining Webinar on December 13, from 10-11am EST.

From the description of the seminar:

This one-hour webinar is a perfect place to start if you are new to data mining and have little-to-no background in statistics or machine learning.

In one hour, we will discuss:

**Data basics: what kind of data is required for data mining and predictive analytics; in what format must the data be; what steps are necessary to prepare data appropriately.

**What kinds of questions can we answer with data mining?

**How data mining models work: the inputs, the outputs, and the nature of the predictive mechanism.

**Evaluation criteria: how predictive models can be assessed and their value measured.

**Specific background knowledge to prepare you to begin a data mining project.

Data mining and the related field of machine learning deal with finding patterns in large sets of data. This is very useful for trying to understand and model complex natural phenomena, and bioinformaticians have not been shy to take advantage of these methods. Just look at any recent issue of BMC Bioinformatics or PLoS Computational Biology and you will see a number of articles involving SVMs, Neural Networks, and Bayesian networks.

This webinar is geared towards people with little or no understanding of data mining, so it should be a good introduction if you haven’t learned about machine learning or data mining. If you are interested in learning more, there are some good tutorials online at here, and here. Videolectures.net and Peteris’s blog include a number of video lectures on the machine learning.

To sign up, go to the event description and click “enroll.”


Bio::Blogs #17 (Courtesy of Mr. Claus) is now available

The seventeenth edition of the premier bioinformatics blog carnival, Bio::Blogs is now available over at Paulo’s blog. Give it a read why don’t you!


(Oh, and the new Futurama movie, Bender’s Big Score is out now too! Oh happy day.)


Get every new post delivered to your Inbox.