public void ItemsCanBeRemovedFromBag() { var bag = new RandomBag <int>(new[] { 1, 2, 3 }); Assert.IsFalse(bag.Empty); bag.Next(); bag.Next(); bag.Next(); Assert.IsTrue(bag.Empty); Assert.AreEqual(0, bag.Count); }
/// <summary> /// Get a question and answers, with a list of possible incorrect answers. /// </summary> /// <param name="question"></param> /// <param name="correctAnswer"></param> /// <param name="wrongAnswers"></param> public void GetQuestion(out FlashCard questionCard, out Translation correctTranslation, out List <FlashCard> wrongQuestionCards, out List <Translation> wrongTranslations) { //grab a random flash card to be the question questionRand.MaxNum = Cards.Count - 1; var cardIndex = questionRand.Next(); questionCard = Cards[cardIndex]; //Get the correct answer var correctIndex = translationRand.Next(questionCard.Translations.Count); var correctAnswer = questionCard.Translations[correctIndex]; correctTranslation = correctAnswer; //add all the possible incorrect answers wrongQuestionCards = new List <FlashCard>(); wrongTranslations = new List <Translation>(); for (int i = 0; i < Cards.Count; i++) { if (cardIndex != i) { //Get the translation from this card that matches the correct answer var wrongCard = Cards[i]; var wrongAnswer = wrongCard.Translations.FirstOrDefault(x => x.Language == correctAnswer.Language); if (null != wrongAnswer) { wrongQuestionCards.Add(wrongCard); wrongTranslations.Add(wrongAnswer); } } } }
public void AllItemsInBagArePresentInOutput() { var items = GetRandomItems(20, 100); var bag = new RandomBag <int>(items); var results = new Dictionary <int, int>(); while (!bag.Empty) { var value = bag.Next(); if (!results.ContainsKey(value)) { results.Add(value, 0); } results[value]++; } foreach (var item in items) { results[item]--; } Assert.IsFalse(results.Any(p => p.Value != 0)); }
public void ItemsCannotBeRemovedWhenBagIsEmpty() { var bag = new RandomBag <int>(); Assert.IsTrue(bag.Empty); Assert.Throws <InvalidOperationException>(() => bag.Next()); }
override protected BubbleType GenerateElement() { ChangeBucket(); if (bag.Empty) { RefillBag(); } currentCount++; return(bag.Next()); }
/// <summary>Генерируется случайная фигура из мешка, исходя из истории.</summary> /// <returns>Возвращается случайное число от 1 до 8.</returns> public static GameShape RandomFigure() { int rnd = _random.Next(); _random.AddShapeToHistory(rnd); if (Tetris.Properties.Game.Default.CheatSquare) { return(new GameShape((CellType)4)); } if (Tetris.Properties.Game.Default.CheatLine) { return(new GameShape((CellType)7)); } return(new GameShape((CellType)rnd)); }
private GameObject CreateNextBubble() { if (bubbleTypePicker.Empty) { bubbleTypePicker.AddRange(possibleBubbleTypes); } var bubble = level.bubbleFactory.CreateByType(bubbleTypePicker.Next()); bubble.transform.parent = launchLocation.transform; bubble.transform.position = launchLocation.transform.position; bubble.layer = (int)Layers.Default; bubble.AddComponent <BubbleParty>(); return(bubble); }
public void ItemsComeFromBagInRandomOrder() { var items = GetRandomItems(50, 100); var bag = new RandomBag <int>(items); var results = items.Select(i => bag.Next()).ToArray(); int differences = 0; for (var index = 0; index < items.Length; index++) { if (items[index] != results[index]) { differences++; } } Assert.Greater(differences, 0); }