bin/parse_tree_abc in ParseTree-1.3.2 vs bin/parse_tree_abc in ParseTree-1.3.3
- old
+ new
@@ -4,10 +4,12 @@
#
# Assignments, Branches, and Calls
#
# A simple way to measure the complexity of a function or method.
+PARSE_TREE_ABC=true
+
begin
require 'rubygems'
require_gem 'ParseTree'
rescue LoadError
require 'parse_tree'
@@ -19,11 +21,15 @@
ObjectSpace.each_object(Module) do |klass|
old_classes << klass
end
ARGV.each do |name|
- require name
+ begin
+ require name
+ rescue NameError => err
+ $stderr.puts "ERROR requiring #{name}. Perhaps you need to add some -I's?\n\n#{err}"
+ end
end
new_classes = []
ObjectSpace.each_object(Module) do |klass|
new_classes << klass
@@ -58,24 +64,24 @@
else
puts "unhandled token #{token.inspect}" if $VERBOSE
end
end
key = ["#{klassname}.#{methodname}", a, b, c]
- val = a+b+c
+ val = Math.sqrt(a*a+b*b+c*c)
score[key] = val
end
end
-puts "Method = assignments + branches + calls = total"
+puts "|ABC| = Math.sqrt(assignments^2 + branches^2 + calls^2)"
puts
count = 1
ta = tb = tc = tval = 0
score.sort_by { |k,v| v }.reverse.each do |key,val|
name, a, b, c = *key
ta += a
tb += b
tc += c
tval += val
- printf "%3d) %-50s = %2d + %2d + %2d = %3d\n", count, name, a, b, c, val
+ printf "%3d) %-50s = %2d + %2d + %2d = %6.2f\n", count, name, a, b, c, val
count += 1
end
-printf "%3d) %-50s = %2d + %2d + %2d = %3d\n", count, "Total", ta, tb, tc, tval
+printf "%3d) %-50s = %2d + %2d + %2d = %6.2f\n", count, "Total", ta, tb, tc, tval