Ejemplo n.º 1
0
        public void ShouldReturnOnlyRelationshipsForCell()
        {
            Cell cell1 = new LiveCell(Guid.NewGuid());
            Cell cell2 = new LiveCell(Guid.NewGuid());

            Relationships relationships = new Relationships();

            relationships.CreateNewRelationship(cell1, cell2);
            relationships.CreateNewRelationship(cell2, cell2);

            List <Relationship> neighbors = relationships.GetNeighbors(cell1);

            neighbors.Should().HaveCount(1);
        }
Ejemplo n.º 2
0
        private void CreateRelationship(IReadOnlyList <Cell> cells, int rows, int columns, int row, Relationships relationships, int column)
        {
            Cell cell     = cells [(row * rows) + column];
            int  position = (row * rows) + column;

            if (AddEast(columns, column))
            {
                relationships.CreateNewRelationship(cell, cells[position + 1]);
            }

            if (AddWest(column))
            {
                relationships.CreateNewRelationship(cell, cells[position - 1]);
            }

            if (AddSouth(rows, row))
            {
                relationships.CreateNewRelationship(cell, cells[position + rows]);
            }

            if (AddNorth(row))
            {
                relationships.CreateNewRelationship(cell, cells[position - rows]);
            }

            if (AddNorthEast(columns, row, column))
            {
                relationships.CreateNewRelationship(cell, cells[position - rows + 1]);
            }

            if (AddNorthWest(row, column))
            {
                relationships.CreateNewRelationship(cell, cells[position - rows - 1]);
            }

            if (AddSouthEast(rows, columns, row, column))
            {
                relationships.CreateNewRelationship(cell, cells[position + rows + 1]);
            }

            if (AddSouthWest(rows, row, column))
            {
                relationships.CreateNewRelationship(cell, cells[position + rows - 1]);
            }
        }