KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > tests > SorterTest


1 package junit.tests;
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 SorterTest(String JavaDoc name) {
19         super(name);
20     }
21     
22     public void testSort() throws Exception JavaDoc {
23         Vector JavaDoc v= new Vector JavaDoc();
24         v.addElement("c");
25         v.addElement("b");
26         v.addElement("a");
27         Sorter.sortStrings(v, 0, v.size()-1, new Swapper());
28         assertEquals(v.elementAt(0), "a");
29         assertEquals(v.elementAt(1), "b");
30         assertEquals(v.elementAt(2), "c");
31     }
32 }
Popular Tags