Skip to content

Added DifferenceOfSquares Test Generator #442

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

Closed
wants to merge 3 commits into from
Closed

Added DifferenceOfSquares Test Generator #442

wants to merge 3 commits into from

Conversation

felix91gr
Copy link
Contributor

Thank you @jpreese for the help :)

I think I'm starting understand the basics of how the Exercises framework works :D

@ErikSchierboom
Copy link
Member

@felix91gr Just to be safe: did you run the test generator project? That is, did you run dotnet run in the generators directory? You might have forgotten that, as I get a compile error when I run your branch on my machine. This compile error is due to a problem in the test generators that was just fixed on the master branch.

What you should do is to rebase your branch on the latest master and then try to run the generator again. If there is no compile error, the test generator should run. Usually, the test file generated by the newly added generator is slightly different from what it was, which I can confirm is the case once you have done the rebase and re-run the generator.

When the generated tests file is different, you have to check to see if the example and default (stub) implementation of that exercise are still correct. You can verify that my running the build script (build.ps1 or build.sh, depending on your operating system).

If you have any further questions, feel free to ask!

@felix91gr
Copy link
Contributor Author

Just to be safe: did you run the test generator project? That is, did you run dotnet run in the generators directory?

No, I didn't, I didn't know. I should've asked. What I did do was run dotnet test in the generators/Exercises/ directory.

This compile error is due to a problem in the test generators that was just fixed on the master branch.

Ohhh, I see. Thanks! I'll rebase it first then :)

If you have any further questions, feel free to ask!

I will! Thank you so much :)

@felix91gr
Copy link
Contributor Author

felix91gr commented Sep 28, 2017

I did the rebase.

But I don't know if the PR now works... this Starbucks' internet flaked out and I think NuGet needs a stable connection to work. NuGet gets invoked when I write run dotnet for some reason.
If Travis passes, it's good?

Anyhow... when I'm back home I'll fix it if it doesn't work :)

@ErikSchierboom
Copy link
Member

dotnet run indeed needs an internet connection as it is downloading the Nuget packages. Having the Travis build pass is not enough unfortunately, as it currently does not run the generators project.

Good luck fixing things and we really appreciate the help!

@felix91gr
Copy link
Contributor Author

felix91gr commented Sep 29, 2017

Now I ran dotnet run without any failures. It generated everything allright.

What should I check next before the merge?

Edit

I was re-reading your first response, and I think you already answered this question :P

You can verify that my running the build script

I'm doing so as we speak! :)

Edit 2

build.sh failed on me, but I'm really drained from today's work... so I'll continue tomorrow :)

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

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

@felix91gr Aha, progress! I can now see the updated DifferenceOfSquaresTest.cs file, so your generator is working. There are a couple of issues that cause your build to fail:

  1. By running dotnet run, all generators run and some other exercises have had their test data updated leading to update test files. The updated data could very well break the existing example. This is actually my fault, as I should have mentioned the option to run the generator for a single exercise by using the -e parameter. Hence, instead of running dotnet run, you should run dotnet run -e difference-of-squares. This will ensure that only the difference of squares test generator is being run.
    For this PR, you should remove the files not directly related to your new test generator. That means the following files should be removed: exercises/largest-series-product/LargestSeriesProductTest.cs, exercises/pig-latin/PigLatinTest.cs, exercises/sum-of-multiples/SumOfMultiplesTest.cs, generators/Exercises/Clock.cs (which should not be there due to the rebase).
  2. As you can see in the diff, the updated DifferenceOfSquaresTest.cs file expects a different API than the current implementation. Whereas previously the tested methods were part of a class named Squares, the updated API expects it to be called DifferenceOfSquares. You should rename the example and stub implementation files to match the updated class name,

With the above changes, I think your PR will be done!

@felix91gr
Copy link
Contributor Author

felix91gr commented Sep 29, 2017

I changed and tested the test generator and the tests generated. Git didn't let me work without automatically changing the files that have CRLF, replacing it with LF, so... there's that 🤔

But everything else worked just fine :)

Btw: I changed the name of the class in the test to Squares, because it better fitted the rest of the code in the exercise ^^

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

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

Ah, I see that you changed the name of the test generator class, but that won't work as the test generator name has to match the exercise name. So could you revert this back to DifferenceOfSquares? You should then modify the example and stub implementation's class names, as explained in my previous comment. Good luck!

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

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

Also, could you remove all files not related to the DifferenceOfSquares exercise from the PR?

@felix91gr
Copy link
Contributor Author

felix91gr commented Sep 29, 2017

So could you revert this back to DifferenceOfSquares?

Yeah, sure! :)

could you remove all files not related to the DifferenceOfSquares exercise from the PR?

I'm not sure. git isn't letting me go on without changing those files. I think that when they are cloned, they aren't written as-is to my machine. I try to git stash them, but nothing happens.

The problem lies within the CRLF combination (aka \r\n). I'll investigate a bit more on this. As I am now, I don't know how to commit without touching them on Linux.

@felix91gr
Copy link
Contributor Author

🤔 do we have a git attributes file? It seems we could streamline the CRLF v/s LF process with one of those :)

@ErikSchierboom
Copy link
Member

I'm off to bed now. I'll have some tips how to deal with the git issues tomorrow!

@felix91gr
Copy link
Contributor Author

Speaking of this:

as the test generator name has to match the exercise name

🤔 we might have to change the canonical-data.json file for this one.

Let me explain: using the name DifferenceOfSquares for the class isn't allowed, as the class has a member with the same name:

public static int DifferenceOfSquares(int max)
{
    throw new NotImplementedException("You need to implement this function.");
}

With the class being named the same as this method, I get the following error while running build.sh:

DifferenceOfSquares.cs(19,23): error CS0542: 'DifferenceOfSquares': member names cannot be the same as their enclosing type [/home/felix/Documents/Programming/exercism/csharp/build/difference-of-squares/DifferenceOfSquares.csproj]

And if I have understood the framework correctly, the method name can't change unless the property name described in the canonical-data.json file changes as well.

What do you think? Should we keep the Tester Generator being named Squares, or should we modify the canonical data file?

@ErikSchierboom
Copy link
Member

ErikSchierboom commented Sep 30, 2017

What do you think? Should we keep the Tester Generator being named Squares, or should we modify the canonical data file?

Excellent question. In general, we never modify the canonical data itself (which we don't control), we just modify our internal representation (which we do control). An example of this is the test generator for the leap exercise, which changes the tested method to a different name by overriding the UpdateCanonicalData method:

public class Leap : Exercise
{
    protected override void UpdateCanonicalData(CanonicalData canonicalData)
    {
        foreach (var canonicalDataCase in canonicalData.Cases)
            canonicalDataCase.Property = "IsLeapYear";
    }
}

I think in our case we have two options:

  1. Use a different name for the class (e.g. Squares). However, I would then also would like the test file named SquaresTests, which would require a modification to the generator framework.
  2. Use a different for the tested method. I'm in favor of this option, where we rename the tested method from DifferenceOfSquares to CalculateDifferenceOfSquares (and I think we should then also change SumOfSquares to CalculateSumOfSquares).

If you agree with me and go for option 2, you should be able to do this using the same approach used in the Leap exercise (as shown above)

do we have a git attributes file? It seems we could streamline the CRLF v/s LF process with one of those :)

We do have a .gitattributes file, and I thought that this worked well on my Mac. I'll have to check another time.

I'm not sure. git isn't letting me go on without changing those files. I think that when they are cloned, they aren't written as-is to my machine. I try to git stash them, but nothing happens.

You shouldn't change the files themselves, you should just use git to revert them to their original version. You can do this using git checkout, but you should first make sure you are up to date with the latest version of this repository. So we'll start with doing that:

git remote add exercism https://github.com/exercism/csharp
git fetch exercism
git rebase exercism/master

You can skip the first line if you already have add the exercism remote.

We then reset the files we don't want to the version in the exercism remote:

git checkout exercism/master exercises/largest-series-product/Example.cs
git checkout exercism/master exercises/largest-series-product/LargestSeriesProductTest.cs
git checkout exercism/master generators/Exercises/Clock.cs
git add exercises/largest-series-product/Example.cs
git add exercises/largest-series-product/LargestSeriesProductTest.cs
git add generators/Exercises/Clock.cs
git commit --amend
git push --force

This should remove the changes in those files from your PR. As long as you never run dotnet run, but always run dotnet run -e difference-of-squares, those changes will not come back.

@felix91gr
Copy link
Contributor Author

(...) If you agree with me and go for option 2 (...)

Awesome explanation! I get it better now, and I completely agree. I'll do that.

We do have a .gitattributes file,

Hmm. It looks like the eol for * files isn't predefined. That might be the problem. One of the commits in the repo's history put CRLF endings in these two files, or something like that:

~/D/P/exercism $ git clone https://github.com/exercism/csharp/ csharp_original
# blablabla
~/D/P/exercism $ cd csharp_original/
~/D/P/e/csharp_original (master) $ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   exercises/largest-series-product/Example.cs
	modified:   exercises/largest-series-product/LargestSeriesProductTest.cs

no changes added to commit (use "git add" and/or "git commit -a")
~/D/P/e/csharp_original (master) $ git add .
warning: CRLF will be replaced by LF in exercises/largest-series-product/Example.cs.
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in exercises/largest-series-product/LargestSeriesProductTest.cs.
The file will have its original line endings in your working directory.

Git's messages are a bit ambiguous here. But I think I'm understanding them allright 🤔

The CRLF endings must be messing with my computer, which has Git set it to default to LF. I think we might be better off picking a default line ending, and saying goodbye to this problem once and for all 🤔

What do you think?

@ErikSchierboom
Copy link
Member

I think we might be better off picking a default line ending, and saying goodbye to this problem once and for all

@robkeim @jpreese What do you think? Should we just use \n as the line endings?

@jpreese
Copy link
Contributor

jpreese commented Oct 2, 2017

As long as we choose one, for consistency, I don't really think it matters. https://help.github.com/articles/dealing-with-line-endings/

@ErikSchierboom
Copy link
Member

@felix91gr Okay, we'll solve the git issue in another issue. Could you cleanup this PR as requested (to remove the extra files)?

@felix91gr
Copy link
Contributor Author

felix91gr commented Oct 2, 2017 via email

@robkeim
Copy link
Contributor

robkeim commented Oct 2, 2017

@ErikSchierboom - I'm with @jpreese and as long as we have consistent way of doing things that sounds good to me! I use Windows and every editor that I know renders \n correctly these days so I don't see any potential concerns from people trying to contribute on Windows if we go that direction.

@ErikSchierboom
Copy link
Member

I've created an issue for the line-ending issue: #452

@jpreese
Copy link
Contributor

jpreese commented Oct 10, 2017

Did you need any help with this @felix91gr ?

@felix91gr
Copy link
Contributor Author

felix91gr commented Oct 10, 2017 via email

@felix91gr
Copy link
Contributor Author

I deleted my fork and started over again. I will link to this PR as reference from a new PR

@felix91gr felix91gr closed this Oct 10, 2017
@jpreese
Copy link
Contributor

jpreese commented Oct 10, 2017

You can push your changes to the same branch -- no need to close and open a new PR.

@felix91gr
Copy link
Contributor Author

Yeah... but I messed up too many things:

  • Used master instead of a new branch
  • Merged progress made in exercism/csharp/master and put it as my commit
  • Made spurious commits with my deprecated git

I get what you mean. But I really would prefer to start this one again clean.

felix91gr added a commit to felix91gr/csharp that referenced this pull request Oct 11, 2017
- Changed name of class for exercise from Squares to DifferenceOfSquares, as per the standards
- Changed names of methods generated in tests to fit restrictions of naming in C# (see PR exercism#442)
- Changed names of methods required in exercise to fit new names generated in tests
felix91gr added a commit to felix91gr/csharp that referenced this pull request Oct 11, 2017
- Changed name of class for exercise from Squares to DifferenceOfSquares, as per the standards
- Changed names of methods generated in tests to fit restrictions of naming in C# (see PR exercism#442)
- Changed names of methods required in exercise to fit new names generated in tests
felix91gr added a commit to felix91gr/csharp that referenced this pull request Oct 11, 2017
- Changed name of class for exercise from Squares to DifferenceOfSquares, as per the standards
- Changed names of methods generated in tests to fit restrictions of naming in C# (see PR exercism#442)
- Changed names of methods required in exercise to fit new names generated in tests
felix91gr added a commit to felix91gr/csharp that referenced this pull request Oct 11, 2017
- Changed name of class for exercise from Squares to DifferenceOfSquares, as per the standards
- Changed names of methods generated in tests to fit restrictions of naming in C# (see PR exercism#442)
- Changed names of methods required in exercise to fit new names generated in tests
ErikSchierboom pushed a commit that referenced this pull request Oct 11, 2017
- Changed name of class for exercise from Squares to DifferenceOfSquares, as per the standards
- Changed names of methods generated in tests to fit restrictions of naming in C# (see PR #442)
- Changed names of methods required in exercise to fit new names generated in tests
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.

4 participants