public void CanonicalHasherl_SameValue_AsResharperImplementation() { var baseline = new EqualitySubject { I = 243, D = 298.75m, S = "dGG" }; int actual = Hasher.Canonical(baseline.I, baseline.D, baseline.S); Assert.That(actual, Is.EqualTo(baseline.GetHashCode())); }
public void Explore() { Func <EqualitySubject, EqualitySubject, bool> compareI = (x, y) => x.I.Equals(y.I); var subject = new DelegatedEqualizer <EqualitySubject>(compareI, s => s.I.GetHashCode()); var x1 = new EqualitySubject("x", 1, 1m); Assert.That(subject.Equals(x1, new EqualitySubject("y", 1, 2m)), Is.True); var custom = new DelegatedEqualizer <EqualitySubject>((x, y) => x.I.Equals(y.I), s => s.I.GetHashCode()); Assert.That(custom.GetHashCode(x1), Is.EqualTo(x1.I.GetHashCode())); custom = new DelegatedEqualizer <EqualitySubject>((x, y) => x.I.Equals(y.I), s => Hasher.Default(s.I)); Assert.That(custom.GetHashCode(x1), Is.EqualTo(x1.I.GetHashCode())); var @default = new DelegatedEqualizer <EqualitySubject>((x, y) => x.I.Equals(y.I), Hasher.Default); Assert.That(@default.GetHashCode(x1), Is.EqualTo(x1.GetHashCode())); var zero = new DelegatedEqualizer <EqualitySubject>((x, y) => x.I.Equals(y.I), Hasher.Zero); Assert.That(zero.GetHashCode(x1), Is.EqualTo(0)); IEqualityComparer <EqualitySubject> bySAndI = new DelegatedEqualizer <EqualitySubject>((x, y) => x.S.Equals(y.S), Hasher.Zero) .Then(new DelegatedEqualizer <EqualitySubject>((x, y) => x.I.Equals(y.I), Hasher.Default)); bySAndI = new DelegatedEqualizer <EqualitySubject>((x, y) => x.S.Equals(y.S), Hasher.Zero) .Then((x, y) => x.I == y.I, Hasher.Default); bySAndI = Eq <EqualitySubject> .By((x, y) => x.S.Equals(y.S), Hasher.Zero) .Then((x, y) => x == y, Hasher.Default); IComparer <EqualitySubject> comparer = Cmp <EqualitySubject> .By(x => x.I); IEqualityComparer <EqualitySubject> eq = new DelegatedEqualizer <EqualitySubject>(comparer, Hasher.Zero); Comparison <EqualitySubject> comparison = (x, y) => x.D.CompareTo(y.D); eq = new DelegatedEqualizer <EqualitySubject>(comparison, Hasher.Zero); }