Skip to content

Commit a490db7

Browse files
author
danieldahan
committed
updated README
1 parent 5624b65 commit a490db7

File tree

4 files changed

+64
-50
lines changed

4 files changed

+64
-50
lines changed

Algorithm.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Algorithm'
3-
s.version = '1.0.0'
3+
s.version = '1.0.1'
44
s.license = 'BSD'
55
s.summary = 'A toolset for writing algorithms in Swift.'
66
s.homepage = 'http://graphkit.io'

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ The above examples are quite simple. They use basic calculations to determine th
5757
```swift
5858
let die: Array<Int> = Array<Int>(arrayLiteral: 1, 2, 3, 4, 5, 6)
5959

60-
let probabilityOfX: Double = purchased.probabilityOf { (number: Int) in
61-
if 1 < number && 0 == number % 3 {
60+
let probabilityOfX: Double = die.probabilityOf { (number: Int) in
61+
if 5 < number || 0 == number % 3 {
6262
// Do more.
6363
return true
6464
}
6565
return false
6666
}
6767

68-
if 33.33 < probabilityOfX {
68+
if 0.33 < probabilityOfX {
6969
// Do something.
7070
}
7171
```

Sources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.0.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Tests/ProbabilityTests.swift

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
2+
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -33,147 +33,161 @@ import XCTest
3333

3434
class ProbabilityTests: XCTestCase {
3535
var saveExpectation: XCTestExpectation?
36-
36+
3737
override func setUp() {
3838
super.setUp()
3939
}
40-
40+
4141
override func tearDown() {
4242
super.tearDown()
4343
}
44-
44+
4545
func testSortedSet() {
4646
let s: SortedSet<Int> = SortedSet<Int>()
4747
XCTAssertEqual(0, s.probabilityOf({ _ -> Bool in return true}))
48-
48+
4949
s.insert(1, 2, 3, 3)
50-
50+
5151
let ev1: Double = 16 * s.probabilityOf(2, 3)
52-
52+
5353
XCTAssertEqual(ev1, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
54-
54+
5555
let ev2: Double = 16 * s.probabilityOf { (element: Int) -> Bool in
5656
return 2 == element || 3 == element
5757
}
58-
58+
5959
XCTAssertEqual(ev2, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
60-
60+
6161
s.removeAll()
6262
XCTAssert(0 == s.count, "Test failed.")
6363
}
64-
64+
6565
func testSortedMultiSet() {
6666
let s: SortedSet<Int> = SortedSet<Int>()
6767
XCTAssertEqual(0, s.probabilityOf({ _ -> Bool in return true}))
68-
68+
6969
s.insert(1, 2, 3, 3)
70-
70+
7171
let ev1: Double = 16 * s.probabilityOf(2, 3)
72-
72+
7373
XCTAssertEqual(ev1, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
74-
74+
7575
let ev2: Double = 16 * s.probabilityOf { (element: Int) -> Bool in
7676
return 2 == element || 3 == element
7777
}
78-
78+
7979
XCTAssertEqual(ev2, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
80-
80+
8181
s.removeAll()
8282
XCTAssert(0 == s.count, "Test failed.")
8383
}
84-
84+
8585
func testSortedDictionary() {
8686
let s: SortedDictionary<Int, Int> = SortedDictionary<Int, Int>()
8787
XCTAssertEqual(0, s.probabilityOf({ _ -> Bool in return true}))
88-
88+
8989
s.insert((1, 1))
9090
s.insert((2, 2))
9191
s.insert((3, 3))
9292
s.insert((3, 3))
93-
93+
9494
let ev1: Double = 16 * s.probabilityOf(2, 3)
95-
95+
9696
XCTAssertEqual(ev1, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
97-
97+
9898
let ev2: Double = 16 * s.probabilityOf { (key: Int, value: Int?) -> Bool in
9999
return 2 == value || 3 == value
100100
}
101-
101+
102102
XCTAssertEqual(ev2, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
103-
103+
104104
s.removeAll()
105105
XCTAssert(0 == s.count, "Test failed.")
106106
}
107-
107+
108108
func testSortedMultiDictionary() {
109109
let s: SortedMultiDictionary<Int, Int> = SortedMultiDictionary<Int, Int>()
110110
XCTAssertEqual(0, s.probabilityOf({ _ -> Bool in return true}))
111-
111+
112112
s.insert((1, 1))
113113
s.insert((2, 2))
114114
s.insert((3, 3))
115115
s.insert((3, 3))
116-
116+
117117
let ev1: Double = 16 * s.probabilityOf(2, 3)
118-
118+
119119
XCTAssertEqual(ev1, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
120-
120+
121121
let ev2: Double = 16 * s.probabilityOf { (key: Int, value: Int?) -> Bool in
122122
return 2 == value || 3 == value
123123
}
124-
124+
125125
XCTAssertEqual(ev2, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
126-
126+
127127
s.removeAll()
128128
XCTAssert(0 == s.count, "Test failed.")
129129
}
130-
130+
131131
func testArray() {
132132
var s: Array<Int> = Array<Int>()
133133
XCTAssertEqual(0, s.probabilityOf({ _ -> Bool in return true}))
134-
134+
135135
s.append(1)
136136
s.append(2)
137137
s.append(3)
138138
s.append(4)
139-
139+
140140
let ev1: Double = 16 * s.probabilityOf(2, 3)
141-
141+
142142
XCTAssertEqual(ev1, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
143-
143+
144144
let ev2: Double = 16 * s.probabilityOf { (element: Int) -> Bool in
145145
return 2 == element || 3 == element
146146
}
147-
147+
148148
XCTAssertEqual(ev2, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
149-
149+
150150
s.removeAll()
151151
XCTAssert(0 == s.count, "Test failed.")
152152
}
153-
153+
154154
func testSet() {
155155
var s: Set<Int> = Set<Int>()
156156
XCTAssertEqual(0, s.probabilityOf({ _ -> Bool in return true}))
157-
157+
158158
s.insert(1)
159159
s.insert(2)
160160
s.insert(3)
161161
s.insert(4)
162-
162+
163163
let ev1: Double = 16 * s.probabilityOf(2, 3)
164-
164+
165165
XCTAssertEqual(ev1, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
166-
166+
167167
let ev2: Double = 16 * s.probabilityOf { (element: Int) -> Bool in
168168
return 2 == element || 3 == element
169169
}
170-
170+
171171
XCTAssertEqual(ev2, s.expectedValueOf(16, elements: 2, 3), "Test failed.")
172-
172+
173173
s.removeAll()
174174
XCTAssertEqual(0, s.count)
175175
}
176176

177+
func testBlock() {
178+
let die: Array<Int> = Array<Int>(arrayLiteral: 1, 2, 3, 4, 5, 6)
179+
180+
let probabilityOfX: Double = die.probabilityOf { (number: Int) in
181+
if 5 < number || 0 == number % 3 {
182+
// Do more.
183+
return true
184+
}
185+
return false
186+
}
187+
188+
XCTAssertTrue(0.33 < probabilityOfX, "Test failed.")
189+
}
190+
177191
func testPerformance() {
178192
self.measureBlock() {}
179193
}

0 commit comments

Comments
 (0)