@@ -11,24 +11,69 @@ import XCTest
11
11
12
12
class SortingAlgorithmsTests : XCTestCase {
13
13
14
- override func setUp ( ) {
15
- // Put setup code here. This method is called before the invocation of each test method in the class.
16
- }
14
+ private let bubbleSort = BubbleSort ( )
15
+ private let insertionSort = InsertionSort ( )
16
+ private let selectionSort = SelectionSort ( )
17
17
18
- override func tearDown( ) {
19
- // Put teardown code here. This method is called after the invocation of each test method in the class.
18
+ func test_BubbleSort_non_sorted( ) {
19
+ let swaps : [ ( x0: Int , x1: Int ) ] = bubbleSort. generateSwaps ( from: [ 1 , 3 , 2 , 5 , 4 ] )
20
+
21
+ XCTAssert ( swaps. count == 2 )
22
+ XCTAssert ( ( x0: 1 , x1: 2 ) == swaps [ 0 ] )
23
+ XCTAssert ( ( x0: 3 , x1: 4 ) == swaps [ 1 ] )
20
24
}
21
-
22
- func testExample( ) {
23
- // This is an example of a functional test case.
24
- // Use XCTAssert and related functions to verify your tests produce the correct results.
25
+
26
+ func test_BubbleSort_already_sorted( ) {
27
+ let swaps : [ ( x0: Int , x1: Int ) ] = bubbleSort. generateSwaps ( from: [ 1 , 2 , 3 , 4 , 5 ] )
28
+
29
+ XCTAssert ( swaps. count == 0 )
25
30
}
31
+
32
+ func test_BubbleSort_equal_values( ) {
33
+ let swaps : [ ( x0: Int , x1: Int ) ] = bubbleSort. generateSwaps ( from: [ 1 , 1 , 1 , 1 , 1 ] )
26
34
27
- func testPerformanceExample( ) {
28
- // This is an example of a performance test case.
29
- self . measure {
30
- // Put the code you want to measure the time of here.
31
- }
35
+ XCTAssert ( swaps. count == 0 )
36
+ }
37
+
38
+ func test_InsertionSort_non_sorted( ) {
39
+ let swaps : [ ( x0: Int , x1: Int ) ] = insertionSort. generateSwaps ( from: [ 1 , 3 , 2 , 5 , 4 ] )
40
+
41
+ XCTAssert ( swaps. count == 2 )
42
+ XCTAssert ( ( x0: 2 , x1: 1 ) == swaps [ 0 ] )
43
+ XCTAssert ( ( x0: 4 , x1: 3 ) == swaps [ 1 ] )
44
+ }
45
+
46
+ func test_InsertionSort_already_sorted( ) {
47
+ let swaps : [ ( x0: Int , x1: Int ) ] = insertionSort. generateSwaps ( from: [ 1 , 2 , 3 , 4 , 5 ] )
48
+
49
+ XCTAssert ( swaps. count == 0 )
50
+ }
51
+
52
+ func test_InsertionSort_equal_values( ) {
53
+ let swaps : [ ( x0: Int , x1: Int ) ] = insertionSort. generateSwaps ( from: [ 1 , 1 , 1 , 1 , 1 ] )
54
+
55
+ XCTAssert ( swaps. count == 0 )
56
+ }
57
+
58
+ func test_SelectionSort_non_sorted( ) {
59
+ let swaps : [ ( x0: Int , x1: Int ) ] = selectionSort. generateSwaps ( from: [ 1 , 3 , 2 , 5 , 4 ] )
60
+ print ( swaps)
61
+ XCTAssert ( swaps. count == 2 )
62
+ XCTAssert ( ( x0: 1 , x1: 2 ) == swaps [ 0 ] )
63
+ XCTAssert ( ( x0: 3 , x1: 4 ) == swaps [ 1 ] )
64
+ }
65
+
66
+ func test_SelectionSort_already_sorted( ) {
67
+ let swaps : [ ( x0: Int , x1: Int ) ] = selectionSort. generateSwaps ( from: [ 1 , 2 , 3 , 4 , 5 ] )
68
+
69
+ XCTAssert ( swaps. count == 0 )
70
+ }
71
+
72
+ func test_SelectionSort_equal_values( ) {
73
+ let swaps : [ ( x0: Int , x1: Int ) ] = selectionSort. generateSwaps ( from: [ 1 , 1 , 1 , 1 , 1 ] )
74
+ print ( swaps)
75
+
76
+ XCTAssert ( swaps. count == 0 )
32
77
}
33
78
34
79
}
0 commit comments