Exemplo n.º 1
0
        public IEnumerator TestPartialUncheckedItemsGeneratedDuringLastSession(
            [Values(0.5)] double previousGenIntervals,
            [Values(3)] double totalItemsToGenerate
            )
        {
            Assume.That(previousGenIntervals, Is.LessThan(1));
            Assume.That(totalItemsToGenerate, Is.GreaterThan(previousGenIntervals));

            GameManager.SaveData =
                FortuneFountainSaveData.NewSaveFile(nameof(TestPartialUncheckedItemsGeneratedDuringLastSession));
            GameManager.SaveData.PlayerValuables = TestData.GetUniformPlayerValuables(GameManager.SaveData);

            yield return(TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval,
                                                   previousGenIntervals));

            GameManager.SaveData.Save(false);

            var genCounters = CreateValuableGenerationCounters(GameManager.SaveData.PlayerValuables);

            yield return(TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval, 2));

            GameManager.SaveData.Reload();

            var sleepIntervals = totalItemsToGenerate - previousGenIntervals + 0.5;

            LogUtils.Log($"{nameof(sleepIntervals)} = {sleepIntervals}");
            yield return(TestUtils.WaitForRealtime(GameManager.SaveData.PlayerValuables[0].GenerateInterval,
                                                   sleepIntervals));

            var itemsGenerated = GameManager.SaveData.PlayerValuables.CheckGenerate();

            Assert.That(itemsGenerated, Has.All.EqualTo(totalItemsToGenerate));
            Assert.That(genCounters,
                        Has.All.Values().EqualTo(new ValuableGenerationCounter()
            {
                Amount = (int)totalItemsToGenerate, Events = 1
            }));
        }
Exemplo n.º 2
0
        public void GenerateEventsLimitedByMaxGenerateTime(
            double generateTimeLimitInSeconds,
            double itemsPerSecond,
            double extraGenerationSeconds
            )
        {
            //the number of items we expect to generate - which should always be limited by maxGenerationSeconds
            var expectedItemsGenerated = generateTimeLimitInSeconds * itemsPerSecond;

            Ignore.Unless(
                () => Assume.That(generateTimeLimitInSeconds, Is.GreaterThan(0),
                                  $"{nameof(generateTimeLimitInSeconds)} must be greater than 0!"),
                () => Assume.That(itemsPerSecond, Is.GreaterThan(0),
                                  $"{nameof(itemsPerSecond)} must be greater than 0!"),
                () => Assume.That(extraGenerationSeconds, Is.GreaterThanOrEqualTo(0),
                                  $"{nameof(extraGenerationSeconds)} must be positive!"),
                () => Assume.That(expectedItemsGenerated, Is.GreaterThanOrEqualTo(1),
                                  $"{nameof(expectedItemsGenerated)} must be at least 1!")
                );

            //this test is very quick and runs a LOT of times, so we should disable logging to prevent it from being crazy slow
            // LogUtils.locations = LogUtils.Locations.None;

            const string nickName = nameof(GenerateEventsLimitedByMaxGenerateTime);

            GameManager.SaveData = FortuneFountainSaveData.NewSaveFile(nickName);


            //Setting up the player data
            GameManager.SaveData.PlayerValuables =
                TestData.GetUniformPlayerValuables(GameManager.SaveData, itemsPerSecond);
            GameManager.SaveData.Hand.LastThrowTime = FrameTime.Now -
                                                      TimeSpan.FromSeconds(generateTimeLimitInSeconds +
                                                                           extraGenerationSeconds);
            GameManager.SaveData.PlayerValuables.ForEach(it =>
                                                         it.LastGenerateCheckTime = GameManager.SaveData.Hand.LastThrowTime);
            GameManager.SaveData.Hand.GenerateTimeLimit = TimeSpan.FromSeconds(generateTimeLimitInSeconds);

            Assert.That(GameManager.SaveData.PlayerValuables[0].GenerateInterval,
                        Is.LessThanOrEqualTo(GameManager.SaveData.Hand.GenerateTimeLimit),
                        $"We must have enough time to generate at least one item - i.e. {nameof(PlayerValuable.GenerateInterval)} <= {nameof(Hand.GenerateTimeLimit)}!");

            var genCounters = CreateValuableGenerationCounters(GameManager.SaveData.PlayerValuables);

            //Generate the items
            GameManager.SaveData.PlayerValuables.CheckGenerate();

            //Check for the proper number of events & actual items generated
            AssertAll.Of(
                () => Assert.That(
                    GroupThrowables(GameManager.SaveData.Hand.Throwables),
                    Has.All.Values().With.Count.InRange(Math.Floor(expectedItemsGenerated),
                                                        Math.Ceiling(expectedItemsGenerated))
                    ),
                () => Assert.That(genCounters,
                                  Has.All.Values().With.Property(nameof(ValuableGenerationCounter.Events)).EqualTo(1)),
                () => Assert.That(genCounters,
                                  Has.All.Values().With.Property(nameof(ValuableGenerationCounter.Amount))
                                  .InRange(Math.Floor(expectedItemsGenerated), Math.Ceiling(expectedItemsGenerated)))
                );
        }