Skip to content

Commit

Permalink
Merge pull request #17 from adamnemecek/removefix
Browse files Browse the repository at this point in the history
fixed return value of remove, fixed some tests
  • Loading branch information
lemire authored Jul 1, 2022
2 parents cbbc242 + a35eaf3 commit 024d4e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Sources/SwiftRoaring/RoaringBitmap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

///
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -962,7 +962,7 @@ public final class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
if self.count >= 100 {
ret.append(", ...")
}
return "{\(ret)}"
return "RoaringBitmap(\(ret))"
}

///
Expand Down
32 changes: 19 additions & 13 deletions Tests/swiftRoaringTests/swiftRoaringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -43,17 +49,17 @@ 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)
}

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)))
}
}

Expand All @@ -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)))
}
}

Expand Down Expand Up @@ -378,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))
Expand Down

0 comments on commit 024d4e8

Please sign in to comment.