Fixed some more resizing bugs in certain situations not covered by mycology
This commit is contained in:
parent
2f66ddcb91
commit
749caa9e26
4 changed files with 43 additions and 5 deletions
|
@ -86,6 +86,9 @@ func (f *Field) Blank(x, y int) {
|
||||||
f.x = f.lines[0].x
|
f.x = f.lines[0].x
|
||||||
x2 := f.lines[0].l + f.lines[0].x
|
x2 := f.lines[0].l + f.lines[0].x
|
||||||
for i := 1; i < f.ly; i++ {
|
for i := 1; i < f.ly; i++ {
|
||||||
|
if f.lines[i].l == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if f.x > f.lines[i].x {
|
if f.x > f.lines[i].x {
|
||||||
f.x = f.lines[i].x
|
f.x = f.lines[i].x
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,13 +45,13 @@ func TestBlankInside(t *testing.T) {
|
||||||
|
|
||||||
func TestBlankInsideLine(t *testing.T) {
|
func TestBlankInsideLine(t *testing.T) {
|
||||||
input := Field{
|
input := Field{
|
||||||
x: 0,
|
x: -5,
|
||||||
y: 0,
|
y: 0,
|
||||||
lx: 3,
|
lx: 8,
|
||||||
ly: 3,
|
ly: 3,
|
||||||
lines: []Line{
|
lines: []Line{
|
||||||
Line{x: 0, l: 3, columns: []int{'@', 'a', 'b'}},
|
Line{x: 0, l: 3, columns: []int{'@', 'a', 'b'}},
|
||||||
Line{x: 0, l: 1, columns: []int{'d'}},
|
Line{x: -5, l: 1, columns: []int{'d'}},
|
||||||
Line{x: 0, l: 1, columns: []int{'c'}},
|
Line{x: 0, l: 1, columns: []int{'c'}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func TestBlankInsideLine(t *testing.T) {
|
||||||
ly: 3,
|
ly: 3,
|
||||||
lines: []Line{
|
lines: []Line{
|
||||||
Line{x: 0, l: 3, columns: []int{'@', 'a', 'b'}},
|
Line{x: 0, l: 3, columns: []int{'@', 'a', 'b'}},
|
||||||
Line{columns: []int{}},
|
Line{x: -5, columns: []int{}},
|
||||||
Line{x: 0, l: 1, columns: []int{'c'}},
|
Line{x: 0, l: 1, columns: []int{'c'}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func TestBlankInsideLine(t *testing.T) {
|
||||||
inputY int
|
inputY int
|
||||||
expected *Field
|
expected *Field
|
||||||
}{
|
}{
|
||||||
{"inside", &input, 0, 1, &expected},
|
{"inside", &input, -5, 1, &expected},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
|
|
@ -13,6 +13,13 @@ func (f *Field) Set(x, y, v int) {
|
||||||
l.x = x
|
l.x = x
|
||||||
l.l = 1
|
l.l = 1
|
||||||
l.columns = append(l.columns, v)
|
l.columns = append(l.columns, v)
|
||||||
|
if f.x > x {
|
||||||
|
f.lx = f.lx + f.x - x
|
||||||
|
f.x = x
|
||||||
|
}
|
||||||
|
if f.lx < x-f.x+1 {
|
||||||
|
f.lx = x - f.x + 1
|
||||||
|
}
|
||||||
} else if x >= l.x {
|
} else if x >= l.x {
|
||||||
if x < l.x+l.l {
|
if x < l.x+l.l {
|
||||||
// just set the value
|
// just set the value
|
||||||
|
|
|
@ -237,6 +237,13 @@ func TestSetAppendResize(t *testing.T) {
|
||||||
Line{x: 0, l: 1, columns: []int{'d'}},
|
Line{x: 0, l: 1, columns: []int{'d'}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
blank := Field{
|
||||||
|
x: 0, y: -1, lx: 2, ly: 3, lines: []Line{
|
||||||
|
Line{x: 0, l: 1, columns: []int{'u'}},
|
||||||
|
Line{x: 0, l: 2, columns: []int{'0', 'r'}},
|
||||||
|
Line{x: 0, l: 1, columns: []int{'d'}},
|
||||||
|
},
|
||||||
|
}
|
||||||
xappend := Field{
|
xappend := Field{
|
||||||
x: -1, y: -1, lx: 5, ly: 3, lines: []Line{
|
x: -1, y: -1, lx: 5, ly: 3, lines: []Line{
|
||||||
Line{x: 0, l: 1, columns: []int{'u'}},
|
Line{x: 0, l: 1, columns: []int{'u'}},
|
||||||
|
@ -287,6 +294,24 @@ func TestSetAppendResize(t *testing.T) {
|
||||||
Line{x: 3, l: 1, columns: []int{'n'}},
|
Line{x: 3, l: 1, columns: []int{'n'}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
xappendyappendEp := Field{
|
||||||
|
x: -5, y: -1, lx: 9, ly: 5, lines: []Line{
|
||||||
|
Line{x: 0, l: 1, columns: []int{'u'}},
|
||||||
|
Line{x: -1, l: 3, columns: []int{'l', '0', 'r'}},
|
||||||
|
Line{x: 0, l: 1, columns: []int{'d'}},
|
||||||
|
Line{x: -5, l: 1, columns: []int{'e'}},
|
||||||
|
Line{x: 3, l: 1, columns: []int{'n'}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
xappendyappendEa := Field{
|
||||||
|
x: -1, y: -1, lx: 7, ly: 5, lines: []Line{
|
||||||
|
Line{x: 0, l: 1, columns: []int{'u'}},
|
||||||
|
Line{x: -1, l: 3, columns: []int{'l', '0', 'r'}},
|
||||||
|
Line{x: 0, l: 1, columns: []int{'d'}},
|
||||||
|
Line{x: 5, l: 1, columns: []int{'e'}},
|
||||||
|
Line{x: 3, l: 1, columns: []int{'n'}},
|
||||||
|
},
|
||||||
|
}
|
||||||
// Test cases
|
// Test cases
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -296,12 +321,15 @@ func TestSetAppendResize(t *testing.T) {
|
||||||
inputV int
|
inputV int
|
||||||
expected Field
|
expected Field
|
||||||
}{
|
}{
|
||||||
|
{"blank", base, -1, 0, ' ', blank},
|
||||||
{"xappend", base, 3, 1, 'n', xappend},
|
{"xappend", base, 3, 1, 'n', xappend},
|
||||||
{"xprepend", base, -3, 1, 'n', xprepend},
|
{"xprepend", base, -3, 1, 'n', xprepend},
|
||||||
{"xprependyprepend", base, -3, -3, 'n', xprependyprepend},
|
{"xprependyprepend", base, -3, -3, 'n', xprependyprepend},
|
||||||
{"xappendyprepend", base, 3, -3, 'n', xappendyprepend},
|
{"xappendyprepend", base, 3, -3, 'n', xappendyprepend},
|
||||||
{"xprependyappend", base, -3, 3, 'n', xprependyappend},
|
{"xprependyappend", base, -3, 3, 'n', xprependyappend},
|
||||||
{"xappendyappend", base, 3, 3, 'n', xappendyappend},
|
{"xappendyappend", base, 3, 3, 'n', xappendyappend},
|
||||||
|
{"xappendyappendEp", xappendyappend, -5, 2, 'e', xappendyappendEp},
|
||||||
|
{"xappendyappendEa", xappendyappend, 5, 2, 'e', xappendyappendEa},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue