-
-
Notifications
You must be signed in to change notification settings - Fork 60
Sync two-bucket tests #605
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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,36 @@ | ||
| return { | ||
| module_name = 'two_bucket', | ||
|
|
||
| generate_test = function(case) | ||
| if case.expected.error then | ||
| local template = [[ | ||
| assert.has_error(function() | ||
| two_bucket.measure({ | ||
| bucket_one_capacity = %d, -- | ||
| bucket_two_capacity = %d, -- | ||
| goal_volume = %d, -- | ||
| start_bucket = %d -- | ||
| }) | ||
| end)]] | ||
|
|
||
| return template:format(case.input.bucketOne, case.input.bucketTwo, case.input.goal, | ||
| case.input.startBucket == 'one' and 1 or 2) | ||
| else | ||
| local template = [[ | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = %d, -- | ||
| bucket_two_capacity = %d, -- | ||
| goal_volume = %d, -- | ||
| start_bucket = %d -- | ||
| }), { | ||
| moves = %d, -- | ||
| other_bucket_volume = %d, -- | ||
| goal_bucket_number = %d -- | ||
| })]] | ||
|
|
||
| return template:format(case.input.bucketOne, case.input.bucketTwo, case.input.goal, | ||
| case.input.startBucket == 'one' and 1 or 2, case.expected.moves, case.expected.otherBucket, | ||
| case.expected.goalBucket == 'one' and 1 or 2) | ||
| end | ||
| end | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,118 +1,143 @@ | ||
| local two_bucket = require 'two-bucket' | ||
| local two_bucket = require('two-bucket') | ||
|
|
||
| -- LuaFormatter off | ||
| describe('two-bucket', function() | ||
| it('measure using bucket one of size 3 and bucket two of size 5 - start with bucket one', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 3, | ||
| bucket_two_capacity = 5, | ||
| goal_volume = 1, | ||
| start_bucket = 1 | ||
| bucket_one_capacity = 3, -- | ||
| bucket_two_capacity = 5, -- | ||
| goal_volume = 1, -- | ||
| start_bucket = 1 -- | ||
| }), { | ||
| moves = 4, | ||
| other_bucket_volume = 5, | ||
| goal_bucket_number = 1 | ||
| moves = 4, -- | ||
| other_bucket_volume = 5, -- | ||
| goal_bucket_number = 1 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('measure using bucket one of size 3 and bucket two of size 5 - start with bucket two', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 3, | ||
| bucket_two_capacity = 5, | ||
| goal_volume = 1, | ||
| start_bucket = 2 | ||
| bucket_one_capacity = 3, -- | ||
| bucket_two_capacity = 5, -- | ||
| goal_volume = 1, -- | ||
| start_bucket = 2 -- | ||
| }), { | ||
| moves = 8, | ||
| other_bucket_volume = 3, | ||
| goal_bucket_number = 2 | ||
| moves = 8, -- | ||
| other_bucket_volume = 3, -- | ||
| goal_bucket_number = 2 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('measure using bucket one of size 7 and bucket two of size 11 - start with bucket one', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 7, | ||
| bucket_two_capacity = 11, | ||
| goal_volume = 2, | ||
| start_bucket = 1 | ||
| bucket_one_capacity = 7, -- | ||
| bucket_two_capacity = 11, -- | ||
| goal_volume = 2, -- | ||
| start_bucket = 1 -- | ||
| }), { | ||
| moves = 14, | ||
| other_bucket_volume = 11, | ||
| goal_bucket_number = 1 | ||
| moves = 14, -- | ||
| other_bucket_volume = 11, -- | ||
| goal_bucket_number = 1 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('measure using bucket one of size 7 and bucket two of size 11 - start with bucket two', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 7, | ||
| bucket_two_capacity = 11, | ||
| goal_volume = 2, | ||
| start_bucket = 2 | ||
| bucket_one_capacity = 7, -- | ||
| bucket_two_capacity = 11, -- | ||
| goal_volume = 2, -- | ||
| start_bucket = 2 -- | ||
| }), { | ||
| moves = 18, | ||
| other_bucket_volume = 7, | ||
| goal_bucket_number = 2 | ||
| moves = 18, -- | ||
| other_bucket_volume = 7, -- | ||
| goal_bucket_number = 2 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('measure one step using bucket one of size 1 and bucket two of size 3 - start with bucket two', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 1, | ||
| bucket_two_capacity = 3, | ||
| goal_volume = 3, | ||
| start_bucket = 2 | ||
| bucket_one_capacity = 1, -- | ||
| bucket_two_capacity = 3, -- | ||
| goal_volume = 3, -- | ||
| start_bucket = 2 -- | ||
| }), { | ||
| moves = 1, | ||
| other_bucket_volume = 0, | ||
| goal_bucket_number = 2 | ||
| moves = 1, -- | ||
| other_bucket_volume = 0, -- | ||
| goal_bucket_number = 2 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two', function() | ||
| it('measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two', | ||
| function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 2, | ||
| bucket_two_capacity = 3, | ||
| goal_volume = 3, | ||
| start_bucket = 1 | ||
| bucket_one_capacity = 2, -- | ||
| bucket_two_capacity = 3, -- | ||
| goal_volume = 3, -- | ||
| start_bucket = 1 -- | ||
| }), { | ||
| moves = 2, | ||
| other_bucket_volume = 2, | ||
| goal_bucket_number = 2 | ||
| moves = 2, -- | ||
| other_bucket_volume = 2, -- | ||
| goal_bucket_number = 2 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('measure using bucket one much bigger than bucket two', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 5, -- | ||
| bucket_two_capacity = 1, -- | ||
| goal_volume = 2, -- | ||
| start_bucket = 1 -- | ||
| }), { | ||
| moves = 6, -- | ||
| other_bucket_volume = 1, -- | ||
| goal_bucket_number = 1 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('measure using bucket one much smaller than bucket two', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 3, -- | ||
| bucket_two_capacity = 15, -- | ||
| goal_volume = 9, -- | ||
| start_bucket = 1 -- | ||
| }), { | ||
| moves = 6, -- | ||
| other_bucket_volume = 0, -- | ||
| goal_bucket_number = 2 -- | ||
| }) | ||
| end) | ||
|
Comment on lines
+83
to
107
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two tests are new |
||
|
|
||
| it('not possible to reach the goal', function() | ||
| assert.has_error(function() | ||
| two_bucket.measure({ | ||
| bucket_one_capacity = 6, | ||
| bucket_two_capacity = 15, | ||
| goal_volume = 5, | ||
| start_bucket = 1 | ||
| bucket_one_capacity = 6, -- | ||
| bucket_two_capacity = 15, -- | ||
| goal_volume = 5, -- | ||
| start_bucket = 1 -- | ||
| }) | ||
| end) | ||
| end) | ||
|
|
||
| it('with the same buckets but a different goal, then it is possible', function() | ||
| assert.are.same(two_bucket.measure({ | ||
| bucket_one_capacity = 6, | ||
| bucket_two_capacity = 15, | ||
| goal_volume = 9, | ||
| start_bucket = 1 | ||
| bucket_one_capacity = 6, -- | ||
| bucket_two_capacity = 15, -- | ||
| goal_volume = 9, -- | ||
| start_bucket = 1 -- | ||
| }), { | ||
| moves = 10, | ||
| other_bucket_volume = 0, | ||
| goal_bucket_number = 2 | ||
| moves = 10, -- | ||
| other_bucket_volume = 0, -- | ||
| goal_bucket_number = 2 -- | ||
| }) | ||
| end) | ||
|
|
||
| it('goal larger than both buckets is impossible', function() | ||
| assert.has_error(function() | ||
| two_bucket.measure({ | ||
| bucket_one_capacity = 5, | ||
| bucket_two_capacity = 7, | ||
| goal_volume = 8, | ||
| start_bucket = 1 | ||
| bucket_one_capacity = 5, -- | ||
| bucket_two_capacity = 7, -- | ||
| goal_volume = 8, -- | ||
| start_bucket = 1 -- | ||
| }) | ||
| end) | ||
| end) | ||
| end) | ||
| -- LuaFormatter on | ||
Oops, something went wrong.
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.
These empty comments force favorable formatting