コード例 #1
0
        public void SeedTest()
        {
            // Arrange
            int seed1 = 1337;
            int seed2 = 13370;

            int rounds = 100;

            IntegerGenerator ig1 = new IntegerGenerator();
            IntegerGenerator ig2 = new IntegerGenerator();

            List <object> gene1Objects = new List <object>(capacity: rounds);
            List <object> gene2Objects = new List <object>(capacity: rounds);

            // Act
            var shouldBeValidInitResult1 = ig1.Init(null, seed1);
            var shouldBeValidInitResult2 = ig2.Init(null, seed2);

            for (int i = 0; i < rounds; i++)
            {
                var genResult1 = ig1.Generate();
                var genResult2 = ig2.Generate();

                gene1Objects.Add(genResult1.result);
                gene2Objects.Add(genResult2.result);

                ig1.NextStep();
                ig2.NextStep();
            }

            CollectionAssert.AreNotEqual(gene1Objects, gene2Objects);
        }
コード例 #2
0
        public void DoubleTest()
        {
            // Arrange
            int seed = 1337;

            int rounds = 100;

            Type doubleType = typeof(double);

            IntegerGenerator ig1 = new IntegerGenerator();

            List <object> gene1Objects = new List <object>(capacity: rounds);
            List <bool>   gene1Success = new List <bool>(capacity: rounds);

            // Act
            var shouldBeValidInitResult1 = ig1.Init(null, seed);

            for (int i = 0; i < rounds; i++)
            {
                var genResult1 = ig1.Generate(null, wantedOutput: doubleType);
                gene1Objects.Add(genResult1.result);
                gene1Success.Add(genResult1.success);

                ig1.NextStep();
            }

            // Assert
            Assert.IsTrue(shouldBeValidInitResult1.success, "Init should have been successful");
            Assert.IsTrue(string.IsNullOrEmpty(shouldBeValidInitResult1.possibleError), "Init should NOT have an error");

            Assert.AreEqual(rounds, gene1Objects.Count);
            Assert.AreEqual(rounds, gene1Success.Count);

            CollectionAssert.AllItemsAreInstancesOfType(gene1Objects, doubleType, "There should be only doubles generated");
        }
コード例 #3
0
        public void IntegerGeneratorWithDefaultTest()
        {
            IGenerator <int> intgen = new IntegerGenerator();
            var checkme             = (int)intgen.Generate();

            Assert.IsNotNull(checkme);
            Assert.That(checkme, Is.InRange(0, 100));
        }
コード例 #4
0
        public void IntegerGenerator_Generate_Output()
        {
            int expected  = 100;
            var generator = new IntegerGenerator(expected, 1);
            int actual    = generator.Generate();

            Assert.Equal(expected, actual);
        }
コード例 #5
0
        public void IntegerGeneratorWithOverrideTest()
        {
            var min = 5;
            var max = 20;
            IGenerator <int> intgen = new IntegerGenerator(min, max);
            var checkme             = (int)intgen.Generate();

            Assert.IsNotNull(checkme);
            Assert.That(checkme, Is.InRange(min, max));
        }
コード例 #6
0
        public void IntegerGenerator_Generate_Properties()
        {
            int expected  = 101;
            var generator = new IntegerGenerator(expected, 1);

            generator.Generate();

            Assert.Equal(expected, generator.Current);
            Assert.Equal(1, generator.Count);
        }
コード例 #7
0
        public void IntegerGenerator_GenerateStep_Properties()
        {
            int iterations = 5;
            int step       = 4;
            var generator  = new IntegerGenerator(0, step);

            for (int i = 0; i < iterations; i++)
            {
                generator.Generate();
            }

            Assert.Equal(iterations * step - 1 * step, generator.Current);
            Assert.Equal(iterations * step - 2 * step, generator.Previous);
            Assert.Equal(iterations, generator.Count);
        }
コード例 #8
0
        public void LoadTest()
        {
            // Arrange
            int    seed       = 13237;
            string range      = "2,556";
            string loadString = $"~{range}~{seed}";

            IntegerGenerator ig1 = new IntegerGenerator();
            IntegerGenerator ig2 = new IntegerGenerator();
            IntegerGenerator ig3 = new IntegerGenerator();

            List <int> results1 = new List <int>();
            List <int> results2 = new List <int>();
            List <int> results3 = new List <int>();

            // Act
            var shouldBeValidInitResult1 = ig1.Init(range, seed);
            var shouldBeValidInitResult2 = ig3.Init(null, 0);

            var shouldBeValidLoadResult = ig2.Load(loadString);

            for (int i = 0; i < 13; i++)
            {
                results1.Add((int)ig1.Generate().result);
                results2.Add((int)ig2.Generate().result);
                results3.Add((int)ig3.Generate().result);
            }

            // Assert
            Assert.IsTrue(shouldBeValidInitResult1.success);
            Assert.IsTrue(shouldBeValidInitResult2.success);
            Assert.IsTrue(shouldBeValidLoadResult.success);

            CollectionAssert.AreEqual(results1, results2);
            Assert.IsTrue(results1.All(item => item >= 2 && item < 556));
            CollectionAssert.AreNotEqual(results1, results3);
        }
コード例 #9
0
ファイル: NameGenerator.cs プロジェクト: gsimion/SlimXUnitDb
        /// <inheritdoc />
        protected override string GenerateNew()
        {
            decimal next = _numberGenerator.Generate();

            return(_prefix + next + _suffix);
        }
コード例 #10
0
ファイル: AppPersonTest.cs プロジェクト: gsimion/SlimXUnitDb
 private void SetupDefaultFakerBahavior(Faker <AppPerson> faker)
 {
     faker.RuleFor(u => u.Name, f => _nameGenerator.Generate())
     .RuleFor(u => u.Id, f => _idGenerator.Generate());
 }
コード例 #11
0
        public void GenerateIntsTest()
        {
            // Arrange
            int seed = 1337;

            int rounds = 100;

            IntegerGenerator ig1 = new IntegerGenerator();
            IntegerGenerator ig2 = new IntegerGenerator();
            IntegerGenerator ig3 = new IntegerGenerator();
            IntegerGenerator ig4 = new IntegerGenerator();
            IntegerGenerator ig5 = new IntegerGenerator();

            var range2 = (min : 2, max : 10);

            List <object> gene1Objects = new List <object>(capacity: rounds);
            List <object> gene2Objects = new List <object>(capacity: rounds);
            List <object> gene3Objects = new List <object>(capacity: rounds);
            List <object> gene4Objects = new List <object>(capacity: rounds);
            List <object> gene5Objects = new List <object>(capacity: rounds);

            List <bool> gene1Success = new List <bool>(capacity: rounds);
            List <bool> gene2Success = new List <bool>(capacity: rounds);
            List <bool> gene3Success = new List <bool>(capacity: rounds);
            List <bool> gene4Success = new List <bool>(capacity: rounds);
            List <bool> gene5Success = new List <bool>(capacity: rounds);

            // Act
            var shouldBeValidInitResult1 = ig1.Init(null, seed);
            var shouldBeValidInitResult2 = ig2.Init($"{range2.min}..{range2.max}", seed);
            var shouldBeValidInitResult3 = ig3.Init("-100,-66", seed);
            var shouldBeValidInitResult4 = ig4.Init($"{int.MinValue}..{int.MaxValue}", seed);
            var shouldBeValidInitResult5 = ig5.Init("0,1", seed);

            for (int i = 0; i < rounds; i++)
            {
                var genResult1 = ig1.Generate();
                var genResult2 = ig2.Generate();
                var genResult3 = ig3.Generate();
                var genResult4 = ig4.Generate();
                var genResult5 = ig5.Generate();

                gene1Objects.Add(genResult1.result);
                gene2Objects.Add(genResult2.result);
                gene3Objects.Add(genResult3.result);
                gene4Objects.Add(genResult4.result);
                gene5Objects.Add(genResult5.result);

                gene1Success.Add(genResult1.success);
                gene2Success.Add(genResult2.success);
                gene3Success.Add(genResult3.success);
                gene4Success.Add(genResult4.success);
                gene5Success.Add(genResult5.success);

                ig1.NextStep();
                ig2.NextStep();
                ig3.NextStep();
                ig4.NextStep();
                ig5.NextStep();
            }

            // Assert
            Assert.AreEqual(rounds, gene1Objects.Count);
            Assert.AreEqual(rounds, gene2Objects.Count);
            Assert.AreEqual(rounds, gene3Objects.Count);
            Assert.AreEqual(rounds, gene4Objects.Count);
            Assert.AreEqual(rounds, gene5Objects.Count);

            Assert.AreEqual(rounds, gene1Success.Count);
            Assert.AreEqual(rounds, gene2Success.Count);
            Assert.AreEqual(rounds, gene3Success.Count);
            Assert.AreEqual(rounds, gene4Success.Count);
            Assert.AreEqual(rounds, gene5Success.Count);

            CollectionAssert.AllItemsAreInstancesOfType(gene1Objects, typeof(int), "There should be only ints generated");
            CollectionAssert.AllItemsAreInstancesOfType(gene2Objects, typeof(int), "There should be only ints generated");
            CollectionAssert.AllItemsAreInstancesOfType(gene3Objects, typeof(int), "There should be only ints generated");
            CollectionAssert.AllItemsAreInstancesOfType(gene4Objects, typeof(int), "There should be only ints generated");
            CollectionAssert.AllItemsAreInstancesOfType(gene5Objects, typeof(int), "There should be only ints generated");

            var range1 = ig1.GetRange();

            foreach (object val in gene1Objects)
            {
                Assert.GreaterOrEqual((int)val, (int)range1.minRangeInclusive);
                Assert.Less((int)val, (int)range1.maxRangeExclusive);
            }

            Assert.AreEqual(range2.min, (int)ig2.GetRange().minRangeInclusive, "Range min should have been parsed correctly");
            Assert.AreEqual(range2.max, (int)ig2.GetRange().maxRangeExclusive, "Range max should have been parsed correctly");

            foreach (object val in gene2Objects)
            {
                Assert.GreaterOrEqual((int)val, range2.min);
                Assert.Less((int)val, range2.max);
            }
        }
コード例 #12
0
        public void GenerateLongsTest()
        {
            // Arrange
            int seed = 1337;

            int rounds = 100;

            Type longType = typeof(long);

            IntegerGenerator ig1 = new IntegerGenerator();
            IntegerGenerator ig2 = new IntegerGenerator();
            IntegerGenerator ig3 = new IntegerGenerator();

            long intMin = int.MinValue;
            long intMax = int.MaxValue;
            var  range1 = (min : intMin - 1, max : 10);
            var  range2 = (min : -10, max : intMax + 1);
            var  range3 = (min : long.MinValue, max : long.MaxValue);

            List <object> gene1Objects = new List <object>(capacity: rounds);
            List <object> gene2Objects = new List <object>(capacity: rounds);
            List <object> gene3Objects = new List <object>(capacity: rounds);

            List <bool> gene1Success = new List <bool>(capacity: rounds);
            List <bool> gene2Success = new List <bool>(capacity: rounds);
            List <bool> gene3Success = new List <bool>(capacity: rounds);

            // Act
            var shouldBeValidInitResult1 = ig1.Init($"{range1.min}..{range1.max}", seed);
            var shouldBeValidInitResult2 = ig2.Init($"{range2.min}..{range2.max}", seed);
            var shouldBeValidInitResult3 = ig3.Init($"{range3.min}..{range3.max}", seed);

            for (int i = 0; i < rounds; i++)
            {
                var genResult1 = ig1.Generate(null, longType);
                var genResult2 = ig2.Generate(null, longType);
                var genResult3 = ig3.Generate(null, longType);

                gene1Objects.Add(genResult1.result);
                gene2Objects.Add(genResult2.result);
                gene3Objects.Add(genResult3.result);

                gene1Success.Add(genResult1.success);
                gene2Success.Add(genResult2.success);
                gene3Success.Add(genResult3.success);

                ig1.NextStep();
                ig2.NextStep();
                ig3.NextStep();
            }

            // Assert
            Assert.AreEqual(rounds, gene1Objects.Count);
            Assert.AreEqual(rounds, gene2Objects.Count);
            Assert.AreEqual(rounds, gene3Objects.Count);

            Assert.AreEqual(rounds, gene1Success.Count);
            Assert.AreEqual(rounds, gene2Success.Count);
            Assert.AreEqual(rounds, gene3Success.Count);

            CollectionAssert.AllItemsAreInstancesOfType(gene1Objects, longType, "There should be only longs generated");
            CollectionAssert.AllItemsAreInstancesOfType(gene2Objects, longType, "There should be only longs generated");
            CollectionAssert.AllItemsAreInstancesOfType(gene3Objects, longType, "There should be only longs generated");

            var rangeTemp = ig1.GetRange();

            foreach (object val in gene1Objects)
            {
                Assert.GreaterOrEqual((long)val, (long)rangeTemp.minRangeInclusive);
                Assert.Less((long)val, (long)rangeTemp.maxRangeExclusive);
            }

            Assert.AreEqual(range2.min, (long)ig2.GetRange().minRangeInclusive, "Range min should have been parsed correctly");
            Assert.AreEqual(range2.max, (long)ig2.GetRange().maxRangeExclusive, "Range max should have been parsed correctly");

            foreach (object val in gene2Objects)
            {
                Assert.GreaterOrEqual((long)val, range2.min);
                Assert.Less((long)val, range2.max);
            }
        }
コード例 #13
0
 public void IntegerGeneratorWithOverrideTest()
 {
     var min = 5;
     var max = 20;
     IGenerator<int> intgen = new IntegerGenerator(min, max);
     var checkme = (int) intgen.Generate();
     Assert.IsNotNull(checkme);
     Assert.That(checkme, Is.InRange(min, max));
 }
コード例 #14
0
 public void IntegerGeneratorWithDefaultTest()
 {
     IGenerator<int> intgen = new IntegerGenerator();
     var checkme = (int) intgen.Generate();
     Assert.IsNotNull(checkme);
     Assert.That(checkme, Is.InRange(0, 100));
 }