public void EnvironmentNegativeBadType()
 {
     using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
     {
         using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
         {
             var name        = TestRandom.RandomString();
             var description = TestRandom.RandomString();
             cmdlet.AddCommand(UiPathStrings.AddUiPathEnvironment)
             .AddParameter(UiPathStrings.Name, name)
             .AddParameter(UiPathStrings.Description, description)
             .AddParameter(UiPathStrings.Type, "Invalid");
             // Not clear if it should be ParameterBindingValidationException or ValidationMetadataException
             // And ParameterBindingValidationException does not resolve...
             try
             {
                 Invoke <Environment>(cmdlet);
                 Assert.Fail("The Invoke was supposed to throw!");
             }
             catch (RuntimeException re)
             {
                 Assert.AreEqual("Cannot validate argument on parameter 'Type'. The argument \"Invalid\" does not belong to the set \"Dev,Test,Prod\" specified by the ValidateEnum attribute. Supply an argument that is in the set and then try the command again", re.Message);
             }
         }
     }
 }
        public void PolynomialOnePositionManipulatorApplyTest()
        {
            TestRandom  random = new TestRandom();
            RealVector  parent, expected;
            DoubleValue contiguity, maxManipulation;
            bool        exceptionFired;

            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers    = new int[] { 3 };
            random.DoubleNumbers = new double[] { 0.2 };
            parent          = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            expected        = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.1261980542102, 0.1 });
            contiguity      = new DoubleValue(0.2);
            maxManipulation = new DoubleValue(0.7);
            PolynomialOnePositionManipulator.Apply(random, parent, contiguity, maxManipulation);
            Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
            // The following test is not based on published examples
            exceptionFired = false;
            random.Reset();
            random.IntNumbers    = new int[] { 3 };
            random.DoubleNumbers = new double[] { 0.2 };
            parent          = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            contiguity      = new DoubleValue(-1); //Contiguity value < 0
            maxManipulation = new DoubleValue(0.2);
            try {
                PolynomialOnePositionManipulator.Apply(random, parent, contiguity, maxManipulation);
            } catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
        public void PositionBasedCrossoverApplyTest()
        {
            TestRandom  random = new TestRandom();
            Permutation parent1, parent2, expected, actual;

            // The following test is based on an example from Larranaga, 1999. Genetic Algorithms for the Traveling Salesman Problem.
            random.Reset();
            random.IntNumbers = new int[] { 3, 1, 2, 5 };
            parent1           = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            Assert.IsTrue(parent1.Validate());
            parent2 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 1, 3, 5, 7, 6, 4, 2, 0 });
            Assert.IsTrue(parent2.Validate());

            expected = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 3, 5, 1, 2, 4, 6, 7 });
            Assert.IsTrue(expected.Validate());
            actual = PositionBasedCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(actual.Validate());
            Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));

            // perform a test when two permutations are of unequal length
            random.Reset();
            bool exceptionFired = false;

            try {
                PositionBasedCrossover.Apply(random, new Permutation(PermutationTypes.RelativeUndirected, 8), new Permutation(PermutationTypes.RelativeUndirected, 6));
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 4
0
        public void CyclicCrossover2ApplyTest()
        {
            TestRandom  random = new TestRandom();
            Permutation parent1, parent2, expected, actual;

            // The following test is based on an example from Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press. pp. 134.
            random.Reset();
            random.IntNumbers = new int[] { 0 };
            parent1           = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            Assert.IsTrue(parent1.Validate());
            parent2 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 2, 5, 6, 0, 7, 1, 3, 8, 4, 9 });
            Assert.IsTrue(parent2.Validate());
            expected = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 5, 2, 3, 7, 1, 6, 8, 4, 9 });
            Assert.IsTrue(expected.Validate());
            actual = CyclicCrossover2.Apply(random, parent1, parent2);
            Assert.IsTrue(actual.Validate());
            Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));

            // perform a test when the two permutations are of unequal length
            random.Reset();
            bool exceptionFired = false;

            try {
                CyclicCrossover.Apply(random, new Permutation(PermutationTypes.RelativeUndirected, 8), new Permutation(PermutationTypes.RelativeUndirected, 6));
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 5
0
        public void Next_with_range_always_returns_the_same_value()
        {
            var expected = 12;
            var sut      = TestRandom <int> .Create(expected);

            Assert.Equal(expected, sut.Next(20.ToRange(50)));
        }
        public void DiscreteCrossoverApplyTest()
        {
            TestRandom    random = new TestRandom();
            IntegerVector parent1, parent2, expected, actual;
            bool          exceptionFired;

            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers = new int[] { 0, 0, 1, 0, 1 };
            parent1           = new IntegerVector(new int[] { 2, 2, 3, 5, 1 });
            parent2           = new IntegerVector(new int[] { 4, 1, 3, 2, 8 });
            expected          = new IntegerVector(new int[] { 2, 2, 3, 5, 8 });
            actual            = DiscreteCrossover.Apply(random, new ItemArray <IntegerVector>(new IntegerVector[] { parent1, parent2 }));
            Assert.IsTrue(Auxiliary.IntegerVectorIsEqualByPosition(actual, expected));

            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers = new int[] { 0, 0, 1, 0, 1 };
            parent1           = new IntegerVector(new int[] { 2, 2, 3, 5, 1, 9 }); // this parent is longer
            parent2           = new IntegerVector(new int[] { 4, 1, 3, 2, 8 });
            exceptionFired    = false;
            try {
                actual = DiscreteCrossover.Apply(random, new ItemArray <IntegerVector>(new IntegerVector[] { parent1, parent2 }));
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 7
0
        public void SinglePointCrossoverCrossTest()
        {
            SinglePointCrossover_Accessor target = new SinglePointCrossover_Accessor(new PrivateObject(typeof(SinglePointCrossover)));
            ItemArray <BinaryVector>      parents;
            TestRandom random = new TestRandom();
            bool       exceptionFired;

            // The following test checks if there is an exception when there are more than 2 parents
            random.Reset();
            parents        = new ItemArray <BinaryVector>(new BinaryVector[] { new BinaryVector(5), new BinaryVector(6), new BinaryVector(4) });
            exceptionFired = false;
            try {
                BinaryVector actual;
                actual = target.Cross(random, parents);
            } catch (ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
            // The following test checks if there is an exception when there are less than 2 parents
            random.Reset();
            parents        = new ItemArray <BinaryVector>(new BinaryVector[] { new BinaryVector(4) });
            exceptionFired = false;
            try {
                BinaryVector actual;
                actual = target.Cross(random, parents);
            } catch (ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
        public void EdgeRecombinationCrossoverApplyTest()
        {
            TestRandom  random = new TestRandom();
            Permutation parent1, parent2, expected, actual;

            // The following test is based on an example from Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, pp. 54-55
            random.Reset();
            random.IntNumbers    = new int[] { 0 };
            random.DoubleNumbers = new double[] { 0.5, 0, 0, 0 };
            parent1 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 });
            Assert.IsTrue(parent1.Validate());
            parent2 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 8, 2, 6, 7, 1, 5, 4, 0, 3 });
            Assert.IsTrue(parent2.Validate());
            expected = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 4, 5, 1, 7, 6, 2, 8, 3 });
            Assert.IsTrue(expected.Validate());
            actual = EdgeRecombinationCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(actual.Validate());
            Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));

            // perform a test when the two permutations are of unequal length
            random.Reset();
            bool exceptionFired = false;

            try {
                EdgeRecombinationCrossover.Apply(random, new Permutation(PermutationTypes.RelativeUndirected, 8), new Permutation(PermutationTypes.RelativeUndirected, 6));
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 9
0
 private static void HalfRandom(byte[] data)
 {
     for (int nx = 0; nx < 32; nx++)
     {
         data[TestRandom.Next(0, data.Length)] = (byte)TestRandom.Next();
     }
 }
Exemplo n.º 10
0
        public void DiscreteCrossoverApplyTest()
        {
            TestRandom             random = new TestRandom();
            RealVector             parent1, parent2, expected, actual;
            ItemArray <RealVector> parents;
            bool exceptionFired;

            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers = new int[] { 0, 0, 1, 0, 1 };
            parent1           = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            parent2           = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            parents           = new ItemArray <RealVector>(new RealVector[] { parent1, parent2 });
            expected          = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.8 });
            actual            = DiscreteCrossover.Apply(random, parents);
            Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers = new int[] { 0, 0, 1, 0, 1, 0 };
            parent1           = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer
            parent2           = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            parents           = new ItemArray <RealVector>(new RealVector[] { parent1, parent2 });
            exceptionFired    = false;
            try {
                actual = DiscreteCrossover.Apply(random, parents);
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 11
0
        public void SetUp()
        {
            _trueCryptoRandom = new CryptoRandom();

            // WARN: order reflects the internal implementation of the service (tests may fail after any refactoring)
            _testRandom = new TestRandom(
                NetTestVectors.NonceA,
                NetTestVectors.EphemeralKeyA.KeyBytes,
                _trueCryptoRandom.GenerateRandomBytes(100),
                NetTestVectors.NonceB,
                NetTestVectors.EphemeralKeyB.KeyBytes,
                _trueCryptoRandom.GenerateRandomBytes(100));

            _messageSerializationService = new MessageSerializationService();
            _messageSerializationService.Register(new AuthMessageSerializer());
            _messageSerializationService.Register(new AuthEip8MessageSerializer(new Eip8MessagePad(_testRandom)));
            _messageSerializationService.Register(new AckMessageSerializer());
            _messageSerializationService.Register(new AckEip8MessageSerializer(new Eip8MessagePad(_testRandom)));

            _eciesCipher = new EciesCipher(_trueCryptoRandom); // TODO: provide a separate test random with specific IV and epehemeral key for testing

            _initiatorService = new EncryptionHandshakeService(_messageSerializationService, _eciesCipher, _testRandom, _signer, NetTestVectors.StaticKeyA, NullLogManager.Instance);
            _recipientService = new EncryptionHandshakeService(_messageSerializationService, _eciesCipher, _testRandom, _signer, NetTestVectors.StaticKeyB, NullLogManager.Instance);

            _initiatorHandshake = new EncryptionHandshake();
            _recipientHandshake = new EncryptionHandshake();

            _auth = null;
            _ack  = null;
        }
Exemplo n.º 12
0
        public void SinglePointCrossoverCrossTest()
        {
            var target = new PrivateObject(typeof(SinglePointCrossover));
            ItemArray <IntegerVector> parents;
            TestRandom random = new TestRandom();
            bool       exceptionFired;

            // The following test checks if there is an exception when there are more than 2 parents
            random.Reset();
            parents        = new ItemArray <IntegerVector>(new IntegerVector[] { new IntegerVector(5), new IntegerVector(6), new IntegerVector(4) });
            exceptionFired = false;
            try {
                IntegerVector actual;
                actual = (IntegerVector)target.Invoke("Cross", random, parents);
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
            // The following test checks if there is an exception when there are less than 2 parents
            random.Reset();
            parents        = new ItemArray <IntegerVector>(new IntegerVector[] { new IntegerVector(4) });
            exceptionFired = false;
            try {
                IntegerVector actual;
                actual = (IntegerVector)target.Invoke("Cross", random, parents);
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 13
0
        public void CyclicCrossoverApplyTest()
        {
            TestRandom  random = new TestRandom();
            Permutation parent1, parent2, expected, actual;

            // The following test is based on an example from Larranaga, P. et al. 1999. Genetic Algorithms for the Travelling Salesman Problem: A Review of Representations and Operators. Artificial Intelligence Review, 13
            random.Reset();
            random.DoubleNumbers = new double[] { 0.9 };
            parent1 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            Assert.IsTrue(parent1.Validate());
            parent2 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 1, 3, 5, 7, 6, 4, 2, 0 });
            Assert.IsTrue(parent2.Validate());
            expected = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 5, 3, 6, 4, 2, 7 });
            Assert.IsTrue(expected.Validate());
            actual = CyclicCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(actual.Validate());
            Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));

            // perform a test when the two permutations are of unequal length
            random.Reset();
            bool exceptionFired = false;

            try {
                CyclicCrossover.Apply(random, new Permutation(PermutationTypes.RelativeUndirected, 8), new Permutation(PermutationTypes.RelativeUndirected, 6));
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 14
0
        public IEnumerable <Product> GenerateCatalog(int count = 1000)
        {
            // Adapted from https://weblogs.asp.net/dfindley/Microsoft-Product-Name-Generator
            var prefixes   = new[] { null, "Visual", "Compact", "Embedded", "Expression" };
            var products   = new[] { null, "Windows", "Office", "SQL", "FoxPro", "BizTalk" };
            var terms      = new[] { "Web", "Robotics", "Network", "Testing", "Project", "Small Business", "Team", "Management", "Graphic", "Presentation", "Communication", "Workflow", "Ajax", "XML", "Content", "Source Control" };
            var type       = new[] { null, "Client", "Workstation", "Server", "System", "Console", "Shell", "Designer" };
            var suffix     = new[] { null, "Express", "Standard", "Professional", "Enterprise", "Ultimate", "Foundation", ".NET", "Framework" };
            var components = new[] { prefixes, products, terms, type, suffix };

#if SNIPPET
            var random = new Random();
#else
            TestRandom random = Recording.Random;
#endif
            string RandomElement(string[] values) => values[(int)(random.NextDouble() * values.Length)];
            double RandomPrice() => (random.Next(2, 20) * 100.0) / 2.0 - .01;

            for (int i = 1; i <= count; i++)
            {
                yield return(new Product
                {
                    Id = i.ToString(),
                    Name = string.Join(" ", components.Select(RandomElement).Where(n => n != null)),
                    Price = RandomPrice()
                });
            }
        }
Exemplo n.º 15
0
        public void TestCircleEmitter()
        {
            var random       = new TestRandom(0.0d);
            var emitterShape = new CircleEmitter(1.0f, new ThreeSixty(1, 10, random), random); // 0 degrees
            var location     = emitterShape.GetLocation();

            Console.WriteLine(location);
            Assert.AreEqual(new Vector2(1, 0), location);

            random       = new TestRandom(0.25d);
            emitterShape = new CircleEmitter(1.0f, new ThreeSixty(1, 10, random), random); // 90 degrees
            location     = emitterShape.GetLocation();
            Console.WriteLine(location);
            Assert.AreEqual(new Vector2(0, 1), location);

            random       = new TestRandom(0.5d);
            emitterShape = new CircleEmitter(1.0f, new ThreeSixty(1, 10, random), random); // 180 degrees
            location     = emitterShape.GetLocation();
            Console.WriteLine(location);
            Assert.AreEqual(new Vector2(-1, 0), location);

            random       = new TestRandom(0.75d);
            emitterShape = new CircleEmitter(1.0f, new ThreeSixty(1, 10, random), random); // 270 degrees
            location     = emitterShape.GetLocation();
            Console.WriteLine(location);
            Assert.AreEqual(new Vector2(0, -1), location);

            random       = new TestRandom(1.0d);
            emitterShape = new CircleEmitter(1.0f, new ThreeSixty(1, 10, random), random); // 360 degrees
            location     = emitterShape.GetLocation();
            Console.WriteLine(location);
            Assert.AreEqual(new Vector2(1, 0), location);
        }
        public void AssetAddRemovePositional()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                Asset asset = null;

                // Positional add
                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    var assetName  = TestRandom.RandomString();
                    var assetValue = TestRandom.RandomString();
                    cmdlet.AddCommand(UiPathStrings.AddUiPathAsset)
                    .AddArgument(assetName)
                    .AddParameter(UiPathStrings.TextValue, assetValue);
                    var assets = Invoke <Asset>(cmdlet);

                    Validators.ValidateAssetResponse(assets, null, assetName, AssetDtoValueType.Text, assetValue);

                    asset = assets[0];
                }

                // positional remove by object
                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveUiPathAsset)
                    .AddArgument(asset);
                    Invoke(cmdlet);
                }
            }
        }
Exemplo n.º 17
0
        public void _Cxkk_RND_vx_byte(byte kk,
                                      byte rand)
        {
            var registers = new RegisterModule();

            var random = new TestRandom(rand);


            var emulator = CHIP8Factory.GetChip8(registers: registers,
                                                 random: random);

            var instructions = new byte[]
            {
                0xC0,                    //Set v0 = kk & random byte
                kk
            };

            emulator.LoadProgram(instructions);

            emulator.Tick += (e,
                              a) =>
            {
                emulator.Stop();
            };

            emulator.Start();

            Assert.Equal(rand & kk,
                         registers.GetGeneralValue(0));
        }
        public void PolynomialAllPositionManipulatorApplyTest()
        {
            TestRandom  random = new TestRandom();
            RealVector  parent, expected;
            DoubleValue contiguity, maxManipulation;
            bool        exceptionFired;

            // The following test is not based on published examples
            random.Reset();
            random.DoubleNumbers = new double[] { 0.2, 0.7, 0.8, 0.01, 0.1 };
            parent          = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            expected        = new RealVector(new double[] { 0.120213215256006, 0.249415354697564, 0.379786784743994, 0.322759240811056, -0.0182075293954083 });
            contiguity      = new DoubleValue(0.8);
            maxManipulation = new DoubleValue(0.2);
            PolynomialAllPositionManipulator.Apply(random, parent, contiguity, maxManipulation);
            Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
            // The following test is not based on published examples
            exceptionFired = false;
            random.Reset();
            random.DoubleNumbers = new double[] { 0.2, 0.7, 0.8, 0.01, 0.1 };
            parent          = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            contiguity      = new DoubleValue(-1); //Contiguity value < 0
            maxManipulation = new DoubleValue(0.2);
            try {
                PolynomialAllPositionManipulator.Apply(random, parent, contiguity, maxManipulation);
            } catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 19
0
        public void LocalCrossoverApplyTest()
        {
            TestRandom random = new TestRandom();
            RealVector parent1, parent2, expected, actual;
            bool       exceptionFired;

            // The following test is not based on published examples
            random.Reset();
            random.DoubleNumbers = new double[] { 0.3, 0.1, 0.2, 0.4, 0.23 };
            parent1  = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            parent2  = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            expected = new RealVector(new double[] { 0.34, 0.11, 0.3, 0.32, 0.639 });
            actual   = LocalCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
            // The following test is not based on published examples
            random.Reset();
            random.DoubleNumbers = new double[] { 0.3, 0.1, 0.2, 0.4, 0.23, 0.5 };
            parent1        = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer
            parent2        = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            exceptionFired = false;
            try {
                actual = LocalCrossover.Apply(random, parent1, parent2);
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
        public void EnvironmentAddType()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                foreach (var envType in Enum.GetValues(typeof(EnvironmentDtoType)))
                {
                    using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                    {
                        var name        = TestRandom.RandomString();
                        var description = TestRandom.RandomString();
                        cmdlet.AddCommand(UiPathStrings.AddUiPathEnvironment)
                        .AddParameter(UiPathStrings.Name, name)
                        .AddParameter(UiPathStrings.Description, description)
                        .AddParameter(UiPathStrings.Type, envType);
                        var environments = Invoke <Environment>(cmdlet);

                        Validators.ValidateEnvironmentResponse(environments, null, name, description, (EnvironmentDtoType)envType);

                        Api.DeleteEnvironmentById(environments[0].Id);

                        TestContext.WriteLine($"Validated Add-UiPathEnvironment type: {envType}");
                    }
                }
            }
        }
Exemplo n.º 21
0
        public void Next_always_returns_the_same_value()
        {
            var expected = "testValue";
            var sut      = TestRandom <string> .Create(expected);

            Assert.Equal(expected, sut.Next());
            Assert.Equal(expected, sut.Next(null));
        }
Exemplo n.º 22
0
        public void FolderAddGetRemove()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                var    displayName   = TestRandom.RandomAlphaNumeric();
                var    description   = TestRandom.RandomAlphaNumeric();
                long?  folderId      = null;
                Folder currentFolder = null;
                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddFolder)
                    .AddParameter(UiPathStrings.DisplayName, displayName)
                    .AddParameter(UiPathStrings.Description, description)
                    .AddParameter(UiPathStrings.PermissionModel, FolderDtoPermissionModel.FineGrained)
                    .AddParameter(UiPathStrings.ProvisionType, FolderDtoProvisionType.Automatic);
                    var folders = Invoke <Folder>(cmdlet);

                    Validators.ValidateFolderResponse(folders, null, displayName, description, FolderDtoProvisionType.Automatic, FolderDtoPermissionModel.FineGrained);

                    folderId = folders[0].Id;
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetFolder)
                    .AddParameter(UiPathStrings.Id, folderId);
                    var folders = Invoke <Folder>(cmdlet);
                    currentFolder = folders[0];

                    Validators.ValidateFolderResponse(folders, folderId, displayName, description, FolderDtoProvisionType.Automatic, FolderDtoPermissionModel.FineGrained);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    var updatedDisplayName = TestRandom.RandomString();
                    cmdlet.AddCommand(UiPathStrings.EditFolder)
                    .AddArgument(currentFolder)
                    .AddParameter(UiPathStrings.DisplayName, updatedDisplayName);
                    Invoke <Folder>(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveFolder)
                    .AddParameter(UiPathStrings.Id, folderId);
                    Invoke(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetFolder)
                    .AddParameter(UiPathStrings.DisplayName, displayName);
                    var folders = Invoke <Folder>(cmdlet);
                    Validators.ValidatEmptyResponse(folders);
                }
            }
        }
Exemplo n.º 23
0
        public void LibraryFind()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                var libSpec1 = TestRandom.RandomPakcageSpec();

                using (var testPackage = TestRandom.RandomPackage(libSpec1))
                {
                    using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                    {
                        cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
                        .AddArgument(testPackage.FileName);
                        Invoke(cmdlet);
                    }
                }

                var libSpec2 = TestRandom.RandomPakcageSpec();


                using (var testPackage = TestRandom.RandomPackage(libSpec2))
                {
                    using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                    {
                        cmdlet.AddCommand(UiPathStrings.AddUiPathLibrary)
                        .AddArgument(testPackage.FileName);
                        Invoke(cmdlet);
                    }
                }

                TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Id, libSpec1.Id), libSpec1);
                TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Id, libSpec2.Id), libSpec2);
                TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Title, libSpec1.Title), libSpec1);
                TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Authors, libSpec1.Authors), libSpec1);
                TestFilter(runspace, (cmdlet) => cmdlet.AddParameter(UiPathStrings.Version, libSpec2.Version), libSpec2);

                // Only Host admin can delete Libraries
                //
                using (var hostRunspace = PowershellFactory.CreateHostAuthenticatedSession(TestContext))
                {
                    // Remove
                    using (var cmdlet = PowershellFactory.CreateCmdlet(hostRunspace))
                    {
                        cmdlet.AddCommand(UiPathStrings.RemoveUiPathLibrary)
                        .AddParameter(UiPathStrings.Id, libSpec1.Id);
                        Invoke(cmdlet);
                    }

                    using (var cmdlet = PowershellFactory.CreateCmdlet(hostRunspace))
                    {
                        cmdlet.AddCommand(UiPathStrings.RemoveUiPathLibrary)
                        .AddParameter(UiPathStrings.Id, libSpec2.Id);
                        Invoke(cmdlet);
                    }
                }
            }
        }
        public void BlendAlphaCrossoverApplyTest()
        {
            TestRandom  random = new TestRandom();
            RealVector  parent1, parent2, expected, actual;
            DoubleValue alpha;
            bool        exceptionFired;

            // The following test is not based on published examples
            random.Reset();
            random.DoubleNumbers = new double[] { 0.5, 0.5, 0.5, 0.5, 0.5 };
            alpha    = new DoubleValue(0.5);
            parent1  = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            parent2  = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            expected = new RealVector(new double[] { 0.3, 0.15, 0.3, 0.35, 0.45 });
            actual   = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
            Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
            // The following test is not based on published examples
            random.Reset();
            random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 };
            alpha    = new DoubleValue(0.25);
            parent1  = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            parent2  = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });
            actual   = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
            Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
            // The following test is not based on published examples
            random.Reset();
            random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 };
            alpha          = new DoubleValue(-0.25); // negative values for alpha are not allowed
            parent1        = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
            parent2        = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            expected       = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });
            exceptionFired = false;
            try {
                actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
            // The following test is not based on published examples
            random.Reset();
            random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25, .75 };
            alpha          = new DoubleValue(0.25);
            parent1        = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer
            parent2        = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
            expected       = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });
            exceptionFired = false;
            try {
                actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 25
0
        private void CheckGroupCrossover(LinearLinkage parent1, LinearLinkage parent2, int[] expectedllee, double[] randomNumbers)
        {
            var expected = LinearLinkage.FromEndLinks(expectedllee);
            var random   = new TestRandom()
            {
                DoubleNumbers = randomNumbers
            };
            var child = GroupCrossover.Apply(random, parent1, parent2);

            Assert.IsTrue(Auxiliary.LinearLinkageIsEqualByPosition(expected, child), "Expected [{0}] but was [{1}]!", string.Join(", ", expected), string.Join(", ", child));
        }
Exemplo n.º 26
0
        public void CosaCrossoverApplyTest()
        {
            TestRandom  random = new TestRandom();
            Permutation parent1, parent2, expected, actual;

            // The following test is based on an example from Wendt, O. 1994. COSA: COoperative Simulated Annealing - Integration von Genetischen Algorithmen und Simulated Annealing am Beispiel der Tourenplanung. Dissertation Thesis. IWI Frankfurt.
            random.Reset();
            random.IntNumbers = new int[] { 1 };
            parent1           = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 5, 2, 4, 3 });
            Assert.IsTrue(parent1.Validate());
            parent2 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 3, 0, 2, 1, 4, 5 });
            Assert.IsTrue(parent2.Validate());
            expected = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 4, 2, 5, 3 });
            Assert.IsTrue(expected.Validate());
            actual = CosaCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(actual.Validate());
            Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers = new int[] { 4 };
            parent1           = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            Assert.IsTrue(parent1.Validate());
            parent2 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 1, 3, 5, 7, 6, 4, 2, 0 });
            Assert.IsTrue(parent2.Validate());
            expected = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 7, 6, 5, 3, 4, 2, 1, 0 });
            Assert.IsTrue(expected.Validate());
            actual = CosaCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(actual.Validate());
            Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
            // The following test is not based on published examples
            random.Reset();
            random.IntNumbers = new int[] { 5 };
            parent1           = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            Assert.IsTrue(parent1.Validate());
            parent2 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 4, 3, 5, 1, 0, 9, 7, 2, 8, 6 });
            Assert.IsTrue(parent2.Validate());
            expected = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 7, 6, 2, 3, 4, 5, 1, 0, 9, 8 });
            Assert.IsTrue(expected.Validate());
            actual = CosaCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(actual.Validate());
            Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));

            // perform a test when the two permutations are of unequal length
            random.Reset();
            bool exceptionFired = false;

            try {
                CosaCrossover.Apply(random, new Permutation(PermutationTypes.RelativeUndirected, 8), new Permutation(PermutationTypes.RelativeUndirected, 6));
            }
            catch (System.ArgumentException) {
                exceptionFired = true;
            }
            Assert.IsTrue(exceptionFired);
        }
Exemplo n.º 27
0
        public void UserAddGetRemove()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                User        user     = default(User);
                var         userName = TestRandom.RandomAlphaNumeric();
                var         password = TestRandom.RandomPassword();
                var         name     = TestRandom.RandomString();
                var         surname  = TestRandom.RandomString();
                var         email    = TestRandom.RandomEmail();
                UserDtoType userType = UserDtoType.User;

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddUiPathUser)
                    .AddParameter(UiPathStrings.Username, userName)
                    .AddParameter(UiPathStrings.Password, password)
                    .AddParameter(UiPathStrings.Name, name)
                    .AddParameter(UiPathStrings.Surname, surname)
                    .AddParameter(UiPathStrings.EmailAddress, email)
                    .AddParameter(UiPathStrings.Type, userType)
                    .AddParameter(UiPathStrings.RolesList, new List <string>()
                    {
                        UiPathStrings.Administrator
                    });
                    var users = Invoke <User>(cmdlet);
                    Validators.ValidateUserResponse(users, null, userName, password, name, surname, email, userType);
                    user = users[0];
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathUser)
                    .AddParameter(UiPathStrings.Id, user.Id);
                    var users = Invoke <User>(cmdlet);
                    Validators.ValidateUserResponse(users, user.Id, userName, password, name, surname, email, userType);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveUiPathUser)
                    .AddParameter(UiPathStrings.Id, user.Id);
                    Invoke(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathUser)
                    .AddParameter(UiPathStrings.Username, userName);
                    var users = Invoke <User>(cmdlet);
                    Validators.ValidatEmptyResponse(users);
                }
            }
        }
Exemplo n.º 28
0
        public void RobotAddGetRemove()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                var  name        = TestRandom.RandomString();
                var  description = TestRandom.RandomString();
                var  licenseKey  = Guid.NewGuid();
                var  machine     = TestRandom.RandomString();
                var  username    = TestRandom.RandomString();
                long?robotId     = null;

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddUiPathRobot)
                    .AddParameter(UiPathStrings.Name, name)
                    .AddParameter(UiPathStrings.MachineName, machine)
                    .AddParameter(UiPathStrings.Description, description)
                    .AddParameter(UiPathStrings.LicenseKey, licenseKey)
                    .AddParameter(UiPathStrings.Username, username)
                    .AddParameter(UiPathStrings.Type, RobotDtoType.NonProduction);
                    var robots = Invoke <Robot>(cmdlet);

                    Validators.ValidateRobotResponse(robots, null, name, description, machine, licenseKey, RobotDtoType.NonProduction);

                    robotId = robots[0].Id;
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRobot)
                    .AddParameter(UiPathStrings.Id, robotId);
                    var robots = Invoke <Robot>(cmdlet);

                    Validators.ValidateRobotResponse(robots, robotId, name, description, machine, licenseKey, RobotDtoType.NonProduction);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveUiPathRobot)
                    .AddParameter(UiPathStrings.Id, robotId);
                    Invoke <Robot>(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRobot)
                    .AddParameter(UiPathStrings.Name, name);
                    var robots = Invoke <Robot>(cmdlet);

                    Validators.ValidatEmptyResponse(robots);
                }
            }
        }
Exemplo n.º 29
0
        public void RoleAddGetRemove()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                Role role       = default(Role);
                var  name       = TestRandom.RandomAlphaNumeric();
                var  displaName = TestRandom.RandomString();

                var permissions = new List <string>()
                {
                    "Robots.View",
                    "Robots.Edit",
                    "Robots.Create",
                    "Robots.Delete"
                };

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddUiPathRole)
                    .AddParameter(UiPathStrings.Name, name)
                    //.AddParameter(UiPathStrings.DisplayName, displaName)  -- bugbug: the displayname is ignored by Orchestrator
                    .AddParameter(UiPathStrings.IsEditable)
                    .AddParameter(UiPathStrings.Permissions, permissions);
                    var roles = Invoke <Role>(cmdlet);
                    Validators.ValidateRoleResult(roles, null, name, name, true, false, null);
                    role = roles[0];
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRole)
                    .AddParameter(UiPathStrings.Name, role.Name);
                    var roles = Invoke <Role>(cmdlet);
                    Validators.ValidateRoleResult(roles, role.Id, name, name, true, false, permissions);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveUiPathRole)
                    .AddParameter(UiPathStrings.Id, role.Id);
                    Invoke(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRole)
                    .AddParameter(UiPathStrings.Name, role.Name);
                    var roles = Invoke <Role>(cmdlet);
                    Validators.ValidatEmptyResponse(roles);
                }
            }
        }
Exemplo n.º 30
0
        public void ApplyTest()
        {
            IRandom     random   = new TestRandom(new int[] { 1, 1, 0, 0, 1, 1, 0, 0, 1 }, null);
            PWREncoding parent1  = TestUtils.CreateTestPWR1();
            PWREncoding parent2  = TestUtils.CreateTestPWR2();
            PWREncoding expected = new PWREncoding();

            expected.PermutationWithRepetition = new IntegerVector(new int[] { 1, 0, 1, 0, 1, 2, 0, 2, 2 });
            PWREncoding actual;

            actual = PWRPPXCrossover.Apply(random, parent1, parent2);
            Assert.IsTrue(TestUtils.PRWEncodingEquals(expected, actual));
        }
Exemplo n.º 31
0
		public void GetColors()
		{
			var db = new ColorMapDb();
			db.Load("../../../../system/db/colormap.dat", true);

			var rnd = new TestRandom(1039548676);

			Assert.Equal((uint)0xA02522, db.GetAt(10, 0, 0));
			Assert.Equal((uint)0xFFD800, db.GetAt(32, 1, 1));

			Assert.Equal((uint)0xF6D1BD, db.GetAt(1, 0, 0));
			Assert.Equal((uint)0xCDD742, db.GetAt(1, 25, 25));
			Assert.Equal((uint)0x087189, db.GetAt(1, 50, 50));
			Assert.Equal((uint)0x0B8EBE, db.GetAt(1, 75, 75));
			Assert.Equal((uint)0xF1ACC9, db.GetAt(1, 100, 100));
			Assert.Equal((uint)0x9C7B6B, db.GetAt(1, 125, 125));
			Assert.Equal((uint)0xC1CBCF, db.GetAt(1, 150, 150));
			Assert.Equal((uint)0xEBE3E1, db.GetAt(1, 175, 175));
			Assert.Equal((uint)0x546C70, db.GetAt(1, 200, 200));
			Assert.Equal((uint)0xC0E2AF, db.GetAt(1, 225, 225));
			Assert.Equal((uint)0x8B2208, db.GetAt(1, 250, 250));

			Assert.Equal((uint)0xFFD800, db.GetRandom(32, rnd));

			Assert.Equal((uint)0xA4657E, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x822E00, db.GetRandom(1, rnd));
			Assert.Equal((uint)0xFFFFFF, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x3CBE95, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x8E7580, db.GetRandom(1, rnd));
			Assert.Equal((uint)0xD64B95, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x805D57, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x806C7C, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x9DD6E7, db.GetRandom(1, rnd));
			Assert.Equal((uint)0xDECFB5, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x84C15E, db.GetRandom(1, rnd));
			Assert.Equal((uint)0xF37333, db.GetRandom(1, rnd));
			Assert.Equal((uint)0x707070, db.GetRandom(1, rnd));


		}
Exemplo n.º 32
0
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Call NextDouble to check the Sample works");

        try
        {
            TestRandom random = new TestRandom(-55);
            double value = random.NextDouble();

            if ((value < 0.0) || (value >= 1.0))
            {
                TestLibrary.TestFramework.LogError("001.1", "NextDouble returns a value less than 0 or equal to 1.0");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] value = " + value);
                retVal = false;
            }

            value = random.CallSample();

            if ((value < 0.0) || (value >= 1.0))
            {
                TestLibrary.TestFramework.LogError("001.2", "NextDouble returns a value less than 0 or equal to 1.0");
                TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLE] value = " + value);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }