Skip to content

Commit 3226454

Browse files
committed
Conversion to Swift 4
1 parent 069caf4 commit 3226454

File tree

2 files changed

+57
-82
lines changed

2 files changed

+57
-82
lines changed
File renamed without changes.

Tests/GeoFeaturesTests/AVLTreeTests.swift renamed to Tests/AVLTreeTests.swift

Lines changed: 57 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/// Created by Tony Stone on 11/26/2016.
1919
///
2020
import XCTest
21-
@testable import GeoFeatures
21+
@testable import AVLTree
2222

2323
///
2424
/// Test AVL Trees
@@ -578,7 +578,7 @@ class AVLTreeTests: XCTestCase {
578578
if let node = input.tree.search(value: input.value) {
579579
XCTAssertEqual(input.tree.next(node: node)?.value, expected)
580580
} else {
581-
XCTFail("Expected value '\(expected)' not found in tree \(input.tree).")
581+
XCTFail("Expected value '\((expected != nil) ? String(describing: expected) : "nil")' not found in tree \(input.tree).")
582582
}
583583
}
584584

@@ -589,7 +589,7 @@ class AVLTreeTests: XCTestCase {
589589
if let node = input.tree.search(value: input.value) {
590590
XCTAssertEqual(input.tree.previous(node: node)?.value, expected)
591591
} else {
592-
XCTFail("Expected value '\(expected)' not found in tree \(input.tree).")
592+
XCTFail("Expected value '\((expected != nil) ? String(describing: expected) : "nil")' not found in tree \(input.tree).")
593593
}
594594
}
595595

@@ -641,94 +641,76 @@ class AVLTreeTests: XCTestCase {
641641

642642
func testSearchPerformance() {
643643

644-
measureMetrics(XCTestCase.defaultPerformanceMetrics(), automaticallyStartMeasuring: false) {
644+
let tree = { () -> AVLTree<Int> in
645+
let tree = AVLTree<Int>()
645646

646-
let tree = { () -> AVLTree<Int> in
647-
let tree = AVLTree<Int>()
648-
649-
/// Prime the tree with initial values
650-
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
651-
tree.insert(value: i)
652-
}
653-
return tree
654-
}()
655-
let input = stride(from: 0, to: 20000, by: 2) /// 10,000 iterations for the test matching stride of tree
656-
657-
self.startMeasuring()
647+
/// Prime the tree with initial values
648+
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
649+
tree.insert(value: i)
650+
}
651+
return tree
652+
}()
653+
let input = stride(from: 0, to: 20000, by: 2) /// 10,000 iterations for the test matching stride of tree
658654

655+
measure {
659656
for value in input {
660657
let _ = tree.search(value: value)
661658
}
662-
663-
self.stopMeasuring()
664659
}
665660
}
666661

667662
func testInsertPerformance() {
668663

669-
measureMetrics(XCTestCase.defaultPerformanceMetrics(), automaticallyStartMeasuring: false) {
670-
671-
let tree = { () -> AVLTree<Int> in
672-
let tree = AVLTree<Int>()
673-
///
674-
/// Prime the tree with initial values
675-
/// Increment by 2 to allow room to insert using a stride starting at 1 for the input
676-
///
677-
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
678-
tree.insert(value: i)
679-
}
680-
return tree
681-
}()
682-
let input = stride(from: 1, to: 20001, by: 2) /// 10,000 iterations for the test
683-
684-
self.startMeasuring()
664+
let tree = { () -> AVLTree<Int> in
665+
let tree = AVLTree<Int>()
666+
///
667+
/// Prime the tree with initial values
668+
/// Increment by 2 to allow room to insert using a stride starting at 1 for the input
669+
///
670+
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
671+
tree.insert(value: i)
672+
}
673+
return tree
674+
}()
675+
let input = stride(from: 1, to: 20001, by: 2) /// 10,000 iterations for the test
685676

677+
measure {
686678
for value in input {
687679
tree.insert(value: value)
688680
}
689-
690-
self.stopMeasuring()
691681
}
692682
}
693683

694684
func testDeletePerformance() {
695685

696-
measureMetrics(XCTestCase.defaultPerformanceMetrics(), automaticallyStartMeasuring: false) {
697-
698-
let tree = { () -> AVLTree<Int> in
699-
let tree = AVLTree<Int>()
700-
///
701-
/// Prime the tree with initial values
702-
/// Increment by 2 to allow room to insert using a stride starting at 1 for the input
703-
///
704-
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
705-
tree.insert(value: i)
706-
}
707-
return tree
708-
}()
709-
let input = stride(from: 0, to: 20000, by: 2) /// 10,000 iterations for the test
710-
711-
self.startMeasuring()
686+
let tree = { () -> AVLTree<Int> in
687+
let tree = AVLTree<Int>()
688+
///
689+
/// Prime the tree with initial values
690+
/// Increment by 2 to allow room to insert using a stride starting at 1 for the input
691+
///
692+
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
693+
tree.insert(value: i)
694+
}
695+
return tree
696+
}()
697+
let input = stride(from: 0, to: 20000, by: 2) /// 10,000 iterations for the test
712698

699+
measure {
713700
for value in input {
714701
tree.delete(value: value)
715702
}
716-
717-
self.stopMeasuring()
718703
}
719704
}
720705

721706
func testInsertDeleteBestTimePerformance() {
722707

723-
measureMetrics(XCTestCase.defaultPerformanceMetrics(), automaticallyStartMeasuring: false) {
724-
725-
let tree = { () -> AVLTree<Int> in
726-
return AVLTree<Int>()
727-
}()
728-
let input = (iterations: 0..<5000, values: [2, 1]) /// We have a total of 20,000 operations 5,000 x (2 inserts + 2 deletes)
729-
730-
self.startMeasuring()
708+
let tree = { () -> AVLTree<Int> in
709+
return AVLTree<Int>()
710+
}()
711+
let input = (iterations: 0..<5000, values: [2, 1]) /// We have a total of 20,000 operations 5,000 x (2 inserts + 2 deletes)
731712

713+
measure {
732714
for _ in input.iterations {
733715
for value in input.values {
734716
tree.insert(value: value)
@@ -737,30 +719,25 @@ class AVLTreeTests: XCTestCase {
737719
tree.delete(value: value)
738720
}
739721
}
740-
741-
self.stopMeasuring()
742722
}
743723
}
744724

745725
func testInsertDeleteWorstTimePerformance() {
746726

747-
measureMetrics(XCTestCase.defaultPerformanceMetrics(), automaticallyStartMeasuring: false) {
748-
749-
let tree = { () -> AVLTree<Int> in
750-
let tree = AVLTree<Int>()
751-
///
752-
/// Prime the tree with initial values
753-
/// Increment by 2 to allow room to insert using a stride starting at 1 for the input
754-
///
755-
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
756-
tree.insert(value: i)
757-
}
758-
return tree
759-
}()
760-
let input = (iterations: 0..<5000, values: [63987, 63989]) /// We have a total of 20,000 operations 5,000 x (2 inserts + 2 deletes)
761-
762-
self.startMeasuring()
727+
let tree = { () -> AVLTree<Int> in
728+
let tree = AVLTree<Int>()
729+
///
730+
/// Prime the tree with initial values
731+
/// Increment by 2 to allow room to insert using a stride starting at 1 for the input
732+
///
733+
for i in stride(from: 0, to: 64000, by: 2) { /// 32,000 initial values in tree
734+
tree.insert(value: i)
735+
}
736+
return tree
737+
}()
738+
let input = (iterations: 0..<5000, values: [63987, 63989]) /// We have a total of 20,000 operations 5,000 x (2 inserts + 2 deletes)
763739

740+
measure {
764741
for _ in input.iterations {
765742
for value in input.values {
766743
tree.insert(value: value)
@@ -769,8 +746,6 @@ class AVLTreeTests: XCTestCase {
769746
tree.delete(value: value)
770747
}
771748
}
772-
773-
self.stopMeasuring()
774749
}
775750
}
776751
}

0 commit comments

Comments
 (0)