public void ValidLocation_ValidLocations_TrueReturned() { //Arrange bool expected = true; TriangularGrid tGrid = new TriangularGrid(60, 60, 10); List <Coordinate> locations = new List <Coordinate> { new Coordinate { X = 10, Y = 50 }, new Coordinate { X = 20, Y = 50 }, new Coordinate { X = 20, Y = 60 } }; //Act bool actual = tGrid.ValidLocations(locations); //Assert Assert.AreEqual(expected, actual); }
public void ReturnsCorrectWidthAndHeight() { TriangularGrid triangularGrid = new TriangularGrid(60, 60, 10); Assert.Equal(60, triangularGrid.Height); Assert.Equal(60, triangularGrid.Width); Assert.Equal(10, triangularGrid.CellSize); }
public void ValidGridReference_ValidLastReference_TrueReturned() { //Arrange bool expected = true; TriangularGrid tGrid = new TriangularGrid(60, 60, 10); string gRef = "F12"; //Act bool actual = tGrid.ValidGridReference(gRef); //Assert Assert.AreEqual(expected, actual); }
public void ValidGridReference_InvalidRow_FalseReturned() { //Arrange bool expected = false; TriangularGrid tGrid = new TriangularGrid(60, 60, 10); string gRef = "A13"; //Act bool actual = tGrid.ValidGridReference(gRef); //Assert Assert.AreEqual(expected, actual); }
public void ValidLocation_InValidHeightLocations_FalseReturned() { //Arrange bool expected = false; int height = 60; TriangularGrid tGrid = new TriangularGrid(height, 60, 10); List <Coordinate> locations = new List <Coordinate> { new Coordinate { X = 10, Y = height + 10 } }; //Act bool actual = tGrid.ValidLocations(locations); //Assert Assert.AreEqual(expected, actual); }
public void ValidLocation_InValidWidthLocations_FalseReturned() { //Arrange bool expected = false; int width = 60; TriangularGrid tGrid = new TriangularGrid(60, width, 10); List <Coordinate> locations = new List <Coordinate> { new Coordinate { X = width + 10, Y = 50 } }; //Act bool actual = tGrid.ValidLocations(locations); //Assert Assert.AreEqual(expected, actual); }
public void ReturnsCorrectColumnCount() { TriangularGrid triangularGrid = new TriangularGrid(60, 60, 10); Assert.Equal(12, triangularGrid.GetColumnCount()); }
public IGrid Provide(string filename) { TriangularGrid grid = new TriangularGrid(); var topology = new TriGridTopology(); if (File.Exists(filename)) { StreamReader sr = new StreamReader(filename); string line = sr.ReadLine(); string[] cstr = TypeConverterEx.Split <string>(line); grid.VertexCount = int.Parse(cstr[2]); grid.Vertex = new Coordinate[grid.VertexCount]; Dictionary <uint, List <uint> > map = new Dictionary <uint, List <uint> >(); for (uint i = 0; i < grid.VertexCount; i++) { line = sr.ReadLine(); cstr = TypeConverterEx.Split <string>(line); grid.Vertex[i] = new Coordinate(double.Parse(cstr[1]), double.Parse(cstr[2]), double.Parse(cstr[3])); map[i] = new List <uint>(); } line = sr.ReadLine(); cstr = TypeConverterEx.Split <string>(line); grid.CellCount = int.Parse(cstr[0]); grid.Centroids = new Coordinate[grid.CellCount]; topology.VertexIndices = new uint[grid.CellCount][]; topology.NodeConnectedCells = new uint[grid.VertexCount][]; for (uint i = 0; i < grid.CellCount; i++) { double bathymetry = 0; topology.VertexIndices[i] = new uint[3]; line = sr.ReadLine(); cstr = TypeConverterEx.Split <string>(line); topology.VertexIndices[i][0] = uint.Parse(cstr[1]) - 1; topology.VertexIndices[i][1] = uint.Parse(cstr[2]) - 1; topology.VertexIndices[i][2] = uint.Parse(cstr[3]) - 1; map[topology.VertexIndices[i][0]].Add(i); map[topology.VertexIndices[i][1]].Add(i); map[topology.VertexIndices[i][2]].Add(i); bathymetry += (grid.Vertex[topology.VertexIndices[i][0]].Z + grid.Vertex[topology.VertexIndices[i][1]].Z + grid.Vertex[topology.VertexIndices[i][2]].Z) / 3.0; Triangle trig = new Triangle(grid.Vertex[topology.VertexIndices[i][0]], grid.Vertex[topology.VertexIndices[i][1]], grid.Vertex[topology.VertexIndices[i][2]]); grid.Centroids[i] = new Coordinate(trig.InCentre()); grid.Centroids[i].Z = bathymetry; } topology.NodeConnectedCells = new uint[grid.VertexCount][]; for (uint i = 0; i < grid.VertexCount; i++) { topology.NodeConnectedCells[i] = map[i].ToArray(); } var elev = (from vert in grid.Vertex select(float) vert.Z).ToArray(); grid.Elevations = new DataCube <float>(1, 1, grid.VertexCount); grid.Elevations[0, "0", ":"] = elev; topology.Grid = grid; grid.Topology = topology; sr.Close(); map.Clear(); } return(grid); }