forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
43 lines (37 loc) · 1.03 KB
/
Test.java
File metadata and controls
43 lines (37 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Test sorting algorithms for decks of cards.
*/
public class Test {
/**
* Checks that the deck is sorted.
*/
public static void checkSorted(Deck deck) {
Card[] cards = deck.getCards();
for (int i = 0; i < cards.length - 1; i++) {
if (cards[i].compareTo(cards[i + 1]) >= 0) {
System.out.println("Card #" + i + " not sorted!");
}
}
}
/**
* Demonstrates how to call the sorting methods.
*/
public static void main(String[] args) {
Deck deck;
System.out.println("Testing selection...");
deck = new Deck();
deck.shuffle();
deck.selectionSort();
checkSorted(deck);
System.out.println("Testing mergesort...");
deck = new Deck();
deck.shuffle();
deck = deck.mergeSort();
checkSorted(deck);
System.out.println("Testing insertion...");
deck = new Deck();
deck.shuffle();
deck.insertionSort();
checkSorted(deck);
}
}