Cosmetics
This commit is contained in:
parent
01884fd45f
commit
0188cd49fe
3 changed files with 33 additions and 31 deletions
|
@ -12,13 +12,13 @@ func Blank*(f: var Field, x, y: int) =
|
||||||
if y < f.y or y >= f.y+f.ly: # outside the field
|
if y < f.y or y >= f.y+f.ly: # outside the field
|
||||||
return
|
return
|
||||||
var l = addr f.lines[y-f.y]
|
var l = addr f.lines[y-f.y]
|
||||||
if x < l.x or x >= l.x+l.l: # outside the field
|
if x < l.x or x >= l.x+l.l: # outside the field
|
||||||
return
|
return
|
||||||
if x > l.x and x < l.x+l.l-1: # just set the value
|
if x > l.x and x < l.x+l.l-1: # just set the value
|
||||||
l.columns[x-l.x] = int(' ')
|
l.columns[x-l.x] = int(' ')
|
||||||
return
|
return
|
||||||
if l.l == 1: # this was the last character on the line
|
if l.l == 1: # this was the last character on the line
|
||||||
if y == f.y: # we need to trim the leading lines
|
if y == f.y: # we need to trim the leading lines
|
||||||
var i = 1
|
var i = 1
|
||||||
while f.lines[i].l == 0:
|
while f.lines[i].l == 0:
|
||||||
inc i
|
inc i
|
||||||
|
@ -34,14 +34,14 @@ func Blank*(f: var Field, x, y: int) =
|
||||||
else: # it was a line in the middle
|
else: # it was a line in the middle
|
||||||
l.l = 0
|
l.l = 0
|
||||||
l.columns = @[]
|
l.columns = @[]
|
||||||
elif x == l.x: # we need to remove leading spaces
|
elif x == l.x: # we need to remove leading spaces
|
||||||
var i = 1
|
var i = 1
|
||||||
while l.columns[i] == int(' '):
|
while l.columns[i] == int(' '):
|
||||||
inc i
|
inc i
|
||||||
l.x += i
|
l.x += i
|
||||||
l.columns = l.columns[i..<l.l]
|
l.columns = l.columns[i..<l.l]
|
||||||
l.l -= i
|
l.l -= i
|
||||||
elif x == l.l+l.x-1: # we need to remove trailing spaces
|
elif x == l.l+l.x-1: # we need to remove trailing spaces
|
||||||
var i = l.l-2
|
var i = l.l-2
|
||||||
while l.columns[i] == int(' '):
|
while l.columns[i] == int(' '):
|
||||||
dec i
|
dec i
|
||||||
|
@ -77,7 +77,7 @@ proc Load*(f: var Field, filename: string): bool =
|
||||||
f.lines.add(Line())
|
f.lines.add(Line())
|
||||||
var l = addr f.lines[0]
|
var l = addr f.lines[0]
|
||||||
var trailingSpaces = 0
|
var trailingSpaces = 0
|
||||||
var data: array[255,char]
|
var data: array[255, char]
|
||||||
while true:
|
while true:
|
||||||
let n = file.readChars(data, 0, 255)
|
let n = file.readChars(data, 0, 255)
|
||||||
if n <= 0:
|
if n <= 0:
|
||||||
|
@ -136,9 +136,9 @@ func Set*(f: var Field, x, y, v: int) =
|
||||||
if v == int(' '):
|
if v == int(' '):
|
||||||
f.Blank(x, y)
|
f.Blank(x, y)
|
||||||
elif y >= f.y:
|
elif y >= f.y:
|
||||||
if y < f.y+f.ly: # the line exists
|
if y < f.y+f.ly: # the line exists
|
||||||
var l = addr f.lines[y-f.y]
|
var l = addr f.lines[y-f.y]
|
||||||
if l.l == 0: # An empty line is a special case
|
if l.l == 0: # An empty line is a special case
|
||||||
l.x = x
|
l.x = x
|
||||||
l.l = 1
|
l.l = 1
|
||||||
l.columns = @[v]
|
l.columns = @[v]
|
||||||
|
|
|
@ -92,14 +92,14 @@ suite "Field":
|
||||||
f.Blank(5, 2)
|
f.Blank(5, 2)
|
||||||
check f == moinsd
|
check f == moinsd
|
||||||
const moinsl = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])])
|
const moinsl = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])])
|
||||||
f.Blank(-2,0)
|
f.Blank(-2, 0)
|
||||||
check f == moinsl
|
check f == moinsl
|
||||||
const moinsr = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @[int('@')])])
|
const moinsr = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @[int('@')])])
|
||||||
f.Blank(4,0)
|
f.Blank(4, 0)
|
||||||
check f == moinsr
|
check f == moinsr
|
||||||
test "Get":
|
test "Get":
|
||||||
check minimal.Get(0,0) == int('@')
|
check minimal.Get(0, 0) == int('@')
|
||||||
check minimal.Get(1,0) == int(' ')
|
check minimal.Get(1, 0) == int(' ')
|
||||||
test "IsIn":
|
test "IsIn":
|
||||||
check minimal.IsIn(0, 0) == true
|
check minimal.IsIn(0, 0) == true
|
||||||
check minimal.IsIn(1, 0) == false
|
check minimal.IsIn(1, 0) == false
|
||||||
|
@ -113,41 +113,43 @@ suite "Field":
|
||||||
var min: Field
|
var min: Field
|
||||||
check min.Load("examples/minimal.b98") == true
|
check min.Load("examples/minimal.b98") == true
|
||||||
check min == minimal
|
check min == minimal
|
||||||
var hello1A: Field; var hello1B = Field(lx: 24, ly: 1, lines: @[Line(l:24, columns: @['6', '4', '+', '"', '!', 'd', 'l', 'r', 'o', 'W', ' ', ',', 'o', 'l', 'l', 'e', 'H', '"', '>', ':', '#', ',', '_', '@'].cols)])
|
var hello1A: Field; var hello1B = Field(lx: 24, ly: 1, lines: @[Line(l: 24, columns: @['6', '4', '+', '"', '!', 'd', 'l', 'r', 'o', 'W', ' ', ',', 'o', 'l', 'l', 'e', 'H', '"',
|
||||||
|
'>', ':', '#', ',', '_', '@'].cols)])
|
||||||
check hello1A.Load("examples/hello.b98") == true
|
check hello1A.Load("examples/hello.b98") == true
|
||||||
check hello1A == hello1B
|
check hello1A == hello1B
|
||||||
var rn: Field
|
var rn: Field
|
||||||
check rn.Load("examples/rn.b98") == true
|
check rn.Load("examples/rn.b98") == true
|
||||||
check rn == hello1B
|
check rn == hello1B
|
||||||
var hello2A: Field; var hello2B = Field(x: 1, lx: 33, ly: 2,lines: @[
|
var hello2A: Field; var hello2B = Field(x: 1, lx: 33, ly: 2, lines: @[
|
||||||
Line(x:33, l:1, columns: @['v'].cols),
|
Line(x: 33, l: 1, columns: @['v'].cols),
|
||||||
Line(x:1, l:33, columns: @['@', ' ', '>', ' ', '#', ';', '>', ':', '#', ',', '_', 'e', '-', 'j', ';', ' ', '"', 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', '"', 'd', 'a', '<'].cols)
|
Line(x: 1, l: 33, columns: @['@', ' ', '>', ' ', '#', ';', '>', ':', '#', ',', '_', 'e', '-', 'j', ';', ' ', '"', 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
|
||||||
|
'"', 'd', 'a', '<'].cols)
|
||||||
])
|
])
|
||||||
check hello2A.Load("examples/hello2.b98") == true
|
check hello2A.Load("examples/hello2.b98") == true
|
||||||
check hello2A == hello2B
|
check hello2A == hello2B
|
||||||
var factorial2A: Field; var factorial2B = Field(x: 0, lx: 15, ly: 2,lines: @[
|
var factorial2A: Field; var factorial2B = Field(x: 0, lx: 15, ly: 2, lines: @[
|
||||||
Line(x:0, l:15, columns: @['&', '>', ':', '1', '-', ':', 'v', ' ', 'v', ' ', '*', '_', '$', '.', '@'].cols),
|
Line(x: 0, l: 15, columns: @['&', '>', ':', '1', '-', ':', 'v', ' ', 'v', ' ', '*', '_', '$', '.', '@'].cols),
|
||||||
Line(x:1, l:11, columns: @['^', ' ', ' ', ' ', ' ', '_', '$', '>', '\\', ':', '^'].cols)
|
Line(x: 1, l: 11, columns: @['^', ' ', ' ', ' ', ' ', '_', '$', '>', '\\', ':', '^'].cols)
|
||||||
])
|
])
|
||||||
check factorial2A.Load("examples/factorial.b98") == true
|
check factorial2A.Load("examples/factorial.b98") == true
|
||||||
check factorial2A == factorial2B
|
check factorial2A == factorial2B
|
||||||
var dna2A: Field; var dna2B = Field(x: 0, lx: 7, ly: 8,lines: @[
|
var dna2A: Field; var dna2B = Field(x: 0, lx: 7, ly: 8, lines: @[
|
||||||
Line(x:0, l:7, columns: @['7', '^', 'D', 'N', '>', 'v', 'A'].cols),
|
Line(x: 0, l: 7, columns: @['7', '^', 'D', 'N', '>', 'v', 'A'].cols),
|
||||||
Line(x:0, l:7, columns: @['v', '_', '#', 'v', '?', ' ', 'v'].cols),
|
Line(x: 0, l: 7, columns: @['v', '_', '#', 'v', '?', ' ', 'v'].cols),
|
||||||
Line(x:0, l:7, columns: @['7', '^', '<', '"', '"', '"', '"'].cols),
|
Line(x: 0, l: 7, columns: @['7', '^', '<', '"', '"', '"', '"'].cols),
|
||||||
Line(x:0, l:7, columns: @['3', ' ', ' ', 'A', 'C', 'G', 'T'].cols),
|
Line(x: 0, l: 7, columns: @['3', ' ', ' ', 'A', 'C', 'G', 'T'].cols),
|
||||||
Line(x:0, l:7, columns: @['9', '0', '!', '"', '"', '"', '"'].cols),
|
Line(x: 0, l: 7, columns: @['9', '0', '!', '"', '"', '"', '"'].cols),
|
||||||
Line(x:0, l:7, columns: @['4', '*', ':', '>', '>', '>', 'v'].cols),
|
Line(x: 0, l: 7, columns: @['4', '*', ':', '>', '>', '>', 'v'].cols),
|
||||||
Line(x:0, l:7, columns: @['+', '8', '^', '-', '1', ',', '<'].cols),
|
Line(x: 0, l: 7, columns: @['+', '8', '^', '-', '1', ',', '<'].cols),
|
||||||
Line(x:0, l:7, columns: @['>', ' ', ',', '+', ',', '@', ')'].cols),
|
Line(x: 0, l: 7, columns: @['>', ' ', ',', '+', ',', '@', ')'].cols),
|
||||||
])
|
])
|
||||||
check dna2A.Load("examples/dna.b98") == true
|
check dna2A.Load("examples/dna.b98") == true
|
||||||
check dna2A == dna2B
|
check dna2A == dna2B
|
||||||
test "Set":
|
test "Set":
|
||||||
var f = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @['>'].cols)])
|
var f = Field(x: 0, y: 0, lx: 1, ly: 1, lines: @[Line(x: 0, l: 1, columns: @['>'].cols)])
|
||||||
f.Set(0,0,int('@'))
|
f.Set(0, 0, int('@'))
|
||||||
check f == minimal
|
check f == minimal
|
||||||
f.Set(1,0,int(' '))
|
f.Set(1, 0, int(' '))
|
||||||
check f == minimal
|
check f == minimal
|
||||||
const xappend = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])])
|
const xappend = Field(x: 0, y: 0, lx: 5, ly: 1, lines: @[Line(x: 0, l: 5, columns: @[int('@'), 32, 32, 32, int('r')])])
|
||||||
f.Set(4, 0, int('r'))
|
f.Set(4, 0, int('r'))
|
||||||
|
|
|
@ -133,5 +133,5 @@ suite "Stack":
|
||||||
test "Next":
|
test "Next":
|
||||||
var empty = NewStack()
|
var empty = NewStack()
|
||||||
check empty[].Next() == nil
|
check empty[].Next() == nil
|
||||||
var some = NewStack(next=empty)
|
var some = NewStack(next = empty)
|
||||||
check some[].Next() == empty
|
check some[].Next() == empty
|
||||||
|
|
Reference in a new issue