Update import/export handling of Vernacular#3626
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3626 +/- ##
==========================================
- Coverage 74.27% 74.24% -0.03%
==========================================
Files 285 285
Lines 11116 11143 +27
Branches 1370 1373 +3
==========================================
+ Hits 8256 8273 +17
- Misses 2467 2476 +9
- Partials 393 394 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
What if we didn't do this? |
Backend.Tests/Models/WordTests.cs
Outdated
| var hashCode = new Word { Guid = _commonGuid, Vernacular = "1" }.GetHashCode(); | ||
| Assert.That(hashCode, Is.Not.EqualTo(new Word { Guid = _commonGuid, Vernacular = "2" }.GetHashCode())); | ||
| Assert.That(hashCode, Is.Not.EqualTo( | ||
| new Word { Guid = _commonGuid, Vernacular = "1", UsingCitationForm = true }.GetHashCode())); |
There was a problem hiding this comment.
you've got a bug in your test. UsingCitationForm is not referenced in GetHashCode for Word, which is a bug. But the real issue is that this test didn't catch that. Here's a failing test that should pass which demonstrates the issue
var word1 = new Word { Guid = _commonGuid, Vernacular = "1" };
var word2 = new Word { Guid = _commonGuid, Vernacular = "1" };
var word1HashCode = word1.GetHashCode();
var word2HashCode = word2.GetHashCode();
Assert.That(word1HashCode, Is.EqualTo(word2HashCode));the hash codes aren't the same even though they should be. I think this is because the HashCode class just calls GetHashCode on the objects passed in, and most objects (List<T> for example) don't overload GetHashCode, which means that the hash code is unique per instance of the list, not based on it's contents. Eg: new List<string>().GetHashCode() != new List<string>().GetHashCode() this is expected and by design as a hash code is expected to not change for a given object over it's lifetime, otherwise it wouldn't work as a key in a dictionary for example. I could go more into this but I'll stop before I write an essay.
jasonleenaylor
left a comment
There was a problem hiding this comment.
Reviewed 8 of 8 files at r1, 7 of 7 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @hahn-kev)
imnasnainaec
left a comment
There was a problem hiding this comment.
Dismissed @hahn-kev from a discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @imnasnainaec)
Fixes #3532
Vernacular(and export to citation form if imported with citation form andVernacularis unchanged)This change is