attaswift / BTree
Showing 16 of 32 files from the diff.

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2016–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
class BTreeBuilderTests: XCTestCase {
13 13
    typealias Builder = BTreeBuilder<Int, String>

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2016–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
private final class Test: Comparable, ExpressibleByIntegerLiteral, CustomStringConvertible {
13 13
    let value: Int
@@ -17,12 +17,11 @@
Loading
17 17
18 18
    var description: String { return "\(value)" }
19 19
20 -
    static func ==(a: Test, b: Test) -> Bool { return a.value == b.value }
21 -
    static func <(a: Test, b: Test) -> Bool { return a.value < b.value }
20 +
    static func == (a: Test, b: Test) -> Bool { return a.value == b.value }
21 +
    static func < (a: Test, b: Test) -> Bool { return a.value < b.value }
22 22
}
23 23
24 24
class SortedBagTests: XCTestCase {
25 -
26 25
    func test_emptyBag() {
27 26
        let bag = SortedBag<Int>()
28 27
@@ -46,7 +45,7 @@
Loading
46 45
    }
47 46
48 47
    func test_unsortedElements_uniqueItems() {
49 -
        let c = 10_000
48 +
        let c = 10000
50 49
        let bag = SortedBag((0 ..< c).reversed())
51 50
52 51
        XCTAssertEqual(bag.count, c)
@@ -54,7 +53,7 @@
Loading
54 53
    }
55 54
56 55
    func test_unsortedElements_duplicateItems() {
57 -
        let c = 10_000
56 +
        let c = 10000
58 57
        let bag = SortedBag((0 ..< c).reversed().repeatEach(10))
59 58
60 59
        XCTAssertEqual(bag.count, 10 * c)
@@ -62,7 +61,7 @@
Loading
62 61
    }
63 62
64 63
    func test_sortedElements_uniqueItems() {
65 -
        let c = 10_000
64 +
        let c = 10000
66 65
        let bag = SortedBag(sortedElements: 0 ..< c)
67 66
68 67
        XCTAssertEqual(bag.count, c)
@@ -70,7 +69,7 @@
Loading
70 69
    }
71 70
72 71
    func test_sortedElements_duplicateItems() {
73 -
        let c = 10_000
72 +
        let c = 10000
74 73
        let bag = SortedBag(sortedElements: (0 ..< c).repeatEach(10))
75 74
76 75
        XCTAssertEqual(bag.count, 10 * c)
@@ -96,7 +95,7 @@
Loading
96 95
    }
97 96
98 97
    func test_subscriptWithIndexing() {
99 -
        let c = 10_000
98 +
        let c = 10000
100 99
        let elements = (0 ..< c).repeatEach(3)
101 100
        let bag = SortedBag(elements)
102 101
        var i = 0
@@ -128,14 +127,14 @@
Loading
128 127
    }
129 128
130 129
    func test_makeIterator() {
131 -
        let c = 10_000
130 +
        let c = 10000
132 131
        let elements = (0 ..< c).repeatEach(2)
133 132
        let bag = SortedBag(elements)
134 133
        assertEqualElements(IteratorSequence(bag.makeIterator()), elements)
135 134
    }
136 135
137 136
    func test_subscriptByOffsets() {
138 -
        let c = 10_000
137 +
        let c = 10000
139 138
        let elements = (0 ..< c).repeatEach(2)
140 139
        let bag = SortedBag(elements)
141 140
        for i in 0 ..< 2 * c {
@@ -155,7 +154,7 @@
Loading
155 154
    }
156 155
157 156
    func test_indexing() {
158 -
        let s = SortedBag(sortedElements: (0..<10))
157 +
        let s = SortedBag(sortedElements: 0 ..< 10)
159 158
        var index = s.startIndex
160 159
        XCTAssertEqual(s.index(after: index), s.index(ofOffset: 1))
161 160
        XCTAssertEqual(s.index(index, offsetBy: 5), s.index(ofOffset: 5))
@@ -190,8 +189,7 @@
Loading
190 189
        for m in 0 ..< 20 {
191 190
            if m & 1 == 0 {
192 191
                XCTAssertEqual(s.offset(of: m), m)
193 -
            }
194 -
            else {
192 +
            } else {
195 193
                XCTAssertNil(s.offset(of: m))
196 194
            }
197 195
        }
@@ -201,7 +199,7 @@
Loading
201 199
    }
202 200
203 201
    func test_forEach() {
204 -
        let c = 10_000
202 +
        let c = 10000
205 203
        let bag = SortedBag(0 ..< c)
206 204
        var i = 0
207 205
        bag.forEach { n in
@@ -211,7 +209,7 @@
Loading
211 209
    }
212 210
213 211
    func test_map() {
214 -
        let c = 10_000
212 +
        let c = 10000
215 213
        let bag = SortedBag(0 ..< c)
216 214
        var i = 0
217 215
        let r = bag.map { (n: Int) -> Int in
@@ -341,8 +339,7 @@
Loading
341 339
        for i in 0 ..< 500 {
342 340
            if i & 1 == 0 {
343 341
                XCTAssertEqual(bag.count(of: i), 2)
344 -
            }
345 -
            else {
342 +
            } else {
346 343
                XCTAssertEqual(bag.count(of: i), 0)
347 344
            }
348 345
        }
@@ -356,8 +353,7 @@
Loading
356 353
            if i & 1 == 0 {
357 354
                XCTAssertEqual(index, bag.index(bag.startIndex, offsetBy: i / 2 * 3))
358 355
                XCTAssertEqual(bag[index!], i)
359 -
            }
360 -
            else {
356 +
            } else {
361 357
                XCTAssertNil(index)
362 358
            }
363 359
        }
@@ -374,8 +370,7 @@
Loading
374 370
                guard let index = index else { continue }
375 371
                XCTAssertEqual(bag.offset(of: index), 3 * (i / 2 + 1))
376 372
                XCTAssertEqual(bag[index], 2 * (i / 2 + 1))
377 -
            }
378 -
            else {
373 +
            } else {
379 374
                XCTAssertNil(index)
380 375
            }
381 376
        }
@@ -395,13 +390,11 @@
Loading
395 390
                if i & 1 == 0 {
396 391
                    XCTAssertEqual(offset, 3 * (i / 2))
397 392
                    XCTAssertEqual(element, i)
398 -
                }
399 -
                else {
393 +
                } else {
400 394
                    XCTAssertEqual(offset, 3 * (i / 2 + 1))
401 395
                    XCTAssertEqual(element, i + 1)
402 396
                }
403 -
            }
404 -
            else {
397 +
            } else {
405 398
                XCTAssertNil(index)
406 399
            }
407 400
        }
@@ -421,13 +414,11 @@
Loading
421 414
                if i & 1 == 0 {
422 415
                    XCTAssertEqual(offset, 3 * (i / 2) - 1)
423 416
                    XCTAssertEqual(element, i - 2)
424 -
                }
425 -
                else {
417 +
                } else {
426 418
                    XCTAssertEqual(offset, 3 * (i / 2) + 2)
427 419
                    XCTAssertEqual(element, i - 1)
428 420
                }
429 -
            }
430 -
            else {
421 +
            } else {
431 422
                XCTAssertNil(index)
432 423
            }
433 424
        }
@@ -444,8 +435,7 @@
Loading
444 435
                guard let index = index else { continue }
445 436
                XCTAssertEqual(bag.offset(of: index), 3 * (i / 2) + 2)
446 437
                XCTAssertEqual(bag[index], i & ~1)
447 -
            }
448 -
            else {
438 +
            } else {
449 439
                XCTAssertNil(index)
450 440
            }
451 441
        }
@@ -539,7 +529,6 @@
Loading
539 529
        assertEqualElements(bag, (1 ... 100).repeatEach(2).map { Test($0) })
540 530
    }
541 531
542 -
543 532
    func test_remove() {
544 533
        let c = 500
545 534
        let elements = (0 ..< c).map { 2 * $0 }.repeatEach(2).map { Test($0) }
@@ -548,8 +537,7 @@
Loading
548 537
            if i & 1 == 0 {
549 538
                let removed = bag.remove(Test(i))
550 539
                XCTAssert(removed === elements[i], "\(i)")
551 -
            }
552 -
            else {
540 +
            } else {
553 541
                XCTAssertNil(bag.remove(Test(i)))
554 542
            }
555 543
        }
@@ -557,8 +545,7 @@
Loading
557 545
            if i & 1 == 0 {
558 546
                let removed = bag.remove(Test(i))
559 547
                XCTAssert(removed === elements[i + 1], "\(i)")
560 -
            }
561 -
            else {
548 +
            } else {
562 549
                XCTAssertNil(bag.remove(Test(i)))
563 550
            }
564 551
        }
@@ -722,25 +709,25 @@
Loading
722 709
        let c = SortedBag(10 ..< 20)
723 710
        let d = SortedBag((20 ..< 30).repeatEach(2))
724 711
725 -
        XCTAssertFalse(a.isDisjoint(with:a))
726 -
        XCTAssertFalse(a.isDisjoint(with:b))
727 -
        XCTAssertFalse(a.isDisjoint(with:c))
728 -
        XCTAssertFalse(a.isDisjoint(with:d))
712 +
        XCTAssertFalse(a.isDisjoint(with: a))
713 +
        XCTAssertFalse(a.isDisjoint(with: b))
714 +
        XCTAssertFalse(a.isDisjoint(with: c))
715 +
        XCTAssertFalse(a.isDisjoint(with: d))
729 716
730 -
        XCTAssertFalse(b.isDisjoint(with:a))
731 -
        XCTAssertFalse(b.isDisjoint(with:b))
732 -
        XCTAssertFalse(b.isDisjoint(with:c))
733 -
        XCTAssertFalse(b.isDisjoint(with:d))
717 +
        XCTAssertFalse(b.isDisjoint(with: a))
718 +
        XCTAssertFalse(b.isDisjoint(with: b))
719 +
        XCTAssertFalse(b.isDisjoint(with: c))
720 +
        XCTAssertFalse(b.isDisjoint(with: d))
734 721
735 -
        XCTAssertFalse(c.isDisjoint(with:a))
736 -
        XCTAssertFalse(c.isDisjoint(with:b))
737 -
        XCTAssertFalse(c.isDisjoint(with:c))
738 -
        XCTAssertTrue(c.isDisjoint(with:d))
722 +
        XCTAssertFalse(c.isDisjoint(with: a))
723 +
        XCTAssertFalse(c.isDisjoint(with: b))
724 +
        XCTAssertFalse(c.isDisjoint(with: c))
725 +
        XCTAssertTrue(c.isDisjoint(with: d))
739 726
740 -
        XCTAssertFalse(d.isDisjoint(with:a))
741 -
        XCTAssertFalse(d.isDisjoint(with:b))
742 -
        XCTAssertTrue(d.isDisjoint(with:c))
743 -
        XCTAssertFalse(d.isDisjoint(with:d))
727 +
        XCTAssertFalse(d.isDisjoint(with: a))
728 +
        XCTAssertFalse(d.isDisjoint(with: b))
729 +
        XCTAssertTrue(d.isDisjoint(with: c))
730 +
        XCTAssertFalse(d.isDisjoint(with: d))
744 731
    }
745 732
746 733
    func test_isSubsetOf() {
@@ -852,73 +839,72 @@
Loading
852 839
    }
853 840
854 841
    func test_countElementsInRange() {
855 -
        let s = SortedBag(sortedElements: (0 ..< 10_000).repeatEach(2))
842 +
        let s = SortedBag(sortedElements: (0 ..< 10000).repeatEach(2))
856 843
        XCTAssertEqual(s.count(elementsIn: -100 ..< -10), 0)
857 844
        XCTAssertEqual(s.count(elementsIn: 0 ..< 100), 2 * 100)
858 -
        XCTAssertEqual(s.count(elementsIn: 3 ..< 9_999), 2 * 9_996)
859 -
        XCTAssertEqual(s.count(elementsIn: 0 ..< 10_000), 2 * 10_000)
845 +
        XCTAssertEqual(s.count(elementsIn: 3 ..< 9999), 2 * 9996)
846 +
        XCTAssertEqual(s.count(elementsIn: 0 ..< 10000), 2 * 10000)
860 847
        XCTAssertEqual(s.count(elementsIn: -100 ..< 100), 2 * 100)
861 -
        XCTAssertEqual(s.count(elementsIn: 9_900 ..< 10_100), 2 * 100)
862 -
        XCTAssertEqual(s.count(elementsIn: -100 ..< 20_000), 2 * 10_000)
863 -
848 +
        XCTAssertEqual(s.count(elementsIn: 9900 ..< 10100), 2 * 100)
849 +
        XCTAssertEqual(s.count(elementsIn: -100 ..< 20000), 2 * 10000)
864 850
865 851
        XCTAssertEqual(s.count(elementsIn: -100 ... -10), 0)
866 852
        XCTAssertEqual(s.count(elementsIn: 0 ... 100), 2 * 101)
867 -
        XCTAssertEqual(s.count(elementsIn: 3 ... 9_999), 2 * 9_997)
868 -
        XCTAssertEqual(s.count(elementsIn: 0 ... 9_999), 2 * 10_000)
853 +
        XCTAssertEqual(s.count(elementsIn: 3 ... 9999), 2 * 9997)
854 +
        XCTAssertEqual(s.count(elementsIn: 0 ... 9999), 2 * 10000)
869 855
        XCTAssertEqual(s.count(elementsIn: -100 ... 100), 2 * 101)
870 -
        XCTAssertEqual(s.count(elementsIn: 9_900 ... 10_100), 2 * 100)
871 -
        XCTAssertEqual(s.count(elementsIn: -100 ... 20_000), 2 * 10_000)
856 +
        XCTAssertEqual(s.count(elementsIn: 9900 ... 10100), 2 * 100)
857 +
        XCTAssertEqual(s.count(elementsIn: -100 ... 20000), 2 * 10000)
872 858
    }
873 859
874 860
    func test_intersectionWithRange() {
875 -
        var s = SortedBag(sortedElements: (0 ..< 10_000).repeatEach(2))
861 +
        var s = SortedBag(sortedElements: (0 ..< 10000).repeatEach(2))
876 862
        assertEqualElements(s.intersection(elementsIn: -100 ..< -10), [])
877 -
        assertEqualElements(s.intersection(elementsIn: 100 ..< 9_900), (100 ..< 9_900).repeatEach(2))
863 +
        assertEqualElements(s.intersection(elementsIn: 100 ..< 9900), (100 ..< 9900).repeatEach(2))
878 864
        assertEqualElements(s.intersection(elementsIn: -100 ..< 100), (0 ..< 100).repeatEach(2))
879 -
        assertEqualElements(s.intersection(elementsIn: 9_900 ..< 10_100), (9_900 ..< 10_000).repeatEach(2))
880 -
        assertEqualElements(s.intersection(elementsIn: 10_100 ..< 10_200), [])
865 +
        assertEqualElements(s.intersection(elementsIn: 9900 ..< 10100), (9900 ..< 10000).repeatEach(2))
866 +
        assertEqualElements(s.intersection(elementsIn: 10100 ..< 10200), [])
881 867
882 868
        assertEqualElements(s.intersection(elementsIn: -100 ... -10), [])
883 -
        assertEqualElements(s.intersection(elementsIn: 100 ... 9_900), (100 ... 9_900).repeatEach(2))
869 +
        assertEqualElements(s.intersection(elementsIn: 100 ... 9900), (100 ... 9900).repeatEach(2))
884 870
        assertEqualElements(s.intersection(elementsIn: -100 ... 100), (0 ... 100).repeatEach(2))
885 -
        assertEqualElements(s.intersection(elementsIn: 9_900 ... 10_100), (9_900 ..< 10_000).repeatEach(2))
886 -
        assertEqualElements(s.intersection(elementsIn: 10_100 ... 10_200), [])
871 +
        assertEqualElements(s.intersection(elementsIn: 9900 ... 10100), (9900 ..< 10000).repeatEach(2))
872 +
        assertEqualElements(s.intersection(elementsIn: 10100 ... 10200), [])
887 873
888 -
        s.formIntersection(elementsIn: 1_000 ..< 2_000)
889 -
        assertEqualElements(s, (1_000 ..< 2_000).repeatEach(2))
874 +
        s.formIntersection(elementsIn: 1000 ..< 2000)
875 +
        assertEqualElements(s, (1000 ..< 2000).repeatEach(2))
890 876
891 -
        s.formIntersection(elementsIn: 1_100 ... 1_200)
892 -
        assertEqualElements(s, (1_100 ... 1_200).repeatEach(2))
877 +
        s.formIntersection(elementsIn: 1100 ... 1200)
878 +
        assertEqualElements(s, (1100 ... 1200).repeatEach(2))
893 879
    }
894 880
895 881
    func test_subtractionOfRange() {
896 -
        var s = SortedBag(sortedElements: (0 ..< 10_000).repeatEach(2))
897 -
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 0), (0 ..< 10_000).repeatEach(2))
898 -
        assertEqualElements(s.subtracting(elementsIn: 100 ..< 9_900), (0 ..< 100).repeatEach(2) + (9_900 ..< 10_000).repeatEach(2))
899 -
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 100), (100 ..< 10_000).repeatEach(2))
900 -
        assertEqualElements(s.subtracting(elementsIn: 9_900 ..< 10_100), (0 ..< 9_900).repeatEach(2))
901 -
        assertEqualElements(s.subtracting(elementsIn: 10_000 ..< 10_100), (0 ..< 10_000).repeatEach(2))
902 -
903 -
        assertEqualElements(s.subtracting(elementsIn: -100 ... -1), (0 ..< 10_000).repeatEach(2))
904 -
        assertEqualElements(s.subtracting(elementsIn: 100 ... 9_900), (0 ..< 100).repeatEach(2) + (9_901 ..< 10_000).repeatEach(2))
905 -
        assertEqualElements(s.subtracting(elementsIn: -100 ... 100), (101 ..< 10_000).repeatEach(2))
906 -
        assertEqualElements(s.subtracting(elementsIn: 9_900 ... 10_100), (0 ..< 9_900).repeatEach(2))
907 -
        assertEqualElements(s.subtracting(elementsIn: 10_000 ... 10_100), (0 ..< 10_000).repeatEach(2))
908 -
909 -
        s.subtract(elementsIn: 1_000 ..< 9_000)
910 -
        assertEqualElements(s, (0 ..< 1_000).repeatEach(2) + (9_000 ..< 10_000).repeatEach(2))
882 +
        var s = SortedBag(sortedElements: (0 ..< 10000).repeatEach(2))
883 +
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 0), (0 ..< 10000).repeatEach(2))
884 +
        assertEqualElements(s.subtracting(elementsIn: 100 ..< 9900), (0 ..< 100).repeatEach(2) + (9900 ..< 10000).repeatEach(2))
885 +
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 100), (100 ..< 10000).repeatEach(2))
886 +
        assertEqualElements(s.subtracting(elementsIn: 9900 ..< 10100), (0 ..< 9900).repeatEach(2))
887 +
        assertEqualElements(s.subtracting(elementsIn: 10000 ..< 10100), (0 ..< 10000).repeatEach(2))
888 +
889 +
        assertEqualElements(s.subtracting(elementsIn: -100 ... -1), (0 ..< 10000).repeatEach(2))
890 +
        assertEqualElements(s.subtracting(elementsIn: 100 ... 9900), (0 ..< 100).repeatEach(2) + (9901 ..< 10000).repeatEach(2))
891 +
        assertEqualElements(s.subtracting(elementsIn: -100 ... 100), (101 ..< 10000).repeatEach(2))
892 +
        assertEqualElements(s.subtracting(elementsIn: 9900 ... 10100), (0 ..< 9900).repeatEach(2))
893 +
        assertEqualElements(s.subtracting(elementsIn: 10000 ... 10100), (0 ..< 10000).repeatEach(2))
894 +
895 +
        s.subtract(elementsIn: 1000 ..< 9000)
896 +
        assertEqualElements(s, (0 ..< 1000).repeatEach(2) + (9000 ..< 10000).repeatEach(2))
911 897
912 898
        s.subtract(elementsIn: 100 ... 900)
913 -
        assertEqualElements(s, (0 ..< 100).repeatEach(2) + (901 ..< 1_000).repeatEach(2) + (9_000 ..< 10_000).repeatEach(2))
899 +
        assertEqualElements(s, (0 ..< 100).repeatEach(2) + (901 ..< 1000).repeatEach(2) + (9000 ..< 10000).repeatEach(2))
914 900
    }
915 -
    
901 +
916 902
    func test_shiftStartingAtElement() {
917 903
        var a = SortedBag((0 ..< 10).map { 2 * $0 }.repeatEach(2))
918 -
        
904 +
919 905
        a.shift(startingAt: 5, by: 5)
920 906
        assertEqualElements(a, [0, 0, 2, 2, 4, 4, 11, 11, 13, 13, 15, 15, 17, 17, 19, 19, 21, 21, 23, 23])
921 -
        
907 +
922 908
        a.shift(startingAt: 19, by: -1)
923 909
        assertEqualElements(a, [0, 0, 2, 2, 4, 4, 11, 11, 13, 13, 15, 15, 17, 17, 18, 18, 20, 20, 22, 22])
924 910

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2015–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
class MapTests: XCTestCase {
13 13
    func testEmptyMap() {
@@ -26,7 +26,7 @@
Loading
26 26
        let dict: [Int: Int] = [1: 20, 2: 40, 3: 60, 4: 80, 5: 100]
27 27
28 28
        // Check that genarator API returns elements in order.
29 -
        var lastKey: Int? = nil
29 +
        var lastKey: Int?
30 30
        var i = 0
31 31
        var iterator = map.makeIterator()
32 32
        while let (key, _) = iterator.next() {
@@ -55,12 +55,12 @@
Loading
55 55
56 56
        // Check that keys are sorted.
57 57
        XCTAssertEqual(Array(map.keys), map.keys.sorted())
58 -
        XCTAssertEqual(dict.keys.sorted(), map.map({ key, _ in key }))
58 +
        XCTAssertEqual(dict.keys.sorted(), map.map { key, _ in key })
59 59
        XCTAssertEqual(dict.keys.sorted(), Array(map.keys))
60 60
61 61
        // Check that values match those in dict
62 62
        XCTAssertEqual(map.count, dict.count)
63 -
        XCTAssertEqual(dict.values.sorted(), map.map({ _, value in value }).sorted())
63 +
        XCTAssertEqual(dict.values.sorted(), map.map { _, value in value }.sorted())
64 64
        XCTAssertEqual(dict.values.sorted(), map.values.sorted())
65 65
        for k in dict.keys {
66 66
            XCTAssertEqual(map[k], dict[k])
@@ -68,7 +68,7 @@
Loading
68 68
    }
69 69
70 70
    func testMapForEach() {
71 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
71 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
72 72
        var i = 0
73 73
        m.forEach { key, value in
74 74
            XCTAssertEqual(key, i)
@@ -79,7 +79,7 @@
Loading
79 79
    }
80 80
81 81
    func testMapMap() {
82 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
82 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
83 83
        var i = 0
84 84
        let r = m.map { key, value -> Int in
85 85
            XCTAssertEqual(key, i)
@@ -88,11 +88,11 @@
Loading
88 88
            return key
89 89
        }
90 90
        XCTAssertEqual(i, 100)
91 -
        assertEqualElements(r, 0..<100)
91 +
        assertEqualElements(r, 0 ..< 100)
92 92
    }
93 93
94 94
    func testSequenceFlatMap() {
95 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
95 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
96 96
        var i = 0
97 97
        let r = m.flatMap { key, value -> [Int] in
98 98
            XCTAssertEqual(key, i)
@@ -103,11 +103,11 @@
Loading
103 103
            }
104 104
            return []
105 105
        }
106 -
        XCTAssertEqual(r, (0..<100).map { $0 & ~1 })
106 +
        XCTAssertEqual(r, (0 ..< 100).map { $0 & ~1 })
107 107
    }
108 108
109 109
    func testOptionalFlatMap() {
110 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
110 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
111 111
        var i = 0
112 112
        let r = m.flatMap { key, value -> Int? in
113 113
            XCTAssertEqual(key, i)
@@ -115,11 +115,11 @@
Loading
115 115
            i += 1
116 116
            return key & 1 == 0 ? key / 2 : nil
117 117
        }
118 -
        assertEqualElements(r, 0..<50)
118 +
        assertEqualElements(r, 0 ..< 50)
119 119
    }
120 120
121 121
    func testReduce() {
122 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
122 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
123 123
        var i = 0
124 124
        let sum = m.reduce(0) { sum, element in
125 125
            XCTAssertEqual(element.0, i)
@@ -131,16 +131,16 @@
Loading
131 131
    }
132 132
133 133
    func testKeysAndValues() {
134 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
134 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
135 135
136 -
        assertEqualElements(m.keys, 0..<100)
137 -
        assertEqualElements(m.values, (0..<100).map { String($0) })
136 +
        assertEqualElements(m.keys, 0 ..< 100)
137 +
        assertEqualElements(m.values, (0 ..< 100).map { String($0) })
138 138
    }
139 139
140 140
    func testSubscriptLookup() {
141 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
141 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
142 142
143 -
        for k in 0..<100 {
143 +
        for k in 0 ..< 100 {
144 144
            XCTAssertEqual(m[k], String(k))
145 145
        }
146 146
        XCTAssertNil(m[-1])
@@ -157,7 +157,7 @@
Loading
157 157
    }
158 158
159 159
    func testSubscriptRange() {
160 -
        let m = Map(sortedElements: (0..<10).map { ($0, String($0)) })
160 +
        let m = Map(sortedElements: (0 ..< 10).map { ($0, String($0)) })
161 161
        let indexes = Array(m.indices) + [m.endIndex]
162 162
        assertEqualElements(m[indexes[0] ..< indexes[10]], m)
163 163
        assertEqualElements(m[indexes[2] ..< indexes[4]], [(2, "2"), (3, "3")])
@@ -166,7 +166,7 @@
Loading
166 166
    }
167 167
168 168
    func testIndexing() {
169 -
        let m = Map(sortedElements: (0..<10).map { ($0, String($0)) })
169 +
        let m = Map(sortedElements: (0 ..< 10).map { ($0, String($0)) })
170 170
        var index = m.startIndex
171 171
        XCTAssertEqual(m.index(after: index), m.index(ofOffset: 1))
172 172
        XCTAssertEqual(m.index(index, offsetBy: 5), m.index(ofOffset: 5))
@@ -197,10 +197,10 @@
Loading
197 197
    }
198 198
199 199
    func testIndexForKey() {
200 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
200 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
201 201
202 202
        var index = m.startIndex
203 -
        for k in 0..<100 {
203 +
        for k in 0 ..< 100 {
204 204
            let i = m.index(forKey: k)
205 205
            XCTAssertEqual(i, index)
206 206
            XCTAssertEqual(m[i!].0, k)
@@ -213,7 +213,7 @@
Loading
213 213
    }
214 214
215 215
    func testRemoveAtIndex() {
216 -
        var m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
216 +
        var m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
217 217
        for i in (0 ..< 100).reversed() {
218 218
            if i & 1 == 1 {
219 219
                let index = m.index(m.startIndex, offsetBy: i)
@@ -222,34 +222,34 @@
Loading
222 222
                XCTAssertEqual(element.1, String(i))
223 223
            }
224 224
        }
225 -
        assertEqualElements(m, (0..<50).map { (2 * $0, String(2 * $0)) })
225 +
        assertEqualElements(m, (0 ..< 50).map { (2 * $0, String(2 * $0)) })
226 226
    }
227 227
228 228
    func testRemoveValueForKey() {
229 -
        var m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
229 +
        var m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
230 230
        for k in (0 ..< 100).filter({ $0 & 1 == 1 }) {
231 231
            let value = m.removeValue(forKey: k)
232 232
            XCTAssertEqual(value, String(k))
233 233
        }
234 -
        assertEqualElements(m, (0..<50).map { (2 * $0, String(2 * $0)) })
234 +
        assertEqualElements(m, (0 ..< 50).map { (2 * $0, String(2 * $0)) })
235 235
    }
236 236
237 237
    func testRemoveAll() {
238 -
        var m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
238 +
        var m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
239 239
        m.removeAll()
240 240
        XCTAssertTrue(m.isEmpty)
241 241
        assertEqualElements(m, [])
242 242
    }
243 243
244 244
    func testIndexOfOffset() {
245 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
246 -
        for i in 0...100 {
245 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
246 +
        for i in 0 ... 100 {
247 247
            XCTAssertEqual(m.index(ofOffset: i), m.index(m.startIndex, offsetBy: i))
248 248
        }
249 249
    }
250 250
251 251
    func testOffsetOfIndex() {
252 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
252 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
253 253
        var index = m.startIndex
254 254
        for i in 0 ..< 100 {
255 255
            XCTAssertEqual(m.offset(of: index), i)
@@ -260,20 +260,19 @@
Loading
260 260
    }
261 261
262 262
    func testOffsetOfKey() {
263 -
        let m = Map<Int, String>(sortedElements: (0..<50).map { (2 * $0, String(2 * $0)) })
263 +
        let m = Map<Int, String>(sortedElements: (0 ..< 50).map { (2 * $0, String(2 * $0)) })
264 264
        for k in 0 ..< 100 {
265 265
            let offset = m.offset(of: k)
266 266
            if k & 1 == 0 {
267 267
                XCTAssertEqual(offset, k / 2)
268 -
            }
269 -
            else {
268 +
            } else {
270 269
                XCTAssertNil(offset)
271 270
            }
272 271
        }
273 272
    }
274 273
275 274
    func testElementAtOffset() {
276 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
275 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
277 276
        for i in 0 ..< 100 {
278 277
            let element = m.element(atOffset: i)
279 278
            XCTAssertEqual(element.0, i)
@@ -282,20 +281,20 @@
Loading
282 281
    }
283 282
284 283
    func testUpdateValueAtOffset() {
285 -
        var m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
284 +
        var m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
286 285
        for i in 0 ..< 100 {
287 286
            m.updateValue(String(i) + "*", atOffset: i)
288 287
        }
289 -
        assertEqualElements(m, (0..<100).map { ($0, String($0) + "*") })
288 +
        assertEqualElements(m, (0 ..< 100).map { ($0, String($0) + "*") })
290 289
    }
291 290
292 291
    func testSubmaps() {
293 -
        let m = Map<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) })
292 +
        let m = Map<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) })
294 293
        let indexRange = m.index(m.startIndex, offsetBy: 30) ..< m.index(m.startIndex, offsetBy: 80)
295 -
        let referenceSeq = (30..<80).map { ($0, String($0)) }
294 +
        let referenceSeq = (30 ..< 80).map { ($0, String($0)) }
296 295
        assertEqualElements(m[indexRange], referenceSeq)
297 296
        assertEqualElements(m.submap(with: indexRange), referenceSeq)
298 -
        assertEqualElements(m.submap(withOffsets: 30..<80), referenceSeq)
297 +
        assertEqualElements(m.submap(withOffsets: 30 ..< 80), referenceSeq)
299 298
        assertEqualElements(m.submap(from: 30, to: 80), referenceSeq)
300 299
        assertEqualElements(m.submap(from: 30, through: 79), referenceSeq)
301 300
    }
@@ -337,8 +336,8 @@
Loading
337 336
        func eq(a: (Int, Int), b: (Int, Int)) -> Bool {
338 337
            var ak = a.0
339 338
            var bk = b.0
340 -
            while ak > 0 && ak & 1 == 0 { ak = ak >> 1 }
341 -
            while bk > 0 && bk & 1 == 0 { bk = bk >> 1 }
339 +
            while ak > 0, ak & 1 == 0 { ak = ak >> 1 }
340 +
            while bk > 0, bk & 1 == 0 { bk = bk >> 1 }
342 341
            return ak == bk
343 342
        }
344 343
@@ -400,7 +399,6 @@
Loading
400 399
        assertEqualElements(m, [(1, 2), (9, 18)])
401 400
    }
402 401
403 -
404 402
    func testReplacements() {
405 403
        var m: Map<Int, Int> = [1: 2, 5: 10, 3: 6, 9: 18]
406 404

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2016–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
@objc
13 13
internal class Foo: NSObject {
@@ -21,13 +21,13 @@
Loading
21 21
22 22
class BridgedListTests: XCTestCase {
23 23
    #if Debug
24 -
    let count = 5_000 // Make sure this is larger than the default tree order to get full code coverage
24 +
        let count = 5000 // Make sure this is larger than the default tree order to get full code coverage
25 25
    #else
26 -
    let count = 100_000
26 +
        let count = 100_000
27 27
    #endif
28 28
29 29
    func testLeaks() {
30 -
        weak var test: Foo? = nil
30 +
        weak var test: Foo?
31 31
        do {
32 32
            let list = List((0 ..< count).lazy.map { Foo($0) })
33 33
            let arrayView = list.arrayView

@@ -16,7 +16,7 @@
Loading
16 16
17 17
extension Array {
18 18
    /// Returns a copy of this array with all elements randomly shuffled.
19 -
    func shuffled() -> Array<Element> {
19 +
    func shuffled() -> [Element] {
20 20
        var copy = self
21 21
        copy.shuffle()
22 22
        return copy
@@ -25,7 +25,7 @@
Loading
25 25
    /// Randomly shuffles the elements of this array.
26 26
    mutating func shuffle() {
27 27
        let count = self.count
28 -
        for i in 0..<count {
28 +
        for i in 0 ..< count {
29 29
            let j = random(count)
30 30
            (self[i], self[j]) = (self[j], self[i])
31 31
        }

@@ -6,9 +6,8 @@
Loading
6 6
//  Copyright © 2016–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
11 -
10 +
import XCTest
12 11
13 12
class PathTests<Path: BTreePath> where Path.Key == Int, Path.Value == String {
14 13
    typealias Tree = BTree<Int, String>
@@ -68,7 +67,7 @@
Loading
68 67
        let contents = range.lazy.map { ($0 & ~1, String($0)) }
69 68
        return Tree(sortedElements: contents, order: 3)
70 69
    }
71 -
    
70 +
72 71
    func testInitKeyFirst() {
73 72
        let c = 26
74 73
        let tree = makeTree(count: c)
@@ -268,7 +267,7 @@
Loading
268 267
        let tree = makeTree(count: c)
269 268
        withClone(tree) { node in
270 269
            var path = Path(endOf: node)
271 -
            for i in 0...c {
270 +
            for i in 0 ... c {
272 271
                path.move(to: 2 * i, choosing: .first)
273 272
                XCTAssertEqual(path.offset, 2 * i)
274 273
                XCTAssertEqual(path.key, 2 * i)
@@ -278,8 +277,7 @@
Loading
278 277
                XCTAssertEqual(path.offset, 2 * j + 2)
279 278
                if i > 0 {
280 279
                    XCTAssertEqual(path.key, 2 * j + 2)
281 -
                }
282 -
                else {
280 +
                } else {
283 281
                    XCTAssertTrue(path.isAtEnd)
284 282
                }
285 283
            }
@@ -292,7 +290,7 @@
Loading
292 290
        let tree = makeTree(count: c)
293 291
        withClone(tree) { node in
294 292
            var path = Path(endOf: node)
295 -
            for i in 0...c {
293 +
            for i in 0 ... c {
296 294
                path.move(to: 2 * i, choosing: .last)
297 295
                XCTAssertEqual(path.offset, 2 * i + 1)
298 296
                XCTAssertEqual(path.key, 2 * i)
@@ -302,8 +300,7 @@
Loading
302 300
                XCTAssertEqual(path.offset, 2 * j + 2)
303 301
                if i > 0 {
304 302
                    XCTAssertEqual(path.key, 2 * j + 2)
305 -
                }
306 -
                else {
303 +
                } else {
307 304
                    XCTAssertTrue(path.isAtEnd)
308 305
                }
309 306
            }
@@ -316,13 +313,12 @@
Loading
316 313
        let tree = makeTree(count: c)
317 314
        withClone(tree) { node in
318 315
            var path = Path(endOf: node)
319 -
            for i in 0...c {
316 +
            for i in 0 ... c {
320 317
                path.move(to: 2 * i, choosing: .after)
321 318
                XCTAssertEqual(path.offset, 2 * i + 2)
322 319
                if i < c {
323 320
                    XCTAssertEqual(path.key, 2 * i + 2)
324 -
                }
325 -
                else {
321 +
                } else {
326 322
                    XCTAssertTrue(path.isAtEnd)
327 323
                }
328 324
@@ -331,8 +327,7 @@
Loading
331 327
                XCTAssertEqual(path.offset, 2 * j + 2)
332 328
                if i > 0 {
333 329
                    XCTAssertEqual(path.key, 2 * j + 2)
334 -
                }
335 -
                else {
330 +
                } else {
336 331
                    XCTAssertTrue(path.isAtEnd)
337 332
                }
338 333
            }
@@ -345,7 +340,7 @@
Loading
345 340
        let tree = makeTree(count: c)
346 341
        withClone(tree) { node in
347 342
            var path = Path(endOf: node)
348 -
            for i in 0...c {
343 +
            for i in 0 ... c {
349 344
                path.move(to: 2 * i, choosing: .any)
350 345
                XCTAssertGreaterThanOrEqual(path.offset, 2 * i)
351 346
                XCTAssertLessThanOrEqual(path.offset, 2 * i + 1)
@@ -356,8 +351,7 @@
Loading
356 351
                XCTAssertEqual(path.offset, 2 * j + 2)
357 352
                if i > 0 {
358 353
                    XCTAssertEqual(path.key, 2 * j + 2)
359 -
                }
360 -
                else {
354 +
                } else {
361 355
                    XCTAssertTrue(path.isAtEnd)
362 356
                }
363 357
            }
@@ -375,7 +369,7 @@
Loading
375 369
                let (prefix, separator, suffix) = path.split()
376 370
377 371
                prefix.assertValid()
378 -
                assertEqualElements(prefix, (0..<i).map { ($0, String($0)) })
372 +
                assertEqualElements(prefix, (0 ..< i).map { ($0, String($0)) })
379 373
380 374
                XCTAssertEqual(separator.0, i)
381 375
                XCTAssertEqual(separator.1, String(i))
@@ -399,7 +393,7 @@
Loading
399 393
400 394
                let prefix = path.prefix()
401 395
                prefix.assertValid()
402 -
                assertEqualElements(prefix, (0..<i).map { ($0, String($0)) })
396 +
                assertEqualElements(prefix, (0 ..< i).map { ($0, String($0)) })
403 397
404 398
                path.moveForward()
405 399
            }
@@ -487,14 +481,11 @@
Loading
487 481
            ("testPrefix", testPrefix),
488 482
            ("testSuffix", testSuffix),
489 483
            ("testForEach", testForEach),
490 -
            ("testForEachSlot", testForEachSlot),
484 +
            ("testForEachSlot", testForEachSlot)
491 485
        ]
492 486
    }
493 -
494 487
}
495 488
496 -
497 -
498 489
class BTreePathTests: XCTestCase {
499 490
    /// Poor man's generic test runner
500 491
    func runTests<Path>(_ tests: PathTests<Path>) {

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2015–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
extension List {
13 13
    func assertValid() {
@@ -16,7 +16,6 @@
Loading
16 16
}
17 17
18 18
class ListTests: XCTestCase {
19 -
20 19
    func testEmptyKey() {
21 20
        let a = EmptyKey()
22 21
        let b = EmptyKey()
@@ -44,8 +43,8 @@
Loading
44 43
        for i in 0 ..< 5 {
45 44
            XCTAssertEqual(list[i], i)
46 45
        }
47 -
        assertEqualElements(IteratorSequence(list.makeIterator()), 0..<5)
48 -
        assertEqualElements(list, 0..<5)
46 +
        assertEqualElements(IteratorSequence(list.makeIterator()), 0 ..< 5)
47 +
        assertEqualElements(list, 0 ..< 5)
49 48
    }
50 49
51 50
    func testSubscriptSetter() {
@@ -58,7 +57,7 @@
Loading
58 57
59 58
    func testGettingSublists() {
60 59
        let count = 20
61 -
        let list = List(0..<count)
60 +
        let list = List(0 ..< count)
62 61
        for i in 0 ... count {
63 62
            for j in i ... count {
64 63
                assertEqualElements(list[i ..< j], i ..< j)
@@ -67,18 +66,18 @@
Loading
67 66
    }
68 67
69 68
    func testSettingSublists() {
70 -
        var list = List(0..<10)
69 +
        var list = List(0 ..< 10)
71 70
72 -
        list[2..<5] = List(8..<11)
71 +
        list[2 ..< 5] = List(8 ..< 11)
73 72
        assertEqualElements(list, [0, 1, 8, 9, 10, 5, 6, 7, 8, 9])
74 73
75 -
        list[0..<3] = List()
74 +
        list[0 ..< 3] = List()
76 75
        assertEqualElements(list, [9, 10, 5, 6, 7, 8, 9])
77 76
78 -
        list[4..<7] = List(1 ..< 6)
77 +
        list[4 ..< 7] = List(1 ..< 6)
79 78
        assertEqualElements(list, [9, 10, 5, 6, 1, 2, 3, 4, 5])
80 79
81 -
        list[0..<9] = List()
80 +
        list[0 ..< 9] = List()
82 81
        assertEqualElements(list, 0 ..< 0)
83 82
    }
84 83
@@ -152,49 +151,48 @@
Loading
152 151
    }
153 152
154 153
    func testFlatMapSequence() {
155 -
        let list = List<Int>(0..<100)
154 +
        let list = List<Int>(0 ..< 100)
156 155
        let r = list.flatMap { n -> [Int] in
157 156
            if n & 1 == 1 {
158 157
                return []
159 -
            }
160 -
            else {
158 +
            } else {
161 159
                return [n, n]
162 160
            }
163 161
        }
164 -
        assertEqualElements(r, (0..<100).map { $0 & ~1 })
162 +
        assertEqualElements(r, (0 ..< 100).map { $0 & ~1 })
165 163
    }
166 164
167 165
    func testFlatMapOptional() {
168 -
        let list = List<Int>(0..<100)
166 +
        let list = List<Int>(0 ..< 100)
169 167
        let r = list.flatMap { n -> Int? in
170 -
            return n & 1 == 0 ? n / 2 : nil
168 +
            n & 1 == 0 ? n / 2 : nil
171 169
        }
172 -
        assertEqualElements(r, 0..<50)
170 +
        assertEqualElements(r, 0 ..< 50)
173 171
    }
174 172
175 173
    func testReduce() {
176 -
        let list = List<Int>(0..<100)
174 +
        let list = List<Int>(0 ..< 100)
177 175
        let sum = list.reduce(0) { $0 + $1 }
178 176
        XCTAssertEqual(sum, 100 * 99 / 2)
179 177
    }
180 178
181 179
    func testFilter() {
182 -
        let list = List<Int>(0..<100)
180 +
        let list = List<Int>(0 ..< 100)
183 181
        let r = list.filter { $0 & 1 == 0 }
184 -
        assertEqualElements(r, (0..<50).map { 2 * $0 })
182 +
        assertEqualElements(r, (0 ..< 50).map { 2 * $0 })
185 183
    }
186 184
187 185
    func testElementsEqualWithEquivalence() {
188 -
        let list1 = List<Int>(0..<100)
189 -
        let list2 = List<Int>((0..<100).map { $0 * 8 })
190 -
        let list3 = List<Int>((0..<100).map { $0 * 3 })
186 +
        let list1 = List<Int>(0 ..< 100)
187 +
        let list2 = List<Int>((0 ..< 100).map { $0 * 8 })
188 +
        let list3 = List<Int>((0 ..< 100).map { $0 * 3 })
191 189
192 190
        // Return true iff v1 and v2 are some multiples of 2 of the same value.
193 191
        func foo(_ v1: Int, _ v2: Int) -> Bool {
194 192
            var v1 = v1
195 193
            var v2 = v2
196 -
            while v1 > 0 && v1 & 1 == 0 { v1 = v1 >> 1 }
197 -
            while v2 > 0 && v2 & 1 == 0 { v2 = v2 >> 1 }
194 +
            while v1 > 0, v1 & 1 == 0 { v1 = v1 >> 1 }
195 +
            while v2 > 0, v2 & 1 == 0 { v2 = v2 >> 1 }
198 196
            return v1 == v2
199 197
        }
200 198
@@ -204,9 +202,9 @@
Loading
204 202
    }
205 203
206 204
    func testElementsEqual() {
207 -
        let list1 = List<Int>(0..<100)
208 -
        let list2 = List<Int>(0..<100)
209 -
        let list3 = List<Int>(Array(0..<99) + [50])
205 +
        let list1 = List<Int>(0 ..< 100)
206 +
        let list2 = List<Int>(0 ..< 100)
207 +
        let list3 = List<Int>(Array(0 ..< 99) + [50])
210 208
211 209
        XCTAssertTrue(list1.elementsEqual(list1))
212 210
        XCTAssertTrue(list1.elementsEqual(list2))
@@ -214,7 +212,7 @@
Loading
214 212
    }
215 213
216 214
    func testIndexOfPredicate() {
217 -
        let list = List<Int>(0..<50)
215 +
        let list = List<Int>(0 ..< 50)
218 216
        for v in 0 ..< 50 {
219 217
            let i = list.index { $0 == v }
220 218
            XCTAssertEqual(i, v)
@@ -224,7 +222,7 @@
Loading
224 222
    }
225 223
226 224
    func testIndexOfValue() {
227 -
        let list = List<Int>(0..<50)
225 +
        let list = List<Int>(0 ..< 50)
228 226
        for v in 0 ..< 50 {
229 227
            let i = list.index(of: v)
230 228
            XCTAssertEqual(i, v)
@@ -234,7 +232,7 @@
Loading
234 232
    }
235 233
236 234
    func testContains() {
237 -
        let list = List<Int>(0..<50)
235 +
        let list = List<Int>(0 ..< 50)
238 236
        for v in 0 ..< 50 {
239 237
            XCTAssertTrue(list.contains(v))
240 238
        }
@@ -249,7 +247,7 @@
Loading
249 247
    }
250 248
251 249
    func testAppend() {
252 -
        let values = 1...10
250 +
        let values = 1 ... 10
253 251
        var list = List<Int>()
254 252
255 253
        for v in values {
@@ -279,36 +277,36 @@
Loading
279 277
        var l1: List<Int> = [0, 1, 2, 3, 4]
280 278
        let l2: List<Int> = [5, 6, 7, 8, 9]
281 279
        l1.append(contentsOf: l2)
282 -
        assertEqualElements(l1, 0..<10)
280 +
        assertEqualElements(l1, 0 ..< 10)
283 281
284 282
        let l3: List<Int> = [10, 11, 12, 13, 14]
285 283
        func appendAsSequence<E, S: Sequence>(_ list: inout List<E>, _ elements: S) where S.Element == E {
286 284
            list.append(contentsOf: elements)
287 285
        }
288 286
        appendAsSequence(&l1, l3)
289 -
        assertEqualElements(l1, 0..<15)
287 +
        assertEqualElements(l1, 0 ..< 15)
290 288
    }
291 289
292 290
    func testAppendContentsOfSequence() {
293 291
        var list: List<Int> = [0, 1, 2, 3, 4]
294 -
        list.append(contentsOf: 5..<10)
295 -
        assertEqualElements(list, 0..<10)
292 +
        list.append(contentsOf: 5 ..< 10)
293 +
        assertEqualElements(list, 0 ..< 10)
296 294
    }
297 295
298 296
    func testInsertContentsOfList() {
299 297
        let list: List<Int> = [0, 1, 2, 3, 4]
300 298
        let l: List<Int> = [5, 6, 7, 8, 9]
301 299
302 -
        for i in 0...5 {
300 +
        for i in 0 ... 5 {
303 301
            var copy = list
304 302
            copy.insert(contentsOf: l, at: i)
305 303
306 -
            var ref = Array(0..<5)
304 +
            var ref = Array(0 ..< 5)
307 305
            ref.insert(contentsOf: l, at: i)
308 306
309 307
            assertEqualElements(copy, ref)
310 308
        }
311 -
        assertEqualElements(list, 0..<5)
309 +
        assertEqualElements(list, 0 ..< 5)
312 310
313 311
        var copy = list
314 312
        func insertAsSequence<E, S: Sequence>(_ list: inout List<E>, _ elements: S, at index: Int) where S.Element == E {
@@ -320,24 +318,24 @@
Loading
320 318
321 319
    func testInsertContentsOfSequence() {
322 320
        let list: List<Int> = [0, 1, 2, 3, 4]
323 -
        let s = 5..<10
321 +
        let s = 5 ..< 10
324 322
325 -
        for i in 0...5 {
323 +
        for i in 0 ... 5 {
326 324
            var copy = list
327 325
            copy.insert(contentsOf: s, at: i)
328 326
329 -
            var ref = Array(0..<5)
327 +
            var ref = Array(0 ..< 5)
330 328
            ref.insert(contentsOf: s, at: i)
331 329
332 330
            assertEqualElements(copy, ref)
333 331
        }
334 -
        assertEqualElements(list, 0..<5)
332 +
        assertEqualElements(list, 0 ..< 5)
335 333
    }
336 334
337 335
    func testRemoveAtIndex() {
338 336
        let count = 6
339 -
        let list = List<Int>(1...count)
340 -
        let referenceArray = Array<Int>(1...count)
337 +
        let list = List<Int>(1 ... count)
338 +
        let referenceArray = [Int](1 ... count)
341 339
342 340
        for inversion in generateInversions(count) {
343 341
            var l = list
@@ -356,15 +354,15 @@
Loading
356 354
357 355
    func testRemoveFirst() {
358 356
        var list: List<Int> = [0, 1, 2, 3, 4]
359 -
        for i in 0..<5 {
357 +
        for i in 0 ..< 5 {
360 358
            XCTAssertEqual(list.removeFirst(), i)
361 359
        }
362 360
        XCTAssertTrue(list.isEmpty)
363 361
    }
364 362
365 363
    func testRemoveFirstN() {
366 -
        var list = List<Int>(0..<100)
367 -
        for i in 0..<5 {
364 +
        var list = List<Int>(0 ..< 100)
365 +
        for i in 0 ..< 5 {
368 366
            list.removeFirst(20)
369 367
            assertEqualElements(list, 20 * (i + 1) ..< 100)
370 368
        }
@@ -373,15 +371,15 @@
Loading
373 371
374 372
    func testRemoveLast() {
375 373
        var list: List<Int> = [0, 1, 2, 3, 4]
376 -
        for i in (0..<5).reversed() {
374 +
        for i in (0 ..< 5).reversed() {
377 375
            XCTAssertEqual(list.removeLast(), i)
378 376
        }
379 377
        XCTAssertTrue(list.isEmpty)
380 378
    }
381 379
382 380
    func testRemoveLastN() {
383 -
        var list = List<Int>(0..<100)
384 -
        for i in (0..<5).reversed() {
381 +
        var list = List<Int>(0 ..< 100)
382 +
        for i in (0 ..< 5).reversed() {
385 383
            list.removeLast(20)
386 384
            assertEqualElements(list, 0 ..< i * 20)
387 385
        }
@@ -390,7 +388,7 @@
Loading
390 388
391 389
    func testPopLast() {
392 390
        var list: List<Int> = [0, 1, 2, 3, 4]
393 -
        for i in (0..<5).reversed() {
391 +
        for i in (0 ..< 5).reversed() {
394 392
            XCTAssertEqual(list.popLast(), i)
395 393
        }
396 394
        XCTAssertNil(list.popLast())
@@ -398,45 +396,45 @@
Loading
398 396
399 397
    func testPopFirst() {
400 398
        var list: List<Int> = [0, 1, 2, 3, 4]
401 -
        for i in 0..<5 {
399 +
        for i in 0 ..< 5 {
402 400
            XCTAssertEqual(list.popFirst(), i)
403 401
        }
404 402
        XCTAssertNil(list.popFirst())
405 403
    }
406 404
407 405
    func testRemoveRange() {
408 -
        var list = List(0..<10)
409 -
        list.removeSubrange(2..<8)
406 +
        var list = List(0 ..< 10)
407 +
        list.removeSubrange(2 ..< 8)
410 408
        assertEqualElements(list, [0, 1, 8, 9])
411 409
    }
412 410
413 411
    func testRemoveAll() {
414 -
        var list = List(0..<10)
412 +
        var list = List(0 ..< 10)
415 413
        list.removeAll()
416 414
        assertEqualElements(list, [])
417 415
    }
418 416
419 417
    func testReplaceRangeWithList() {
420 -
        var list = List(0..<10)
418 +
        var list = List(0 ..< 10)
421 419
422 -
        list.replaceSubrange(2..<5, with: List(8..<11))
420 +
        list.replaceSubrange(2 ..< 5, with: List(8 ..< 11))
423 421
        assertEqualElements(list, [0, 1, 8, 9, 10, 5, 6, 7, 8, 9])
424 422
425 -
        list.replaceSubrange(0..<3, with: List())
423 +
        list.replaceSubrange(0 ..< 3, with: List())
426 424
        assertEqualElements(list, [9, 10, 5, 6, 7, 8, 9])
427 425
428 -
        list.replaceSubrange(4..<7, with: List(1 ..< 6))
426 +
        list.replaceSubrange(4 ..< 7, with: List(1 ..< 6))
429 427
        assertEqualElements(list, [9, 10, 5, 6, 1, 2, 3, 4, 5])
430 428
431 -
        list.replaceSubrange(0..<9, with: List())
429 +
        list.replaceSubrange(0 ..< 9, with: List())
432 430
        assertEqualElements(list, 0 ..< 0)
433 431
    }
434 432
435 433
    func testReplaceRangeWithSequence() {
436 -
        var list = List(0..<10)
437 -
        list.replaceSubrange(2..<8, with: [10, 20, 30])
434 +
        var list = List(0 ..< 10)
435 +
        list.replaceSubrange(2 ..< 8, with: [10, 20, 30])
438 436
        assertEqualElements(list, [0, 1, 10, 20, 30, 8, 9])
439 -
        list.replaceSubrange(1..<3, with: [50, 51, 52, 53, 54, 55])
437 +
        list.replaceSubrange(1 ..< 3, with: [50, 51, 52, 53, 54, 55])
440 438
        assertEqualElements(list, [0, 50, 51, 52, 53, 54, 55, 20, 30, 8, 9])
441 439
442 440
        func replaceAsSequence<E, C: Collection>(_ list: inout List<E>, range: CountableRange<Int>, with elements: C) where C.Element == E {
@@ -447,9 +445,9 @@
Loading
447 445
    }
448 446
449 447
    func testListEquality() {
450 -
        let l1 = List(0..<10)
451 -
        let l2 = List(0..<5)
452 -
        let l3 = List((0..<10).reversed())
448 +
        let l1 = List(0 ..< 10)
449 +
        let l2 = List(0 ..< 5)
450 +
        let l3 = List((0 ..< 10).reversed())
453 451
454 452
        XCTAssertTrue(l1 == l1)
455 453
        XCTAssertTrue(l2 == l2)
@@ -467,7 +465,7 @@
Loading
467 465
        for i in 0 ..< 1000 {
468 466
            list.append("item \(i)")
469 467
        }
470 -
        assertEqualElements(list, (0..<1000).map { "item \($0)" })
468 +
        assertEqualElements(list, (0 ..< 1000).map { "item \($0)" })
471 469
    }
472 470
473 471
    func testConcatenationOperator() {

@@ -31,4 +31,3 @@
Loading
31 31
    }
32 32
    return result
33 33
}
34 -

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2015–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
class BTreeTests: XCTestCase {
13 13
    typealias Tree = BTree<Int, String>
@@ -101,14 +101,14 @@
Loading
101 101
102 102
    func testForEach() {
103 103
        let tree = maximalTree(depth: 2, order: order)
104 -
        var values: Array<Int> = []
104 +
        var values: [Int] = []
105 105
        tree.forEach { values.append($0.0) }
106 -
        assertEqualElements(values, 0..<tree.count)
106 +
        assertEqualElements(values, 0 ..< tree.count)
107 107
    }
108 108
109 109
    func testInterruptibleForEach() {
110 110
        let tree = maximalTree(depth: 1, order: 5)
111 -
        for i in 0...tree.count {
111 +
        for i in 0 ... tree.count {
112 112
            var j = 0
113 113
            tree.forEach { pair -> Bool in
114 114
                XCTAssertEqual(pair.0, j)
@@ -250,7 +250,7 @@
Loading
250 250
            XCTAssertNil(tree.index(tree.endIndex, offsetBy: -i, limitedBy: tree.startIndex))
251 251
        }
252 252
    }
253 -
    
253 +
254 254
    func testFormIndexAdvancedByWithLimit() {
255 255
        let tree = maximalTree(depth: 3, order: 3)
256 256
        let c = tree.count
@@ -370,17 +370,14 @@
Loading
370 370
                XCTAssertEqual(tree[first].1, "\(k)")
371 371
                if k == (count - 1) & ~1 {
372 372
                    XCTAssertEqual(last, tree.endIndex)
373 -
                }
374 -
                else {
373 +
                } else {
375 374
                    XCTAssertEqual(tree[last].1, "\(k + 2)")
376 375
                }
377 -
            }
378 -
            else { // Odd keys aren't in the tree
376 +
            } else { // Odd keys aren't in the tree
379 377
                XCTAssertEqual(first, last)
380 378
                if k - 1 == (count - 1) & ~1 {
381 379
                    XCTAssertEqual(first, tree.endIndex)
382 -
                }
383 -
                else {
380 +
                } else {
384 381
                    XCTAssertEqual(tree[first].1, "\(k + 1)")
385 382
                }
386 383
            }
@@ -394,7 +391,6 @@
Loading
394 391
        }
395 392
    }
396 393
397 -
398 394
    func testOffsetOfKey() {
399 395
        let count = 42
400 396
        let tree = Tree(sortedElements: (0 ..< count).map { (2 * $0, String(2 * $0)) }, order: 3)
@@ -456,7 +452,7 @@
Loading
456 452
457 453
    func testInsertAtOffset_tryEveryOffset() {
458 454
        let count = 10
459 -
        let tree = Tree(sortedElements: (0 ..< count).map { (2 * $0 , String(2 * $0)) }, order: 3)
455 +
        let tree = Tree(sortedElements: (0 ..< count).map { (2 * $0, String(2 * $0)) }, order: 3)
460 456
        for i in 0 ..< count {
461 457
            var copy = tree
462 458
            let k = 2 * i + 1
@@ -528,8 +524,7 @@
Loading
528 524
            if key & 1 == 0 {
529 525
                XCTAssertEqual(old?.0, key)
530 526
                XCTAssertEqual(old?.1, "*\(key)")
531 -
            }
532 -
            else {
527 +
            } else {
533 528
                XCTAssertNil(old)
534 529
            }
535 530
        }
@@ -570,7 +565,7 @@
Loading
570 565
            assertEqualElements(tree.map { $0.1 }, (0 ..< 42).flatMap { key -> [String] in
571 566
                let ks = String(key)
572 567
                return [ks + "/1", ks + "/2", ks + "/3*"]
573 -
                })
568 +
            })
574 569
        }
575 570
    }
576 571
@@ -583,8 +578,7 @@
Loading
583 578
            if key & 1 == 0 {
584 579
                XCTAssertEqual(old?.0, key)
585 580
                XCTAssertEqual(old?.1, "*\(key)")
586 -
            }
587 -
            else {
581 +
            } else {
588 582
                XCTAssertNil(old)
589 583
            }
590 584
        }
@@ -604,8 +598,7 @@
Loading
604 598
            if k & 1 == 0 {
605 599
                XCTAssertEqual(found?.0, k)
606 600
                XCTAssertEqual(found?.1, "\(k)/1")
607 -
            }
608 -
            else {
601 +
            } else {
609 602
                XCTAssertNil(found)
610 603
            }
611 604
            tree.assertValid()
@@ -613,8 +606,7 @@
Loading
613 606
        assertEqualElements(tree.map { $0.1 }, (0 ..< 42).flatMap { key -> [String] in
614 607
            if key & 1 == 0 {
615 608
                return ["\(key)/1", "\(key)/2", "\(key)/3"]
616 -
            }
617 -
            else {
609 +
            } else {
618 610
                return ["\(key)/*"]
619 611
            }
620 612
        })
@@ -634,8 +626,7 @@
Loading
634 626
                if k & 1 == 0 {
635 627
                    XCTAssertEqual(found?.0, k)
636 628
                    XCTAssertEqual(found?.1, "\(k)/3")
637 -
                }
638 -
                else {
629 +
                } else {
639 630
                    XCTAssertNil(found)
640 631
                }
641 632
                tree.assertValid()
@@ -643,8 +634,7 @@
Loading
643 634
            assertEqualElements(tree.map { $0.1 }, (0 ..< 42).flatMap { key -> [String] in
644 635
                if key & 1 == 0 {
645 636
                    return ["\(key)/1", "\(key)/2", "\(key)/3"]
646 -
                }
647 -
                else {
637 +
                } else {
648 638
                    return ["\(key)/*"]
649 639
                }
650 640
            })
@@ -656,7 +646,7 @@
Loading
656 646
        XCTAssertNil(empty.popFirst())
657 647
        XCTAssertNil(empty.popLast())
658 648
659 -
        var tree = BTree(sortedElements: (0..<20).map { ($0, String($0)) }, order: 3)
649 +
        var tree = BTree(sortedElements: (0 ..< 20).map { ($0, String($0)) }, order: 3)
660 650
        XCTAssertEqual(tree.popFirst()?.0, 0)
661 651
        tree.assertValid()
662 652
        XCTAssertEqual(tree.removeFirst().0, 1)
@@ -665,7 +655,7 @@
Loading
665 655
        tree.assertValid()
666 656
        XCTAssertEqual(tree.removeLast().0, 18)
667 657
        tree.assertValid()
668 -
        assertEqualElements(tree, (2..<18).map { ($0, String($0)) })
658 +
        assertEqualElements(tree, (2 ..< 18).map { ($0, String($0)) })
669 659
    }
670 660
671 661
    func testRemoveFirstN() {
@@ -711,7 +701,7 @@
Loading
711 701
    func testRemoveAtOffset() {
712 702
        var tree = maximalTree(depth: 3, order: 3)
713 703
        let c = tree.count
714 -
        var reference = Array((0..<c).map { ($0, String($0)) })
704 +
        var reference = Array((0 ..< c).map { ($0, String($0)) })
715 705
        while tree.count > 0 {
716 706
            let p = tree.count / 2
717 707
            let element = tree.remove(atOffset: p)
@@ -745,8 +735,7 @@
Loading
745 735
            assertEqualElements(tree.map { $0.1 }, (0 ..< count).flatMap { key -> [String] in
746 736
                let ks = String(2 * key)
747 737
                return [ks + "/2", ks + "/3"]
748 -
                }
749 -
            )
738 +
            })
750 739
        }
751 740
    }
752 741
@@ -772,8 +761,7 @@
Loading
772 761
            assertEqualElements(tree.map { $0.1 }, (0 ..< count).flatMap { key -> [String] in
773 762
                let ks = String(2 * key)
774 763
                return [ks + "/1", ks + "/2"]
775 -
                }
776 -
            )
764 +
            })
777 765
        }
778 766
    }
779 767
@@ -791,7 +779,7 @@
Loading
791 779
792 780
            assertEqualElements(copy, reference)
793 781
        }
794 -
        assertEqualElements(tree.map { $0.0 }, 0..<c)
782 +
        assertEqualElements(tree.map { $0.0 }, 0 ..< c)
795 783
    }
796 784
797 785
    func testRemoveAll() {
@@ -918,9 +906,9 @@
Loading
918 906
        for i in 0 ... count {
919 907
            var end = start
920 908
            for j in i ... count {
921 -
                let subtree = tree[start..<end]
909 +
                let subtree = tree[start ..< end]
922 910
                subtree.assertValid()
923 -
                assertEqualElements(subtree, (i..<j).map { ($0, String($0)) })
911 +
                assertEqualElements(subtree, (i ..< j).map { ($0, String($0)) })
924 912
                if j < count {
925 913
                    tree.formIndex(after: &end)
926 914
                }
@@ -938,14 +926,14 @@
Loading
938 926
            for j in i ... count {
939 927
                let subtree = tree.subtree(withOffsets: i ..< j)
940 928
                subtree.assertValid()
941 -
                assertEqualElements(subtree, (i..<j).map { ($0, String($0)) })
929 +
                assertEqualElements(subtree, (i ..< j).map { ($0, String($0)) })
942 930
            }
943 931
        }
944 932
    }
945 933
946 934
    func testSubtreeFromHalfOpenKeyRange() {
947 935
        let count = 28
948 -
        let tree = BTree(sortedElements: (0..<count).map { ($0 & ~1, String($0)) }, order: 3)
936 +
        let tree = BTree(sortedElements: (0 ..< count).map { ($0 & ~1, String($0)) }, order: 3)
949 937
        for i in 0 ... count {
950 938
            for j in i ... count {
951 939
                let subtree = tree.subtree(from: i, to: j)
@@ -959,7 +947,7 @@
Loading
959 947
960 948
    func testSubtreeFromClosedKeyRange() {
961 949
        let count = 28
962 -
        let tree = BTree(sortedElements: (0..<count).map { ($0 & ~1, String($0)) }, order: 3)
950 +
        let tree = BTree(sortedElements: (0 ..< count).map { ($0 & ~1, String($0)) }, order: 3)
963 951
        for i in 0 ..< count {
964 952
            for j in i ..< count {
965 953
                let subtree = tree.subtree(from: i, through: j)
@@ -1033,8 +1021,8 @@
Loading
1033 1021
1034 1022
    func testSplittingRoot() {
1035 1023
        var tree = Tree(order: order)
1036 -
        var reference = Array<(Int, String)>()
1037 -
        for i in 0..<tree.order {
1024 +
        var reference = [(Int, String)]()
1025 +
        for i in 0 ..< tree.order {
1038 1026
            tree.insert((i, "\(i)"))
1039 1027
            tree.assertValid()
1040 1028
            reference.append((i, "\(i)"))
@@ -1051,19 +1039,19 @@
Loading
1051 1039
1052 1040
    func testRemovingNonexistentKeys() {
1053 1041
        var tree = Tree(order: order)
1054 -
        for i in 0..<tree.order {
1042 +
        for i in 0 ..< tree.order {
1055 1043
            tree.insert((2 * i, "\(2 * i)"))
1056 1044
            tree.assertValid()
1057 1045
        }
1058 -
        for i in 0..<tree.order {
1046 +
        for i in 0 ..< tree.order {
1059 1047
            XCTAssertNil(tree.remove(2 * i + 1))
1060 1048
        }
1061 1049
    }
1062 1050
1063 1051
    func testCollapsingRoot() {
1064 1052
        var tree = Tree(order: order)
1065 -
        var reference = Array<(Int, String)>()
1066 -
        for i in 0..<tree.order {
1053 +
        var reference = [(Int, String)]()
1054 +
        for i in 0 ..< tree.order {
1067 1055
            tree.insert((i, String(i)))
1068 1056
            tree.assertValid()
1069 1057
            reference.append((i, "\(i)"))
@@ -1079,7 +1067,7 @@
Loading
1079 1067
1080 1068
    func testSplittingInternalNode() {
1081 1069
        var tree = Tree(order: order)
1082 -
        var reference = Array<(Int, String)>()
1070 +
        var reference = [(Int, String)]()
1083 1071
        let c = (3 * tree.order + 1) / 2
1084 1072
        for i in 0 ..< c {
1085 1073
            tree.insert((i, String(i)))
@@ -1095,7 +1083,7 @@
Loading
1095 1083
1096 1084
    func testCreatingMinimalTreeWithThreeLevels() {
1097 1085
        var tree = Tree(order: order)
1098 -
        var reference = Array<(Int, String)>()
1086 +
        var reference = [(Int, String)]()
1099 1087
        let c = (tree.order * tree.order - 1) / 2 + tree.order
1100 1088
        for i in 0 ..< c {
1101 1089
            tree.insert((i, String(i)))
@@ -1134,34 +1122,34 @@
Loading
1134 1122
            tree.insert((i, String(i)))
1135 1123
            tree.assertValid()
1136 1124
        }
1137 -
        XCTAssertEqual(tree.remove(c / 2)?.1, "\(c/2)")
1125 +
        XCTAssertEqual(tree.remove(c / 2)?.1, "\(c / 2)")
1138 1126
        tree.assertValid()
1139 1127
        XCTAssertEqual(tree.depth, 1)
1140 1128
    }
1141 1129
1142 1130
    func testMaximalTreeOfDepth() {
1143 -
        for depth in 0..<3 {
1131 +
        for depth in 0 ..< 3 {
1144 1132
            let tree = maximalTree(depth: depth, order: order)
1145 1133
            tree.assertValid()
1146 1134
            XCTAssertEqual(tree.depth, depth)
1147 -
            XCTAssertEqual(tree.count, (0...depth).reduce(1, { p, _ in p * tree.order }) - 1)
1135 +
            XCTAssertEqual(tree.count, (0 ... depth).reduce(1) { p, _ in p * tree.order } - 1)
1148 1136
        }
1149 1137
    }
1150 1138
1151 1139
    func testRemovingFromBeginningOfMaximalTreeWithThreeLevels() {
1152 1140
        // This test exercises left rotations.
1153 1141
        var tree = maximalTree(depth: 2, order: order)
1154 -
        for key in 0..<tree.count {
1142 +
        for key in 0 ..< tree.count {
1155 1143
            XCTAssertEqual(tree.remove(key)?.1, String(key))
1156 1144
            tree.assertValid()
1157 1145
        }
1158 1146
        XCTAssertTrue(tree.isEmpty)
1159 1147
    }
1160 -
    
1148 +
1161 1149
    func testRemovingFromEndOfMaximalTreeWithThreeLevels() {
1162 1150
        // This test exercises right rotations.
1163 1151
        var tree = maximalTree(depth: 2, order: order)
1164 -
        for key in (0..<tree.count).reversed() {
1152 +
        for key in (0 ..< tree.count).reversed() {
1165 1153
            XCTAssertEqual(tree.remove(key)?.1, String(key))
1166 1154
            tree.assertValid()
1167 1155
        }

@@ -6,9 +6,9 @@
Loading
6 6
//  Copyright © 2015–2017 Károly Lőrentey.
7 7
//
8 8
9 +
@testable import BTree
9 10
import Foundation
10 11
import XCTest
11 -
@testable import BTree
12 12
13 13
class BTreeCursorTests: XCTestCase {
14 14
    typealias Tree = BTree<Int, String>
@@ -216,7 +216,7 @@
Loading
216 216
            }
217 217
        }
218 218
    }
219 -
    
219 +
220 220
    func testMoveToOffset() {
221 221
        var tree = maximalTree(depth: 2, order: 5)
222 222
        tree.withCursorAtStart { cursor in
@@ -230,8 +230,7 @@
Loading
230 230
                    XCTAssertEqual(cursor.key, i)
231 231
                    i += 1
232 232
                    toggle = false
233 -
                }
234 -
                else {
233 +
                } else {
235 234
                    cursor.move(toOffset: j)
236 235
                    XCTAssertEqual(cursor.offset, j)
237 236
                    XCTAssertEqual(cursor.key, j)
@@ -248,8 +247,8 @@
Loading
248 247
249 248
    func testMoveToKey() {
250 249
        let count = 42
251 -
        var tree = BTree((0..<count).map { (2 * $0, String(2 * $0)) }, order: 3)
252 -
        tree.withCursorAtStart() { cursor in
250 +
        var tree = BTree((0 ..< count).map { (2 * $0, String(2 * $0)) }, order: 3)
251 +
        tree.withCursorAtStart { cursor in
253 252
            var start = 0
254 253
            var end = count - 1
255 254
            while start < end {
@@ -340,28 +339,28 @@
Loading
340 339
        var tree = Tree(order: 3)
341 340
        tree.withCursorAtEnd { cursor in
342 341
            XCTAssertTrue(cursor.isAtEnd)
343 -
            for i in 0..<30 {
342 +
            for i in 0 ..< 30 {
344 343
                cursor.insert((i, String(i)))
345 344
                XCTAssertTrue(cursor.isAtEnd)
346 345
            }
347 346
        }
348 347
        tree.assertValid()
349 -
        assertEqualElements(tree, (0..<30).map { ($0, String($0)) })
348 +
        assertEqualElements(tree, (0 ..< 30).map { ($0, String($0)) })
350 349
    }
351 350
352 351
    func testBuildingATreeInTwoPassesUsingInsertBefore() {
353 352
        var tree = Tree(order: 5)
354 353
        let c = 30
355 -
        tree.withCursorAtStart() { cursor in
354 +
        tree.withCursorAtStart { cursor in
356 355
            XCTAssertTrue(cursor.isAtEnd)
357 -
            for i in 0..<c {
356 +
            for i in 0 ..< c {
358 357
                cursor.insert((2 * i + 1, String(2 * i + 1)))
359 358
                XCTAssertTrue(cursor.isAtEnd)
360 359
            }
361 360
362 361
            cursor.moveToStart()
363 362
            XCTAssertEqual(cursor.offset, 0)
364 -
            for i in 0..<c {
363 +
            for i in 0 ..< c {
365 364
                XCTAssertEqual(cursor.key, 2 * i + 1)
366 365
                XCTAssertEqual(cursor.offset, 2 * i)
367 366
                XCTAssertEqual(cursor.count, c + i)
@@ -379,7 +378,7 @@
Loading
379 378
    func testBuildingATreeUsingInsertAfter() {
380 379
        var tree = Tree(order: 5)
381 380
        let c = 30
382 -
        tree.withCursorAtStart() { cursor in
381 +
        tree.withCursorAtStart { cursor in
383 382
            cursor.insert((0, "0"))
384 383
            cursor.moveToStart()
385 384
            for i in 1 ..< c {
@@ -389,21 +388,21 @@
Loading
389 388
            }
390 389
        }
391 390
        tree.assertValid()
392 -
        assertEqualElements(tree, (0..<30).map { ($0, String($0)) })
391 +
        assertEqualElements(tree, (0 ..< 30).map { ($0, String($0)) })
393 392
    }
394 393
395 394
    func testBuildingATreeInTwoPassesUsingInsertAfter() {
396 395
        var tree = Tree(order: 5)
397 396
        let c = 30
398 -
        tree.withCursorAtStart() { cursor in
397 +
        tree.withCursorAtStart { cursor in
399 398
            XCTAssertTrue(cursor.isAtEnd)
400 -
            for i in 0..<c {
399 +
            for i in 0 ..< c {
401 400
                cursor.insert((2 * i, String(2 * i)))
402 401
            }
403 402
404 403
            cursor.moveToStart()
405 404
            XCTAssertEqual(cursor.offset, 0)
406 -
            for i in 0..<c {
405 +
            for i in 0 ..< c {
407 406
                XCTAssertEqual(cursor.key, 2 * i)
408 407
                XCTAssertEqual(cursor.offset, 2 * i)
409 408
                XCTAssertEqual(cursor.count, c + i)
@@ -421,7 +420,7 @@
Loading
421 420
    func testBuildingATreeBackward() {
422 421
        var tree = Tree(order: 5)
423 422
        let c = 30
424 -
        tree.withCursorAtStart() { cursor in
423 +
        tree.withCursorAtStart { cursor in
425 424
            XCTAssertTrue(cursor.isAtEnd)
426 425
            for i in stride(from: c - 1, through: 0, by: -1) {
427 426
                cursor.insert((i, String(i)))
@@ -503,7 +502,7 @@
Loading
503 502
504 503
    func testRemoveEachElement() {
505 504
        let tree = maximalTree(depth: 2, order: 5)
506 -
        for i in 0..<tree.count {
505 +
        for i in 0 ..< tree.count {
507 506
            var copy = tree
508 507
            copy.withCursor(atOffset: i) { cursor in
509 508
                let removed = cursor.remove()
@@ -511,7 +510,7 @@
Loading
511 510
                XCTAssertEqual(removed.1, String(i))
512 511
            }
513 512
            copy.assertValid()
514 -
            assertEqualElements(copy, (0..<tree.count).filter{$0 != i}.map{ ($0, String($0)) })
513 +
            assertEqualElements(copy, (0 ..< tree.count).filter { $0 != i }.map { ($0, String($0)) })
515 514
        }
516 515
    }
517 516
@@ -525,12 +524,12 @@
Loading
525 524
                    cursor.remove(n)
526 525
                }
527 526
                copy.assertValid()
528 -
                let keys = Array(0..<i) + Array(i + n ..< count)
527 +
                let keys = Array(0 ..< i) + Array(i + n ..< count)
529 528
                assertEqualElements(copy, keys.map { ($0, String($0)) })
530 529
            }
531 530
        }
532 531
        tree.assertValid()
533 -
        assertEqualElements(tree, (0..<count).map { ($0, String($0)) })
532 +
        assertEqualElements(tree, (0 ..< count).map { ($0, String($0)) })
534 533
    }
535 534
536 535
    func testExtractRangeFromMaximalTree() {
@@ -545,12 +544,12 @@
Loading
545 544
                    assertEqualElements(extracted, (i ..< i + n).map { ($0, String($0)) })
546 545
                }
547 546
                copy.assertValid()
548 -
                let keys = Array(0..<i) + Array(i + n ..< count)
547 +
                let keys = Array(0 ..< i) + Array(i + n ..< count)
549 548
                assertEqualElements(copy, keys.map { ($0, String($0)) })
550 549
            }
551 550
        }
552 551
        tree.assertValid()
553 -
        assertEqualElements(tree, (0..<count).map { ($0, String($0)) })
552 +
        assertEqualElements(tree, (0 ..< count).map { ($0, String($0)) })
554 553
    }
555 554
556 555
    func testRemoveAll() {
@@ -657,7 +656,5 @@
Loading
657 656
            cursor.removeAllAfter(includingCurrent: false)
658 657
        }
659 658
        assertEqualElements(t8, maximalTree(depth: 2, order: 3))
660 -
661 659
    }
662 -
663 660
}

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2016–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
private typealias Builder = BTreeBuilder<Int, Void>
13 13
private typealias Node = BTreeNode<Int, Void>
@@ -91,8 +91,8 @@
Loading
91 91
    }
92 92
93 93
    func test_elementsEqual_equatableValue() {
94 -
        let a = BTree<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) }, order: 5)
95 -
        let b = BTree<Int, String>(sortedElements: (0..<100).map { ($0, String($0)) }, order: 7)
94 +
        let a = BTree<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) }, order: 5)
95 +
        let b = BTree<Int, String>(sortedElements: (0 ..< 100).map { ($0, String($0)) }, order: 7)
96 96
        var c = a
97 97
        c.setValue(atOffset: 99, to: "*")
98 98
@@ -121,7 +121,6 @@
Loading
121 121
        XCTAssertTrue(b.elementsEqual(a, by: { $0.0 == $1.0 }))
122 122
    }
123 123
124 -
125 124
    func test_isDisjointWith_SimpleCases() {
126 125
        let firstHalf = makeTree(0 ..< 100)
127 126
        let secondHalf = makeTree(100 ..< 200)

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2015–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
class BTreeNodeTests: XCTestCase {
13 13
    typealias Node = BTreeNode<Int, String>
@@ -45,12 +45,12 @@
Loading
45 45
        XCTAssertTrue(node.children[1] === right)
46 46
        XCTAssertEqual(node.count, left.count + 1 + right.count)
47 47
48 -
        assertEqualElements(node, (0..<node.count).map { ($0, String($0)) })
48 +
        assertEqualElements(node, (0 ..< node.count).map { ($0, String($0)) })
49 49
    }
50 50
51 51
    func testNodeInitRange() {
52 52
        let source = maximalNode(depth: 1, order: 5)
53 -
        let node = Node(node: source, slotRange: 1..<3)
53 +
        let node = Node(node: source, slotRange: 1 ..< 3)
54 54
55 55
        assertEqualElements(node.elements, [(9, "9"), (14, "14")])
56 56
        XCTAssertEqual(node.depth, 1)
@@ -62,21 +62,20 @@
Loading
62 62
        XCTAssertEqual(node.order, 5)
63 63
        XCTAssertEqual(node.depth, 1)
64 64
65 -
        let node2 = Node(node: maximalNode(depth: 0, order: 5), slotRange: 1..<3)
65 +
        let node2 = Node(node: maximalNode(depth: 0, order: 5), slotRange: 1 ..< 3)
66 66
        assertEqualElements(node2.elements, [(1, "1"), (2, "2")])
67 67
        XCTAssertEqual(node2.children.count, 0)
68 68
        XCTAssertEqual(node2.count, 2)
69 69
        XCTAssertEqual(node2.order, 5)
70 70
        XCTAssertEqual(node2.depth, 0)
71 71
72 -
        let node3 = Node(node: source, slotRange: 1..<1)
72 +
        let node3 = Node(node: source, slotRange: 1 ..< 1)
73 73
        assertEqualElements(node3.elements, [(5, "5"), (6, "6"), (7, "7"), (8, "8")])
74 74
        XCTAssertEqual(node3.depth, 0)
75 75
        XCTAssertEqual(node3.children.count, 0)
76 76
        XCTAssertEqual(node3.count, 4)
77 77
        XCTAssertEqual(node3.order, 5)
78 78
        XCTAssertEqual(node3.depth, 0)
79 -
80 79
    }
81 80
82 81
    func testMakeChildUnique() {
@@ -99,7 +98,7 @@
Loading
99 98
        XCTAssertFalse(node === clone)
100 99
        assertEqualElements(node.elements, clone.elements)
101 100
        XCTAssertEqual(node.children.count, clone.children.count)
102 -
        for i in 0..<node.children.count {
101 +
        for i in 0 ..< node.children.count {
103 102
            XCTAssertTrue(node.children[i] === clone.children[i])
104 103
        }
105 104
        XCTAssertEqual(node.count, clone.count)
@@ -129,11 +128,11 @@
Loading
129 128
        let node = Node(order: 5)
130 129
        assertEqualElements(IteratorSequence(node.makeIterator()), [])
131 130
    }
132 -
    
131 +
133 132
    func testGenerateOnNonemptyNode() {
134 133
        let node = maximalNode(depth: 2, order: 5)
135 134
136 -
        assertEqualElements(IteratorSequence(node.makeIterator()), (0..<124).map { ($0, String($0)) })
135 +
        assertEqualElements(IteratorSequence(node.makeIterator()), (0 ..< 124).map { ($0, String($0)) })
137 136
    }
138 137
139 138
    func testStandardForEach() {
@@ -161,11 +160,11 @@
Loading
161 160
        XCTAssertEqual(i, 24 * 5 + 4)
162 161
163 162
        i = 0
164 -
        XCTAssertFalse(node.forEach { _,_ in i += 1; return false })
163 +
        XCTAssertFalse(node.forEach { _, _ in i += 1; return false })
165 164
        XCTAssertEqual(i, 1)
166 165
167 166
        i = 0
168 -
        XCTAssertFalse(node.forEach { (key, value) -> Bool in
167 +
        XCTAssertFalse(node.forEach { (_, _) -> Bool in
169 168
            XCTAssertLessThan(i, 100)
170 169
            i += 1
171 170
            return i != 100
@@ -173,11 +172,11 @@
Loading
173 172
        XCTAssertEqual(i, 100)
174 173
175 174
        i = 0
176 -
        XCTAssertFalse(node.forEach { (key, value) -> Bool in
175 +
        XCTAssertFalse(node.forEach { (_, _) -> Bool in
177 176
            XCTAssertLessThan(i, 120)
178 177
            i += 1
179 178
            return i != 120
180 -
            })
179 +
        })
181 180
        XCTAssertEqual(i, 120)
182 181
    }
183 182
@@ -205,7 +204,7 @@
Loading
205 204
        node.append((4, "4"))
206 205
207 206
        XCTAssertTrue(node.isTooLarge)
208 -
        assertEqualElements(node, (0..<5).map { ($0, String($0)) })
207 +
        assertEqualElements(node, (0 ..< 5).map { ($0, String($0)) })
209 208
    }
210 209
211 210
    func testRemoveSlot() {
@@ -362,10 +361,10 @@
Loading
362 361
        let splinter = node.split()
363 362
364 363
        XCTAssertEqual(node.count, 5)
365 -
        assertEqualElements(node.map { $0.0 }, 0..<5)
364 +
        assertEqualElements(node.map { $0.0 }, 0 ..< 5)
366 365
        XCTAssertEqual(splinter.separator.0, 5)
367 366
        XCTAssertEqual(splinter.node.count, 4)
368 -
        assertEqualElements(splinter.node.map { $0.0 }, 6..<10)
367 +
        assertEqualElements(splinter.node.map { $0.0 }, 6 ..< 10)
369 368
    }
370 369
371 370
    func testRotations() {
@@ -453,18 +452,18 @@
Loading
453 452
        checkNode(Node.join(left: createNode(), separator: (0, "0"), right: createNode()), 0 ..< 1)
454 453
        checkNode(Node.join(left: createNode(), separator: (0, "0"), right: createNode(1 ..< 2)), 0 ..< 2)
455 454
        checkNode(Node.join(left: createNode(0 ..< 1), separator: (1, "1"), right: createNode()), 0 ..< 2)
456 -
        checkNode(Node.join(left: createNode(0...0), separator: (1, "1"), right: createNode(2 ..< 3)), 0 ..< 3)
455 +
        checkNode(Node.join(left: createNode(0 ... 0), separator: (1, "1"), right: createNode(2 ..< 3)), 0 ..< 3)
457 456
458 -
        checkNode(Node.join(left: createNode(0...98), separator: (99, "99"), right: createNode(100 ..< 101)), 0 ..< 101)
459 -
        checkNode(Node.join(left: createNode(0...0), separator: (1, "1"), right: createNode(2 ..< 101)), 0 ..< 101)
460 -
        checkNode(Node.join(left: createNode(0...99), separator: (100, "100"), right: createNode(101 ..< 200)), 0 ..< 200)
457 +
        checkNode(Node.join(left: createNode(0 ... 98), separator: (99, "99"), right: createNode(100 ..< 101)), 0 ..< 101)
458 +
        checkNode(Node.join(left: createNode(0 ... 0), separator: (1, "1"), right: createNode(2 ..< 101)), 0 ..< 101)
459 +
        checkNode(Node.join(left: createNode(0 ... 99), separator: (100, "100"), right: createNode(101 ..< 200)), 0 ..< 200)
461 460
462 461
        do {
463 462
            let l = maximalNode(depth: 2, order: 3)
464 463
            let r = maximalNode(depth: 2, order: 3, offset: l.count + 1)
465 464
            let s = (l.count, String(l.count))
466 465
            let c = l.count + r.count + 1
467 -
            checkNode(Node.join(left: l, separator: s, right: r), 0..<c)
466 +
            checkNode(Node.join(left: l, separator: s, right: r), 0 ..< c)
468 467
        }
469 468
470 469
        do {
@@ -472,7 +471,7 @@
Loading
472 471
            let r = maximalNode(depth: 2, order: 3, offset: l.count + 1)
473 472
            let s = (l.count, String(l.count))
474 473
            let c = l.count + r.count + 1
475 -
            checkNode(Node.join(left: l, separator: s, right: r), 0..<c)
474 +
            checkNode(Node.join(left: l, separator: s, right: r), 0 ..< c)
476 475
        }
477 476
478 477
        do {
@@ -480,16 +479,16 @@
Loading
480 479
            let r = maximalNode(depth: 1, order: 3, offset: l.count + 1)
481 480
            let s = (l.count, String(l.count))
482 481
            let c = l.count + r.count + 1
483 -
            checkNode(Node.join(left: l, separator: s, right: r), 0..<c)
482 +
            checkNode(Node.join(left: l, separator: s, right: r), 0 ..< c)
484 483
        }
485 484
    }
486 485
487 486
    func testJoinWithDuplicateKeys() {
488 -
        let left = BTree(sortedElements: (0..<50).map { (0, $0) }, order: 3).root
487 +
        let left = BTree(sortedElements: (0 ..< 50).map { (0, $0) }, order: 3).root
489 488
        let sep = (0, 50)
490 -
        let right = BTree(sortedElements: (51..<100).map { (0, $0) }, order: 3).root
489 +
        let right = BTree(sortedElements: (51 ..< 100).map { (0, $0) }, order: 3).root
491 490
        let node = BTreeNode.join(left: left, separator: sep, right: right)
492 491
        node.assertValid()
493 -
        assertEqualElements(node, (0..<100).map { (0, $0) })
492 +
        assertEqualElements(node, (0 ..< 100).map { (0, $0) })
494 493
    }
495 494
}

@@ -8,8 +8,8 @@
Loading
8 8
9 9
import Foundation
10 10
11 -
import XCTest
12 11
import BTree
12 +
import XCTest
13 13
14 14
func assertEqualElements<Element: Equatable, S1: Sequence, S2: Sequence>(_ a: S1, _ b: S2, file: StaticString = #file, line: UInt = #line) where S1.Element == Element, S2.Element == Element {
15 15
    let aa = Array(a)
@@ -27,7 +27,7 @@
Loading
27 27
    }
28 28
}
29 29
30 -
func assertEqualElements<Element: Equatable, S1: Sequence, S2: Sequence, S1W: Sequence, S2W: Sequence>(_ a: S1, _ b: S2, element: Element.Type = Element.self, file: StaticString = #file, line: UInt = #line) where S1.Element == S1W, S2.Element == S2W, S1W.Element == Element, S2W.Element == Element {
30 +
func assertEqualElements<Element: Equatable, S1: Sequence, S2: Sequence, S1W: Sequence, S2W: Sequence>(_ a: S1, _ b: S2, element _: Element.Type = Element.self, file: StaticString = #file, line: UInt = #line) where S1.Element == S1W, S2.Element == S2W, S1W.Element == Element, S2W.Element == Element {
31 31
    let aa = a.map { Array($0) }
32 32
    let ba = b.map { Array($0) }
33 33
    if !aa.elementsEqual(ba, by: { $0.elementsEqual($1) }) {
@@ -35,19 +35,18 @@
Loading
35 35
    }
36 36
}
37 37
38 -
39 38
extension BTree {
40 39
    internal func assertKeysEqual(_ other: BTree<Key, Value>, file: StaticString = #file, line: UInt = #line) {
41 -
        assertEqualElements(self.map { $0.0 }, other.map { $0.0 }, file: file, line: line)
40 +
        assertEqualElements(map { $0.0 }, other.map { $0.0 }, file: file, line: line)
42 41
    }
43 42
44 43
    internal func assertKeysEqual<S: Sequence>(_ s: S, file: StaticString = #file, line: UInt = #line) where S.Element == Key {
45 -
        assertEqualElements(self.map { $0.0 }, s, file: file, line: line)
44 +
        assertEqualElements(map { $0.0 }, s, file: file, line: line)
46 45
    }
47 46
}
48 47
49 48
internal extension Sequence {
50 -
    func repeatEach(_ count: Int) -> Array<Element> {
49 +
    func repeatEach(_ count: Int) -> [Element] {
51 50
        var result: [Element] = []
52 51
        result.reserveCapacity(count * underestimatedCount)
53 52
        for element in self {

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2016–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
import BTree
10 +
import XCTest
11 11
12 12
private final class Test: Comparable, ExpressibleByIntegerLiteral {
13 13
    let value: Int
@@ -15,12 +15,11 @@
Loading
15 15
    init(_ value: Int) { self.value = value }
16 16
    init(integerLiteral value: Int) { self.value = value }
17 17
18 -
    static func ==(a: Test, b: Test) -> Bool { return a.value == b.value }
19 -
    static func <(a: Test, b: Test) -> Bool { return a.value < b.value }
18 +
    static func == (a: Test, b: Test) -> Bool { return a.value == b.value }
19 +
    static func < (a: Test, b: Test) -> Bool { return a.value < b.value }
20 20
}
21 21
22 22
class SortedSetTests: XCTestCase {
23 -
24 23
    func test_emptySet() {
25 24
        let set = SortedSet<Int>()
26 25
@@ -44,7 +43,7 @@
Loading
44 43
    }
45 44
46 45
    func test_unsortedElements_uniqueItems() {
47 -
        let c = 10_000
46 +
        let c = 10000
48 47
        let set = SortedSet((0 ..< c).reversed())
49 48
50 49
        XCTAssertEqual(set.count, c)
@@ -52,7 +51,7 @@
Loading
52 51
    }
53 52
54 53
    func test_unsortedElements_duplicateItems() {
55 -
        let c = 10_000
54 +
        let c = 10000
56 55
        let set = SortedSet((0 ..< c).reversed().repeatEach(10))
57 56
58 57
        XCTAssertEqual(set.count, c)
@@ -60,7 +59,7 @@
Loading
60 59
    }
61 60
62 61
    func test_sortedElements_uniqueItems() {
63 -
        let c = 10_000
62 +
        let c = 10000
64 63
        let set = SortedSet(sortedElements: 0 ..< c)
65 64
66 65
        XCTAssertEqual(set.count, c)
@@ -68,7 +67,7 @@
Loading
68 67
    }
69 68
70 69
    func test_sortedElements_duplicateItems() {
71 -
        let c = 10_000
70 +
        let c = 10000
72 71
        let set = SortedSet(sortedElements: (0 ..< c).repeatEach(10))
73 72
74 73
        XCTAssertEqual(set.count, c)
@@ -83,7 +82,7 @@
Loading
83 82
    }
84 83
85 84
    func test_subscriptWithIndexing() {
86 -
        let c = 10_000
85 +
        let c = 10000
87 86
        let set = SortedSet(0 ..< c)
88 87
        var i = 0
89 88
        var index = set.startIndex
@@ -113,13 +112,13 @@
Loading
113 112
    }
114 113
115 114
    func test_makeIterator() {
116 -
        let c = 10_000
115 +
        let c = 10000
117 116
        let set = SortedSet(0 ..< c)
118 117
        assertEqualElements(IteratorSequence(set.makeIterator()), 0 ..< c)
119 118
    }
120 119
121 120
    func test_subscriptByOffsets() {
122 -
        let c = 10_000
121 +
        let c = 10000
123 122
        let set = SortedSet(0 ..< c)
124 123
        for i in 0 ..< c {
125 124
            XCTAssertEqual(set[i], i)
@@ -137,7 +136,7 @@
Loading
137 136
    }
138 137
139 138
    func test_indexing() {
140 -
        let s = SortedSet(sortedElements: (0..<10))
139 +
        let s = SortedSet(sortedElements: 0 ..< 10)
141 140
        var index = s.startIndex
142 141
        XCTAssertEqual(s.index(after: index), s.index(ofOffset: 1))
143 142
        XCTAssertEqual(s.index(index, offsetBy: 5), s.index(ofOffset: 5))
@@ -172,8 +171,7 @@
Loading
172 171
        for m in 0 ..< 20 {
173 172
            if m & 1 == 0 {
174 173
                XCTAssertEqual(s.offset(of: m), m / 2)
175 -
            }
176 -
            else {
174 +
            } else {
177 175
                XCTAssertNil(s.offset(of: m))
178 176
            }
179 177
        }
@@ -183,7 +181,7 @@
Loading
183 181
    }
184 182
185 183
    func test_forEach() {
186 -
        let c = 10_000
184 +
        let c = 10000
187 185
        let set = SortedSet(0 ..< c)
188 186
        var i = 0
189 187
        set.forEach { n in
@@ -193,7 +191,7 @@
Loading
193 191
    }
194 192
195 193
    func test_map() {
196 -
        let c = 10_000
194 +
        let c = 10000
197 195
        let set = SortedSet(0 ..< c)
198 196
        var i = 0
199 197
        let r = set.map { (n: Int) -> Int in
@@ -271,7 +269,6 @@
Loading
271 269
        assertEqualElements(set.prefix(upTo: c), 0 ..< c)
272 270
273 271
        assertEqualElements(set.prefix(upTo: 2 * c), 0 ..< c)
274 -
275 272
    }
276 273
277 274
    func test_suffix() {
@@ -313,8 +310,7 @@
Loading
313 310
            if i & 1 == 0 {
314 311
                XCTAssertEqual(index, set.index(set.startIndex, offsetBy: i / 2))
315 312
                XCTAssertEqual(set[index!], i)
316 -
            }
317 -
            else {
313 +
            } else {
318 314
                XCTAssertNil(index)
319 315
            }
320 316
        }
@@ -332,12 +328,10 @@
Loading
332 328
                let element = set[index]
333 329
                if i & 1 == 0 {
334 330
                    XCTAssertEqual(element, i + 2)
335 -
                }
336 -
                else {
331 +
                } else {
337 332
                    XCTAssertEqual(element, i + 1)
338 333
                }
339 -
            }
340 -
            else {
334 +
            } else {
341 335
                XCTAssertNil(index)
342 336
            }
343 337
        }
@@ -355,12 +349,10 @@
Loading
355 349
                let element = set[index]
356 350
                if i & 1 == 0 {
357 351
                    XCTAssertEqual(element, i)
358 -
                }
359 -
                else {
352 +
                } else {
360 353
                    XCTAssertEqual(element, i + 1)
361 354
                }
362 -
            }
363 -
            else {
355 +
            } else {
364 356
                XCTAssertNil(index)
365 357
            }
366 358
        }
@@ -378,12 +370,10 @@
Loading
378 370
                let element = set[index]
379 371
                if i & 1 == 0 {
380 372
                    XCTAssertEqual(element, i - 2)
381 -
                }
382 -
                else {
373 +
                } else {
383 374
                    XCTAssertEqual(element, i - 1)
384 375
                }
385 -
            }
386 -
            else {
376 +
            } else {
387 377
                XCTAssertNil(index)
388 378
            }
389 379
        }
@@ -401,12 +391,10 @@
Loading
401 391
                let element = set[index]
402 392
                if i & 1 == 0 {
403 393
                    XCTAssertEqual(element, i)
404 -
                }
405 -
                else {
394 +
                } else {
406 395
                    XCTAssertEqual(element, i - 1)
407 396
                }
408 -
            }
409 -
            else {
397 +
            } else {
410 398
                XCTAssertNil(index)
411 399
            }
412 400
        }
@@ -488,15 +476,13 @@
Loading
488 476
        assertEqualElements(set, (1 ... 100).map { Test($0) })
489 477
    }
490 478
491 -
492 479
    func test_remove() {
493 480
        let c = 500
494 481
        var set = SortedSet((0 ..< c).map { 2 * $0 })
495 482
        for i in 0 ..< 2 * c {
496 483
            if i & 1 == 0 {
497 484
                XCTAssertEqual(set.remove(i), i)
498 -
            }
499 -
            else {
485 +
            } else {
500 486
                XCTAssertNil(set.remove(i))
501 487
            }
502 488
        }
@@ -591,8 +577,8 @@
Loading
591 577
        XCTAssertFalse(a == b)
592 578
        XCTAssertFalse(a == c)
593 579
594 -
        XCTAssertFalse(a.isDisjoint(with:b))
595 -
        XCTAssertTrue(b.isDisjoint(with:c))
580 +
        XCTAssertFalse(a.isDisjoint(with: b))
581 +
        XCTAssertTrue(b.isDisjoint(with: c))
596 582
597 583
        XCTAssertTrue(b.isSubset(of: a))
598 584
        XCTAssertTrue(c.isSubset(of: a))
@@ -612,65 +598,64 @@
Loading
612 598
    }
613 599
614 600
    func test_countElementsInRange() {
615 -
        let s = SortedSet(sortedElements: 0 ..< 10_000)
601 +
        let s = SortedSet(sortedElements: 0 ..< 10000)
616 602
        XCTAssertEqual(s.count(elementsIn: -100 ..< -10), 0)
617 603
        XCTAssertEqual(s.count(elementsIn: 0 ..< 100), 100)
618 -
        XCTAssertEqual(s.count(elementsIn: 3 ..< 9_999), 9_996)
619 -
        XCTAssertEqual(s.count(elementsIn: 0 ..< 10_000), 10_000)
604 +
        XCTAssertEqual(s.count(elementsIn: 3 ..< 9999), 9996)
605 +
        XCTAssertEqual(s.count(elementsIn: 0 ..< 10000), 10000)
620 606
        XCTAssertEqual(s.count(elementsIn: -100 ..< 100), 100)
621 -
        XCTAssertEqual(s.count(elementsIn: 9_900 ..< 10_100), 100)
622 -
        XCTAssertEqual(s.count(elementsIn: -100 ..< 20_000), 10_000)
623 -
607 +
        XCTAssertEqual(s.count(elementsIn: 9900 ..< 10100), 100)
608 +
        XCTAssertEqual(s.count(elementsIn: -100 ..< 20000), 10000)
624 609
625 610
        XCTAssertEqual(s.count(elementsIn: -100 ... -10), 0)
626 611
        XCTAssertEqual(s.count(elementsIn: 0 ... 100), 101)
627 -
        XCTAssertEqual(s.count(elementsIn: 3 ... 9_999), 9_997)
628 -
        XCTAssertEqual(s.count(elementsIn: 0 ... 9_999), 10_000)
612 +
        XCTAssertEqual(s.count(elementsIn: 3 ... 9999), 9997)
613 +
        XCTAssertEqual(s.count(elementsIn: 0 ... 9999), 10000)
629 614
        XCTAssertEqual(s.count(elementsIn: -100 ... 100), 101)
630 -
        XCTAssertEqual(s.count(elementsIn: 9_900 ... 10_100), 100)
631 -
        XCTAssertEqual(s.count(elementsIn: -100 ... 20_000), 10_000)
615 +
        XCTAssertEqual(s.count(elementsIn: 9900 ... 10100), 100)
616 +
        XCTAssertEqual(s.count(elementsIn: -100 ... 20000), 10000)
632 617
    }
633 618
634 619
    func test_intersectionWithRange() {
635 -
        var s = SortedSet(sortedElements: 0 ..< 10_000)
620 +
        var s = SortedSet(sortedElements: 0 ..< 10000)
636 621
        assertEqualElements(s.intersection(elementsIn: -100 ..< -10), [])
637 -
        assertEqualElements(s.intersection(elementsIn: 100 ..< 9_900), 100 ..< 9_900)
622 +
        assertEqualElements(s.intersection(elementsIn: 100 ..< 9900), 100 ..< 9900)
638 623
        assertEqualElements(s.intersection(elementsIn: -100 ..< 100), 0 ..< 100)
639 -
        assertEqualElements(s.intersection(elementsIn: 9_900 ..< 10_100), 9_900 ..< 10_000)
640 -
        assertEqualElements(s.intersection(elementsIn: 10_100 ..< 10_200), [])
624 +
        assertEqualElements(s.intersection(elementsIn: 9900 ..< 10100), 9900 ..< 10000)
625 +
        assertEqualElements(s.intersection(elementsIn: 10100 ..< 10200), [])
641 626
642 627
        assertEqualElements(s.intersection(elementsIn: -100 ... -10), [])
643 -
        assertEqualElements(s.intersection(elementsIn: 100 ... 9_900), 100 ... 9_900)
628 +
        assertEqualElements(s.intersection(elementsIn: 100 ... 9900), 100 ... 9900)
644 629
        assertEqualElements(s.intersection(elementsIn: -100 ... 100), 0 ... 100)
645 -
        assertEqualElements(s.intersection(elementsIn: 9_900 ... 10_100), 9_900 ..< 10_000)
646 -
        assertEqualElements(s.intersection(elementsIn: 10_100 ... 10_200), [])
630 +
        assertEqualElements(s.intersection(elementsIn: 9900 ... 10100), 9900 ..< 10000)
631 +
        assertEqualElements(s.intersection(elementsIn: 10100 ... 10200), [])
647 632
648 -
        s.formIntersection(elementsIn: 1_000 ..< 2_000)
649 -
        assertEqualElements(s, 1_000 ..< 2_000)
633 +
        s.formIntersection(elementsIn: 1000 ..< 2000)
634 +
        assertEqualElements(s, 1000 ..< 2000)
650 635
651 -
        s.formIntersection(elementsIn: 1_100 ... 1_200)
652 -
        assertEqualElements(s, 1_100 ... 1_200)
636 +
        s.formIntersection(elementsIn: 1100 ... 1200)
637 +
        assertEqualElements(s, 1100 ... 1200)
653 638
    }
654 639
655 640
    func test_subtractionOfRange() {
656 -
        var s = SortedSet(sortedElements: 0 ..< 10_000)
657 -
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 0), 0 ..< 10_000)
658 -
        assertEqualElements(s.subtracting(elementsIn: 100 ..< 9_900), Array(0 ..< 100) + Array(9_900 ..< 10_000))
659 -
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 100), 100 ..< 10_000)
660 -
        assertEqualElements(s.subtracting(elementsIn: 9_900 ..< 10_100), 0 ..< 9_900)
661 -
        assertEqualElements(s.subtracting(elementsIn: 10_000 ..< 10_100), 0 ..< 10_000)
662 -
663 -
        assertEqualElements(s.subtracting(elementsIn: -100 ... -1), 0 ..< 10_000)
664 -
        assertEqualElements(s.subtracting(elementsIn: 100 ... 9_900), Array(0 ..< 100) + Array(9_901 ..< 10_000))
665 -
        assertEqualElements(s.subtracting(elementsIn: -100 ... 100), 101 ..< 10_000)
666 -
        assertEqualElements(s.subtracting(elementsIn: 9_900 ... 10_100), 0 ..< 9_900)
667 -
        assertEqualElements(s.subtracting(elementsIn: 10_000 ... 10_100), 0 ..< 10_000)
668 -
669 -
        s.subtract(elementsIn: 1_000 ..< 9_000)
670 -
        assertEqualElements(s, Array(0 ..< 1_000) + Array(9_000 ..< 10_000))
641 +
        var s = SortedSet(sortedElements: 0 ..< 10000)
642 +
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 0), 0 ..< 10000)
643 +
        assertEqualElements(s.subtracting(elementsIn: 100 ..< 9900), Array(0 ..< 100) + Array(9900 ..< 10000))
644 +
        assertEqualElements(s.subtracting(elementsIn: -100 ..< 100), 100 ..< 10000)
645 +
        assertEqualElements(s.subtracting(elementsIn: 9900 ..< 10100), 0 ..< 9900)
646 +
        assertEqualElements(s.subtracting(elementsIn: 10000 ..< 10100), 0 ..< 10000)
647 +
648 +
        assertEqualElements(s.subtracting(elementsIn: -100 ... -1), 0 ..< 10000)
649 +
        assertEqualElements(s.subtracting(elementsIn: 100 ... 9900), Array(0 ..< 100) + Array(9901 ..< 10000))
650 +
        assertEqualElements(s.subtracting(elementsIn: -100 ... 100), 101 ..< 10000)
651 +
        assertEqualElements(s.subtracting(elementsIn: 9900 ... 10100), 0 ..< 9900)
652 +
        assertEqualElements(s.subtracting(elementsIn: 10000 ... 10100), 0 ..< 10000)
653 +
654 +
        s.subtract(elementsIn: 1000 ..< 9000)
655 +
        assertEqualElements(s, Array(0 ..< 1000) + Array(9000 ..< 10000))
671 656
672 657
        s.subtract(elementsIn: 100 ... 900)
673 -
        assertEqualElements(s, Array(0 ..< 100) + Array(901 ..< 1_000) + Array(9_000 ..< 10_000))
658 +
        assertEqualElements(s, Array(0 ..< 100) + Array(901 ..< 1000) + Array(9000 ..< 10000))
674 659
    }
675 660
676 661
    func test_shift() {

@@ -6,8 +6,8 @@
Loading
6 6
//  Copyright © 2016–2017 Károly Lőrentey.
7 7
//
8 8
9 -
import XCTest
10 9
@testable import BTree
10 +
import XCTest
11 11
12 12
class BTreeMergeTests: XCTestCase {
13 13
    typealias Builder = BTreeBuilder<Int, Void>
@@ -31,7 +31,7 @@
Loading
31 31
        return Tree(b.finish())
32 32
    }
33 33
34 -
    //MARK: Union by grouping matches
34 +
    // MARK: Union by grouping matches
35 35
36 36
    func test_unionByGrouping_simple() {
37 37
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -67,8 +67,8 @@
Loading
67 67
    }
68 68
69 69
    func test_unionByGrouping_halves() {
70 -
        let first = makeTree(0..<50)
71 -
        let second = makeTree(50..<100)
70 +
        let first = makeTree(0 ..< 50)
71 +
        let second = makeTree(50 ..< 100)
72 72
73 73
        let u1 = first.union(second, by: .groupingMatches)
74 74
        u1.assertValid()
@@ -134,7 +134,7 @@
Loading
134 134
        }
135 135
    }
136 136
137 -
    //MARK: Union by counting matches
137 +
    // MARK: Union by counting matches
138 138
139 139
    func test_unionByCounting_simple() {
140 140
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -170,8 +170,8 @@
Loading
170 170
    }
171 171
172 172
    func test_unionByCounting_halves() {
173 -
        let first = makeTree(0..<50)
174 -
        let second = makeTree(50..<100)
173 +
        let first = makeTree(0 ..< 50)
174 +
        let second = makeTree(50 ..< 100)
175 175
176 176
        let u1 = first.union(second, by: .countingMatches)
177 177
        u1.assertValid()
@@ -229,7 +229,7 @@
Loading
229 229
        let tree = makeTree(keys)
230 230
        tree.forEachSubtree { subtree in
231 231
            let expected = keys.union(subtree.map { $0.0 }).sorted()
232 -
            
232 +
233 233
            let u1 = subtree.union(tree, by: .countingMatches)
234 234
            u1.assertKeysEqual(expected)
235 235
@@ -238,7 +238,7 @@
Loading
238 238
        }
239 239
    }
240 240
241 -
    //MARK: Subtracting by grouping matches
241 +
    // MARK: Subtracting by grouping matches
242 242
243 243
    func test_subtractingByGrouping_simple() {
244 244
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -274,8 +274,8 @@
Loading
274 274
    }
275 275
276 276
    func test_subtractingByGrouping_halves() {
277 -
        let first = makeTree(0..<50)
278 -
        let second = makeTree(50..<100)
277 +
        let first = makeTree(0 ..< 50)
278 +
        let second = makeTree(50 ..< 100)
279 279
280 280
        let u1 = first.subtracting(second, by: .groupingMatches)
281 281
        u1.assertValid()
@@ -341,7 +341,7 @@
Loading
341 341
        }
342 342
    }
343 343
344 -
    //MARK: Subtracting by counting matches
344 +
    // MARK: Subtracting by counting matches
345 345
346 346
    func test_subtractingByCounting_simple() {
347 347
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -377,8 +377,8 @@
Loading
377 377
    }
378 378
379 379
    func test_subtractingByCounting_halves() {
380 -
        let first = makeTree(0..<50)
381 -
        let second = makeTree(50..<100)
380 +
        let first = makeTree(0 ..< 50)
381 +
        let second = makeTree(50 ..< 100)
382 382
383 383
        let u1 = first.subtracting(second, by: .countingMatches)
384 384
        u1.assertValid()
@@ -425,7 +425,7 @@
Loading
425 425
        let u1 = first.subtracting(second, by: .countingMatches)
426 426
        u1.assertValid()
427 427
        u1.assertKeysEqual([3].repeatEach(20))
428 -
        
428 +
429 429
        let u2 = second.subtracting(first, by: .countingMatches)
430 430
        u2.assertValid()
431 431
        u2.assertKeysEqual([7].repeatEach(20))
@@ -445,7 +445,7 @@
Loading
445 445
        }
446 446
    }
447 447
448 -
    //MARK: Symmetric difference by grouping matches
448 +
    // MARK: Symmetric difference by grouping matches
449 449
450 450
    func test_symmetricDifferenceByGrouping_simple() {
451 451
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -481,8 +481,8 @@
Loading
481 481
    }
482 482
483 483
    func test_symmetricDifferenceByGrouping_halves() {
484 -
        let first = makeTree(0..<50)
485 -
        let second = makeTree(50..<100)
484 +
        let first = makeTree(0 ..< 50)
485 +
        let second = makeTree(50 ..< 100)
486 486
487 487
        let u1 = first.symmetricDifference(second, by: .groupingMatches)
488 488
        u1.assertValid()
@@ -550,7 +550,7 @@
Loading
550 550
        }
551 551
    }
552 552
553 -
    //MARK: Symmetric Difference by counting matches
553 +
    // MARK: Symmetric Difference by counting matches
554 554
555 555
    func test_symmetricDifferenceByCounting_simple() {
556 556
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -586,8 +586,8 @@
Loading
586 586
    }
587 587
588 588
    func test_symmetricDifferenceByCounting_halves() {
589 -
        let first = makeTree(0..<50)
590 -
        let second = makeTree(50..<100)
589 +
        let first = makeTree(0 ..< 50)
590 +
        let second = makeTree(50 ..< 100)
591 591
592 592
        let u1 = first.symmetricDifference(second, by: .countingMatches)
593 593
        u1.assertValid()
@@ -655,7 +655,7 @@
Loading
655 655
        }
656 656
    }
657 657
658 -
    //MARK: Intersection by grouping matches
658 +
    // MARK: Intersection by grouping matches
659 659
660 660
    func test_IntersectionByGrouping_simple() {
661 661
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -691,8 +691,8 @@
Loading
691 691
    }
692 692
693 693
    func test_IntersectionByGrouping_halves() {
694 -
        let first = makeTree(0..<50)
695 -
        let second = makeTree(50..<100)
694 +
        let first = makeTree(0 ..< 50)
695 +
        let second = makeTree(50 ..< 100)
696 696
697 697
        let u1 = first.intersection(second, by: .groupingMatches)
698 698
        u1.assertValid()
@@ -778,7 +778,7 @@
Loading
778 778
        }
779 779
    }
780 780
781 -
    //MARK: Intersection by counting matches
781 +
    // MARK: Intersection by counting matches
782 782
783 783
    func test_IntersectionByCounting_simple() {
784 784
        let even = makeTree(stride(from: 0, to: 100, by: 2))
@@ -814,8 +814,8 @@
Loading
814 814
    }
815 815
816 816
    func test_IntersectionByCounting_halves() {
817 -
        let first = makeTree(0..<50)
818 -
        let second = makeTree(50..<100)
817 +
        let first = makeTree(0 ..< 50)
818 +
        let second = makeTree(50 ..< 100)
819 819
820 820
        let u1 = first.intersection(second, by: .countingMatches)
821 821
        u1.assertValid()
@@ -974,6 +974,6 @@
Loading
974 974
975 975
        let tree2 = BTree(sortedElements: (0 ..< 100).map { ($0 / 2, String($0)) })
976 976
        let t5 = tree2.intersection(sortedKeys: 0 ..< 50, by: .countingMatches)
977 -
        assertEqualElements(t5.map { $0.0 }, (0 ..< 50))
977 +
        assertEqualElements(t5.map { $0.0 }, 0 ..< 50)
978 978
    }
979 979
}

@@ -6,9 +6,9 @@
Loading
6 6
//  Copyright © 2015–2017 Károly Lőrentey.
7 7
//
8 8
9 +
@testable import BTree
9 10
import Foundation
10 11
import XCTest
11 -
@testable import BTree
12 12
13 13
extension BTree {
14 14
    func assertValid(file: StaticString = #file, line: UInt = #line) {
@@ -42,7 +42,7 @@
Loading
42 42
                if node.elements.count > node.order - 1 {
43 43
                    defects.append("Oversize leaf node: \(node.elements.count) > \(node.order - 1)")
44 44
                }
45 -
                if level > 0 && node.elements.count < (node.order - 1) / 2 {
45 +
                if level > 0, node.elements.count < (node.order - 1) / 2 {
46 46
                    defects.append("Undersize leaf node: \(node.elements.count) < \((node.order - 1) / 2)")
47 47
                }
48 48
                if !node.children.isEmpty {
@@ -58,10 +58,10 @@
Loading
58 58
            if node.children.count > node.order {
59 59
                defects.append("Oversize internal node: \(node.children.count) > \(node.order)")
60 60
            }
61 -
            if level > 0 && node.children.count < (node.order + 1) / 2 {
61 +
            if level > 0, node.children.count < (node.order + 1) / 2 {
62 62
                defects.append("Undersize internal node: \(node.children.count) < \((node.order + 1) / 2)")
63 63
            }
64 -
            if level == 0 && node.children.count < 2 {
64 +
            if level == 0, node.children.count < 2 {
65 65
                defects.append("Undersize root node: \(node.children.count) < 2")
66 66
            }
67 67
            // Check item count
@@ -77,7 +77,8 @@
Loading
77 77
                    level: level + 1,
78 78
                    node: child,
79 79
                    minKey: (slot > 0 ? node.elements.map { $0.0 }[slot - 1] : minKey),
80 -
                    maxKey: (slot < node.elements.count - 1 ? node.elements.map { $0.0 }[slot + 1] : maxKey))
80 +
                    maxKey: (slot < node.elements.count - 1 ? node.elements.map { $0.0 }[slot + 1] : maxKey)
81 +
                )
81 82
                if node.depth != child.depth + 1 {
82 83
                    defects.append("Invalid depth: \(node.depth) in parent vs \(child.depth) in child")
83 84
                }
@@ -97,7 +98,7 @@
Loading
97 98
    }
98 99
99 100
    func forEachNode(_ operation: (Node) -> Void) {
100 -
        for level in (0 ... self.depth).reversed() {
101 +
        for level in (0 ... depth).reversed() {
101 102
            forEachNode(onLevel: level, operation)
102 103
        }
103 104
    }
@@ -105,8 +106,7 @@
Loading
105 106
    func forEachNode(onLevel level: Int, _ operation: (Node) -> Void) {
106 107
        if level == 0 {
107 108
            operation(self)
108 -
        }
109 -
        else {
109 +
        } else {
110 110
            for child in children {
111 111
                child.forEachNode(onLevel: level - 1, operation)
112 112
            }
@@ -118,8 +118,7 @@
Loading
118 118
        if isLeaf {
119 119
            let keys = elements.lazy.map { "\($0.0)" }
120 120
            r += keys.joined(separator: " ")
121 -
        }
122 -
        else {
121 +
        } else {
123 122
            for i in 0 ..< elements.count {
124 123
                r += children[i].dump
125 124
                r += " \(elements[i].0) "
@@ -201,7 +200,7 @@
Loading
201 200
            i += 3
202 201
        }
203 202
204 -
        assertEqualElements(node, (0..<8).map { ($0, String($0)) })
203 +
        assertEqualElements(node, (0 ..< 8).map { ($0, String($0)) })
205 204
    }
206 205
207 206
    func testMinimalNodeOfDepth0() {
@@ -240,8 +239,8 @@
Loading
240 239
            XCTAssertEqual(child.depth, 0)
241 240
            i += 2
242 241
        }
243 -
        
244 -
        assertEqualElements(node, (0..<3).map { ($0, String($0)) })
242 +
243 +
        assertEqualElements(node, (0 ..< 3).map { ($0, String($0)) })
245 244
    }
246 245
}
247 246
@@ -254,11 +253,11 @@
Loading
254 253
        self.elementIndex = elementIndex
255 254
    }
256 255
257 -
    static func <(left: DictionaryBagIndex, right: DictionaryBagIndex) -> Bool {
256 +
    static func < (left: DictionaryBagIndex, right: DictionaryBagIndex) -> Bool {
258 257
        return (left.dictionaryIndex, left.elementIndex) < (right.dictionaryIndex, right.elementIndex)
259 258
    }
260 259
261 -
    static func ==(left: DictionaryBagIndex, right: DictionaryBagIndex) -> Bool {
260 +
    static func == (left: DictionaryBagIndex, right: DictionaryBagIndex) -> Bool {
262 261
        return (left.dictionaryIndex, left.elementIndex) == (right.dictionaryIndex, right.elementIndex)
263 262
    }
264 263
}
@@ -274,7 +273,7 @@
Loading
274 273
275 274
    init<S: Sequence>(_ elements: S) where S.Element == Element {
276 275
        self.init()
277 -
        self.formUnion(elements)
276 +
        formUnion(elements)
278 277
    }
279 278
280 279
    var startIndex: Index {
@@ -289,8 +288,7 @@
Loading
289 288
        let c = bag[i.dictionaryIndex].value
290 289
        if i.elementIndex < c - 1 {
291 290
            return Index(i.dictionaryIndex, i.elementIndex + 1)
292 -
        }
293 -
        else {
291 +
        } else {
294 292
            return Index(bag.index(after: i.dictionaryIndex), 0)
295 293
        }
296 294
    }
@@ -312,8 +310,7 @@
Loading
312 310
        if c == 1 {
313 311
            bag[element] = nil
314 312
            count -= 1
315 -
        }
316 -
        else if c > 1 {
313 +
        } else if c > 1 {
317 314
            bag[element] = c - 1
318 315
            count -= 1
319 316
        }
@@ -321,7 +318,7 @@
Loading
321 318
322 319
    mutating func subtract<S: Sequence>(_ elements: S) where S.Element == Element {
323 320
        for element in elements {
324 -
            self.remove(element)
321 +
            remove(element)
325 322
        }
326 323
    }
327 324
@@ -348,7 +345,7 @@
Loading
348 345
349 346
    mutating func formUnion<S: Sequence>(_ elements: S) where S.Element == Element {
350 347
        for element in elements {
351 -
            self.insert(element)
348 +
            insert(element)
352 349
        }
353 350
    }
354 351
@@ -364,7 +361,8 @@
Loading
364 361
    var hashValue: Int {
365 362
        return ObjectIdentifier(target).hashValue
366 363
    }
367 -
    static func ==(left: Ref, right: Ref) -> Bool {
364 +
365 +
    static func == (left: Ref, right: Ref) -> Bool {
368 366
        return left.target === right.target
369 367
    }
370 368
}
Files Coverage
Tests/BTreeTests 98.56%
Project Totals (18 files) 98.56%
295.1
default=
TRAVIS_OS_NAME=osx
1
ignore:
2
  - "/Tests/*"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.