Skip to content
Permalink
Browse files

Str - Equality

  • Loading branch information...
bobbymcr committed Apr 3, 2019
1 parent 64f7a5f commit e749030482bbcd98b5088659eec770066549a8f5
Showing with 29 additions and 1 deletion.
  1. +3 −1 src/Words.Core/Str.cs
  2. +26 −0 test/Words.Test/StrTest.cs
@@ -7,7 +7,7 @@ namespace Words
using System;
using System.Text;

public struct Str
public struct Str : IEquatable<Str>
{
private readonly ulong data;

@@ -32,6 +32,8 @@ private Str(ulong data)
}
}

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

public Str Append(Ch c)
{
if (this.Length == 12)
@@ -308,5 +308,31 @@ public void ChopChars()
t.Length.Should().Be(0);
t.ToString().Should().Be(string.Empty);
}

[Fact]
public void Equality()
{
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);

TestEquals(empty, a, false);
TestEquals(empty, empty, true);
TestEquals(a, a, true);
TestEquals(a, b, false);
TestEquals(ab, ba, false);
TestEquals(ba, ba, true);
TestEquals(cdefgh, ba, false);
TestEquals(cdefgh, cdefgh, true);
}

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

0 comments on commit e749030

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