Skip to content

Commit

Permalink
Merge pull request #44 from siyusong/fix-comparison-hashvalue
Browse files Browse the repository at this point in the history
Do not use hashValue in comparison
  • Loading branch information
inamiy committed Feb 24, 2016
2 parents a4a5698 + 77bbf39 commit a0bfd80
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
14 changes: 12 additions & 2 deletions Sources/EventType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,22 @@ public func == <E: EventType>(lhs: Event<E>, rhs: Event<E>) -> Bool

public func == <E: EventType>(lhs: Event<E>, rhs: E) -> Bool
{
return lhs.hashValue == rhs.hashValue
switch lhs {
case .Some(let x):
return x == rhs
case .Any:
return false
}
}

public func == <E: EventType>(lhs: E, rhs: Event<E>) -> Bool
{
return lhs.hashValue == rhs.hashValue
switch rhs {
case .Some(let x):
return x == lhs
case .Any:
return false
}
}

// MARK: NoEvent
Expand Down
23 changes: 20 additions & 3 deletions Sources/StateType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,34 @@ extension State: RawRepresentable

public func == <S: StateType>(lhs: State<S>, rhs: State<S>) -> Bool
{
return lhs.hashValue == rhs.hashValue
switch (lhs, rhs) {
case let (.Some(x1), .Some(x2)) where x1 == x2:
return true
case (.Any, .Any):
return true
default:
return false
}
}

public func == <S: StateType>(lhs: State<S>, rhs: S) -> Bool
{
return lhs.hashValue == rhs.hashValue
switch lhs {
case .Some(let x):
return x == rhs
case .Any:
return false
}
}

public func == <S: StateType>(lhs: S, rhs: State<S>) -> Bool
{
return lhs.hashValue == rhs.hashValue
switch rhs {
case .Some(let x):
return x == lhs
case .Any:
return false
}
}

// MARK: Private
Expand Down
2 changes: 1 addition & 1 deletion Sources/Transition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct Transition<S: StateType>: Hashable
// for Transition Equatable
public func == <S: StateType>(left: Transition<S>, right: Transition<S>) -> Bool
{
return left.hashValue == right.hashValue
return left.fromState == right.fromState && left.toState == right.toState
}

//--------------------------------------------------
Expand Down

0 comments on commit a0bfd80

Please sign in to comment.