Skip to content

Commit

Permalink
Four4Sample - support custom numeral count for Results
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Mar 17, 2018
1 parent 3a11cc3 commit 45d07d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions projects/Four4Sample/Four4.Test/ResultsTest.cs
Expand Up @@ -79,6 +79,23 @@ public void SortOrder()
.And.HaveCount(2); .And.HaveCount(2);
} }


[Fact]
public void CustomNumeralCount()
{
Results results = new Results { NumeralCount = 2 };
Expression exprTooFew = default(Expression).Append("4").Append("R");
Expression exprTooMany = default(Expression).Append("44").Append("4").Append("+");
Expression exprJustRight = default(Expression).Append("4").Append("4").Append("/");

results.Add(exprTooFew);
results.Add(exprTooMany);
results.Add(exprJustRight);

Expression[] all = results.ToArray();
all.Select(e => e.ToString()).Should().ContainInOrder(
"4 4 /").And.HaveCount(1);
}

private static void TestAdd(string x, string y, string op, int count) private static void TestAdd(string x, string y, string op, int count)
{ {
Results results = new Results(); Results results = new Results();
Expand Down
5 changes: 4 additions & 1 deletion projects/Four4Sample/Four4/Results.cs
Expand Up @@ -14,13 +14,16 @@ public sealed class Results : IEnumerable<Expression>
public Results() public Results()
{ {
this.results = new SortedDictionary<int, Expression>(); this.results = new SortedDictionary<int, Expression>();
this.NumeralCount = 4;
} }


public int Count => this.results.Count; public int Count => this.results.Count;


public int NumeralCount { get; set; }

public void Add(Expression expr) public void Add(Expression expr)
{ {
if (expr.NumeralCount != 4) if (expr.NumeralCount != this.NumeralCount)
{ {
return; return;
} }
Expand Down

0 comments on commit 45d07d6

Please sign in to comment.