From 349405b20914c918b88951397aeff9058683e3e2 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Fri, 1 Jul 2022 11:29:51 -0700 Subject: [PATCH 1/2] fixed return value of remove, fixed some tests --- Sources/SwiftRoaring/RoaringBitmap.swift | 8 +++--- .../swiftRoaringTests/swiftRoaringTests.swift | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Sources/SwiftRoaring/RoaringBitmap.swift b/Sources/SwiftRoaring/RoaringBitmap.swift index 6574273..47ef793 100644 --- a/Sources/SwiftRoaring/RoaringBitmap.swift +++ b/Sources/SwiftRoaring/RoaringBitmap.swift @@ -543,8 +543,8 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible, @inlinable @inline(__always) @discardableResult public func remove(_ value: UInt32) -> UInt32? { - guard self.removeCheck(value) else { return value } - return nil + guard self.removeCheck(value) else { return nil } + return value } /// @@ -740,7 +740,7 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible, } /// - /// use with roaring_bitmap_serialize + /// use with `roaring_bitmap_serialize` /// see `roaring_bitmap_portable_deserialize` if you want a format that's /// compatible with Java and Go implementations /// @@ -962,7 +962,7 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible, if self.count >= 100 { ret.append(", ...") } - return "{\(ret)}" + return "RoaringBitmap(\(ret))" } /// diff --git a/Tests/swiftRoaringTests/swiftRoaringTests.swift b/Tests/swiftRoaringTests/swiftRoaringTests.swift index 8539c85..ce8ba17 100644 --- a/Tests/swiftRoaringTests/swiftRoaringTests.swift +++ b/Tests/swiftRoaringTests/swiftRoaringTests.swift @@ -11,22 +11,28 @@ class swiftRoaringTests: XCTestCase { func testAdd() { rbm.add(35) - XCTAssertEqual(rbm.contains(35), true) + XCTAssertTrue(rbm.contains(35)) } func testRemove() { rbm.add(35) - rbm.remove(35) - XCTAssertEqual(rbm.contains(35), false) + XCTAssert(rbm.remove(35) == 35) + XCTAssertFalse(rbm.contains(35)) + } + + func testUpdate() { + rbm.add(35) + XCTAssert(rbm.update(with: 35) == 35) + XCTAssertTrue(rbm.contains(35)) } func testRemoveAll() { for k in stride(from: 0, to: 10000, by: 100) { rbm.add(UInt32(k)) } - XCTAssertEqual(rbm.isEmpty, false) + XCTAssertFalse(rbm.isEmpty) rbm.removeAll() - XCTAssertEqual(rbm.isEmpty, true) + XCTAssertTrue(rbm.isEmpty) } func testRemoveAllWhere() { @@ -43,9 +49,9 @@ class swiftRoaringTests: XCTestCase { count += 1 } for i in rbm { - XCTAssertEqual(rbm.contains(i), true) + XCTAssertTrue(rbm.contains(i)) count -= 1 - if count < 0 {break} + if count < 0 { break } } XCTAssertEqual(count, 0) } @@ -53,7 +59,7 @@ class swiftRoaringTests: XCTestCase { func testInitRange() { let rbmRange = RoaringBitmap(min: 0, max: 1000, step: 50) for k in stride(from: 0, to: 1000, by: 50) { - XCTAssertEqual(rbmRange.contains(UInt32(k)), true) + XCTAssertTrue(rbmRange.contains(UInt32(k))) } } @@ -66,11 +72,11 @@ class swiftRoaringTests: XCTestCase { let array = [0, 1, 2, 4, 5, 6] let rbmArray = RoaringBitmap(values: array.map { UInt32($0) }) for i in array { - XCTAssertEqual(rbmArray.contains(UInt32(i)), true) + XCTAssertTrue(rbmArray.contains(UInt32(i))) } let l: RoaringBitmap = [0, 1, 2, 4, 5, 6] for i in array { - XCTAssertEqual(l.contains(UInt32(i)), true) + XCTAssertTrue(l.contains(UInt32(i))) } } From a35eaf3e01cd9ee5e1c1fbae2c627dc853832797 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Fri, 1 Jul 2022 11:32:41 -0700 Subject: [PATCH 2/2] fix formatting --- Tests/swiftRoaringTests/swiftRoaringTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/swiftRoaringTests/swiftRoaringTests.swift b/Tests/swiftRoaringTests/swiftRoaringTests.swift index ce8ba17..c97d9d4 100644 --- a/Tests/swiftRoaringTests/swiftRoaringTests.swift +++ b/Tests/swiftRoaringTests/swiftRoaringTests.swift @@ -384,10 +384,10 @@ class swiftRoaringTests: XCTestCase { } func testIsDisjoint() { - let a: RoaringBitmap = [1,2,3,4,5] - let b: RoaringBitmap = [6,7,8,9,10] + let a: RoaringBitmap = [1, 2, 3, 4, 5] + let b: RoaringBitmap = [6, 7, 8, 9, 10] - let c: RoaringBitmap = [5,6,7,8] + let c: RoaringBitmap = [5, 6, 7, 8] XCTAssert(a.isDisjoint(with: b)) XCTAssert(!a.isDisjoint(with: c))