KNNClassifier extends Classifier { public ArrayList<ComputedDistance> sortDistances(List<ComputedDistance> computedDistance) { ArrayList<ComputedDistance> sortedDistance = new ArrayList<ComputedDistance>(); for (int i = 0; i < model.k; i++) { double minDistance = Double.MAX_VALUE; int minIndex = -1; for (int j = 0; j < computedDistance.size(); j++) if (minDistance > computedDistance.get(j).distance) { minIndex = j; minDistance = computedDistance.get(j).distance; } if (minIndex == -1) break; sortedDistance.add(new ComputedDistance( computedDistance.get(minIndex).label, computedDistance.get(minIndex).distance)); computedDistance.remove(minIndex); } return sortedDistance; } KNNClassifier(int k, int numFeatures);  KNNClassifier(Object objModel); @Override boolean train(List<FeatureVector> data); @Override int classify(FeatureVector featureVector); @Override Object getModel(); ArrayList<ComputedDistance> sortDistances(List<ComputedDistance> 
	computedDistance); int getMajorityLabel(List<ComputedDistance> sortedDistance ); int getK(); void setK(int k); int getNumFeatures(); boolean setNumFeatures(int numFeatures); public KNNModel model; }
@Test public void testSortDistances() { ArrayList<ComputedDistance> computedDistance = new ArrayList<ComputedDistance>(); for (int i = 8; i > 0; i--) { ComputedDistance cd = new ComputedDistance(1, i*2.0); computedDistance.add(cd); } ArrayList<ComputedDistance> sortedDistance = knnClassifier.sortDistances(computedDistance); assertEquals("Elements returned by sortDistance != k", sortedDistance.size(), k); for (int i = 0; i < sortedDistance.size(); i++) { assertEquals("Elements sorting failed by sortDistance", sortedDistance.get(i).distance, (i+1)*2.0, 0.0); } }