Created
January 14, 2012 10:08
-
-
Save dmitrygusev/1610889 to your computer and use it in GitHub Desktop.
SSF4J Usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.anjlab.ssf4j; | |
import static org.junit.Assert.assertArrayEquals; | |
import org.junit.Test; | |
public class SortHandlerTest { | |
@Test | |
public void testSort() { | |
final String[] names = new String[] { "Three", "One", "Two", "Zero" }; | |
final int[] weights = new int[] { 3, 1, 2, 0 }; | |
SortHandler<Integer> handler = | |
new SortHandler<Integer>() { | |
public int from() { | |
return 0; | |
} | |
public int to() { | |
return weights.length - 1; | |
} | |
public Integer get(int index) { | |
return weights[index]; | |
} | |
public int compare(Integer a, Integer b) { | |
return b - a; | |
} | |
public void swap(int i, int j) { | |
Utils.swap(weights, i, j); | |
Utils.swap(names, i, j); | |
} | |
}; | |
handler.sort(); | |
assertArrayEquals(new String[] { "Zero", "One", "Two", "Three" }, names); | |
assertArrayEquals(new int[] { 0, 1, 2, 3 }, weights); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment