public void Calculate_GetLessChance_ExpectSuccess( int deckSize, int handSize, int copiesInDeck, int copiesInHand, string expected ) { var service = new HandProbability(deckSize, handSize, copiesInDeck, copiesInHand); var actual = service.GetLess(); Assert.Equal(decimal.Parse(expected), actual); }
public async Task ProbabilityCommand( [Summary(description: "deck size")] int deckSize, [Summary(description: "copies in deck")] int inDeck, [Summary(description: "hand size")] int handSize, [Summary(description: "copies you want in hand")] int inHand ) { if (inDeck > deckSize) { await RespondAsync($"There are more cards in deck `({inDeck})` than the deck size `({deckSize})`!"); return; } if (handSize > deckSize) { await RespondAsync($"The hand is larger `({handSize})` than the deck size `({deckSize})`!"); return; } if (inHand > deckSize) { await RespondAsync($"There are more copies of the card in hand `({inHand})` than the deck size `({deckSize})`!"); return; } if (inHand > inDeck) { await RespondAsync($"There are more copies of the card in hand `({inHand})` than the copies in deck `({inDeck})`!"); return; } if (inHand > handSize) { await RespondAsync($"There are more cards in hand `({inHand})` than the hand size `({handSize})`!"); return; } try { var probability = new HandProbability(deckSize, handSize, inDeck, inHand); var display = $"{deckSize} cards in deck\n" + $"{inDeck} copies in deck\n" + $"{handSize} cards in hand\n" + $"{inHand} copies in hand\n" + $"Exactly {inHand} in hand: {probability.GetExact()}%\n" + $"Less than {inHand} in hand: {probability.GetLess()}%\n" + $"Less or equal to {inHand} in hand: {probability.GetLessOrEqual()}%\n" + $"More than {inHand} in hand: {probability.GetMore()}%\n" + $"More or equal to {inHand} in hand: {probability.GetMoreOrEqual()}%"; if (inHand == 1) { await RespondAsync($"```{display}```"); return; } decimal onetoInHand = 0; for (var i = inHand; i >= 1; i--) { onetoInHand += Probability(deckSize, inDeck, handSize, i); } display += $"\n1-{inHand} copies in hand: {onetoInHand}%"; await RespondAsync($"```{display}```"); } catch { await RespondAsync("There was an error. Please check your values and try again!\nEx. `y!prob 40 7 5 2`"); } }