X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FQuickSortTest.java;h=4acb490acdb6275115e014a938d821cead0fba37;hb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;hp=fac463ac5c3ca813037ea4719de364c019457dab;hpb=ab22918ab8fc67d30dad1fb1ae0f37e51f49df95;p=jalview.git diff --git a/test/jalview/util/QuickSortTest.java b/test/jalview/util/QuickSortTest.java index fac463a..4acb490 100644 --- a/test/jalview/util/QuickSortTest.java +++ b/test/jalview/util/QuickSortTest.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) + * Copyright (C) 2015 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.util; import static org.testng.AssertJUnit.assertEquals; @@ -20,87 +40,74 @@ public class QuickSortTest private Object[] things; - private final Object[] sortedThings = new Object[] - { c4, c2, c1, c3 }; + private final Object[] sortedThings = new Object[] { c4, c2, c1, c3 }; - @BeforeMethod + @BeforeMethod(alwaysRun = true) public void setUp() { - things = new Object[] - { c1, c2, c3, c4 }; + things = new Object[] { c1, c2, c3, c4 }; } - @Test(groups ={ "Functional" }) + @Test(groups = { "Functional" }) public void testSort_byIntValues() { - int[] values = new int[] - { 3, 2, 4, 1 }; + int[] values = new int[] { 3, 2, 4, 1 }; QuickSort.sort(values, things); - assertTrue(Arrays.equals(new int[] - { 1, 2, 3, 4 }, values)); + assertTrue(Arrays.equals(new int[] { 1, 2, 3, 4 }, values)); assertTrue(Arrays.equals(sortedThings, things)); } - @Test(groups ={ "Functional" }) + @Test(groups = { "Functional" }) public void testSort_byFloatValues() { - float[] values = new float[] - { 3f, 2f, 4f, 1f }; + float[] values = new float[] { 3f, 2f, 4f, 1f }; QuickSort.sort(values, things); - assertTrue(Arrays.equals(new float[] - { 1f, 2f, 3f, 4f }, values)); + assertTrue(Arrays.equals(new float[] { 1f, 2f, 3f, 4f }, values)); assertTrue(Arrays.equals(sortedThings, things)); } - @Test(groups ={ "Functional" }) + @Test(groups = { "Functional" }) public void testSort_byDoubleValues() { - double[] values = new double[] - { 3d, 2d, 4d, 1d }; + double[] values = new double[] { 3d, 2d, 4d, 1d }; QuickSort.sort(values, things); - assertTrue(Arrays.equals(new double[] - { 1d, 2d, 3d, 4d }, values)); + assertTrue(Arrays.equals(new double[] { 1d, 2d, 3d, 4d }, values)); assertTrue(Arrays.equals(sortedThings, things)); } /** * Sort by String is descending order, case-sensitive */ - @Test(groups ={ "Functional" }) + @Test(groups = { "Functional" }) public void testSort_byStringValues() { - String[] values = new String[] - { "JOHN", "henry", "lucy", "ALISON" }; + String[] values = new String[] { "JOHN", "henry", "lucy", "ALISON" }; QuickSort.sort(values, things); - assertTrue(Arrays.equals(new String[] - { "lucy", "henry", "JOHN", "ALISON" }, values)); - assertTrue(Arrays.equals(new Object[] - { c3, c2, c1, c4 }, things)); + assertTrue(Arrays.equals(new String[] { "lucy", "henry", "JOHN", + "ALISON" }, values)); + assertTrue(Arrays.equals(new Object[] { c3, c2, c1, c4 }, things)); } /** * Test whether sort is stable i.e. equal values retain their mutual ordering. */ - @Test(groups = - { "Functional" }, enabled = false) + @Test(groups = { "Functional" }, enabled = false) public void testSort_withDuplicates() { - int[] values = new int[] - { 3, 4, 2, 4, 1 }; - Object [] things = new Object [] {"A", "X", "Y", "B", "Z"}; + int[] values = new int[] { 3, 4, 2, 4, 1 }; + Object[] things = new Object[] { "A", "X", "Y", "B", "Z" }; QuickSort.sort(values, things); - assertTrue(Arrays.equals(new int[] - { 1, 2, 3, 4, 4 }, values)); + assertTrue(Arrays.equals(new int[] { 1, 2, 3, 4, 4 }, values)); // this fails - do we care? - assertTrue(Arrays.equals(new Object[] - { "Z", "Y", "A", "X", "B" }, things)); + assertTrue(Arrays.equals(new Object[] { "Z", "Y", "A", "X", "B" }, + things)); } /** * Test that exercises sort with a mostly zero-valued sortby array. May be of * interest to check the sort algorithm is efficient. */ - @Test(groups ={ "Functional" }) + @Test(groups = { "Functional" }) public void testSort_MostlyZeroValues() { char[] residues = new char[64];