Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions exercise.main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,41 @@ public class Core
{



//TODO: complete the following method, keeping the signature the same
public bool winningPair(IEnumerable<Tuple<string, string>> hand, out Tuple<string, string> result)
{
result = new Tuple<string,string>(string.Empty, string.Empty);





foreach (var pair in hand)
{
if (pair.Item1 == pair.Item2)
{
if (result.Item1 != string.Empty && GetValueOfCard(pair.Item1) > GetValueOfCard(result.Item1))
{
result = pair;
}
else if (result.Item1 == string.Empty)
{
result = pair;
}
}
}

return result.Item1!=string.Empty ? true : false;
}
public int GetValueOfCard(string card)
{
return 0;
Dictionary<string, int> _cv = new Dictionary<string, int>()
{
{"1", 1}, {"2", 2}, {"3", 3},{"4", 4}, {"5", 5}, {"6", 6},
{"7", 7}, {"8", 8}, {"9", 9}, {"10", 10}, {"J", 11}, {"Q", 12},
{"K", 13}, {"A", 14}
};

return _cv[card];


}
}
}
33 changes: 32 additions & 1 deletion exercise.main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,39 @@ public bool winningThree(IEnumerable<Tuple<string, string, string>> hand, out Tu
{
result = new Tuple<string, string, string>(string.Empty, string.Empty, string.Empty);

return false;

foreach (var cards in hand)
{
if (cards.Item1 == cards.Item2 && cards.Item2 == cards.Item3)
{
if (result.Item1 != string.Empty && GetValueOfCard(cards.Item1) > GetValueOfCard(result.Item1))
{
result = cards;
}
else if (result.Item1 == string.Empty)
{
result = cards;
}
}
}


return result.Item1 != string.Empty ? true : false;
}
public int GetValueOfCard(string card)
{
Dictionary<string, int> _cv = new Dictionary<string, int>()
{
{"1", 1}, {"2", 2}, {"3", 3},{"4", 4}, {"5", 5}, {"6", 6},
{"7", 7}, {"8", 8}, {"9", 9}, {"10", 10}, {"J", 11}, {"Q", 12},
{"K", 13}, {"A", 14}
};

return _cv[card];


}


}
}
75 changes: 75 additions & 0 deletions exercise.tests/ExtensionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using exercise.main;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.tests
{
internal class ExtensionTests
{
[Order(0)]
[Test]
public void Scenario1()
{


Extension extension = new Extension();

List<Tuple<string, string, string>> hand = new List<Tuple<string, string, string>>
{
new Tuple<string, string, string>("K", "5", "Q"),
new Tuple<string, string, string>("3","7", "Q")
};
Tuple<string, string, string> winner;

bool result = extension.winningThree(hand, out winner);

Assert.That(result, Is.False);
Assert.That(winner.Item1, Is.EqualTo(String.Empty));
Assert.That(winner.Item2, Is.EqualTo(String.Empty));
}
//("K","K","K"), ("A","A","A")} => true out ("A","A","A")
[Test]
public void Scenario2()
{


Extension extension = new Extension();

List<Tuple<string, string, string>> hand = new List<Tuple<string, string, string>>
{
new Tuple<string, string, string>("K", "K", "K"),
new Tuple<string, string, string>("A","A", "A")
};
Tuple<string, string, string> winner;
bool result = extension.winningThree(hand, out winner);

Assert.That(result, Is.True);

Assert.IsTrue(winner.Item1 == "A" && winner.Item2 == "A" && winner.Item3 == "A");

}
//{("4", "3", "2"),("6","6","6"),("7","7","7"),("3","3","3")} => true ("7", "7", "7")
[Test]
public void Scenario3()
{
Extension extension = new Extension();

List<Tuple<string, string, string>> hand = new List<Tuple<string, string, string>>
{
new Tuple<string, string, string>("4", "3", "2"),
new Tuple<string, string, string>("6", "6", "6"),
new Tuple<string, string, string>("7", "7", "7"),
new Tuple<string, string, string>("3", "3", "3")
};
Tuple<string, string, string> winner;
bool result = extension.winningThree(hand, out winner);

Assert.That(result, Is.True);

Assert.IsTrue(winner.Item1 == "7" && winner.Item2 == "7" && winner.Item3 == "7");
}
}
}