public void Equality() { var segment1 = new Segment("E", false); var segment2 = new Segment("+", true); var segment3 = new Segment("Number", true); var production1 = new Production(segment1, ImmutableArray.Create(segment1, segment2, segment3)); var production2 = new Production(segment1, ImmutableArray.Create(segment1, segment2, segment3)); var production3 = new Production(segment1, ImmutableArray.Create(segment3)); var itemA = new ParseItem(production1, 1); var itemB = new ParseItem(production2, 1); var itemC = new ParseItem(production3, 1); var itemD = new ParseItem(production1, 2); Assert.That(itemA.Equals(itemB), Is.EqualTo(true), "itemA == itemB"); Assert.That(itemB.Equals(itemA), Is.EqualTo(true), "itemB == itemA"); Assert.That(itemA.GetHashCode() == itemB.GetHashCode(), Is.EqualTo(true), "itemA.HC == itemB.HC"); Assert.That(itemA.Equals(itemC), Is.EqualTo(false), "itemA == itemC"); Assert.That(itemC.Equals(itemA), Is.EqualTo(false), "itemC == itemA"); Assert.That(itemA.GetHashCode() == itemC.GetHashCode(), Is.EqualTo(false), "itemA.HC == itemC.HC"); Assert.That(itemA.Equals(itemD), Is.EqualTo(false), "itemA == itemD"); Assert.That(itemD.Equals(itemA), Is.EqualTo(false), "itemD == itemA"); Assert.That(itemA.GetHashCode() == itemD.GetHashCode(), Is.EqualTo(false), "itemA.HC == itemD.HC"); }
public void Equals() { var a = new ParseItem(default(EditorConfigDocument), ItemType.Keyword, new Span(10, 10), "a text"); var b = new ParseItem(default(EditorConfigDocument), ItemType.Section, new Span(20, 10), "b text"); var c = new ParseItem(default(EditorConfigDocument), ItemType.Keyword, new Span(10, 10), "a text"); Assert.IsTrue(a == c); Assert.IsFalse(a != c); Assert.IsTrue(a != b); Assert.IsFalse(a == b); Assert.IsTrue(a.GetHashCode() != b.GetHashCode()); Assert.IsTrue(a.Equals(a)); Assert.IsTrue(a.Equals(c)); Assert.IsFalse(a.Equals(b)); }