diff --git a/Source/Factories/Sorting.swift b/Source/Factories/Sorting.swift index 34e0303..77d5eed 100644 --- a/Source/Factories/Sorting.swift +++ b/Source/Factories/Sorting.swift @@ -186,11 +186,11 @@ public class Sorting { insertion sort algorithm - (Generics) */ - func insertionSortG(numberList: [T]) -> [T] { + func insertionSortG(sequence: [T]) -> [T] { //mutated copy - var output = Array(numberList) + var output = Array(sequence) for primaryIndex in 0.. -1; secondaryIndex-- { - print("comparing \(key) and \(numberList[secondaryIndex])") + print("comparing \(key) and \(sequence[secondaryIndex])") if key < output[secondaryIndex] { @@ -268,14 +268,14 @@ public class Sorting { bubble sort algorithm - (Generics) */ - func bubbleSortG(numberList: [T]) -> [T] { + func bubbleSortG(sequence: [T]) -> [T] { //mutated copy - var output = Array(numberList) + var output = Array(sequence) - for primaryIndex in 0..(numberList: [T]) -> [T] { + func selectionSortG(sequence: [T]) -> [T] { //mutated copy - var output = Array(numberList) + var output = Array(sequence) for primaryIndex in 0.. + + + + + + diff --git a/SwiftTests/SortingTest.swift b/SwiftTests/SortingTest.swift index ba16b6b..677a892 100644 --- a/SwiftTests/SortingTest.swift +++ b/SwiftTests/SortingTest.swift @@ -16,13 +16,15 @@ class SortingTest: XCTestCase { private var numberList: Array! + private var textList: Array! private var sortTest: Sorting! - override func setUp() { super.setUp() + numberList = [8, 2, 10, 9, 7, 5] + textList = ["Dog", "Cat", "Dinasour", "Lion", "Cheetah", "Gazelle", "Elephant", "Aardvark"] sortTest = Sorting() } @@ -54,7 +56,7 @@ class SortingTest: XCTestCase { */ func testBinarySearchClosure() { - + var searchList: Array = Array() var isFound: Bool = false @@ -86,9 +88,12 @@ class SortingTest: XCTestCase { func testInsertionSort() { let resultList: Array = sortTest.insertionSort(numberList) + let sequence = sortTest.insertionSortG(textList) + //evaluate results XCTAssertTrue(self.IsSorted(resultList), "item sequence not in sorted order..") + XCTAssertTrue(self.IsSorted(sequence), "item sequence not in sorted order..") } @@ -96,10 +101,13 @@ class SortingTest: XCTestCase { func testBubbleSort() { - let resultList: Array = sortTest.bubbleSort(numberList) - + let resultsList: Array = sortTest.bubbleSort(numberList) + let sequence = sortTest.bubbleSortG(textList) + + //evaluate results - XCTAssertTrue(self.IsSorted(resultList), "item sequence not in sorted order..") + XCTAssertTrue(self.IsSorted(resultsList), "item sequence not in sorted order..") + XCTAssertTrue(self.IsSorted(sequence), "item sequence not in sorted order..") } @@ -108,10 +116,12 @@ class SortingTest: XCTestCase { func testSelectionSort() { let resultList: Array = sortTest.selectionSort(numberList) + let sequence = sortTest.insertionSortG(textList) + //evaulate results XCTAssertTrue(self.IsSorted(resultList), "item sequence not in sorted order..") - + XCTAssertTrue(self.IsSorted(sequence), "item sequence not in sorted order..") } @@ -142,8 +152,8 @@ class SortingTest: XCTestCase { //MARK: Helper Function - //determine sorted list - func IsSorted(sequence: Array) -> Bool { + //generic method to determine sorted order + func IsSorted(sequence: [T]) -> Bool { for var primaryIndex = 0; primaryIndex < sequence.count; primaryIndex++ {