Skip to content

Simplify generators#302

Merged
robkeim merged 22 commits intoexercism:masterfrom
ErikSchierboom:refactoring-generators
Jun 22, 2017
Merged

Simplify generators#302
robkeim merged 22 commits intoexercism:masterfrom
ErikSchierboom:refactoring-generators

Conversation

@ErikSchierboom
Copy link
Copy Markdown
Member

This is the first step in refactoring the test generators. The aim is to make it really, really simple. In this PR, we default to using all the non-default properties as input properties. In a future PR I would like to get rid of the virtual methods as much as possible. Why not use constructor parameters instead, or otherwise use properties that can be set in the constructor?

I've also used used @robkeim's suggestion of losing the "Exercise" postfix for the exercises.

@ErikSchierboom ErikSchierboom requested a review from robkeim June 12, 2017 13:44
Comment thread generators/Exercises/Acronym.cs Outdated
{
public class Acronym : EqualityExercise
{
public Acronym() : base("acronym")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another potential simplification would be to generate the exercise name from the Class name using reflection. The rules are pretty simple:

  1. Acronym -> acronym
  2. NthPrime -> nth-prime

You could argue it actually makes the code more obscure but it's some food for thought :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! The PR has been updated. Don't merge it yet, as there is still a problem with the multi-line formatting in beer-song. I think that's the next thing I want to get right: figuring out how to best configure how the output is formatted.

@ErikSchierboom ErikSchierboom changed the title Simplify generators [WIP] Simplify generators Jun 12, 2017
Comment thread generators/Exercises/Exercise.cs Outdated
Index = index,
Options = CreateTestMethodOptions(canonicalData, canonicalDataCase, index)
};
if (testMethodData.Options.TestedMethodType == TestedMethodType.BooleanComparison)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: To future proof this you may want to have a switch with the two types existing today and then throw an exception for the default. That way if we need to add a new type in the future it's clear where it needs to be plumbed through to.

Copy link
Copy Markdown
Member Author

@ErikSchierboom ErikSchierboom Jun 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this!

edit: I have to modify it slightly, as the expection must be tested before the switch

case TestedMethodFormat.Static:
return new[] { $"{Assertion}({TestedClassName}.{TestedMethodName}({Input}));" };
case TestedMethodFormat.Instance:
return new[] { $"var sut = new {TestedClassName}();", $"{Assertion}(sut.{TestedMethodName}({Input}));" };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is sut?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It stands for "system under test" and is common jargon in some test frameworks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, you learn something new everyday!

if (lines.Length == 1)
return lines[0];

return "\n" + string.Join("\n", lines.Select(line => $"{line}"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between what you have an line => line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it used to have tabs! I'll fix it.

Comment thread generators/Output/TestedMethodFormat.cs Outdated
{
public enum TestedMethodFormat
{
Static = 0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: no need to start with 0 as it's the default

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same below

Copy link
Copy Markdown
Contributor

@robkeim robkeim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted offline about this and it looks great @ErikSchierboom! Once you've got the beer-song bug fixed either you can merge or if you'd like me to look at the finishing touches I'd be happy to do that and merge as well.

@ErikSchierboom
Copy link
Copy Markdown
Member Author

@robkeim I've made some further simplifications that I think turned out quite nice :) There are two major open points left:

  • Better handle large expected values (by introducing a variable)
  • Better handle large strings (by concatenating them over multiple lines)
  • Fix the failing tests (which are due to namespace issues)

Copy link
Copy Markdown
Contributor

@robkeim robkeim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @ErikSchierboom!

@ErikSchierboom ErikSchierboom changed the title [WIP] Simplify generators Simplify generators Jun 22, 2017
@ErikSchierboom
Copy link
Copy Markdown
Member Author

@robkeim I've updated the PR and I am happy with the end result. Let me know how you feel!

@robkeim
Copy link
Copy Markdown
Contributor

robkeim commented Jun 22, 2017

Excellent work @ErikSchierboom, thanks for the hard work!

@robkeim robkeim merged commit 5854b9b into exercism:master Jun 22, 2017
@ErikSchierboom ErikSchierboom deleted the refactoring-generators branch August 3, 2017 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants