Skip to content
Permalink
Browse files

Str - HashCode

  • Loading branch information...
bobbymcr committed Apr 3, 2019
1 parent e749030 commit c2c8fa3db82277b81227eb057e0d8f72c4cc0784
Showing with 18 additions and 0 deletions.
  1. +2 −0 src/Words.Core/Str.cs
  2. +16 −0 test/Words.Test/StrTest.cs
@@ -34,6 +34,8 @@ private Str(ulong data)

public bool Equals(Str other) => this.data == other.data;

public override int GetHashCode() => this.data.GetHashCode();

public Str Append(Ch c)
{
if (this.Length == 12)
@@ -5,6 +5,7 @@
namespace Words.Test
{
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Xunit;
@@ -329,6 +330,21 @@ public void Equality()
TestEquals(cdefgh, cdefgh, true);
}

[Fact]
public void HashCode()
{
Str empty = default(Str);
Str a = default(Str).Append(Ch.A);
Str b = default(Str).Append(Ch.B);
Str ab = default(Str).Append(Ch.A).Append(Ch.B);
Str ba = default(Str).Append(Ch.B).Append(Ch.A);
Str cdefgh = default(Str).Append(Ch.C).Append(Ch.D).Append(Ch.E).Append(Ch.F).Append(Ch.G).Append(Ch.H);

HashSet<int> codes = new HashSet<int>(new Str[] { empty, a, b, ab, ba, cdefgh }.Select(s => s.GetHashCode()));

codes.Should().HaveCount(6);
}

private static void TestEquals(Str x, Str y, bool expected)
{
x.Equals(y).Should().Be(expected);

0 comments on commit c2c8fa3

Please sign in to comment.
You can’t perform that action at this time.