public async Task Spreadsheet_AddRow_CellWithVeryLongStringValue(int length, Type type)
    {
        // Arrange
        var value = new string('a', length);

        using var stream = new MemoryStream();
        var options = new SpreadCheetahOptions {
            BufferSize = SpreadCheetahOptions.MinimumBufferSize
        };

        await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream, options))
        {
            await spreadsheet.StartWorksheetAsync("Sheet");

            var cell = CellFactory.Create(type, value);

            // Act
            await spreadsheet.AddRowAsync(cell);

            await spreadsheet.FinishAsync();
        }

        // Assert
        SpreadsheetAssert.Valid(stream);
        using var actual = SpreadsheetDocument.Open(stream, true);
        var sheetPart  = actual.WorkbookPart !.WorksheetParts.Single();
        var actualCell = sheetPart.Worksheet.Descendants <OpenXmlCell>().Single();

        Assert.Equal(CellValues.InlineString, actualCell.DataType?.Value);
        Assert.Equal(value, actualCell.InnerText);
    }
    public async Task Spreadsheet_AddRow_FontNameCellWithStringValue(string? fontName, Type type)
    {
        // Arrange
        const string cellValue = "Font name test";
        using var stream = new MemoryStream();
        await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
        {
            await spreadsheet.StartWorksheetAsync("Sheet");

            var style = new Style();
            style.Font.Name = fontName;
            var styleId = spreadsheet.AddStyle(style);
            var styledCell = CellFactory.Create(type, cellValue, styleId);

            // Act
            await spreadsheet.AddRowAsync(styledCell);
            await spreadsheet.FinishAsync();
        }

        // Assert
        SpreadsheetAssert.Valid(stream);
        using var workbook = new XLWorkbook(stream);
        var worksheet = workbook.Worksheets.Single();
        var actualCell = worksheet.Cell(1, 1);
        Assert.Equal(cellValue, actualCell.Value);
        Assert.Equal(fontName ?? "Calibri", actualCell.Style.Font.FontName);
    }
    public async Task Spreadsheet_AddRow_MixedBoldStyleCells(bool firstCellBold, Type type)
    {
        // Arrange
        const string firstCellValue = "First";
        const string secondCellValue = "Second";
        using var stream = new MemoryStream();
        await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
        {
            await spreadsheet.StartWorksheetAsync("Sheet");

            var style = new Style();
            style.Font.Bold = true;
            var styleId = spreadsheet.AddStyle(style);

            var firstCell = CellFactory.Create(type, firstCellValue, firstCellBold ? styleId : null);
            var secondCell = CellFactory.Create(type, secondCellValue, firstCellBold ? null : styleId);

            // Act
            await spreadsheet.AddRowAsync(new[] { firstCell, secondCell });
            await spreadsheet.FinishAsync();
        }

        // Assert
        SpreadsheetAssert.Valid(stream);
        using var workbook = new XLWorkbook(stream);
        var worksheet = workbook.Worksheets.Single();
        var actualFirstCell = worksheet.Cell(1, 1);
        var actualSecondCell = worksheet.Cell(1, 2);
        Assert.Equal(firstCellValue, actualFirstCell.Value);
        Assert.Equal(secondCellValue, actualSecondCell.Value);
        Assert.Equal(firstCellBold, actualFirstCell.Style.Font.Bold);
        Assert.Equal(!firstCellBold, actualSecondCell.Style.Font.Bold);
    }
    public async Task Spreadsheet_AddRow_FillColorCellWithStringValue(Type type)
    {
        // Arrange
        const string cellValue = "Color test";
        var color = Color.Brown;
        using var stream = new MemoryStream();
        await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
        {
            await spreadsheet.StartWorksheetAsync("Sheet");

            var style = new Style();
            style.Fill.Color = color;
            var styleId = spreadsheet.AddStyle(style);
            var styledCell = CellFactory.Create(type, cellValue, styleId);

            // Act
            await spreadsheet.AddRowAsync(styledCell);
            await spreadsheet.FinishAsync();
        }

        // Assert
        SpreadsheetAssert.Valid(stream);
        using var workbook = new XLWorkbook(stream);
        var worksheet = workbook.Worksheets.Single();
        var actualCell = worksheet.Cell(1, 1);
        Assert.Equal(cellValue, actualCell.Value);
        Assert.Equal(color, actualCell.Style.Fill.BackgroundColor.Color);
    }
    public async Task Spreadsheet_AddRow_CellWithIntegerValue(int?value, Type type)
    {
        // Arrange
        using var stream = new MemoryStream();
        await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
        {
            await spreadsheet.StartWorksheetAsync("Sheet");

            var cell = CellFactory.Create(type, value);

            // Act
            await spreadsheet.AddRowAsync(cell);

            await spreadsheet.FinishAsync();
        }

        // Assert
        SpreadsheetAssert.Valid(stream);
        using var actual = SpreadsheetDocument.Open(stream, true);
        var sheetPart  = actual.WorkbookPart !.WorksheetParts.Single();
        var actualCell = sheetPart.Worksheet.Descendants <OpenXmlCell>().Single();

        Assert.Equal(CellValues.Number, actualCell.GetDataType());
        Assert.Equal(value?.ToString() ?? string.Empty, actualCell.InnerText);
    }
    public async Task Spreadsheet_AddRow_CellWithStringValue(string?value, Type type)
    {
        // Arrange
        using var stream = new MemoryStream();
        await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
        {
            await spreadsheet.StartWorksheetAsync("Sheet");

            var cell = CellFactory.Create(type, value);

            // Act
            await spreadsheet.AddRowAsync(cell);

            await spreadsheet.FinishAsync();
        }

        // Assert
        SpreadsheetAssert.Valid(stream);
        using var actual = SpreadsheetDocument.Open(stream, true);
        var        sheetPart        = actual.WorkbookPart !.WorksheetParts.Single();
        var        actualCell       = sheetPart.Worksheet.Descendants <OpenXmlCell>().Single();
        CellValues?expectedDataType = value is null ? null : CellValues.InlineString;

        Assert.Equal(expectedDataType, actualCell.DataType?.Value);
        Assert.Equal(value ?? string.Empty, actualCell.InnerText);
    }
Exemplo n.º 7
0
        /// <summary>
        /// Generates the output
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string GenerateOutput(string input)
        {
            List <Minefield> minefields = new List <Minefield>();
            Minefield        minefield  = null;
            StringBuilder    output     = new StringBuilder();

            string[] delimiter = { Environment.NewLine };
            string[] words     = input.Split(delimiter, StringSplitOptions.None);

            foreach (string s in words)
            {
                if (MinefieldValidator.IsHeader(s))
                {
                    minefield = MinefieldFactory.Create(minefields.Count + 1, s);
                    minefields.Add(minefield);
                }
                else if (MinefieldValidator.isFooter(s))
                {
                    break;
                }
                else
                {
                    foreach (char c in s.ToCharArray())
                    {
                        if (CellValidator.isMineOrSafe(c.ToString()))
                        {
                            minefield.Cells.Add(CellFactory.Create(c));
                        }
                        else
                        {
                            ErroMessage = "Your input data is not valid.";
                            return(output.ToString());
                        }
                    }
                }
            }
            try
            {
                foreach (Minefield field in minefields)
                {
                    MinesweeperConverter converter = new MinesweeperConverter();
                    converter.ConvertMinefield(field);
                    //header
                    output.Append(String.Format(MinefieldValidator.headerOutput, field.Id));
                    output.Append(Environment.NewLine);
                    //result
                    output.Append(converter.output);
                    output.Append(Environment.NewLine);
                }
            }
            catch
            {
                ErroMessage = "Your input data is not valid.";
                return(output.ToString());
            }

            return(output.ToString());
        }
Exemplo n.º 8
0
 internal void GenerateSea()
 {
     for (var i = 0; i < size; i++)
     {
         for (var j = 0; j < size; j++)
         {
             field[i].Add(CellFactory.Create(CellType.Water, i, j));
         }
     }
 }
Exemplo n.º 9
0
 public void Generate(CellType cellType, int times)
 {
     times = times > playableArea.Count
         ? playableArea.Count
         : times;
     for (var i = 0; i < times; i++)
     {
         var cell    = GetPlayableCell();
         var newType = CellFactory.Create(cellType, cell.Position.Column, cell.Position.Row);
         newType.Field = this;
         Draw(newType);
     }
 }
Exemplo n.º 10
0
    public Board()
    {
        Matrix = new CellState[SIZE, SIZE];

        for (int x = 0; x < SIZE; x++)
        {
            for (int y = 0; y < SIZE; y++)
            {
                var position = new Vector3(x - (SIZE / 2), y - (SIZE / 2), 0);
                Matrix[x, y] = CellFactory.Create(position, Random.Range(1, 3) == 1);
            }
        }
    }
Exemplo n.º 11
0
 /// <summary>
 /// Filling the minefield with cells.
 /// </summary>
 /// <param name="minefield">The minefield.</param>
 /// <param name="input">The input.</param>
 private void CreateCells(Minefield minefield, string input)
 {
     foreach (char c in input.ToCharArray())
     {
         if (CellValidator.isMineOrSafe(c.ToString()))
         {
             minefield.Cells.Add(CellFactory.Create(c));
         }
         else
         {
             //invalid input
             this.Renderer.ClearCurrentLine();
             break;
         }
     }
 }
Exemplo n.º 12
0
        public void CanCreateAllTypes()
        {
            var missedCellTypes = new List <CellType>();

            var values = (IList)Enum.GetValues(typeof(CellType));

            for (var i = 0; i < values.Count; i++)
            {
                var cellType = (CellType)values[i];
                try {
                    CellFactory.Create(cellType, 1, 1);
                }
                catch (Exception) {
                    missedCellTypes.Add(cellType);
                    Console.WriteLine(cellType.ToString());
                }
            }

            missedCellTypes.ShouldBeEmpty();
        }
    public async Task Spreadsheet_AddRow_MultiFormatCellWithStringValue(bool formatting, Type type)
    {
        // Arrange
        const string cellValue = "Formatting test";
        var fontName = formatting ? "Arial" : null;
        var fillColor = formatting ? Color.Green as Color? : null;
        var fontColor = formatting ? Color.Red as Color? : null;
        using var stream = new MemoryStream();
        await using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
        {
            await spreadsheet.StartWorksheetAsync("Sheet");

            var style = new Style();
            style.Fill.Color = fillColor;
            style.Font.Bold = formatting;
            style.Font.Color = fontColor;
            style.Font.Italic = formatting;
            style.Font.Name = fontName;
            style.Font.Strikethrough = formatting;
            var styleId = spreadsheet.AddStyle(style);
            var styledCell = CellFactory.Create(type, cellValue, styleId);

            // Act
            await spreadsheet.AddRowAsync(styledCell);
            await spreadsheet.FinishAsync();
        }

        // Assert
        SpreadsheetAssert.Valid(stream);
        using var workbook = new XLWorkbook(stream);
        var worksheet = workbook.Worksheets.Single();
        var actualCell = worksheet.Cell(1, 1);
        Assert.Equal(cellValue, actualCell.Value);
        Assert.Equal(formatting, actualCell.Style.Fill.BackgroundColor.Color == fillColor);
        Assert.Equal(formatting, actualCell.Style.Font.Bold);
        Assert.Equal(formatting, actualCell.Style.Font.FontColor.Color == fontColor);
        Assert.Equal(formatting, string.Equals(actualCell.Style.Font.FontName, fontName, StringComparison.Ordinal));
        Assert.Equal(formatting, actualCell.Style.Font.Italic);
        Assert.Equal(formatting, actualCell.Style.Font.Strikethrough);
    }
Exemplo n.º 14
0
        internal void GenerateGrass()
        {
            for (var i = 1; i < size - 1; i++)
            {
                for (var j = 1; j < size - 1; j++)
                {
                    var cell = CellFactory.Create(CellType.Grass, i, j);
                    field[i][j] = cell;
                    playableArea.Add(cell);
                }
            }

            playableArea.Remove(field[1][1]);
            playableArea.Remove(field[1][size - 2]);
            playableArea.Remove(field[size - 2][size - 2]);
            playableArea.Remove(field[size - 2][1]);

            field[1][1]               = CellFactory.Create(CellType.Water, 1, 1);
            field[1][size - 2]        = CellFactory.Create(CellType.Water, 1, size - 2);
            field[size - 2][size - 2] = CellFactory.Create(CellType.Water, size - 2, size - 2);
            field[size - 2][1]        = CellFactory.Create(CellType.Water, size - 2, 1);
        }
Exemplo n.º 15
0
    public Cell GetCellOrCreate(Vector2 point)
    {
        // cellIndex is the index of the cell
        var cellIndex = point;

        cellIndex.x = Util.RoundTo(cellIndex.x + 0.5f, NumberOfTiles);
        cellIndex.y = Util.RoundTo(cellIndex.y + 0.5f, NumberOfTiles);

        cellIndex = cellIndex / NumberOfTiles;
        var groupName = "(" + cellIndex.x + "," + cellIndex.y + ")";

        var cell = Cells.Find(element => element.name == groupName);

        // If it doesn't exist time to create it
        if (cell == null)
        {
            cell = CellFactory.Create(cellIndex, this);
            Cells.Add(cell);
        }

        return(cell);
    }
Exemplo n.º 16
0
    Vector3 pointPos;                                    //position to place each prefab along the given circle/eliptoid

    public BoardCircle()
    {
        Matrix = new CellState[SIZE_X, SIZE_Y];

        for (int x = 0; x < SIZE_X; x++)
        {
            for (int y = 0; y < SIZE_Y; y++)
            {
                //multiply 'i' by '1.0f' to ensure the result is a fraction
                float pointNum = (x * 1.0f) / SIZE_X;
                //angle along the unit circle for placing points
                float angle = pointNum * Mathf.PI * 2;

                float X = Mathf.Sin(angle) * radiusX;                 // for radial placement and simple height
                float Y = Mathf.Cos(angle) * radiusY;                 // for radial placement and simple height
                //float X = Mathf.Sin (angle)*(radiusX + radiusOffset* y); // for placement in a ring like fasion on the ground
                //float Y = Mathf.Cos (angle)*(radiusY + radiusOffset* y); // for placement in a ring like fasion on the ground

                //position for the point prefab
                if (vertical)
                {
                    pointPos = new Vector3(X, Y) + centerPos;
                }
                else if (!vertical)
                {
                    pointPos = new Vector3(X, y * SCALE - (SIZE_Y / 2) * SCALE, Y) + centerPos; // for centered pivot of the entire group
                    pointPos = new Vector3(X, y * SCALE, Y) + centerPos;                        // for placement from bottom to top
                    //pointPos = new Vector3(X, centerPos.y, Y)+centerPos; // for placement in a ring like fasion on the ground
                }
                //var position = new Vector3(x - (SIZE_X / 2), y - (SIZE_Y / 2), 0);
                //var position = new Vector3(x*SCALE- (SIZE_X / 2)*SCALE,y*SCALE- (SIZE_Y / 2)*SCALE,0);
                var position = pointPos;
                Matrix[x, y] = CellFactory.Create(position, Random.Range(1, 3) == 1);
            }
        }
    }
Exemplo n.º 17
0
        public Entity RequestCell(Cell cell, float verticalOffset, Transform parent)
        {
            Entity?cellEntity = data.Find(e => !e.Value.IsEnabled() && e.Value.Get <Cell>().Color == cell.Color);

            if (!cellEntity.HasValue)
            {
                cellEntity = _cellFactory.Create(cell, parent);
                data.Add(cellEntity.Value);
            }
            else
            {
                Reset(cellEntity, cell);
            }
            var localPosition = GetLocalPosition(cell);

            PlaceCell(cellEntity, localPosition, verticalOffset);
            if (verticalOffset != 0)
            {
                cellEntity.Value.Set(new TargetPosition {
                    Position = localPosition, UseLocalPosition = true
                });
            }
            return(cellEntity.Value);
        }
Exemplo n.º 18
0
 public void TestInit()
 {
     ship = new Ship(new Team(TeamType.Black, new TestEmptyRules()), (WaterCell)CellFactory.Create(CellType.Water, 1, 1));
 }
 public IPropertyGirdCell Create(PropertyEditorAttribute attribute)
 {
     return(_factory.Create(attribute));
 }