flog 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,15 @@
1
+ === 4.1.0 / 2013-05-10
2
+
3
+ * 3 minor enhancements:
4
+
5
+ * Cleaned up tests by adding assert_hash_in_epsilon. yay!
6
+ * Fixed method_location is now cleared on #reset. (makaroni4)
7
+ * to_proc_normal is now penalized based on RUBY_VERSION. Scores were benchmarked.
8
+
9
+ * 1 bug fix:
10
+
11
+ * Fixed code/home urls in readme/gem.
12
+
1
13
  === 4.0.0 / 2013-04-18
2
14
 
3
15
  * 1 major enhancement:
data/README.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  = flog
2
2
 
3
3
  home :: http://ruby.sadi.st/
4
- repo :: https://github.com/seattlerb/flog
4
+ code :: https://github.com/seattlerb/flog
5
5
  rdoc :: http://seattlerb.rubyforge.org/flog
6
6
 
7
7
  == DESCRIPTION:
@@ -11,7 +11,7 @@ class File
11
11
  end
12
12
 
13
13
  class Flog < SexpProcessor
14
- VERSION = "4.0.0" # :nodoc:
14
+ VERSION = "4.1.0" # :nodoc:
15
15
 
16
16
  ##
17
17
  # Cut off point where the report should stop unless --all given.
@@ -42,7 +42,16 @@ class Flog < SexpProcessor
42
42
  :super => 1,
43
43
  :to_proc_icky! => 10,
44
44
  :to_proc_lasgn => 15,
45
- :to_proc_normal => 5,
45
+ :to_proc_normal => case RUBY_VERSION
46
+ when /^1\.8\.7/ then
47
+ 2
48
+ when /^1\.9/ then
49
+ 1.5
50
+ when /^2\.[01]/ then
51
+ 1
52
+ else
53
+ 5
54
+ end,
46
55
  :yield => 1,
47
56
  }
48
57
 
@@ -330,11 +339,12 @@ class Flog < SexpProcessor
330
339
  # Reset score data
331
340
 
332
341
  def reset
333
- @totals = @total_score = nil
334
- @multiplier = 1.0
335
- @calls = Hash.new { |h,k| h[k] = Hash.new 0 }
336
- @method_scores = Hash.new { |h,k| h[k] = [] }
337
- @scores = Hash.new 0
342
+ @totals = @total_score = nil
343
+ @multiplier = 1.0
344
+ @calls = Hash.new { |h,k| h[k] = Hash.new 0 }
345
+ @method_scores = Hash.new { |h,k| h[k] = [] }
346
+ @scores = Hash.new 0
347
+ @method_locations = {}
338
348
  end
339
349
 
340
350
  ##
@@ -190,11 +190,19 @@ class TestFlog < FlogTest
190
190
  s(:block_pass,
191
191
  s(:call, nil, :b)))
192
192
 
193
- util_process(sexp, 9.4,
193
+ bonus = case RUBY_VERSION
194
+ when /^1\.8\.7/ then 0.4
195
+ when /^1\.9/ then 0.3
196
+ when /^2\.[01]/ then 0.2
197
+ end
198
+
199
+ bonus += Flog::OTHER_SCORES[:to_proc_normal]
200
+
201
+ util_process(sexp, 3.4 + bonus,
194
202
  :a => 1.0,
195
203
  :block_pass => 1.2,
196
204
  :b => 1.2,
197
- :to_proc_normal => 6.0)
205
+ :to_proc_normal => 0.0 + bonus)
198
206
  end
199
207
 
200
208
  def test_process_block_pass_colon2
@@ -559,6 +567,14 @@ class TestFlog < FlogTest
559
567
  assert_equal 16.0, @flog.max_score
560
568
  end
561
569
 
570
+ def assert_hash_in_epsilon exp, act
571
+ assert_equal exp.keys.sort_by(&:to_s), act.keys.sort_by(&:to_s)
572
+
573
+ exp.keys.each do |k|
574
+ assert_in_epsilon exp[k], act[k], 0.001, k
575
+ end
576
+ end
577
+
562
578
  def util_process sexp, score = -1, hash = {}
563
579
  setup
564
580
  @flog.process sexp
@@ -567,13 +583,16 @@ class TestFlog < FlogTest
567
583
  @meth ||= "#none"
568
584
 
569
585
  unless score != -1 && hash.empty? then
570
- exp = {"#{@klass}#{@meth}" => hash}
571
- assert_equal exp, @flog.calls
586
+ key = "#{@klass}#{@meth}"
587
+ act = @flog.calls
588
+
589
+ assert_equal [key], act.keys.sort
590
+ assert_hash_in_epsilon hash, act[key]
572
591
  end
573
592
 
574
593
  @flog.calculate_total_scores
575
594
 
576
- assert_in_delta score, @flog.total_score
595
+ assert_in_epsilon score, @flog.total_score
577
596
  end
578
597
 
579
598
  def test_threshold
@@ -596,6 +615,50 @@ class TestFlog < FlogTest
596
615
  assert_equal({ 'MyKlass' => [["MyKlass::Base#mymethod", 42.0]] }, @flog.method_scores)
597
616
  end
598
617
 
618
+ def test_reset
619
+ user_class = %(
620
+ class User
621
+ def blah n
622
+ puts "blah" * n
623
+ end
624
+ end
625
+ )
626
+ user_file = "user.rb"
627
+
628
+ @flog.flog_ruby user_class, user_file
629
+ @flog.calculate_total_scores
630
+ @flog.calculate
631
+
632
+ assert_equal({ 'User#blah' => 'user.rb:3' }, @flog.method_locations)
633
+ assert_equal({ "User#blah" => 2.2 }, @flog.totals)
634
+ assert_equal(2.2, @flog.total_score)
635
+ assert_equal(1.0, @flog.multiplier)
636
+ assert_equal({ "User#blah" => { :* => 1.2, :puts => 1.0 } }, @flog.calls)
637
+ assert_equal({ "User" => 2.2 }, @flog.scores)
638
+
639
+ @flog.reset
640
+
641
+ coder_class = %(
642
+ class Coder
643
+ def happy?
644
+ [true, false].sample
645
+ end
646
+ end
647
+ )
648
+ coder_file = "coder.rb"
649
+
650
+ @flog.flog_ruby coder_class, coder_file
651
+ @flog.calculate_total_scores
652
+ @flog.calculate
653
+
654
+ assert_equal({ 'Coder#happy?' => 'coder.rb:3' }, @flog.method_locations)
655
+ assert_equal({ "Coder#happy?" => 1.0 }, @flog.totals)
656
+ assert_equal(1.0, @flog.total_score)
657
+ assert_equal(1.0, @flog.multiplier)
658
+ assert_equal({ "Coder#happy?" => { :sample => 1.0 } }, @flog.calls)
659
+ assert_equal({ "Coder" => 1.0 }, @flog.scores)
660
+ end
661
+
599
662
  def setup_my_klass
600
663
  @flog.class_stack << "Base" << "MyKlass"
601
664
  @flog.method_stack << "mymethod"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 4
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 4.0.0
10
+ version: 4.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2013-04-18 00:00:00 Z
39
+ date: 2013-05-10 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sexp_processor
@@ -84,11 +84,11 @@ dependencies:
84
84
  requirements:
85
85
  - - ~>
86
86
  - !ruby/object:Gem::Version
87
- hash: 21
87
+ hash: 31
88
88
  segments:
89
- - 4
90
- - 7
91
- version: "4.7"
89
+ - 5
90
+ - 0
91
+ version: "5.0"
92
92
  type: :development
93
93
  version_requirements: *id003
94
94
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file