public void SolveTest()
        {
            //Arrange
            IMatrixSolver target = new MatrixSolver();
            var matrix = new int[7, 7]
            {
                {1,0,1,0,0,0,2},
                {0,1,0,1,0,0,3},

                {1,0,0,0,1,0,4},
                {0,1,0,0,0,1,8},

                {0,0,1,0,1,0,6},
                {1,0,0,0,0,0,5},
                {0,1,0,0,0,0,10}
            };

            var expected = new int[7, 7]
            {
                {1,0,0,0,0,0,5},
                {0,1,0,0,0,0,10},
                {0,0,1,0,0,0,7},
                {0,0,0,1,0,0,9},
                {0,0,0,0,1,0,1},
                {0,0,0,0,0,1,2},
                {0,0,0,0,0,0,0}
            };

            //Act
            var result = target.Solve(matrix);

            //Assert
            Assert.IsTrue(result, "couldnt solve matrix");
            Common.CheckArraysAreEqual(matrix, expected);
        }
示例#2
0
        public void BuildMatrixTest()
        {
            //Arrange
            IMatrixSolver matrixSolver = new MatrixSolver();
            Decode_Accessor target = new Decode_Accessor(matrixSolver);
            IList<Drop> drops = new Drop[3]
            {
                new Drop(){SelectedParts=new int[2]{0,1},Data=new byte[2]{1,2}},
                new Drop(){SelectedParts=new int[2]{0,2},Data=new byte[2]{3,4}},
                new Drop(){SelectedParts=new int[2]{1,2},Data=new byte[2]{5,6}}
            };
            var expected = new int[6, 7]
            {
                {1,0,1,0,0,0,1},
                {0,1,0,1,0,0,2},

                {1,0,0,0,1,0,3},
                {0,1,0,0,0,1,4},

                {0,0,1,0,1,0,5},
                {0,0,0,1,0,1,6}
            };
            int blocksCount = 3;
            int chunkSize = 2;
            //Act
            var actual = target.BuildMatrix(drops, blocksCount, chunkSize);

            //Assert
            Common.CheckArraysAreEqual(expected, actual);
        }
示例#3
0
 private void Application_Startup(object sender, StartupEventArgs e)
 {
     var decoderView = new Views.DecoderView();
     IMatrixSolver matrixSolver = new MatrixSolver();
     IDecode decoder = new Decode(matrixSolver);
     IEncodeService encodeServiceClient = new EncodeService.EncodeServiceClient();
     var decoderViewModel = new DecoderViewModel(decoder, encodeServiceClient);
     decoderView.DataContext = decoderViewModel;
     decoderView.Show();
 }
        public void Encode_DecodeTest()
        {
            //Arrange
            string sentMessage = "Message";
            byte[] file = Encoding.ASCII.GetBytes(sentMessage);
            IEncode encoder = new Encode(file);
            var blocksCount = encoder.NumberOfBlocks;
            var overHead = 20;
            IList<Drop> drops = new List<Drop>();
            for (int i = 0; i < blocksCount + overHead; i++)
            {
                var drop = encoder.Encode();
                drops.Add(drop);
            }
            IMatrixSolver matrixSolver = new MatrixSolver();
            IDecode target = new Decode(matrixSolver);

            //Act
            var actualByte = target.Decode(drops, blocksCount, encoder.ChunkSize, encoder.FileSize);
            var receievdMessage = Encoding.ASCII.GetString(actualByte);

            //Assert
            Assert.AreEqual(sentMessage, receievdMessage);
        }