Class: Rant::Property
- Inherits:
-
Object
- Object
- Rant::Property
- Defined in:
- lib/rant/check.rb
Instance Method Summary collapse
- #check(n = 100, limit = 10, &assertion) ⇒ Object
-
#initialize(property) ⇒ Property
constructor
A new instance of Property.
- #report ⇒ Object
Constructor Details
#initialize(property) ⇒ Property
Returns a new instance of Property.
7 8 9 |
# File 'lib/rant/check.rb', line 7 def initialize(property) @property = property end |
Instance Method Details
#check(n = 100, limit = 10, &assertion) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rant/check.rb', line 11 def check(n=100,limit=10,&assertion) i = 0 test_data = nil begin Rant.singleton.generate(n,limit,@property) do |val| test_data = val assertion.call(val) if assertion puts "" if i % 100 == 0 print "." if i % 10 == 0 i += 1 end puts puts "success: #{i} tests" rescue Rant::TooManyTries => e puts puts "too many tries: #{e.tries}" raise e rescue => boom puts puts "failure: #{i} tests, on:" pp test_data raise boom end end |
#report ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rant/check.rb', line 36 def report distribs = self.classifiers.sort { |a,b| b[1] <=> a[1] } total = distribs.inject(0) { |sum,pair| sum + pair[1]} distribs.each do |(classifier,count)| format "%10.5f%% of => %s", count, classifier end end |