Skip to content

Commit

Permalink
Fix and add test for MultiLineString
Browse files Browse the repository at this point in the history
  • Loading branch information
shaxbee committed Apr 20, 2016
1 parent 2799a88 commit 4b18cf9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wkb/linestring.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func readMultiLineString(b []byte, dec binary.ByteOrder) ([]byte, MultiLineStrin

mls := make([]LineString, n)
for i := 0; i < n; i++ {
b, dec, err = byteHeader(b, GeomLineString)
if err != nil {
return nil, nil, err
}

b, mls[i], err = readLineString(b, dec)
if err != nil {
return nil, nil, err
Expand Down
71 changes: 71 additions & 0 deletions wkb/linestring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package wkb

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLineString(t *testing.T) {
valid := []byte{
0x01, 0x02, 0x00, 0x00, 0x00, // header
0x03, 0x00, 0x00, 0x00, // numpoints - 3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40, // point 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40, // point 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x40, // point 3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x40,
}

ls := LineString{}
if err := ls.Scan(valid); assert.NoError(t, err) {
assert.Equal(t, LineString{
Point{30, 10},
Point{10, 30},
Point{40, 40},
}, ls)
}
}

func TestMultiLineString(t *testing.T) {
valid := []byte{
0x01, 0x05, 0x00, 0x00, 0x00, // header
0x02, 0x00, 0x00, 0x00, // numlinestring - 2
0x01, 0x02, 0x00, 0x00, 0x00, // linestring - 1
0x03, 0x00, 0x00, 0x00, // numpoints - 3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x40,
0x01, 0x02, 0x00, 0x00, 0x00, // linestring - 2
0x04, 0x00, 0x00, 0x00, // numpoints - 4
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x40,
}

mls := MultiLineString{}
if err := mls.Scan(valid); assert.NoError(t, err) {
assert.Equal(t, MultiLineString{
LineString{
Point{10, 10},
Point{20, 20},
Point{10, 40},
},
LineString{
Point{40, 40},
Point{30, 30},
Point{40, 20},
Point{30, 10},
},
}, mls)
}
}

0 comments on commit 4b18cf9

Please sign in to comment.