public bool IsEquipped(Gear g) { foreach (Gear e in equipment) { if (g.Equals(e)) { return(true); } } return(false); }
static void TestProductEqualsWithInheritance() { // these 2 objects should be equal. They reference the same object. //Product p1 = new Product(1, "T100", "This is a test product", 100M, 10); //Product p2 = new Product(1, "T100", "This is a test product", 100M, 10); 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 equals."); //Console.WriteLine("2 products that have the same properties should be equal. Expecting true. " + p1.Equals(p2)); Console.WriteLine("2 clothing that have the same properties should be equal. Expecting true. " + c1.Equals(c2)); Console.WriteLine("2 gear that have the same properties should be equal. Expecting true. " + g1.Equals(g2)); Console.WriteLine("Clothing and Gear should not be equal. Expecting false. " + c3.Equals(g3)); Console.WriteLine("Testing product ==."); //Console.WriteLine("2 products that have the same properties should be equal. Expecting true. " + (p1 == p2)); Console.WriteLine("2 clothing that have the same properties should be equal. Expecting true. " + (c1 == c2)); Console.WriteLine("2 gear that have the same properties should be equal. Expecting true. " + (g1 == g2)); Console.WriteLine("Clothing and Gear should not be equal. Expecting false. " + (c3 == g3)); Console.WriteLine("2 clothing that have the same product attributes should not be equal. Expecting false. " + (c1 == c3)); Console.WriteLine(); }
/// <summary> /// Returns true if DetailedActivity instances are equal /// </summary> /// <param name="other">Instance of DetailedActivity to be compared</param> /// <returns>Boolean</returns> public bool Equals(DetailedActivity other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Description == other.Description || Description != null && Description.Equals(other.Description) ) && ( Photos == other.Photos || Photos != null && Photos.Equals(other.Photos) ) && ( Gear == other.Gear || Gear != null && Gear.Equals(other.Gear) ) && ( Calories == other.Calories || Calories != null && Calories.Equals(other.Calories) ) && ( SegmentEfforts == other.SegmentEfforts || SegmentEfforts != null && SegmentEfforts.SequenceEqual(other.SegmentEfforts) ) && ( DeviceName == other.DeviceName || DeviceName != null && DeviceName.Equals(other.DeviceName) ) && ( EmbedToken == other.EmbedToken || EmbedToken != null && EmbedToken.Equals(other.EmbedToken) ) && ( SplitsMetric == other.SplitsMetric || SplitsMetric != null && SplitsMetric.SequenceEqual(other.SplitsMetric) ) && ( SplitsStandard == other.SplitsStandard || SplitsStandard != null && SplitsStandard.SequenceEqual(other.SplitsStandard) ) && ( Laps == other.Laps || Laps != null && Laps.SequenceEqual(other.Laps) ) && ( BestEfforts == other.BestEfforts || BestEfforts != null && BestEfforts.SequenceEqual(other.BestEfforts) )); }