public void TestComplexExpression() { IItem item1 = new AddItem(ONE, TWO); Assert.AreEqual(3, item1.Value); IItem item2 = new MulItem(item1, TWO); Assert.AreEqual(6, item2.Value); Assert.IsTrue(item1.Equals(item1)); Assert.IsTrue(item2.Equals(item2)); Assert.IsFalse(item1.Equals(item2)); IItem item3 = new AddItem(ONE, TWO); Assert.AreEqual(3, item1.Value); IItem item4 = new MulItem(item1, TWO); Assert.AreEqual(6, item2.Value); Assert.IsTrue(item1.Equals(item3)); Assert.IsTrue(item2.Equals(item4)); Assert.IsFalse(item1.Equals(item4)); Assert.IsFalse(item2.Equals(item3)); Assert.IsFalse(item3.Equals(item4)); item3 = new MulItem(TWO, TWO); Assert.AreEqual(4, item3.Value); item4 = new AddItem(item3, TWO); Assert.AreEqual(6, item4.Value); Assert.IsFalse(item2.Equals(item4)); Assert.AreEqual(item2.Value, item4.Value); }
public void TestMulItemEquals() { var item = new MulItem(ONE, TWO); Assert.IsTrue(item.Equals(item)); Assert.IsTrue(item.Equals(new MulItem(ONE, TWO))); Assert.IsFalse(item.Equals(new MulItem(TWO, ONE))); Assert.IsFalse(item.Equals(new MulItem(TWO, (IntegerItem)(-1)))); Assert.IsFalse(item.Equals(null)); Assert.IsFalse(item.Equals(new AddItem(ONE, ZERO))); }