static void TestProductGetHashCodeWithInheritance() { //Product p1 = new Product(1, "T100", "This is a test product", 100M, 10); //// these 2 objects should have the same hashcode. The attribute values are all equal. //Product p2 = new Product(1, "T100", "This is a test product", 100M, 10); //// this one should have a unique hashcode //Product p3 = new Product(3, "T300", "This is a test product 3", 300M, 30); Clothing c1 = new Clothing(3, "C100", "Running tights", 69.99M, 3, "pants", "womens", "large", "blue", "Lucy"); Clothing c2 = new Clothing(3, "C100", "Running tights", 69.99M, 3, "pants", "womens", "large", "blue", "Lucy"); Clothing c3 = new Clothing(1, "T100", "This is a test product", 100M, 10, "not pants", "womens", "large", "blue", "Lucy"); Gear g1 = new Gear(5, "G100", "Sky 10 Kayak", 1049M, 2, "paddle", "Eddyline", "plastic laminate", 32); Gear g2 = new Gear(5, "G100", "Sky 10 Kayak", 1049M, 2, "paddle", "Eddyline", "plastic laminate", 32); Gear g3 = new Gear(1, "T100", "This is a test product", 100M, 10, "paddle", "Eddyline", "plastic laminate", 32); Console.WriteLine("Testing product GetHashCode"); //Console.WriteLine("2 products that have the same properties should have the same hashcode. Expecting true. " + (p1.GetHashCode() == p2.GetHashCode())); //Console.WriteLine("2 products that have different properties should have different hashcodes. Expecting false. " + (p1.GetHashCode() == p3.GetHashCode())); Console.WriteLine("2 clothing that have the same properties should have the same hashcode. Expecting true. " + (c1.GetHashCode() == c2.GetHashCode())); Console.WriteLine("2 clothing that have different properties should have different hashcodes. Expecting false. " + (c1.GetHashCode() == c3.GetHashCode())); Console.WriteLine("2 gear that have the same properties should have the same hashcode. Expecting true. " + (g1.GetHashCode() == g2.GetHashCode())); Console.WriteLine("2 gear that have different properties should have different hashcodes. Expecting false. " + (g1.GetHashCode() == g3.GetHashCode())); Console.WriteLine("clothing and gear that have same properties should have different hashcodes. Expecting false. " + (c3.GetHashCode() == g3.GetHashCode())); Console.WriteLine(); // this will fail before overriding GetHashCode HashSet <Product> set = new HashSet <Product>(); //set.Add(p1); //set.Add(p3); set.Add(c1); set.Add(c3); set.Add(g1); set.Add(g3); Console.WriteLine("Testing product GetHashCode by using a hash set"); //Console.WriteLine("The hash set should be able to find a product with the same attributes. Expecting true. " + set.Contains(p2)); Console.WriteLine("The hash set should be able to find a clothing with the same attributes. Expecting true. " + set.Contains(c2)); Console.WriteLine("The hash set should be able to find a gear with the same attributes. Expecting true. " + set.Contains(g2)); Console.WriteLine(); }