-
-
Notifications
You must be signed in to change notification settings - Fork 365
Add Two Bucket Test Generator #447
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a0d0ba3
Match exercise variables with canonical data
65d8ad8
Add TwoBucket test generator
1bd02d6
Fix generated test
48b17ca
- Fix variables naming (follow .NET guidelines)
988a992
Fix class name
4f7492a
match method name to match with solution
365aac8
Fix OtherBucket variable name
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
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,68 +1,66 @@ | ||
using Xunit; | ||
// This file was auto-generated based on version 1.1.0 of the canonical data. | ||
|
||
using Xunit; | ||
|
||
public class TwoBucketTest | ||
{ | ||
[Fact] | ||
public void First_example() | ||
public void Measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_one() | ||
{ | ||
var bucketOneSize = 3; | ||
var bucketTwoSize = 5; | ||
var goal = 1; | ||
var startBucket = Bucket.One; | ||
var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket); | ||
|
||
var actual = twoBuckets.Solve(goal); | ||
|
||
Assert.Equal(4, actual.Moves); | ||
Assert.Equal(Bucket.One, actual.GoalBucket); | ||
Assert.Equal(5, actual.OtherBucketContents); | ||
var sut = new TwoBucket(3, 5, Bucket.One); | ||
var result = sut.Measure(1); | ||
Assert.Equal(4, result.Moves); | ||
Assert.Equal(5, result.OtherBucket); | ||
Assert.Equal(Bucket.One, result.GoalBucket); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Second_example() | ||
public void Measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_two() | ||
{ | ||
var bucketOneSize = 3; | ||
var bucketTwoSize = 5; | ||
var goal = 1; | ||
var startBucket = Bucket.Two; | ||
var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket); | ||
|
||
var actual = twoBuckets.Solve(goal); | ||
|
||
Assert.Equal(8, actual.Moves); | ||
Assert.Equal(Bucket.Two, actual.GoalBucket); | ||
Assert.Equal(3, actual.OtherBucketContents); | ||
var sut = new TwoBucket(3, 5, Bucket.Two); | ||
var result = sut.Measure(1); | ||
Assert.Equal(8, result.Moves); | ||
Assert.Equal(3, result.OtherBucket); | ||
Assert.Equal(Bucket.Two, result.GoalBucket); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Third_example() | ||
public void Measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_one() | ||
{ | ||
var bucketOneSize = 7; | ||
var bucketTwoSize = 11; | ||
var goal = 2; | ||
var startBucket = Bucket.One; | ||
var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket); | ||
|
||
var actual = twoBuckets.Solve(goal); | ||
|
||
Assert.Equal(14, actual.Moves); | ||
Assert.Equal(Bucket.One, actual.GoalBucket); | ||
Assert.Equal(11, actual.OtherBucketContents); | ||
var sut = new TwoBucket(7, 11, Bucket.One); | ||
var result = sut.Measure(2); | ||
Assert.Equal(14, result.Moves); | ||
Assert.Equal(11, result.OtherBucket); | ||
Assert.Equal(Bucket.One, result.GoalBucket); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Fourth_example() | ||
public void Measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_two() | ||
{ | ||
var bucketOneSize = 7; | ||
var bucketTwoSize = 11; | ||
var goal = 2; | ||
var startBucket = Bucket.Two; | ||
var twoBuckets = new TwoBuckets(bucketOneSize, bucketTwoSize, startBucket); | ||
var sut = new TwoBucket(7, 11, Bucket.Two); | ||
var result = sut.Measure(2); | ||
Assert.Equal(18, result.Moves); | ||
Assert.Equal(7, result.OtherBucket); | ||
Assert.Equal(Bucket.Two, result.GoalBucket); | ||
} | ||
|
||
var actual = twoBuckets.Solve(goal); | ||
[Fact(Skip = "Remove to run test")] | ||
public void Measure_one_step_using_bucket_one_of_size_1_and_bucket_two_of_size_3_start_with_bucket_two() | ||
{ | ||
var sut = new TwoBucket(1, 3, Bucket.Two); | ||
var result = sut.Measure(3); | ||
Assert.Equal(1, result.Moves); | ||
Assert.Equal(0, result.OtherBucket); | ||
Assert.Equal(Bucket.Two, result.GoalBucket); | ||
} | ||
|
||
Assert.Equal(18, actual.Moves); | ||
Assert.Equal(Bucket.Two, actual.GoalBucket); | ||
Assert.Equal(7, actual.OtherBucketContents); | ||
[Fact(Skip = "Remove to run test")] | ||
public void Measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3_start_with_bucket_one_and_end_with_bucket_two() | ||
{ | ||
var sut = new TwoBucket(2, 3, Bucket.One); | ||
var result = sut.Measure(3); | ||
Assert.Equal(4, result.Moves); | ||
Assert.Equal(1, result.OtherBucket); | ||
Assert.Equal(Bucket.Two, result.GoalBucket); | ||
} | ||
} |
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,49 @@ | ||
using Generators.Input; | ||
using Generators.Output; | ||
|
||
namespace Generators.Exercises | ||
{ | ||
public class TwoBucket : Exercise | ||
{ | ||
protected override void UpdateCanonicalData(CanonicalData canonicalData) | ||
{ | ||
foreach (var canonicalDataCase in canonicalData.Cases) | ||
{ | ||
canonicalDataCase.TestedMethodType = TestedMethodType.Instance; | ||
canonicalDataCase.SetConstructorInputParameters("bucket_one", "bucket_two", "start_bucket"); | ||
|
||
var start_bucket = canonicalDataCase.Properties["start_bucket"]; | ||
canonicalDataCase.Properties["start_bucket"] = new UnescapedValue(start_bucket == "two" ? "Bucket.Two" : "Bucket.One"); | ||
} | ||
} | ||
|
||
protected override string RenderTestMethodBodyAct(TestMethodBody testMethodBody) | ||
{ | ||
const string template = @"var result = {{MethodInvocation}};"; | ||
|
||
var templateParameters = new | ||
{ | ||
MethodInvocation = testMethodBody.Data.TestedMethodInvocation | ||
}; | ||
|
||
return TemplateRenderer.RenderInline(template, templateParameters); | ||
} | ||
|
||
protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) | ||
{ | ||
const string template = | ||
@"Assert.Equal({{MovesExpected}}, result.Moves); | ||
Assert.Equal({{OtherBucketExpected}}, result.OtherBucket); | ||
Assert.Equal({% if GoalBucketExpected == 'two' %}Bucket.Two{% else %}Bucket.One{% endif %}, result.GoalBucket);"; | ||
|
||
var templateParameters = new | ||
{ | ||
MovesExpected = testMethodBody.CanonicalDataCase.Expected["moves"], | ||
OtherBucketExpected = testMethodBody.CanonicalDataCase.Expected["other_bucket"], | ||
GoalBucketExpected = testMethodBody.CanonicalDataCase.Expected["goal_bucket"], | ||
}; | ||
|
||
return TemplateRenderer.RenderInline(template, templateParameters); | ||
} | ||
} | ||
} |
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.
Example.cs should be changed as well.