Skip to content

Commit

Permalink
No move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlopez committed May 3, 2014
1 parent 3773e8a commit 88fe906
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Gcj2014/Repeater.Tests/RepeaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,21 @@ public void GetNoGroupFromNullString()
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}

[TestMethod]
public void AreSolvable()
{
Assert.IsTrue(this.repeater.AreSolvable(new IList<Group>[] { this.repeater.ToGroups("ab"), this.repeater.ToGroups("aabbb"), this.repeater.ToGroups("aaab") }));
Assert.IsFalse(this.repeater.AreSolvable(new IList<Group>[] { this.repeater.ToGroups("ab"), this.repeater.ToGroups("aabbb"), this.repeater.ToGroups("aaabc") }));
Assert.IsFalse(this.repeater.AreSolvable(new IList<Group>[] { this.repeater.ToGroups("abc"), this.repeater.ToGroups("aabbb"), this.repeater.ToGroups("aaab") }));
}

[TestMethod]
public void NoMove()
{
Assert.AreEqual(-1, this.repeater.Moves(new string[] { "ab", "bc" }));
Assert.AreEqual(-1, this.repeater.Moves(new string[] { "ab", "abc" }));
Assert.AreEqual(-1, this.repeater.Moves(new string[] { "cab", "bc" }));
}
}
}
27 changes: 27 additions & 0 deletions Gcj2014/Repeater/Repeater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,35 @@ public IList<Group> ToGroups(string text)
return groups;
}

public bool AreSolvable(IList<IList<Group>> groups)
{
var initial = groups[0];
int ng = initial.Count;

if (!groups.All(gr => gr.Count == ng))
return false;

for (int k = 1; k < groups.Count; k++)
{
var group = groups[k];
for (int j = 0; j < ng; j++)
if (initial[j].Letter != group[j].Letter)
return false;
}

return true;
}

public int Moves(IList<string> strings)
{
IList<IList<Group>> groups = new List<IList<Group>>();

foreach (var str in strings)
groups.Add(this.ToGroups(str));

if (!this.AreSolvable(groups))
return -1;

throw new NotImplementedException();
}
}
Expand Down

0 comments on commit 88fe906

Please sign in to comment.