KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > runner > SorterTest


1 package junit.tests.runner;
2
3 import java.util.Vector JavaDoc;
4
5 import junit.framework.*;
6 import junit.runner.Sorter;
7
8 public class SorterTest extends TestCase {
9     
10     static class Swapper implements Sorter.Swapper {
11         public void swap(Vector JavaDoc values, int left, int right) {
12             Object JavaDoc tmp= values.elementAt(left);
13             values.setElementAt(values.elementAt(right), left);
14             values.setElementAt(tmp, right);
15         }
16     }
17     
18     public void testSort() throws Exception JavaDoc {
19         Vector JavaDoc v= new Vector JavaDoc();
20         v.addElement("c");
21         v.addElement("b");
22         v.addElement("a");
23         Sorter.sortStrings(v, 0, v.size()-1, new Swapper());
24         assertEquals(v.elementAt(0), "a");
25         assertEquals(v.elementAt(1), "b");
26         assertEquals(v.elementAt(2), "c");
27     }
28 }
Popular Tags