-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHashTest.swift
83 lines (52 loc) · 1.98 KB
/
HashTest.swift
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// ListTest.swift
// SwiftStructures
//
// Created by Wayne Bishop on 7/6/16.
// Copyright © 2016 Arbutus Software Inc. All rights reserved.
//
import XCTest
@testable import SwiftStructures
class HashTest: XCTestCase {
override func setUp() {
super.setUp()
}
//test strings
func testStringList() {
/*
note: each element has its own potential 'slot' in the
hash list. In this scenario, the hash table algorithm will
implement 'separate chaining' to support 'hash collisions'.
*/
//new string list
let slist = HashTable<String>(capacity: 3)
_ = slist.insert("Wayne Bishop")
_ = slist.insert("Frank Smith")
_ = slist.insert("Jennifer Hobbs")
_ = slist.insert("Tim Cook")
_ = slist.insert("Steve Jobs")
_ = slist.insert("Wayne Bishop") //should produce collision
_ = slist.insert("Larry Page")
_ = slist.insert("Albert Einstien")
//test list compliance
XCTAssertTrue(slist.contains("Frank Smith"), "hash table element not found..")
}
//test verticies - custom
func testVertexList() {
let testVertex: Vertex = Vertex()
testVertex.key = "A"
let vList: HashTable = HashTable<Vertex>(capacity: 10)
_ = vList.insert(testVertex)
//test list compliance
XCTAssertTrue(vList.contains("A"), "hash table element not found..")
}
//test floats
func testMissingList() {
//new float list
let fList = HashTable<Double>(capacity: 5)
_ = fList.insert(10.2)
_ = fList.insert(8.6)
//element doesn't exist
XCTAssertFalse(fList.contains(3.7), "hash table element not found..")
}
}