Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed return value of remove, fixed some tests #17

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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