Skip to content

Commit

Permalink
B-Tree Playground & Tests updated to Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
shabirjan committed Jul 31, 2017
1 parent 0e0ae64 commit aad5d28
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 44 deletions.
7 changes: 6 additions & 1 deletion B-Tree/BTree.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import Foundation

// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif

let bTree = BTree<Int, Int>(order: 1)!

bTree.insert(1, for: 1)
Expand All @@ -15,7 +20,7 @@ bTree[3]
bTree.remove(2)

bTree.traverseKeysInOrder { key in
print(key)
print(key)
}

bTree.numberOfKeys
Expand Down
6 changes: 4 additions & 2 deletions B-Tree/Tests/Tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand Down Expand Up @@ -219,6 +220,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -232,7 +234,7 @@
PRODUCT_BUNDLE_IDENTIFIER = viktorsimko.Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -245,7 +247,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = viktorsimko.Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
87 changes: 46 additions & 41 deletions B-Tree/Tests/Tests/BTreeNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,50 @@
import XCTest

class BTreeNodeTests: XCTestCase {

let owner = BTree<Int, Int>(order: 2)!
var root: BTreeNode<Int, Int>!
var leftChild: BTreeNode<Int, Int>!
var rightChild: BTreeNode<Int, Int>!

override func setUp() {
super.setUp()

root = BTreeNode(owner: owner)
leftChild = BTreeNode(owner: owner)
rightChild = BTreeNode(owner: owner)

root.insert(1, for: 1)
root.children = [leftChild, rightChild]
}

func testIsLeafRoot() {
XCTAssertFalse(root.isLeaf)
}

func testIsLeafLeaf() {
XCTAssertTrue(leftChild.isLeaf)
XCTAssertTrue(rightChild.isLeaf)
}

func testOwner() {
XCTAssert(root.owner === owner)
XCTAssert(leftChild.owner === owner)
XCTAssert(rightChild.owner === owner)
}

func testNumberOfKeys() {
XCTAssertEqual(root.numberOfKeys, 1)
XCTAssertEqual(leftChild.numberOfKeys, 0)
XCTAssertEqual(rightChild.numberOfKeys, 0)
}

func testChildren() {
XCTAssertEqual(root.children!.count, 2)
}

let owner = BTree<Int, Int>(order: 2)!
var root: BTreeNode<Int, Int>!
var leftChild: BTreeNode<Int, Int>!
var rightChild: BTreeNode<Int, Int>!
func testSwift4() {
// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif
}
override func setUp() {
super.setUp()

root = BTreeNode(owner: owner)
leftChild = BTreeNode(owner: owner)
rightChild = BTreeNode(owner: owner)

root.insert(1, for: 1)
root.children = [leftChild, rightChild]
}

func testIsLeafRoot() {
XCTAssertFalse(root.isLeaf)
}

func testIsLeafLeaf() {
XCTAssertTrue(leftChild.isLeaf)
XCTAssertTrue(rightChild.isLeaf)
}

func testOwner() {
XCTAssert(root.owner === owner)
XCTAssert(leftChild.owner === owner)
XCTAssert(rightChild.owner === owner)
}

func testNumberOfKeys() {
XCTAssertEqual(root.numberOfKeys, 1)
XCTAssertEqual(leftChild.numberOfKeys, 0)
XCTAssertEqual(rightChild.numberOfKeys, 0)
}

func testChildren() {
XCTAssertEqual(root.children!.count, 2)
}
}
7 changes: 7 additions & 0 deletions B-Tree/Tests/Tests/BTreeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import XCTest
class BTreeTests: XCTestCase {
var bTree: BTree<Int, Int>!

func testSwift4() {
// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif
}

override func setUp() {
super.setUp()
bTree = BTree<Int, Int>(order: 3)!
Expand Down

0 comments on commit aad5d28

Please sign in to comment.