Ejemplo n.º 1
0
        public void TestIsomorph()
        {
            ////IsoMorph
            byte[] matrixOrg = new byte[] {
                (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e',
                (byte)'f', (byte)'g', (byte)'h', (byte)'i', (byte)'j',
                (byte)'k', (byte)'l', (byte)'m', (byte)'n', (byte)'o',
                (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t',
                (byte)'u', (byte)'v', (byte)'w', (byte)'x', (byte)'y'
            };


            //IsomorphMatrices im = new IsomorphMatrices(5,1,matrixOrg,matrixMod);
            uint[] substitution = new uint[] { 1, 0, 3, 4, 2 };

            BasicMatrix bm = new BasicMatrix(5, 1, matrixOrg);
            Task        t  = bm.Transposition(substitution);

            t.Wait();
            byte[] matrixMod = bm.GetMatrix();

            IsomorphMatrices im = new IsomorphMatrices(5, 1, matrixOrg, matrixMod);

            uint[] substitution2 = new uint[] { 0, 1, 2, 3, 4 };
            Task   tt            = im.SearchIsomorph(1, substitution2);

            tt.Wait();
            uint count = im.GetSubstitutionsCount();

            Assert.AreEqual(count, (uint)1);

            uint[] a = im.GetSubstitutions(0);
            Assert.IsTrue(a.SequenceEqual(new uint[] { 1, 0, 3, 4, 2 }));
        }
Ejemplo n.º 2
0
        public void Constructor_ShouldReturnANewBasicMatrixInstance_WhenAllParametersAreValid()
        {
            var validMatrixSize = 12;
            Func <int, int, int, ICell> createCellMethod = InstantiatingMethods.CreateMatrixCell;

            var actualMatrix = new BasicMatrix(validMatrixSize, createCellMethod);

            Assert.That(actualMatrix, Is.InstanceOf <BasicMatrix>());
        }
Ejemplo n.º 3
0
        public void Populate_ShouldThrow_WhenValueProviderParameterIsInvalid()
        {
            var validMatrixSize = 12;
            Func <int, int, int, ICell> createCellMethod = InstantiatingMethods.CreateMatrixCell;
            var matrix = new BasicMatrix(validMatrixSize, createCellMethod);

            var mockPosition = new Mock <IPosition>();
            var mockSequence = new Mock <IDirectionSequence>();

            Assert.That(
                () => matrix.Populate(mockPosition.Object, mockSequence.Object, null),
                Throws.ArgumentNullException.With.Message.Contains("valueProvider"));
        }
Ejemplo n.º 4
0
        public void TestIsomophImg()
        {
            ////IsoMorph

            MainWindow mw = new MainWindow();

            byte[] matrixOrg = mw.ImageSourceToByteArray();
            uint   mtxSize   = (uint)Math.Sqrt(matrixOrg.Length / 4);

            //IsomorphMatrices im = new IsomorphMatrices(5,1,matrixOrg,matrixMod);
            uint[] substitution = new uint[mtxSize];
            for (int i = 0; i < substitution.Length; ++i)
            {
                substitution[i] = (uint)((i + 1) % (substitution.Length));
            }

            BasicMatrix bm = new BasicMatrix(mtxSize, 4, matrixOrg);
            Task        t  = bm.Transposition(substitution);

            t.Wait();
            byte[]           matrixMod = bm.GetMatrix();
            IsomorphMatrices im        = new IsomorphMatrices(mtxSize, 4, matrixOrg, matrixMod);

            uint[] substitution2 = new uint[mtxSize];
            for (int i = 0; i < substitution2.Length; ++i)
            {
                substitution2[i] = (uint)i;
            }

            Task tt = im.SearchIsomorph(1, substitution2);

            tt.Wait();
            uint   count = im.GetSubstitutionsCount();
            string s     = "";

            for (uint i = 0; i < count; i++)
            {
                uint[] a = im.GetSubstitutions(i);
                s += String.Join(",", a) + "\n";;
            }
            s = "IsomorphMatrices Test:\n" + s;
            MessageBox.Show(s);
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            var ui = new BasicUserInterface(Console.WriteLine, Console.ReadLine);
            var inputMatrixSize = ui.AskForInput("Enter matrix size: ");

            int parsedMatrixSize;
            var isSuccessfullyParsed = int.TryParse(inputMatrixSize, out parsedMatrixSize);

            if (isSuccessfullyParsed)
            {
                var theMatrix = new BasicMatrix(parsedMatrixSize, InstantiatingMethods.CreateMatrixCell);

                var directionSequence = new BasicPathDirectionSequence(InstantiatingMethods.CreateDirection);
                var valuesGenerator   = new BasicCellValueSequence();
                var startPosition     = new Position(0, 0);

                theMatrix.Populate(startPosition, directionSequence, valuesGenerator);
                ui.PostMessage(theMatrix.ToString());
            }
            else
            {
                ui.PostMessage("Invalid matrix size input.");
            }
        }