Skip to content

Commit

Permalink
additional merging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Aug 23, 2022
1 parent 25d4f67 commit fbf23bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Tests/CRDTTests/ORSetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,29 @@ final class ORSetTests: XCTestCase {
let c = await a.mergeDelta(delta)
XCTAssertEqual(c.values, b.values)
}

func testUnrelatedMerges() async {
let orset_1 = ORSet(actorId: UInt(31), [1, 2, 3, 4])
let orset_2 = ORSet(actorId: UInt(13), [4, 5])

let diff_a = await orset_1.delta(await orset_2.state)
// diff_a is the delta from set 1
XCTAssertNotNil(diff_a)
XCTAssertEqual(diff_a.updates.count, 4)

let diff_b = await orset_2.delta(await orset_1.state)
// diff_b is the delta from set 2
XCTAssertNotNil(diff_b)
XCTAssertEqual(diff_b.updates.count, 2)

// merge the diff from set 1 into set 2
let mergedFrom1 = await orset_2.mergeDelta(diff_a)
XCTAssertEqual(mergedFrom1.count, 5)

// merge the diff from set 2 into set 1
let mergedFrom2 = await orset_1.mergeDelta(diff_b)
XCTAssertEqual(mergedFrom2.count, 5)

XCTAssertEqual(mergedFrom1.values, mergedFrom2.values)
}
}
2 changes: 1 addition & 1 deletion Tests/CRDTTests/grokTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class grokTests: XCTestCase {

func testORSetSizing() async throws {
let orset_1 = ORSet(actorId: UInt(31), [1, 2, 3, 4])
let orset_2 = ORSet(actorId: UInt(31), [4, 5])
let orset_2 = ORSet(actorId: UInt(13), [4, 5])

print("ORSet1(4 elements, UInt actorId) = \(orset_1.sizeInBytes())")
print("ORSet2(2 elements, UInt actorId) = \(orset_2.sizeInBytes())")
Expand Down

0 comments on commit fbf23bf

Please sign in to comment.