public void GetHashCode_Should_Return_The_Same_Hashes_For_CookedFood_With_Equal_Properties() { var bakedApple1 = new CookedFood(100, "apple", FoodGroup.Fruit, "Baked"); var bakedApple2 = new CookedFood(100, "apple", FoodGroup.Fruit, "Baked"); Assert.AreEqual(bakedApple1.GetHashCode(), bakedApple2.GetHashCode()); }
public void GetHashCode_Should_Return_The_Same_Hashes_For_CookedFood_With_Different_Properties() { var bakedApple = new CookedFood(100, "apple", FoodGroup.Fruit, "Baked"); var bakedBanana = new CookedFood(100, "banana", FoodGroup.Fruit, "Baked"); Assert.AreNotEqual(bakedApple.GetHashCode(), bakedBanana.GetHashCode()); }
public void DerivedType_GetHashCode_EquivalentItems_ExpectEqualHashCodes() { CookedFood banana1 = new CookedFood("Banana", Shared.FoodGroup.Fruit, "Baked"); CookedFood banana2 = new CookedFood("Banana", Shared.FoodGroup.Fruit, "Baked"); int b1hc = banana1.GetHashCode(); int b2hc = banana2.GetHashCode(); Assert.AreEqual(b1hc, b2hc); }
public void HasSet_Should_Have_Two_CookedFood_When_They_Have_Different_HashCodes() { var foodItem1 = new CookedFood(100, "apple", FoodGroup.Fruit, "Baked"); var foodItem2 = new CookedFood(100, "banana", FoodGroup.Fruit, "Baked"); var hashSet = new HashSet <CookedFood> { foodItem1, foodItem2 }; Assert.AreNotEqual(foodItem1.GetHashCode(), foodItem2.GetHashCode()); Assert.AreEqual(hashSet.Count, 2); }
public void HashSet_Should_Have_Only_One_CookedFood_Despite_Inserting_Two_With_The_Same_HashCode() { var apple1 = new CookedFood(100, "apple", FoodGroup.Fruit, "Baked"); var apple2 = new CookedFood(100, "apple", FoodGroup.Fruit, "Baked"); var hashSet = new HashSet <CookedFood> { apple1, apple2 }; Assert.AreEqual(apple1.GetHashCode(), apple2.GetHashCode()); Assert.AreEqual(hashSet.Count, 1); }