Skip to content

All generators use common interface #463

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

Conversation

bmulvihill
Copy link
Contributor

@bmulvihill bmulvihill commented Oct 18, 2016

Finishes #452
Starts the work of creating a common interface. This PR attempts to standardize 3 public methods

  • test_name - The method will output the name of the test

  • workload - This method will output the body of the test

  • skipped - This method will output skip syntax

    I ran all the generators locally and they appear to be working as intended. Once this gets standardized, we may be able to utilize a single example.tt file.

Future ideas:

  • Utilize a single example.tt for all generated tests
  • Implement some sort of Generator abstract class/module (Generatable?) where subclasses are required to implement two methods: test_name && workload. We can then move common methods i.e. skipped into this class/module

@kotp
Copy link
Member

kotp commented Oct 18, 2016

Quick visual scan says "YAY!"

@@ -0,0 +1 @@
2.3.0
Copy link
Contributor

Choose a reason for hiding this comment

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

This file probably shouldn't be updated as part of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops! yeah I'll remove this

def do
defined?(name) ? "HelloWorld.hello('#{name}')" : 'HelloWorld.hello'
def work_load
assertion =
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you extract this to a method?

@@ -8,15 +8,15 @@ def do
"TwoBucket.new(#{bucket_one}, #{bucket_two}, #{goal}, '#{start_bucket}')"
end

def test_body
def work_load
"two_bucket = #{self.do}
assert_equal #{expected['moves']}, two_bucket.moves
assert_equal '#{expected['goal_bucket']}', two_bucket.goal_bucket
assert_equal #{expected['other_bucket']}, two_bucket.other_bucket"
Copy link
Contributor

@Insti Insti Oct 18, 2016

Choose a reason for hiding this comment

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

I'd like to see work_load itself not have to be responsible for whitespace/indenting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I tried not to do too much refactoring though and keep the scope of this PR narrow - just focusing and getting the API in place

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, that's sensible.

@Insti
Copy link
Contributor

Insti commented Oct 18, 2016

The first one I tried bin/generate acronym didn't work correctly. 😞
The test methods had no names.

@Insti
Copy link
Contributor

Insti commented Oct 18, 2016

The way to test this would be to regenerate all the test files and ensure that the output was identical to the old versions.

@bmulvihill
Copy link
Contributor Author

@Insti I did regenerate all of them locally, but obviously I missed something 🙂, Ill fix it in my next push!

@bmulvihill
Copy link
Contributor Author

@Insti @kotp Made some additional changes, its a lot of files so hopefully I haven't missed anything else. As mentioned above I tried not to do any refactoring and just implement the API.

@kotp
Copy link
Member

kotp commented Oct 18, 2016

I just tried to do the generate on word-count as it is on #448 which is rebased on master since #451 has been brought in, getting errors there as well. In that case, it is due to single quotes inside of strings that have single quotes as the delimiters. (That is of course the first cause, once fixed the other errors may fix, I did not look that closely)

Of course, this may not reflect work done on this PR, since this is not in master yet.

@Insti
Copy link
Contributor

Insti commented Oct 19, 2016

@bmulvihill the conversions are still very broken. I think you need to go through them all individually and check that the new generated file is the same as the old one.

Both of the ones I "randomly" looked at: leap, acronym were very broken.
Running: rubocop exercises will detect syntax errors in the files.

Maybe it would be better to split this PR into smaller PRs that look at each generator individually?

@Insti
Copy link
Contributor

Insti commented Oct 19, 2016

I'd like to see a PR with some documentation of what the common interface is, you've given a good summary in the OP here, but it probably belongs in the README.md

@Insti
Copy link
Contributor

Insti commented Oct 19, 2016

I'd rather work_load be renamed workload if that's the name we're going with.

'work' and 'load' are 2 words with many different meanings, 'workload' is one word with a more specific meaning.

My but preference for name would be assertion which would make the generic template:

  def <%= test_case.test_name %>
    <%= test_case.skipped %>
    <%= test_case.assertion %>
  end

@Insti
Copy link
Contributor

Insti commented Oct 19, 2016

Those last 2 probably should be separate issues so that they can be discussed individually.

I really appreciate the effort you're putting into this @bmulvihill ❤️ and agree that it is an important thing to work on, so if we're going to do a lot of work getting it right, we should try to make sure we're doing the right thing and I want to try to help that be as easy as possible.

@bmulvihill
Copy link
Contributor Author

bmulvihill commented Oct 19, 2016

@Insti I agree with the name assertion over work_load, I believe in the original issue work_load was suggested. Another name which might make more sense is test_body, since it could technically include more than just an assertion.

I can make that change if you want and add a README update to this PR, since I think that makes sense. I will also go back through each generator and compare outputs.

@Insti
Copy link
Contributor

Insti commented Oct 19, 2016

@kotp, @bmulvihill is there anywhere other than #452 where naming was discussed?

test_body [...] it could technically include more than just an assertion.

Good point. I'd prefer just body over test_body since the test_ prefix is redundant.

  def <%= test_case.test_name %>
    <%= test_case.skipped %>
    <%= test_case.body %>
  end

Either that or go fully prefixed to try and avoid the situation where one of the json files in the future has a property called 'skipped' or 'body', or 'test_body'

  def <%= test_case.test_case_name %>
    <%= test_case.test_case_skipped %>
    <%= test_case.test_case_body %>
  end

But that seems a bit redundant.

I guess we could discuss it forever.

As the person making the PR you have the power to decide what you call it 😉 so choose what you think is best.

@kotp
Copy link
Member

kotp commented Oct 19, 2016

I do prefer the one word workload as it is a single word, and means what it says.

Here is where any mention of workload or work_load was discussed or mentioned.

@bmulvihill
Copy link
Contributor Author

@Insti @kotp I went back through each exercise and generated/ran the tests and everything appears to be working. What I hadn't done before, which I should have, was actually run the tests for each newly generated file. I also renamed work_load to body.

@kotp
Copy link
Member

kotp commented Oct 20, 2016

The name "body" I think in the discussions that we did have was determined to be too generic. Body of what? I think this was an important reason why workload or work_load was finally chosen. I can't look at the discussions right now, but I hope you did at least scan through them via the link I gave, if so, you could verify, better than I can at the moment.

I can't find it at the moment though, even with that search.

@bmulvihill
Copy link
Contributor Author

@kotp I scanned through the discussions, but nothing jumped out at me besides ours and one where @kytrinyx mentioned work_load. Its an easy switch to workload if you find that more descriptive, I think consistency is the most important thing here

@Insti
Copy link
Contributor

Insti commented Oct 20, 2016

I looked through that search result and also couldn't find any discussion on naming.
If we need to compromise, I'm OK with using workload

@kotp
Copy link
Member

kotp commented Oct 20, 2016

I would go with what @kytrinyx mentioned, because it is likely to be the same in other tracks.

@bmulvihill
Copy link
Contributor Author

@Insti @kotp This has been rebased, and the method has been renamed to workload - I also added in the two new generators that have been added since this opened, word-count and anagram

@kotp
Copy link
Member

kotp commented Oct 21, 2016

I think I sent you a message on Gitter @bmulvihill Let me know if you can't get to it.

Can you look at this error, when I generated all files, ran make to run the tests (and this takes a while due to alphametics) but got this error.

running tests for: alphametics
Run options: --seed 62490

# Running:

.F.....

Finished in 306.960573s, 0.0228 runs/s, 0.0228 assertions/s.

  1) Failure:
AlphameticsTest#test_solve_puzzle_with_many_words [/tmp/alphametics.7i3sjoNLoE/alphametics_test.rb:60]:
--- expected
+++ actual
@@ -1 +1 @@
-{"A"=>5, "D"=>3, "E"=>4, "F"=>7, "G"=>8, "N"=>0, "O"=>2, "R"=>1, "S"=>6, "T"=>9}
+nil


7 runs, 7 assertions, 1 failures, 0 errors, 0 skips

@bmulvihill
Copy link
Contributor Author

@kotp That test is currently commented out - and when I run it prior to these changes it fails the same way

@kotp
Copy link
Member

kotp commented Oct 21, 2016

Alright. I will look into it more tonight. Wonder why it tests if it is commented out.

@bmulvihill
Copy link
Contributor Author

@kotp I think maybe the tests were manually commented out, so when it was regenerated it doesn't have the comments

@Insti
Copy link
Contributor

Insti commented Oct 21, 2016

tests were manually commented out

I think this is quite likely.

The generator needs to be updated to do the commenting out itself.

@kotp
Copy link
Member

kotp commented Oct 22, 2016

Yep, I think we hit this before, where we would have to manually comment them out, which is not something I think we should have to remember to do. Unfortunately, there is nothing in the canonical to indicate these are "long running tests" to help to programmatically trigger this commenting behavior.

@Insti
Copy link
Contributor

Insti commented Oct 22, 2016

It is possible to detect and special case them in the *_cases.rb file though.

@bmulvihill
Copy link
Contributor Author

@Insti @kotp I updated the README as well. As far as programmatically triggering the comments, I believe that should be a different PR, do you agree?

@Insti Insti mentioned this pull request Oct 23, 2016
@Insti
Copy link
Contributor

Insti commented Oct 24, 2016

@bmulvihill it probably is a different PR, but it needs to happen before this one can be merged as the tests need to run at a reasonable speed.

@bmulvihill
Copy link
Contributor Author

@Insti hmmm ok - I'll take a look at that

@Insti
Copy link
Contributor

Insti commented Oct 24, 2016

@bmulvihill I'm currently working on the alphametics generator.

@Insti
Copy link
Contributor

Insti commented Oct 24, 2016

Alphametics generator: #469

@bmulvihill
Copy link
Contributor Author

@Insti @kotp Im going to close this PR - I think since the README is updated and the generator implementation is still kind of up in the air we can tackle this on a smaller scale

@bmulvihill bmulvihill closed this Dec 7, 2016
@Insti
Copy link
Contributor

Insti commented Dec 7, 2016

@bmulvihill fine, thanks for getting us going on this. It started a lot of useful discussion.

I need to find some time to work on my new generator branch again.

@Insti Insti removed the in progress label May 19, 2017
@Insti Insti removed the ready label Jun 8, 2017
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.

3 participants