-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
fix: chunkIntoN to chunk correctly #6035
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ee8af34
fix: fixed chunkIntoN to chunk correctly (#6018)
rdvorkin b34291d
Add more test cases
nazarhussain 19838a4
Update test title
nazarhussain 100c447
Update packages/prover/test/unit/utils/conversion.test.ts
nazarhussain 173dce3
Update the test description
nazarhussain a4ec47a
Update the test description
nazarhussain 7a6cd92
Update the test description
nazarhussain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {expect} from "chai"; | ||
import {chunkIntoN} from "../../../src/utils/conversion.js"; | ||
|
||
describe("utils/conversion", () => { | ||
describe("chunkIntoN", () => { | ||
const testCases = [ | ||
{ | ||
title: "even number of chunks", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6], | ||
n: 2, | ||
}, | ||
output: [ | ||
[1, 2], | ||
[3, 4], | ||
[5, 6], | ||
], | ||
}, | ||
{ | ||
title: "even number of chunks with additional element", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6, 7], | ||
n: 2, | ||
}, | ||
output: [[1, 2], [3, 4], [5, 6], [7]], | ||
}, | ||
{ | ||
title: "odd number of chunks", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6], | ||
n: 3, | ||
}, | ||
output: [ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
], | ||
}, | ||
{ | ||
title: "odd number of chunks with additional element", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6, 7], | ||
n: 3, | ||
}, | ||
output: [[1, 2, 3], [4, 5, 6], [7]], | ||
}, | ||
{ | ||
title: "data less than chunk size", | ||
input: { | ||
data: [1], | ||
n: 3, | ||
}, | ||
output: [[1]], | ||
}, | ||
{ | ||
title: "data 1 less than chunk size", | ||
input: { | ||
data: [1, 2], | ||
n: 3, | ||
}, | ||
output: [[1, 2]], | ||
}, | ||
{ | ||
title: "data 1 extra than chunk size", | ||
input: { | ||
data: [1, 2, 3, 4], | ||
n: 3, | ||
}, | ||
output: [[1, 2, 3], [4]], | ||
}, | ||
{ | ||
title: "when data have different order", | ||
input: { | ||
data: [6, 5, 4, 3, 2, 1], | ||
n: 2, | ||
}, | ||
output: [ | ||
[6, 5], | ||
[4, 3], | ||
[2, 1], | ||
], | ||
}, | ||
]; | ||
|
||
for (const {title, input, output} of testCases) { | ||
it(`should split the chunks correctly for "${title}"`, async () => { | ||
nflaig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(chunkIntoN(input.data, input.n)).to.be.deep.eq(output); | ||
}); | ||
} | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this test case make sense? it makes it seem like the type of elements are relevant, rather would add 1-2 tests cases that show that it works with any type of elements, e.g. objects or nested arrays
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.
Yes just want to make sure doing chunk does not change the order.
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.
All the other existing test cases already assert that.
My point is that why would the values of elements impact that?
Makes it sounds like this
chunkIntoN
inspects the value of elements, which it does not. IMO better way to prove this is to use different types of elements.