Skip to content

Commit 024d4e8

Browse files
authored
Merge pull request #17 from adamnemecek/removefix
fixed return value of remove, fixed some tests
2 parents cbbc242 + a35eaf3 commit 024d4e8

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

Sources/SwiftRoaring/RoaringBitmap.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,8 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
543543
@inlinable @inline(__always)
544544
@discardableResult
545545
public func remove(_ value: UInt32) -> UInt32? {
546-
guard self.removeCheck(value) else { return value }
547-
return nil
546+
guard self.removeCheck(value) else { return nil }
547+
return value
548548
}
549549

550550
///
@@ -740,7 +740,7 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
740740
}
741741

742742
///
743-
/// use with roaring_bitmap_serialize
743+
/// use with `roaring_bitmap_serialize`
744744
/// see `roaring_bitmap_portable_deserialize` if you want a format that's
745745
/// compatible with Java and Go implementations
746746
///
@@ -962,7 +962,7 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
962962
if self.count >= 100 {
963963
ret.append(", ...")
964964
}
965-
return "{\(ret)}"
965+
return "RoaringBitmap(\(ret))"
966966
}
967967

968968
///

Tests/swiftRoaringTests/swiftRoaringTests.swift

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@ class swiftRoaringTests: XCTestCase {
1111

1212
func testAdd() {
1313
rbm.add(35)
14-
XCTAssertEqual(rbm.contains(35), true)
14+
XCTAssertTrue(rbm.contains(35))
1515
}
1616

1717
func testRemove() {
1818
rbm.add(35)
19-
rbm.remove(35)
20-
XCTAssertEqual(rbm.contains(35), false)
19+
XCTAssert(rbm.remove(35) == 35)
20+
XCTAssertFalse(rbm.contains(35))
21+
}
22+
23+
func testUpdate() {
24+
rbm.add(35)
25+
XCTAssert(rbm.update(with: 35) == 35)
26+
XCTAssertTrue(rbm.contains(35))
2127
}
2228

2329
func testRemoveAll() {
2430
for k in stride(from: 0, to: 10000, by: 100) {
2531
rbm.add(UInt32(k))
2632
}
27-
XCTAssertEqual(rbm.isEmpty, false)
33+
XCTAssertFalse(rbm.isEmpty)
2834
rbm.removeAll()
29-
XCTAssertEqual(rbm.isEmpty, true)
35+
XCTAssertTrue(rbm.isEmpty)
3036
}
3137

3238
func testRemoveAllWhere() {
@@ -43,17 +49,17 @@ class swiftRoaringTests: XCTestCase {
4349
count += 1
4450
}
4551
for i in rbm {
46-
XCTAssertEqual(rbm.contains(i), true)
52+
XCTAssertTrue(rbm.contains(i))
4753
count -= 1
48-
if count < 0 {break}
54+
if count < 0 { break }
4955
}
5056
XCTAssertEqual(count, 0)
5157
}
5258

5359
func testInitRange() {
5460
let rbmRange = RoaringBitmap(min: 0, max: 1000, step: 50)
5561
for k in stride(from: 0, to: 1000, by: 50) {
56-
XCTAssertEqual(rbmRange.contains(UInt32(k)), true)
62+
XCTAssertTrue(rbmRange.contains(UInt32(k)))
5763
}
5864
}
5965

@@ -66,11 +72,11 @@ class swiftRoaringTests: XCTestCase {
6672
let array = [0, 1, 2, 4, 5, 6]
6773
let rbmArray = RoaringBitmap(values: array.map { UInt32($0) })
6874
for i in array {
69-
XCTAssertEqual(rbmArray.contains(UInt32(i)), true)
75+
XCTAssertTrue(rbmArray.contains(UInt32(i)))
7076
}
7177
let l: RoaringBitmap = [0, 1, 2, 4, 5, 6]
7278
for i in array {
73-
XCTAssertEqual(l.contains(UInt32(i)), true)
79+
XCTAssertTrue(l.contains(UInt32(i)))
7480
}
7581
}
7682

@@ -378,10 +384,10 @@ class swiftRoaringTests: XCTestCase {
378384
}
379385

380386
func testIsDisjoint() {
381-
let a: RoaringBitmap = [1,2,3,4,5]
382-
let b: RoaringBitmap = [6,7,8,9,10]
387+
let a: RoaringBitmap = [1, 2, 3, 4, 5]
388+
let b: RoaringBitmap = [6, 7, 8, 9, 10]
383389

384-
let c: RoaringBitmap = [5,6,7,8]
390+
let c: RoaringBitmap = [5, 6, 7, 8]
385391

386392
XCTAssert(a.isDisjoint(with: b))
387393
XCTAssert(!a.isDisjoint(with: c))

0 commit comments

Comments
 (0)