public void GenerateMatrix_GenerateMatrixWithIncorrectSize_Exception() { //Arrange var size = -9; var matrixService = new MatrixService(matrixRepositoryMock.Object); //Act ActualValueDelegate <Task <Matrix> > generateDelegate = async() => await matrixService.GenerateMatrix(size); //Assert Assert.That(generateDelegate, Throws.Exception); }
//private ProblemService _problemService; //private IterationSystemService _iterationSystemService; /// <summary> /// Window constructor, receiving vertices collection /// </summary> /// <param name="vertices"></param> public TriangulationData(VertexCollection vertices, List <Triangle> triangles, Boundary boundary) { InitializeComponent(); // this._problemService = new ProblemService(vertices, triangles, boundary); DataContext = this; this.vertices = vertices; this.triangles = triangles; dataGrid.ItemsSource = this.vertices; problemService = new ProblemService(this.vertices, this.triangles, new Boundary((0, 0), (2, 0), (2, 2), (0, 2))); MatrixService = new MatrixService(vertices, triangles); InitData(); }
public void GetRotateMatrix() { var mock = new MatrixService(); var controller = new MatrixApiController(mock, new ConvertService()); // Act var result = controller.GetRotateMatrix(); var currentMatrix = mock.GetCurrentMatrix(); // Assert Assert.AreEqual(result, currentMatrix); }
private IMatrixService InitializeMatrixService() { var martixService = new MatrixService(); var matrixWidthX = 3; var matrixHeightY = 3; var inputArgsStr = $"{matrixWidthX}, {matrixHeightY}"; martixService.GetMatrixDimensions(inputArgsStr); return(martixService); }
public void WorksCorrect() { var validWidthX = 3; var validHeightY = 3; var inputArgsStr = $"{validWidthX}, {validHeightY}"; var matrixService = new MatrixService(); matrixService.GetMatrixDimensions(inputArgsStr); Assert.Equal(validWidthX, matrixService.GetMatrixWidth()); }
public async Task TransposeMatrix_RotatedMatrixIsEqualToMatrixAfterService_True() { //Arrange var matrix = new int[5][] { new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3, 4, 5 } }; var rotatedMatrix = new int[5][] { new int[] { 1, 1, 1, 1, 1 }, new int[] { 2, 2, 2, 2, 2 }, new int[] { 3, 3, 3, 3, 3 }, new int[] { 4, 4, 4, 4, 4 }, new int[] { 5, 5, 5, 5, 5 } }; var matrixId = "1"; matrixRepositoryMock.Setup(r => r.Get(matrixId)).Returns <string>(id => Task.FromResult(new Matrix() { Rows = matrix })); var matrixRepository = matrixRepositoryMock.Object; var matrixService = new MatrixService(matrixRepository); //Act var result = await matrixService.TransposeMatrix(matrixId); //Assert matrixRepositoryMock.Verify(x => x.Get("1"), Times.Once); matrixRepositoryMock.Verify(x => x.Update(result), Times.Once); Assert.AreEqual(rotatedMatrix.Length, result.Rows.Length); for (var i = 0; i < rotatedMatrix.Length; i++) { Assert.AreEqual(rotatedMatrix[i].Length, result.Rows[i].Length); } for (var i = 0; i < rotatedMatrix.Length; i++) { for (var j = 0; j < rotatedMatrix.Length; j++) { Assert.AreEqual(rotatedMatrix[i][j], result.Rows[i][j]); } } }
public async Task Test_MatrixService_WriteMatrixAsync_WithNotSquareMatrix() { var matrix = new int[2][] { new int[3] { 1, 2, 3 }, new int[3] { 4, 5, 6 } }; var service = new MatrixService(); await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => service.WriteMatrixAsync(matrix)); }
public void ReturnErrorMissingPointX() { var inputArgsStr = $",1,1"; var matrixService = new MatrixService(); try { matrixService.GetGameConditions(inputArgsStr); } catch (Exception e) { var errMsg = ErrMsg.TargetConditionsException; Assert.Equal(errMsg, e.Message); } }
public void ReturnErrorMissingXY() { var inputArgsStr = $""; var matrixService = new MatrixService(); try { matrixService.GetMatrixDimensions(inputArgsStr); } catch (Exception e) { var errMsg = ErrMsg.MatrixDimentionException; Assert.Equal(errMsg, e.Message); } }
public async Task GenerateMatrix_GenerateMatrixWithExactSize() { //Arrange var size = 3000; var matrixService = new MatrixService(matrixRepositoryMock.Object); //Act var result = await matrixService.GenerateMatrix(size); //Assert Assert.AreEqual(size, result.Rows.Length); foreach (var row in result.Rows) { Assert.AreEqual(row.Length, size); } }
public void ErrorMissingX() { var validHeightY = 3; var inputArgsStr = $", {validHeightY}"; var matrixService = new MatrixService(); try { matrixService.GetMatrixDimensions(inputArgsStr); } catch (Exception e) { var errMsg = ErrMsg.MatrixDimentionException; Assert.Equal(errMsg, e.Message); } }
public async Task GetAll_GetAllMatrixes() { //Arrange IEnumerable <Matrix> matrixes = new List <Matrix>() { new Matrix(), new Matrix(), new Matrix() }; matrixRepositoryMock.Setup(r => r.GetAll()).Returns(() => Task.FromResult(matrixes)); var matrixService = new MatrixService(matrixRepositoryMock.Object); //Act var result = await matrixService.GetAll(); //Assert matrixRepositoryMock.Verify(x => x.GetAll(), Times.Once); Assert.AreEqual(matrixes, result); }
public void ReturnErrorOutOfRangeX() { var widthX = 1000; var heightY = 3; var inputArgsStr = $"{widthX}, {heightY}"; var matrixService = new MatrixService(); try { matrixService.GetMatrixDimensions(inputArgsStr); } catch (Exception e) { var errMsg = string.Format(ErrMsg.OutOfRangeWidth, GeneralConstants.MinMatrixSize, GeneralConstants.MaxMatrixSize); Assert.Equal(errMsg, e.Message); } }
public async Task GetMatrixById_ReturnMatrixWithSameId() { //Arrange var matrixObjectId = ObjectId.GenerateNewId(); var matrix = new Matrix() { Id = matrixObjectId }; matrixRepositoryMock.Setup(r => r.Get(matrixObjectId.ToString())).Returns <string>(id => Task.FromResult(matrix)); var matrixService = new MatrixService(matrixRepositoryMock.Object); //Act var result = await matrixService.GetMatrixById(matrixObjectId.ToString()); //Assert matrixRepositoryMock.Verify(x => x.Get(matrixObjectId.ToString()), Times.Once); Assert.AreEqual(matrixObjectId, result.Id); }
public Form1() { InitializeComponent(); V = new List <Vertex>(); G = new DrawGraph(sheet.Width, sheet.Height); E = new List <Edge>(); W = new List <Weight>(); CurV = new List <Vertex>(); CurW = new List <Weight>(); CurE = new List <Edge>(); Value = new List <String>(); Euler = new List <int>(); algoService = new ReqAlgosService(); matrixService = new MatrixService(); dfsService = new DFSService(); sheet.Image = G.GetBitmap(); }
private IMatrixService InitializeMatrixService() { var martixService = new MatrixService(); var matrixWidthX = 3; var matrixHeightY = 3; var inputArgsStr = $"{matrixWidthX}, {matrixHeightY}"; martixService.GetMatrixDimensions(inputArgsStr); var rowStr1 = "000"; var rowStr2 = "111"; var rowStr3 = "000"; martixService.CreateMatrixRow(rowStr1); martixService.CreateMatrixRow(rowStr2); martixService.CreateMatrixRow(rowStr3); return(martixService); }
public async Task Test_MatrixService_ToMatrixAsync() { var str = "1;2;3\r\n4;5;6\r\n7;8;9"; var originMatrix = new int[3][] { new int[3] { 1, 2, 3 }, new int[3] { 4, 5, 6 }, new int[3] { 7, 8, 9 } }; var stream = new MemoryStream(Encoding.UTF8.GetBytes(str)); var service = new MatrixService(); var matrix = await service.ToMatrixAsync(stream); Assert.IsTrue(IsMatrixEqual(originMatrix, matrix)); }
private async void InitData() { await Task.Delay(1); Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; MatrixService.UpdateSystem(); problemService.SolveProblem(MatrixService.GlobalStiffnessMatrix, MatrixService.GlobalForceVector); dataGrid1.ItemsSource = problemService.Values; await WriteDataInFile(); await RunPlot(); var sb = new StringBuilder(); if (problemService.MatrixA.ColumnCount <= 10) { sb.AppendLine("Problem matrix:"); sb.AppendLine(problemService.MatrixA.ToString()); } if (problemService.VectorF.Count <= 10) { sb.AppendLine("Problem vector:"); sb.AppendLine(problemService.VectorF.ToString()); } sb.AppendLine(); sb.AppendLine("L2:"); sb.AppendLine($"Absolute error: {problemService.AbsoluteErrorL2}"); sb.AppendLine($"Real error: {problemService.RealErrorL2:0.00}%"); sb.AppendLine($"W2:"); sb.AppendLine($"Absolute error: {problemService.AbsoluteErrorW2}"); sb.AppendLine($"Real error: {problemService.RealErrorW2:0.00}%"); Data.Text = sb.ToString(); }
private static void TestElementsFromDB(NpgsqlConnection connection) { Console.WriteLine("Testing random data from database"); for (var i = 0; i < 10; i++) { var containerIndex = random.Next(1, containerArraySize); var matrixIndex = random.Next(1, matrixArraySize); var positionIndex = random.Next(1, positionArraySize); var pointIndex = random.Next(1, pointArraySize); var container = ContainerService.Find(connection, containerIndex); var matrix = MatrixService.Find(connection, matrixIndex); var position = PositionService.Find(connection, positionIndex); var point = IntPointService.Find(connection, pointIndex); if (container == null || matrix == null || position == null) { throw new CustomException("Can't find data in database.", (byte)CustomErrorCode.MissingDataInDatabase); } Console.WriteLine(point.ToString()); } }
public MatrixController(MatrixService matrixService) { this.matrixService = matrixService; }
public MatrixController(MatrixService matrixService) { this.matrixService = matrixService; viewmodel = new Viewmodel(); }
public async Task Test_MatrixService_ToMatrixAsync_WithNullStream() { var service = new MatrixService(); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => service.ToMatrixAsync(null)); }
private static void WriteTestDataToDB(NpgsqlConnection connection) { var pointIds1D = new int[pointArraySize]; var pointIds2D = new int[pointArraySize]; var pointIds3D = new int[pointArraySize]; Console.WriteLine("Creating Points"); for (var i = 0; i < pointArraySize; i++) { pointIds1D[i] = IntPointService.Create(connection, RandomNumber()); pointIds2D[i] = IntPointService.Create(connection, RandomNumber(), RandomNumber()); pointIds3D[i] = IntPointService.Create(connection, RandomNumber(), RandomNumber(), RandomNumber()); } var positionIds1D = new int[positionArraySize]; var positionIds2D = new int[positionArraySize]; var positionIds3D = new int[positionArraySize]; Console.WriteLine("Creating Positions"); for (var i = 0; i < positionArraySize; i++) { if (i != 0 && i % 100 == 0) { Console.WriteLine("Created {0} positions", i); } var position1D = PositionService.CreateNewPosition(connection, (byte)DataType.Int); var position2D = PositionService.CreateNewPosition(connection, (byte)DataType.Int); var position3D = PositionService.CreateNewPosition(connection, (byte)DataType.Int); positionIds1D[i] = position1D; positionIds2D[i] = position2D; positionIds3D[i] = position3D; for (var j = 0; j < pointArraySize; j++) { PositionService.AddPoint(connection, position1D, pointIds1D[j]); PositionService.AddPoint(connection, position2D, pointIds2D[j]); PositionService.AddPoint(connection, position3D, pointIds3D[j]); } } var matrixIds = new int[matrixArraySize]; Console.WriteLine("Creating Matrices"); for (var i = 0; i < matrixArraySize; i++) { if (i != 0 && i % 10 == 0) { Console.WriteLine("Created {0} matrices", i); } var matrixId = MatrixService.CreateNewMatrix(connection, (byte)DataType.Int); matrixIds[i] = matrixId; for (var j = 0; j < positionArraySize; j++) { switch (i / 20) { case 0: MatrixService.AddPosition(connection, matrixId, positionIds1D[j]); break; case 1: MatrixService.AddPosition(connection, matrixId, positionIds2D[j]); break; case 2: MatrixService.AddPosition(connection, matrixId, positionIds3D[j]); break; } } } var containerIds = new int[containerArraySize]; Console.WriteLine("Creating Containers"); for (var i = 0; i < containerArraySize; i++) { if (i != 0 && i % 100 == 0) { Console.WriteLine("Created {0} containers", i); } var containerId = ContainerService.CreateNewContainer(connection, (byte)DataType.Int); containerIds[i] = containerId; for (var j = 0; j < matrixArraySize; j++) { ContainerService.AddMatrix(connection, containerId, matrixIds[j]); } } Console.WriteLine("Creating Container Collection."); var containerCollectionId = ContainerCollectionService.CreateNewContainerCollection(connection, (byte)DataType.Int); for (var i = 0; i < containerArraySize; i++) { if (i != 0 && i % 100 == 0) { Console.WriteLine("Added {0} containers to collection", i); } ContainerCollectionService.AddContainer(connection, containerCollectionId, containerIds[i]); } Console.WriteLine("All items are created."); }
public async Task StartAsync() { _paretoChartData = new List <ICanvasJSDataPoint>(); _bestChromosomeChartData = new List <ICanvasJSDataPoint>(); _evolutionChartData = new Dictionary <ChromosomeFactor, List <ICanvasJSDataPoint> >(); _evolutionConfig = CanvasJsChartService.GetBasicOptionsForEvolutionChart(); _paretoConfig = CanvasJsChartService.GetBasicOptionsForParetoChart(); _matrix = MatrixService.GenerateMatrix(nodeCount: _nodeCount, probability: _edgeProbability); var startPopulation = PopulationService.Initialize(_matrix, populationSize: _populationSize, maxDiffBetweenNode: _maxDiffBetweenNode); _populationHistory = new Dictionary <int, IPopulationResult> { [0] = startPopulation }; _graphData = GraphChartService.GraphDataFromMatrix(_matrix); _graphOptions = GraphChartService.GetDefaultGraphOptions(); var sampleDictionary = new Dictionary <ChromosomeFactor, List <ICanvasJSDataPoint> > { [ChromosomeFactor.ConnectedEdgeWeigthSum] = new List <ICanvasJSDataPoint> { new CanvasJSDataPoint { X = 0, Y = 0 }, }, [ChromosomeFactor.EdgeCount] = new List <ICanvasJSDataPoint> { new CanvasJSDataPoint { X = 0, Y = 0 }, }, [ChromosomeFactor.ConnectedEdgeWeigthSum | ChromosomeFactor.EdgeCount] = new List <ICanvasJSDataPoint> { new CanvasJSDataPoint { X = 0, Y = 0 }, } }; var sampleBest = new List <ICanvasJSDataPoint> { new CanvasJSDataPoint { X = 0, Y = 0 } }; _evolutionConfig.Data = CanvasJsChartService.GetEvolutionChartData(sampleDictionary, sampleBest); _paretoConfig.Data = CanvasJsChartService.GetParetoChartData(new List <ICanvasJSDataPoint> { new CanvasJSDataPoint { X = 0, Y = 0 }, }); await Task.Run(() => { _graphChart.RenderAsync(_graphData, _graphOptions); }); await Task.Run(() => { _evolutionChart.RenderAsync(_evolutionConfig); }); await Task.Run(() => { _paretoChart.RenderAsync(_paretoConfig); }); }
private static Containers <int> LoadDataFromDbToModel(NpgsqlConnection connection) { Console.WriteLine("Loading data to Containers PMC Model"); var containerCollection = ContainerCollectionService.Find(connection, validCollectionContainerId); var dataType = containerCollection.DataType; var containerCollectionData = ContainerCollectionService.Query(connection, containerCollection.Id); var pmsContainers = new Container <int> [containerCollectionData.Count]; for (var i = 0; i < containerCollectionData.Count; i++) { if (i % 100 == 0 && i != 0) { Console.WriteLine("Loaded {0} containers", i); } var containerModel = ContainerService.Find(connection, containerCollectionData[i].ContainerId); if (containerModel.DataType != dataType) { throw new CustomException("Containers has incorrect data type", (byte)CustomErrorCode.IncorrectDataTypeInContainers); } var containerMatrices = ContainerService.Query(connection, containerModel.Id); var pmsMatrices = new Matrix <int> [containerMatrices.Count]; for (var j = 0; j < containerMatrices.Count; j++) { if (j % 10 == 0 && j != 0) { Console.WriteLine("Loaded {0} matrices", j); } var matrixModel = MatrixService.Find(connection, containerMatrices[j].MatrixId); if (matrixModel.DataType != dataType) { throw new CustomException("Containers has incorrect data type", (byte)CustomErrorCode.IncorrectDataTypeInContainers); } var matrixPositions = MatrixService.Query(connection, matrixModel.Id); var pmsPositions = new Position <int> [matrixPositions.Count]; for (var k = 0; k < matrixPositions.Count; k++) { var positionModel = PositionService.Find(connection, matrixPositions[k].PositionId); if (positionModel.DataType != dataType) { throw new CustomException("Containers has incorrect data type", (byte)CustomErrorCode.IncorrectDataTypeInContainers); } var positionPoints = PositionService.Query(connection, positionModel.Id); var pmsPoints = new Point <int> [positionPoints.Count]; var dimension = Dimension.D1; for (var s = 0; s < positionPoints.Count; s++) { var pointModel = IntPointService.Find(connection, positionPoints[s].PointId); if (pointModel == null) { continue; } var pointModelDimension = (Dimension)pointModel.Dimension; if (dimension != pointModelDimension) { dimension = pointModelDimension; } pmsPoints[s] = new Point <int>(pointModel.GetPointArray()); } pmsPositions[k] = new Position <int>(pmsPoints, dimension); } pmsMatrices[j] = new Matrix <int>(pmsPositions); } pmsContainers[i] = new Container <int>(pmsMatrices); } ContainerCollectionBuilder <int> builder = new IntContainers(); var containers = builder.Create(); containers.ContainerArray = pmsContainers; return(containers); }