public void GenerateCombination_OnlyOneFeature_ResultingListContainsOnlyOneFeature()
        {
            // Arrange
            var candidate = new RandomCombinationGenerator(new FakeRandomizer(4231));

            // Act
            var combination = candidate.GenerateCombination(new[]
            {
                this._feature1,
            });

            // Assert
            Assert.AreEqual(1, combination.Features.Count);
            Assert.AreEqual(this._feature1, combination.Features[0]);
        }
예제 #2
0
        private void Add(BankSystemContext context, string[] args)
        {
            if (this._bankSystemController.LogedUser == null)
            {
                Console.WriteLine($"You should Login first!");
                return;
            }

            string acountType = args[0];

            decimal initialBallance = decimal.Parse(args[1]);

            Account account = default(Account);

            switch (acountType)
            {
            case "SavingsAccount":
                double rate = double.Parse(args[2]);
                account = new SavingAccount
                {
                    Ballance      = initialBallance,
                    AccountNumber = RandomCombinationGenerator.Generate(),
                    Rate          = rate
                };
                break;

            case "CheckingAccount":
                double fee = double.Parse(args[2]);
                account = new CheckingAccount
                {
                    Ballance      = initialBallance,
                    AccountNumber = RandomCombinationGenerator.Generate(),
                    Fee           = fee
                };
                break;

            default:
                Console.WriteLine("Invalid command!");
                return;
            }

            this._bankSystemController.LogedUser.Accounts.Add(account);
            context.Users.Find(this._bankSystemController.LogedUser.Id).Accounts.Add(account);

            context.SaveChanges();

            Console.WriteLine($"Succesfully added account with number {account.AccountNumber}");
        }
        public void GenerateCombination_WildRandomIndices_ResultingListContainsAllFeature()
        {
            // Arrange
            var candidate = new RandomCombinationGenerator(new FakeRandomizer(53, 895348, 765));

            // Act
            var combination = candidate.GenerateCombination(new[]
            {
                this._feature1,
                this._feature2,
                this._feature3,
            });

            // Assert
            Assert.AreEqual(3, combination.Features.Count);
            Assert.IsTrue(combination.Features.Contains(this._feature1));
            Assert.IsTrue(combination.Features.Contains(this._feature2));
            Assert.IsTrue(combination.Features.Contains(this._feature3));
        }
        public void GenerateCombination_RandomIndexIsAlwaysLastPosition_ResultingOrderIsInverted()
        {
            // Arrange
            var candidate = new RandomCombinationGenerator(new FakeRandomizer(2, 1, 0));

            // Act
            var combination = candidate.GenerateCombination(new[]
            {
                this._feature1,
                this._feature2,
                this._feature3
            });

            // Assert
            Assert.AreEqual(3, combination.Features.Count);
            Assert.AreEqual(this._feature3, combination.Features[0]);
            Assert.AreEqual(this._feature2, combination.Features[1]);
            Assert.AreEqual(this._feature1, combination.Features[2]);
        }
        public void GenerateCombination_LargeFeatureSet_ResultingListContainsAllFeature()
        {
            // Arrange
            var candidate = new RandomCombinationGenerator(new FakeRandomizer(
                                                               6282527,
                                                               8424440,
                                                               2490841,
                                                               10467771,
                                                               2148918,
                                                               12670802));

            var numberOfFeatures = 13523;
            var features         = new List <Feature>();

            for (int i = 0; i < numberOfFeatures; i++)
            {
                features.Add(new Feature("Feature XY", 1, 3));
            }

            // Act
            var combination = candidate.GenerateCombination(features);

            // Assert
            Assert.AreEqual(numberOfFeatures, combination.Features.Count);
            foreach (var feature in features)
            {
                // Each feature is contained in the combination.
                Assert.IsTrue(combination.Features.Contains(feature));

                // Non of the features in the combinations have the same position as in the original
                // feature list. This is not always guaranteed, but is the case for the specified
                // input feature list and generated "random" numbers.
                var combinationFeatures = combination.Features.ToList();
                Assert.AreNotEqual(
                    features.IndexOf(feature),
                    combinationFeatures.IndexOf(feature));
            }
        }