Skip to content

Commit

Permalink
Define and use constants for input chars and output strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ermanimer committed Jun 18, 2022
1 parent 728d394 commit 56592b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import (
)

const (
aliveChar = '*'
aliveCellInput = '*'
deadCellInput = '.'

aliveCellOutput = "● "
deadCellOutput = " "
newLineOutput = "\n"

aliveCell cell = 1
deadCell cell = 0
)
Expand All @@ -36,7 +42,7 @@ func newCells(input []string) (cells, error) {
if len(input[i]) <= j {
continue
}
if input[i][j] == aliveChar {
if input[i][j] == aliveCellInput {
cells[i][j] = aliveCell
}
}
Expand Down Expand Up @@ -137,14 +143,14 @@ func (c cells) print(w io.StringWriter) {
for i := 0; i < c.height(); i++ {
for j := 0; j < c.width(); j++ {
if c[i][j] == aliveCell {
w.WriteString("● ")
w.WriteString(aliveCellOutput)
continue
}

w.WriteString(" ")
w.WriteString(deadCellOutput)
}

w.WriteString("\n")
w.WriteString(newLineOutput)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func TestCells(t *testing.T) {
}

func mockPrint(line string) string {
l := strings.Replace(line, ".", " ", -1)
l = strings.Replace(l, "*", "● ", -1)
l := strings.Replace(line, string(deadCellInput), deadCellOutput, -1)
l = strings.Replace(l, string(aliveCellInput), aliveCellOutput, -1)
l += "\n"
return l
}

0 comments on commit 56592b0

Please sign in to comment.