-
Notifications
You must be signed in to change notification settings - Fork 3
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
test generattion #22
Comments
génére 8000~ tests |
comment faire mieux : liste de wide interval, liste d'intervals/state puis combo en gerant que si wide_interval.second.equal || contain wide_interval.first, alors overwrite |
@products = []
wide_intervals = ['', '2030', '2030 week 1', '2030 week 1,3', '2030 week 1,3,10-30', '2030 week 1,3,10-30/2',
'2030 week 1,3,10-30/2,50', 'week 1', 'week 1,3', 'week 1,3,10-30', 'week 1,3,10-30/2', 'week 1,3,10-30/2,50',
'2030 Jan 01-31', '2030 Jan 01-2030 Jun 30', '2030 Jan 01-2050 Jun 30', '2030 Jan 10-2050 Jun 30', '2030-2050', 'Jan', 'Jan-Jun', 'Jan 10-Jun 30']
weekdays = ['', 'Mo', 'Mo,We-Fr,Su', 'Mo-We,Fr,Sa', 'PH', 'PH,Mo,We-Fr', 'Mo[1]', 'Su[-1]', 'We[2]']
weekdays = ['', 'Mo', 'Mo,We-Fr,Su', 'Mo-We,Fr,Sa', 'PH', 'PH,Mo,We-Fr']
hours_and_modifiers = ['10:00-20:00', 'off', '23:00-3:00', '9:00-12:30,14:00-18:30']
hours_and_modifiers = ['10:00-20:00', 'off', '09:00-12:30,14:00-18:30']
comments = ["", "\"commentaire\"", "\"commentaire avec des espaces\""]
possibilities = wide_intervals.product(weekdays, hours_and_modifiers, comments).map { |p| p.join(' ').gsub(' ', ' ').strip }
passing = possibilities.select { |oh| @builder.build(@parser.parse(oh)) == oh }
not_passing = possibilities - passing
File.open('spec/automaticaly_generated_no_combo_parser_passing_spec.rb', 'w') do |f|
f.write("require 'opening_hours_converter'\n\nRSpec.describe OpeningHoursConverter::OpeningHoursParser, '#parse' do\n")
f.write(passing.map do |oh|
" it '#{oh}' do\n expect(OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse('#{oh}'))).to eql('#{oh}')\n end\n"
end.join)
f.write('end')
end
File.open('spec/automaticaly_generated_no_combo_parser_not_passing_spec.rb', 'w') do |f|
f.write("require 'opening_hours_converter'\n\nRSpec.describe OpeningHoursConverter::OpeningHoursParser, '#parse' do\n")
f.write(not_passing.map do |oh|
" it '#{oh}' do\n expect(OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse('#{oh}'))).to eql('#{oh}')\n # #{OpeningHoursConverter::OpeningHoursBuilder.new.build(OpeningHoursConverter::OpeningHoursParser.new.parse(oh))}\n end\n"
end.join)
f.write('end')
end |
Would it not make more sense to have an "opening-hours-strings.txt" and fill that with edge-cases, and common cases, then have one test iterate over all the lines and check if we can parse it successfully? Or is this code attempting something different? |
The aim of this was to generate all the non edge case specs. For the edge case, I add them one by one in https://github.com/Publidata/opening_hours_converter/blob/master/spec/opening_hours_parser_spec.rb It's not too readable and a txt file would make that better but I wonder if it wouldn't make it harder to determine what line broke if a test fail. There is also the fact that if you build(parse(oh)) the resulting string can be modified while still being valid For example build(parse('Jan: 10:00-11:00')) => 'Jan 10:00-11:00' or build(parse('Mo,Tu,We 10:00-11:00')) => 'Mo-We 10:00-11:00' In the generated exemples I avoided all the case where the output will be different. |
The text was updated successfully, but these errors were encountered: