Skip to content
Open
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
4 changes: 2 additions & 2 deletions Sources/ContentIdentifiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public protocol ContentIdentifiable {
public extension ContentIdentifiable where Self: Hashable {
/// The `self` value as an identifier for difference calculation.
@inlinable
var differenceIdentifier: Self {
return self
var differenceIdentifier: Int {
return hashValue
}
}
22 changes: 14 additions & 8 deletions Tests/AlgorithmTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,16 @@ extension AlgorithmTestCase {

func testSameHashValue() {
struct A: Hashable, Differentiable {
let actualValue: Int
let id: Int
let actualValue: String

init(_ actualValue: Int) {
init(_ id: Int, _ actualValue: String) {
self.id = id
self.actualValue = actualValue
}

func hash(into hasher: inout Hasher) {
hasher.combine(0)
hasher.combine(id)
}

func isContentEqual(to source: A) -> Bool {
Expand All @@ -262,21 +264,25 @@ extension AlgorithmTestCase {

let section = 0

let source = [A(0), A(1)]
let target = [A(0), A(2)]
let source = [A(0, "a"), A(1, "b"), A(2, "c")]
let target = [A(0, "a"), A(1, "c"), A(3, "c")]

XCTAssertExactDifferences(
source: source,
target: target,
section: section,
expected: [
Changeset(
data: [A(0)],
elementDeleted: [ElementPath(element: 1, section: section)]
data: [A(0, "a"), A(1, "c"), A(2, "c")],
elementUpdated: [ElementPath(element: 1, section: 0)]
),
Changeset(
data: [A(0, "a"), A(1, "c")],
elementDeleted: [ElementPath(element: 2, section: 0)]
),
Changeset(
data: target,
elementInserted: [ElementPath(element: 1, section: section)]
elementInserted: [ElementPath(element: 2, section: 0)]
)
]
)
Expand Down