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()); }
/// <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); }
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()); }
/// <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); }
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()); }
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()); }
/// <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); }
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); }
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); }
/// <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; }
/// <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; }
/// <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; }
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; }
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()); }
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()); }
public override AType Execute(AType right, AType left, Aplus environment = null) { EncodeInformation arguments = ExtractEncodeInformation(left, right); return(Compute(left, right, arguments)); }