-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore!: check newChunk size #172
Conversation
Codecov Report
@@ Coverage Diff @@
## master #172 +/- ##
==========================================
+ Coverage 81.00% 81.22% +0.21%
==========================================
Files 7 7
Lines 516 522 +6
==========================================
+ Hits 418 424 +6
Misses 58 58
Partials 40 40
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only one fix is needed for the tests.
I just noticed #127 so tagging @Wondertan for review |
Based on #127 (comment) we may not want to return an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
// SetCell sets a specific cell. The cell to set must be `nil`. Returns an error | ||
// if the cell to set is not `nil` or newChunk is not the correct size. | ||
func (ds *dataSquare) SetCell(x uint, y uint, newChunk []byte) error { | ||
if ds.squareRow[x][y] != nil { | ||
panic(fmt.Sprintf("cannot set cell (%d, %d) as it already has a value %x", x, y, ds.squareRow[x][y])) | ||
return fmt.Errorf("cannot set cell (%d, %d) as it already has a value %x", x, y, ds.squareRow[x][y]) | ||
} | ||
if len(newChunk) != int(ds.chunkSize) { | ||
return fmt.Errorf("cannot set cell with chunk size %d because dataSquare chunk size is %d", len(newChunk), ds.chunkSize) | ||
} | ||
ds.squareRow[x][y] = newChunk | ||
ds.squareCol[y][x] = newChunk | ||
ds.resetRoots() | ||
return nil | ||
} | ||
|
||
// setCell sets a specific cell. | ||
func (ds *dataSquare) setCell(x uint, y uint, newChunk []byte) { | ||
// setCell sets a specific cell. setCell will overwrite any existing value. | ||
// Returns an error if the newChunk is not the correct size. | ||
func (ds *dataSquare) setCell(x uint, y uint, newChunk []byte) error { | ||
if len(newChunk) != int(ds.chunkSize) { | ||
return fmt.Errorf("cannot set cell with chunk size %d because dataSquare chunk size is %d", len(newChunk), ds.chunkSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for having two setters? I don't remember
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is the exported SetCell
shouldn't have access to overwrite populated cells but the internal setCell
should 🤷♂️
Closes #170
Closes #127
Breaking b/c modifies the function signature of a public function:
SetCell