add equality checks and fuzz testing for chunk and storage data comparison
This commit is contained in:
+17
-2
@@ -7,8 +7,8 @@ type Chunk struct {
|
||||
version string
|
||||
}
|
||||
|
||||
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (err error) {
|
||||
c := &Chunk{}
|
||||
func ReadChunkFromChunkPacketData(r io.Reader, version string, worldHeight int) (c *Chunk, err error) {
|
||||
c = &Chunk{}
|
||||
c.version = version
|
||||
nSections := worldHeight / ChunkWidth
|
||||
|
||||
@@ -31,3 +31,18 @@ func (c *Chunk) WriteChunkData(w io.Writer) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Chunk) Equals(other *Chunk) bool {
|
||||
if c.version != other.version {
|
||||
return false
|
||||
}
|
||||
if len(c.Sections) != len(other.Sections) {
|
||||
return false
|
||||
}
|
||||
for i, s := range c.Sections {
|
||||
if !SectionEquals(s, other.Sections[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user