Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b354715

Browse files
Modified Insertion and Selection Sort test class to use SortTester
1 parent 02a91b7 commit b354715

File tree

2 files changed

+7
-59
lines changed

2 files changed

+7
-59
lines changed
Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
11
package br.com.zevolution.algorithms.sorting.insertionsort;
22

3-
import static org.junit.Assert.assertEquals;
3+
import static br.com.zevolution.algorithms.sorting.SortTester.testSort;
44

5-
import org.junit.Before;
65
import org.junit.Test;
76

8-
import br.com.zevolution.algorithms.sorting.Product;
9-
107
public class InsertionSortTest {
118

12-
private static final double CHEAPEST_PRODUCT = 5;
13-
private static final double MOST_EXPENSIVE_PRODUCT = 50;
14-
private Product[] products;
15-
16-
@Before
17-
public void init() {
18-
Product[] array = {
19-
new Product("iMac", MOST_EXPENSIVE_PRODUCT),
20-
new Product("iPhone", 8),
21-
new Product("Notebook", 7),
22-
new Product("Keyboard", 9),
23-
new Product("Mouse", CHEAPEST_PRODUCT)
24-
};
25-
this.products = array;
26-
}
27-
28-
@Test
29-
public void should_Get_CheapestProduct() {
30-
Product[] ordened = InsertionSort.sortingByCheapest(this.products, this.products.length);
31-
assertEquals(CHEAPEST_PRODUCT, ordened[0].getPrice(), 0);
32-
}
33-
349
@Test
35-
public void should_Get_MostExpensiveProduct() {
36-
Product[] ordened = InsertionSort.sortingByCheapest(this.products, this.products.length);
37-
assertEquals(MOST_EXPENSIVE_PRODUCT, ordened[ordened.length - 1].getPrice(), 0);
10+
public void should_Sort_Array() {
11+
testSort(new InsertionSort());
3812
}
3913

4014
}
Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
11
package br.com.zevolution.algorithms.sorting.selectionsort;
22

3-
import static org.junit.Assert.assertEquals;
3+
import static br.com.zevolution.algorithms.sorting.SortTester.testSort;
44

5-
import org.junit.Before;
65
import org.junit.Test;
76

8-
import br.com.zevolution.algorithms.sorting.Product;
9-
107
public class SelectionSortTest {
118

12-
private static final double CHEAPEST_PRODUCT = 5;
13-
private static final double MOST_EXPENSIVE_PRODUCT = 50;
14-
private Product[] products;
15-
16-
@Before
17-
public void init() {
18-
Product[] array = {
19-
new Product("iMac", MOST_EXPENSIVE_PRODUCT),
20-
new Product("iPhone", 8),
21-
new Product("Notebook", 7),
22-
new Product("Keyboard", 9),
23-
new Product("Mouse", CHEAPEST_PRODUCT)
24-
};
25-
this.products = array;
26-
}
27-
289
@Test
29-
public void should_Get_CheapestProduct() {
30-
Product[] ordened = SelectionSort.sortingByCheapest(this.products, this.products.length);
31-
assertEquals(CHEAPEST_PRODUCT, ordened[0].getPrice(), 0);
10+
public void should_Sort_Array() {
11+
testSort(new SelectionSort());
3212
}
33-
34-
@Test
35-
public void should_Get_MostExpensiveProduct() {
36-
Product[] ordened = SelectionSort.sortingByCheapest(this.products, this.products.length);
37-
assertEquals(MOST_EXPENSIVE_PRODUCT, ordened[ordened.length - 1].getPrice(), 0);
38-
}
39-
13+
4014
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /