1 package junit.tests; 2 3 import java.util.Vector ; 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 values, int left, int right) { 12 Object tmp= values.elementAt(left); 13 values.setElementAt(values.elementAt(right), left); 14 values.setElementAt(tmp, right); 15 } 16 } 17 18 public SorterTest(String name) { 19 super(name); 20 } 21 22 public void testSort() throws Exception { 23 Vector v= new Vector (); 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 |