Пример #1
0
        public void ChooseHighestRated_WithFirstBehavior(List <KeyValuePair <int, float>[]> hypotheses, List <float> ratings,
                                                         KeyValuePair <int, float> expectedIndexToRating)
        {
            var tieBuffer     = new int[4];
            var matchesBuffer = new SetMatchesBuffer(hypotheses[0].Length, 10);

            AddMultipleHypotheses(matchesBuffer, hypotheses, ratings);

            var chosenIndexToRating = matchesBuffer.ChooseHighestRated(tieBuffer, TieChoiceBehavior.First);

            Assert.AreEqual(expectedIndexToRating, chosenIndexToRating);
        }
Пример #2
0
        public void ChooseHighestRated_WithRandomBehavior(List <KeyValuePair <int, float>[]> hypotheses, List <float> ratings,
                                                          KeyValuePair <int, float> expectedIndexToRating)
        {
            var tieBuffer     = new int[4];
            var matchesBuffer = new SetMatchesBuffer(hypotheses[0].Length, 10);

            AddMultipleHypotheses(matchesBuffer, hypotheses, ratings);

            var anyNonFirstChoices = false;

            for (var i = 0; i < 10; i++)
            {
                UnityEngine.Random.InitState((i + 1) * 1000);
                var chosenIndexToRating = matchesBuffer.ChooseHighestRated(tieBuffer, TieChoiceBehavior.Random);

                Assert.Contains(chosenIndexToRating.Key, tieBuffer);
                anyNonFirstChoices |= chosenIndexToRating.Key != expectedIndexToRating.Key;
                // all random choices should be sure to have the same value
                Assert.AreEqual(expectedIndexToRating.Value, chosenIndexToRating.Value);
            }

            // make sure that a random choice resulted in something different than a first choice would have
            Assert.True(anyNonFirstChoices);
        }