Class: Emendate::Examples::ExampleSet

Inherits:
Object
  • Object
show all
Includes:
Taggable
Defined in:
lib/emendate/examples/example_set.rb

Overview

Holder for a list of TestableExamples, with some convenience

methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Taggable

#set_up_tags, #tags_to_s

Constructor Details

#initialize(data_sets: "", date_types: "", rows: nil) ⇒ ExampleSet

Returns a new instance of ExampleSet.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/emendate/examples/example_set.rb', line 16

def initialize(data_sets: "", date_types: "", rows: nil)
  @rows = rows || Examples::RowSet.new(data_sets: data_sets,
    date_types: date_types)
    .rows
    .sort_by do |row|
    row.dateval_occurrence
  end

  set_up_tags(data_sets, date_types)

  @examples = @rows.group_by { |row| row.test_fingerprint }
    .values
    .map { |rows| Examples::TestableExample.new(rows) }
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



14
15
16
# File 'lib/emendate/examples/example_set.rb', line 14

def examples
  @examples
end

Instance Method Details

#all_tagsObject



31
32
33
# File 'lib/emendate/examples/example_set.rb', line 31

def all_tags
  examples.map(&:all_tags).flatten.uniq.sort
end

#by_type_pattern(date_only: false, stage: :tokens) ⇒ Object



35
36
37
38
39
40
# File 'lib/emendate/examples/example_set.rb', line 35

def by_type_pattern(date_only: false, stage: :tokens)
  examples.group_by do |example|
    example.type_pattern(date_only: date_only, stage: stage)
  end
    .sort_by { |pattern, data| pattern }
end

#failuresObject



42
43
44
# File 'lib/emendate/examples/example_set.rb', line 42

def failures
  grouped_by_test_status[:failure]
end

#get_example_data(data_method:, examples_method: :examples) ⇒ Object

Parameters:

  • data_method (Symbol)

    name of method to call on each TestableExample to get data

  • examples_method (Symbol) (defaults to: :examples)

    name of a method that returns Array of TestableExamples



50
51
52
53
54
55
# File 'lib/emendate/examples/example_set.rb', line 50

def get_example_data(data_method:, examples_method: :examples)
  exobjs = send(examples_method)
  return [] if exobjs.empty?

  exobjs.map(&data_method).uniq.sort
end

#not_runObject



57
58
59
# File 'lib/emendate/examples/example_set.rb', line 57

def not_run
  grouped_by_test_status[:no_tests_run]
end

#report_failuresObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/emendate/examples/example_set.rb', line 61

def report_failures
  return unless failures
  return if failures.empty?

  puts "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
  puts "FAILURES"
  puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
  failures.each { |failure| failure.report_failure }
  ""
end

#report_fingerprint(type) ⇒ Object

Parameters:

  • type (:successes, :not_run)


73
74
75
76
77
78
79
80
81
82
# File 'lib/emendate/examples/example_set.rb', line 73

def report_fingerprint(type)
  array = send(type)
  return if array.blank?

  puts "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
  puts type.to_s.upcase
  puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
  puts get_example_data(examples_method: type, data_method: :fingerprint)
  ""
end

#report_type_patterns(date_only: false, stage: :tokens) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/emendate/examples/example_set.rb', line 84

def report_type_patterns(date_only: false, stage: :tokens)
  by_type_pattern(date_only: date_only,
    stage: stage).each do |pattern, exset|
    puts pattern.inspect
    exset.each { |ex| puts "  #{ex.fingerprint}" }
  end

  puts "\n#{failures.length} examples could not be parsed" if failures
end

#run_tests(tests: nil, fail_fast: false, mode: :normal) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/emendate/examples/example_set.rb', line 107

def run_tests(tests: nil, fail_fast: false, mode: :normal)
  to_run = tests ? tests.intersection(runnable_tests) : runnable_tests
  examples.each do |example|
    example.run_tests(tests: to_run, fail_fast: fail_fast, mode: mode)
  end
  report_fingerprint(:successes)
  report_fingerprint(:not_run)
  report_failures
  puts summary
end

#runnable_testsObject



118
119
120
# File 'lib/emendate/examples/example_set.rb', line 118

def runnable_tests
  @runnable_tests ||= determine_runnable_tests
end

#successesObject



122
123
124
# File 'lib/emendate/examples/example_set.rb', line 122

def successes
  grouped_by_test_status[:success]
end

#summaryObject



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/emendate/examples/example_set.rb', line 94

def summary
  puts "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
  puts "SUMMARY"
  puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"

  str = %i[successes failures not_run].map { |meth| [meth, send(meth)] }
    .to_h
    .compact
    .map { |meth, vals| "#{vals.length} #{meth}" }
    .join(" -- ")
  puts str
end

#tags(type) ⇒ Object

Parameters:

  • type ('data_set', 'date_type')


127
128
129
# File 'lib/emendate/examples/example_set.rb', line 127

def tags(type)
  examples.map { |example| example.tags(type) }.flatten.uniq.sort
end

#to_sObject Also known as: inspect



138
139
140
141
142
# File 'lib/emendate/examples/example_set.rb', line 138

def to_s
  # rubocop:todo Layout/LineLength
  "#{self.class.name}: #{examples.length} examples from #{rows.length} rows #{tags_to_s}"
  # rubocop:enable Layout/LineLength
end

#type_patterns(date_only: false, stage: :tokens) ⇒ Object



131
132
133
134
135
136
# File 'lib/emendate/examples/example_set.rb', line 131

def type_patterns(date_only: false, stage: :tokens)
  by_type_pattern(date_only: date_only, stage: stage).keys.each do |key|
    puts key.inspect
  end
  ""
end