[csharp/dot-dsl] Tests require implementing GetHashCode() for mutable object

Tests use collection initializer, which requires Add method, which means objects are mutable.

Moreover, tests compare enumerables using HashSet, which requires “proper” GetHashCode() implementation.

AFAIK, mutable object cannot provide “proper” GetHashCode().

Suggestion (choose one)

  1. Make Node/Edge/Attr immutable; create objects using builder pattern
  2. Use Assert.Contains or Assert.Equivalent for final test instead using HashSet

I would prefer the second option. Are you interested in submitting a PR?

I’d love to. However, I don’t have any experience regarding Exercism PR.
Maybe I have to learn how to generate proper Exercism PR.


I just found the following text on practice instructions:

This exercise requires you to implement classes with a custom equality check. For more information, see this page.

According to System.Object.Equals method - .NET | Microsoft Learn:

  • You should not override Equals on a mutable reference type. This is because overriding Equals requires that you also override the GetHashCode method, as discussed in the previous section. This means that the hash code of an instance of a mutable reference type can change during its lifetime, which can cause the object to be lost in a hash table.

It seems that this won’t be easy task, especially not to break existing solutions.
I have to think more thoughtfully how to handle this issue.

By and large we use the standard Github PR process: Creating a pull request - GitHub Docs

  1. Fork the repo.
  2. Push a commit to your fork.
  3. Create a PR to merge your commit into the upstream repo.

The file you want to edit is likely this one: csharp/exercises/practice/dot-dsl/DotDslTests.cs at main · exercism/csharp · GitHub

Maybe we should be converting the exercise to use records instead?