コード例 #1
0
        public void BrunchOfDeleteTest()
        {
            //Arragnge
            var uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);

            var encodeInfo = new EncodeInformation()
            {
                DownloadInformation = new DownloadInformation()
                {
                    QueueInformation = new QueueInformation()
                    {
                        VideoMessage = new VideoMessage()
                        {
                            Delete = true
                        }
                    }
                }
            };

            //Act
            var uploadInfo = uploadProcess.ProcessMethod(encodeInfo, new CancellationToken());

            //Assert
            Assert.AreEqual(encodeInfo.DownloadInformation, uploadInfo.DownloadInformation);

            _videoRepository.Verify(m => m.DeleteWatchVideos(It.IsAny <string>(), It.IsAny <string>()), Times.Once());
            _screenshotRepository.Verify(m => m.DeleteScreenshots(It.IsAny <string>(), It.IsAny <string>()), Times.Once());
        }
コード例 #2
0
        /// <summary>
        /// Encode right side with left side.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="counter"></param>
        /// <param name="encodeInfo"></param>
        /// <returns></returns>
        private static AType EncodeArray(List <int> shape, int counter, EncodeInformation encodeInfo)
        {
            List <int> cutShape;
            AType      result = AArray.Create(encodeInfo.ResultingType);

            for (int i = 0; i < shape[0]; i++)
            {
                if (shape.Count > 1)
                {
                    cutShape = shape.GetRange(1, shape.Count - 1);

                    result.AddWithNoUpdate(EncodeArray(cutShape, counter, encodeInfo));
                }
                else
                {
                    result.AddWithNoUpdate(EncodeOneStep(counter, encodeInfo));
                }
            }

            result.Length = shape[0];
            result.Shape  = new List <int>(shape);
            result.Rank   = shape.Count;

            return(result);
        }
コード例 #3
0
        public void UploadExceptionHandlerTest()
        {
            //Arrange
            const string localPath     = "local path";
            var          uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);

            _fileSystem.Setup(m => m.DirectoryExists(localPath)).Returns(true);

            var encodeInfo = new EncodeInformation()
            {
                DownloadInformation = new DownloadInformation()
                {
                    LocalPath        = localPath,
                    QueueInformation = new QueueInformation()
                    {
                        VideoMessage = new VideoMessage()
                    }
                }
            };

            //Act
            uploadProcess.ExceptionHandler(new Exception(), encodeInfo);

            //Asert
            _videoRepository.Verify(m => m.SetEncodingState(It.IsAny <string>(), EncodingState.Failed, EncodingStage.Uploading, null));
            _fileSystem.Verify(m => m.DirectoryExists(localPath), Times.Once());
            _fileSystem.Verify(m => m.DirectoryDelete(localPath), Times.Once());
        }
コード例 #4
0
        /// <summary>
        /// Type check, and extract data from left and right side.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        private EncodeInformation ExtractEncodeInformation(AType left, AType right)
        {
            // Error if the arguments are not numbers or Null
            if (!((left.IsNumber || left.Type == ATypes.ANull) && (right.IsNumber || right.Type == ATypes.ANull)))
            {
                throw new Error.Type(TypeErrorText);
            }

            // Left argument must be a scalar or vector.
            if (left.Rank > 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            double[] encodeKeys;
            if (left.IsArray)
            {
                encodeKeys = left.Select(item => item.asFloat).ToArray();
            }
            else
            {
                encodeKeys = new double[] { left.asFloat };
            }

            ATypes resultingType;

            if (left.Type == ATypes.AFloat || right.Type == ATypes.AFloat ||
                left.Type == ATypes.ANull || right.Type == ATypes.ANull)
            {
                resultingType = ATypes.AFloat;
            }
            else
            {
                resultingType = ATypes.AInteger;
            }

            List <double> encodeValues = new List <double>();

            ExtractItems(encodeValues, right);

            EncodeInformation arguments = new EncodeInformation(encodeKeys, encodeValues.ToArray(), resultingType);

            return(arguments);
        }
コード例 #5
0
        public void UploadVerifyTest()
        {
            //Arrange
            var uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);

            var encodeInfo = new EncodeInformation()
                                 {
                                     EncodeScreenshotList = new List<ScreenshotData>()
                                                                {
                                                                    new ScreenshotData(),
                                                                    new ScreenshotData()
                                                                },
                                     EncodeVideoList = new List<VideoData>()
                                                           {
                                                               new VideoData(),
                                                               new VideoData()
                                                           },
                                     DownloadInformation = new DownloadInformation()
                                                               {
                                                                   QueueInformation = new QueueInformation()
                                                                                          {
                                                                                              VideoMessage = new VideoMessage()
                                                                                          }
                                                               }
                                 };

            //Act
            uploadProcess.ProcessMethod(encodeInfo, new CancellationToken());

            //Assert
            _videoRepository.Verify(m=>m.SetEncodingState(It.IsAny<string>(),EncodingState.InProcess, EncodingStage.Uploading, null), Times.Once());
            _videoRepository.Verify(m => m.UploadEncodedVideo(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<DateTime>(), It.IsAny<DateTime>()), 
                Times.Exactly(encodeInfo.EncodeVideoList.Count));

            _screenshotRepository.Verify(m => m.UploadScreenshot(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<long>(), It.IsAny<string>()), 
                Times.Exactly(encodeInfo.EncodeScreenshotList.Count));

            _videoRepository.Verify(m => m.DeleteWatchVideos(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
            _videoRepository.Verify(m => m.AddWatchVideos(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()), Times.Once());
            _screenshotRepository.Verify(m => m.DeleteScreenshots(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
            _screenshotRepository.Verify(m => m.AddScreenshots(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()), Times.Once());
        }
コード例 #6
0
        public void UploadVerifyTest()
        {
            //Arrange
            var uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);

            var encodeInfo = new EncodeInformation()
            {
                EncodeScreenshotList = new List <ScreenshotData>()
                {
                    new ScreenshotData(),
                    new ScreenshotData()
                },
                EncodeVideoList = new List <VideoData>()
                {
                    new VideoData(),
                    new VideoData()
                },
                DownloadInformation = new DownloadInformation()
                {
                    QueueInformation = new QueueInformation()
                    {
                        VideoMessage = new VideoMessage()
                    }
                }
            };

            //Act
            uploadProcess.ProcessMethod(encodeInfo, new CancellationToken());

            //Assert
            _videoRepository.Verify(m => m.SetEncodingState(It.IsAny <string>(), EncodingState.InProcess, EncodingStage.Uploading, null), Times.Once());
            _videoRepository.Verify(m => m.UploadEncodedVideo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()),
                                    Times.Exactly(encodeInfo.EncodeVideoList.Count));

            _screenshotRepository.Verify(m => m.UploadScreenshot(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <long>(), It.IsAny <string>()),
                                         Times.Exactly(encodeInfo.EncodeScreenshotList.Count));

            _videoRepository.Verify(m => m.DeleteWatchVideos(It.IsAny <string>(), It.IsAny <string>()), Times.Once());
            _videoRepository.Verify(m => m.AddWatchVideos(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Once());
            _screenshotRepository.Verify(m => m.DeleteScreenshots(It.IsAny <string>(), It.IsAny <string>()), Times.Once());
            _screenshotRepository.Verify(m => m.AddScreenshots(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Once());
        }
コード例 #7
0
        /// <summary>
        /// Encode x[index] with y[counter].
        /// </summary>
        /// <param name="counter"></param>
        /// <param name="encodeInfo"></param>
        /// <returns></returns>
        private static AType EncodeOneStep(int counter, EncodeInformation encodeInfo)
        {
            double remainder;

            if (encodeInfo.EncodeKeys[counter] != 0)
            {
                remainder = encodeInfo.EncodeValues[encodeInfo.Index] % encodeInfo.EncodeKeys[counter];

                bool signDifference =
                    (encodeInfo.EncodeKeys[counter] < 0 && encodeInfo.EncodeValues[encodeInfo.Index] > 0) ||
                    (encodeInfo.EncodeKeys[counter] > 0 && encodeInfo.EncodeValues[encodeInfo.Index] < 0);

                if (signDifference && remainder != 0)
                {
                    remainder += encodeInfo.EncodeKeys[counter];
                }

                encodeInfo.EncodeValues[encodeInfo.Index] =
                    (encodeInfo.EncodeValues[encodeInfo.Index] - remainder) / encodeInfo.EncodeKeys[counter];
            }
            else
            {
                remainder = encodeInfo.EncodeValues[encodeInfo.Index];
                encodeInfo.EncodeValues[encodeInfo.Index] = 0;
            }

            encodeInfo.Index++;

            AType result;

            if (encodeInfo.ResultingType == ATypes.AInteger)
            {
                result = AInteger.Create((int)remainder);
            }
            else
            {
                result = AFloat.Create(remainder);
            }

            return(result);
        }
コード例 #8
0
        public void UploadSuccessfulTest()
        {
            //Arrange
            var uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);
            var encodeInfo = new EncodeInformation()
                                 {
                                     DownloadInformation = new DownloadInformation()
                                                               {
                                                                   QueueInformation = new QueueInformation()
                                                                                          {
                                                                                              VideoMessage = new VideoMessage()
                                                                                          }
                                                               }
                                 };

            //Act
            var uploadInfo = uploadProcess.ProcessMethod(encodeInfo, new CancellationToken());

            //Assert
            Assert.AreEqual(encodeInfo.DownloadInformation, uploadInfo.DownloadInformation);
        }
コード例 #9
0
        public void UploadSuccessfulTest()
        {
            //Arrange
            var uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);
            var encodeInfo    = new EncodeInformation()
            {
                DownloadInformation = new DownloadInformation()
                {
                    QueueInformation = new QueueInformation()
                    {
                        VideoMessage = new VideoMessage()
                    }
                }
            };

            //Act
            var uploadInfo = uploadProcess.ProcessMethod(encodeInfo, new CancellationToken());

            //Assert
            Assert.AreEqual(encodeInfo.DownloadInformation, uploadInfo.DownloadInformation);
        }
コード例 #10
0
        private static AType Compute(AType left, AType right, EncodeInformation encodeInfo)
        {
            AType result;

            // Left and right side are scalars.
            if (left.Rank == 0 && right.Rank == 0)
            {
                result = EncodeOneStep(0, encodeInfo);
            }
            else if (left.Rank == 0 && right.Rank > 0)
            {
                result = EncodeArray(right.Shape, 0, encodeInfo);
            }
            else
            {
                result = AArray.Create(encodeInfo.ResultingType);

                for (int i = encodeInfo.EncodeKeys.Length - 1; i >= 0; i--)
                {
                    encodeInfo.Index = 0;
                    AType item = right.Shape.Count > 0
                        ? EncodeArray(right.Shape, i, encodeInfo)
                        : EncodeOneStep(i, encodeInfo);
                    result.AddWithNoUpdate(item);
                }

                result.Length = encodeInfo.EncodeKeys.Length;
                result.Shape  = new List <int>()
                {
                    result.Length
                };
                result.Shape.AddRange(right.Shape);
                result.Rank = 1 + right.Rank;

                result = MonadicFunctionInstance.Reverse.Execute(result);
            }

            return(result);
        }
コード例 #11
0
ファイル: Encode.cs プロジェクト: sammoorhouse/aplusdotnet
        /// <summary>
        /// Type check, and extract data from left and right side.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        private EncodeInformation ExtractEncodeInformation(AType left, AType right)
        {
            // Error if the arguments are not numbers or Null
            if (!((left.IsNumber || left.Type == ATypes.ANull) && (right.IsNumber || right.Type == ATypes.ANull))) 
            {
                throw new Error.Type(TypeErrorText);
            }

            // Left argument must be a scalar or vector.
            if (left.Rank > 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            double[] encodeKeys;
            if (left.IsArray)
            {
                encodeKeys = left.Select(item => item.asFloat).ToArray();
            }
            else
            {
                encodeKeys = new double[] { left.asFloat };
            }

            ATypes resultingType;
            if (left.Type == ATypes.AFloat || right.Type == ATypes.AFloat ||
                left.Type == ATypes.ANull || right.Type == ATypes.ANull)
            {
                resultingType = ATypes.AFloat;
            }
            else
            {
                resultingType = ATypes.AInteger;
            }

            List<double> encodeValues = new List<double>();
            ExtractItems(encodeValues, right);

            EncodeInformation arguments = new EncodeInformation(encodeKeys, encodeValues.ToArray(), resultingType);
            return arguments;
        }
コード例 #12
0
ファイル: Encode.cs プロジェクト: sammoorhouse/aplusdotnet
        /// <summary>
        /// Encode x[index] with y[counter].
        /// </summary>
        /// <param name="counter"></param>
        /// <param name="encodeInfo"></param>
        /// <returns></returns>
        private static AType EncodeOneStep(int counter, EncodeInformation encodeInfo)
        {
            double remainder;

            if (encodeInfo.EncodeKeys[counter] != 0)
            {
                remainder = encodeInfo.EncodeValues[encodeInfo.Index] % encodeInfo.EncodeKeys[counter];

                bool signDifference = 
                    (encodeInfo.EncodeKeys[counter] < 0 && encodeInfo.EncodeValues[encodeInfo.Index] > 0)
                    || (encodeInfo.EncodeKeys[counter] > 0 && encodeInfo.EncodeValues[encodeInfo.Index] < 0);

                if (signDifference && remainder != 0)
                {
                    remainder += encodeInfo.EncodeKeys[counter];
                }

                encodeInfo.EncodeValues[encodeInfo.Index] = 
                    (encodeInfo.EncodeValues[encodeInfo.Index] - remainder) / encodeInfo.EncodeKeys[counter];
            }
            else
            {
                remainder = encodeInfo.EncodeValues[encodeInfo.Index];
                encodeInfo.EncodeValues[encodeInfo.Index] = 0;
            }

            encodeInfo.Index++;

            AType result;

            if (encodeInfo.ResultingType == ATypes.AInteger)
            {
                result = AInteger.Create((int)remainder);
            }
            else
            {
                result = AFloat.Create(remainder);
            }

            return result;
        }
コード例 #13
0
ファイル: Encode.cs プロジェクト: sammoorhouse/aplusdotnet
        /// <summary>
        /// Encode right side with left side.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="counter"></param>
        /// <param name="encodeInfo"></param>
        /// <returns></returns>
        private static AType EncodeArray(List<int> shape, int counter, EncodeInformation encodeInfo)
        {
            List<int> cutShape;
            AType result = AArray.Create(encodeInfo.ResultingType);

            for (int i = 0; i < shape[0]; i++)
            {
                if (shape.Count > 1)
                {
                    cutShape = shape.GetRange(1, shape.Count - 1);

                    result.AddWithNoUpdate(EncodeArray(cutShape, counter, encodeInfo));
                }
                else
                {
                    result.AddWithNoUpdate(EncodeOneStep(counter, encodeInfo));
                }
            }

            result.Length = shape[0];
            result.Shape = new List<int>(shape);
            result.Rank = shape.Count;

            return result;
        }
コード例 #14
0
ファイル: Encode.cs プロジェクト: sammoorhouse/aplusdotnet
        private static AType Compute(AType left, AType right, EncodeInformation encodeInfo)
        {
            AType result;

            // Left and right side are scalars.
            if (left.Rank == 0 && right.Rank == 0)
            {
                result = EncodeOneStep(0, encodeInfo);
            }
            else if (left.Rank == 0 && right.Rank > 0)
            {
                result = EncodeArray(right.Shape, 0, encodeInfo);
            }
            else
            {
                result = AArray.Create(encodeInfo.ResultingType);

                for (int i = encodeInfo.EncodeKeys.Length - 1; i >= 0; i--)
                {
                    encodeInfo.Index = 0;
                    AType item = right.Shape.Count > 0
                        ? EncodeArray(right.Shape, i, encodeInfo)
                        : EncodeOneStep(i, encodeInfo);
                    result.AddWithNoUpdate(item);
                }

                result.Length = encodeInfo.EncodeKeys.Length;
                result.Shape = new List<int>() { result.Length };
                result.Shape.AddRange(right.Shape);
                result.Rank = 1 + right.Rank;

                result = MonadicFunctionInstance.Reverse.Execute(result);
            }

            return result;
        }
コード例 #15
0
        public void BrunchOfDeleteTest()
        {
            //Arragnge
            var uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);

            var encodeInfo = new EncodeInformation()
            {
                DownloadInformation = new DownloadInformation()
                {
                    QueueInformation = new QueueInformation()
                    {
                        VideoMessage = new VideoMessage() { Delete=true}
                    }
                }
            };

            //Act
            var uploadInfo = uploadProcess.ProcessMethod(encodeInfo, new CancellationToken());

            //Assert
            Assert.AreEqual(encodeInfo.DownloadInformation, uploadInfo.DownloadInformation);

            _videoRepository.Verify(m => m.DeleteWatchVideos(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
            _screenshotRepository.Verify(m => m.DeleteScreenshots(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
        }
コード例 #16
0
        public void UploadExceptionHandlerTest()
        {
            //Arrange
            const string localPath = "local path";
            var uploadProcess = new UploadProcess(5, _videoRepository.Object, _screenshotRepository.Object, _fileSystem.Object);

            _fileSystem.Setup(m => m.DirectoryExists(localPath)).Returns(true);

            var encodeInfo = new EncodeInformation()
                                 {
                                     DownloadInformation = new DownloadInformation()
                                                               {
                                                                   LocalPath = localPath,
                                                                   QueueInformation = new QueueInformation()
                                                                                          {
                                                                                              VideoMessage = new VideoMessage()
                                                                                          }
                                                               }
                                 };

            //Act
            uploadProcess.ExceptionHandler(new Exception(), encodeInfo);

            //Asert
            _videoRepository.Verify(m => m.SetEncodingState(It.IsAny<string>(), EncodingState.Failed, EncodingStage.Uploading, null));
            _fileSystem.Verify(m => m.DirectoryExists(localPath), Times.Once());
            _fileSystem.Verify(m => m.DirectoryDelete(localPath), Times.Once());
        }
コード例 #17
0
        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            EncodeInformation arguments = ExtractEncodeInformation(left, right);

            return(Compute(left, right, arguments));
        }