File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ samples/
6868- Use modern C# features where the target frameworks support them
6969- Follow SOLID, DRY principles; remove unused code and parameters
7070- Clear, descriptive naming; prefer explicit over clever
71+ - For existing public value-like types, prefer additive equality fixes over record conversions unless an API shape change is explicitly intended
7172- Handle cancellation tokens properly: pass through call chains
7273- Always dispose resources: use ` using ` statements
7374
Original file line number Diff line number Diff line change @@ -139,7 +139,10 @@ public bool Equals(Location? coor)
139139 /// <returns>A hash code for this location.</returns>
140140 public override int GetHashCode ( )
141141 {
142- return Latitude . GetHashCode ( ) ^ Latitude . GetHashCode ( ) ;
142+ unchecked
143+ {
144+ return ( Latitude . GetHashCode ( ) * 397 ) ^ Longitude . GetHashCode ( ) ;
145+ }
143146 }
144147
145148 /// <summary>
Original file line number Diff line number Diff line change @@ -31,6 +31,17 @@ public void Equals_SameCoordinates_ReturnsTrue()
3131 Assert . Equal ( loc1 . GetHashCode ( ) , loc2 . GetHashCode ( ) ) ;
3232 }
3333
34+ [ Fact ]
35+ public void GetHashCode_IncludesLongitudeHash ( )
36+ {
37+ // Arrange
38+ Location loc = new Location ( 85.6789 , 92.4517 ) ;
39+ int expectedHashCode = unchecked ( ( loc . Latitude . GetHashCode ( ) * 397 ) ^ loc . Longitude . GetHashCode ( ) ) ;
40+
41+ // Assert
42+ Assert . Equal ( expectedHashCode , loc . GetHashCode ( ) ) ;
43+ }
44+
3445 [ Fact ]
3546 public void DistanceBetween_TwoLocations_ReturnsSameDistanceBothDirections ( )
3647 {
You can’t perform that action at this time.
0 commit comments