cognitive_distance 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.autotest +19 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.md +221 -0
  6. data/README.md +50 -0
  7. data/Rakefile +14 -0
  8. data/cognitive_distance.gemspec +23 -0
  9. data/lib/cognitive_distance.rb +23 -0
  10. data/lib/cognitive_distance/measurements.rb +16 -0
  11. data/lib/cognitive_distance/measurements/distinct_module_hops.rb +19 -0
  12. data/lib/cognitive_distance/measurements/measurement.rb +7 -0
  13. data/lib/cognitive_distance/measurements/module_hops.rb +17 -0
  14. data/lib/cognitive_distance/presenters.rb +2 -0
  15. data/lib/cognitive_distance/presenters/graph_to_dot.rb +11 -0
  16. data/lib/cognitive_distance/structures.rb +9 -0
  17. data/lib/cognitive_distance/structures/call_node.rb +74 -0
  18. data/lib/cognitive_distance/structures/call_node_root.rb +29 -0
  19. data/lib/cognitive_distance/structures/call_tree.rb +34 -0
  20. data/lib/cognitive_distance/structures/graph.rb +77 -0
  21. data/lib/cognitive_distance/structures/missing_call_context.rb +10 -0
  22. data/lib/cognitive_distance/tracer.rb +32 -0
  23. data/lib/cognitive_distance/transforms.rb +5 -0
  24. data/lib/cognitive_distance/transforms/call_tree_to_module_boundary_graph.rb +30 -0
  25. data/lib/cognitive_distance/version.rb +3 -0
  26. data/spec/cognitive_distance/measurements/distinct_module_hops_spec.rb +52 -0
  27. data/spec/cognitive_distance/measurements/measurement_spec.rb +44 -0
  28. data/spec/cognitive_distance/measurements/module_hops_spec.rb +54 -0
  29. data/spec/cognitive_distance/measurements_spec.rb +19 -0
  30. data/spec/cognitive_distance/presenters/graph_to_dot_spec.rb +26 -0
  31. data/spec/cognitive_distance/structures/call_node_root_spec.rb +31 -0
  32. data/spec/cognitive_distance/structures/call_node_spec.rb +91 -0
  33. data/spec/cognitive_distance/structures/call_tree_spec.rb +55 -0
  34. data/spec/cognitive_distance/structures/graph_spec.rb +142 -0
  35. data/spec/cognitive_distance/structures/missing_call_context_spec.rb +21 -0
  36. data/spec/cognitive_distance/tracer_spec.rb +57 -0
  37. data/spec/cognitive_distance/transforms/call_tree_to_module_boundary_graph_spec.rb +57 -0
  38. data/spec/spec_dummies.rb +60 -0
  39. data/spec/spec_helper.rb +12 -0
  40. metadata +111 -0
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ describe CognitiveDistance::Transforms::CallTreeToModuleBoundaryGraph do
4
+ def make_binding
5
+ [].method(:length).to_proc.binding
6
+ end
7
+
8
+ def make_tree
9
+ b1, b2, b3, b4 = 4.times.map { make_binding }
10
+ nils = [nil, nil, nil]
11
+ CognitiveDistance::Structures::CallTree.new.tap do |tree|
12
+ tree.called 1, *nils, b1
13
+ tree.called 2, *nils, b3
14
+ tree.returned 2, *nils, b3 # => 1
15
+ tree.called 3, *nils, b1
16
+ tree.called 4, *nils, b1
17
+ tree.called 5, *nils, b4
18
+ tree.returned 5, *nils, b4 # => 4
19
+ tree.returned 4, *nils, b1 # => 3
20
+ tree.returned 3, *nils, b1 # => 1
21
+ tree.returned 1, *nils, b1 # => ROOT
22
+
23
+ tree.called 20, *nils, b2
24
+ tree.called 21, *nils, b2
25
+ tree.called 22, *nils, b1
26
+ tree.returned 22, *nils, b1 # => 21
27
+ tree.returned 21, *nils, b2 # => 20
28
+ tree.called 23, *nils, b1
29
+ tree.returned 23, *nils, b1 # => 20
30
+ tree.returned 20, *nils, b2 # => ROOT
31
+ end
32
+ end
33
+
34
+ before do
35
+ @transformer = CognitiveDistance::Transforms::CallTreeToModuleBoundaryGraph.new
36
+ # We're specifically transforming a call tree, so let's use a real one
37
+ @tree = make_tree
38
+ end
39
+
40
+ it "transforms a CallTree into a graph of boundary crossings" do
41
+ graph = @transformer.transform(@tree)
42
+ graph.vertices.size.must_equal 8
43
+ graph.edges.size.must_equal 4
44
+ mapped = graph.map { |(v1,v2)| [v1.trace_class, v2.trace_class] }
45
+ mapped.must_include [1, 2]
46
+ mapped.must_include [4, 5]
47
+ mapped.must_include [20, 23]
48
+ mapped.must_include [21, 22]
49
+ end
50
+
51
+ it "provides a singleton convenience method" do
52
+ graph1 = @transformer.transform(@tree)
53
+ graph2 = CognitiveDistance::Transforms::CallTreeToModuleBoundaryGraph.transform(@tree)
54
+ graph1.must_equal graph2
55
+ end
56
+ end
57
+
@@ -0,0 +1,60 @@
1
+ # Generally I will favor mocks, but I need real bindings, and
2
+ # mocking those seemed just as tedious. Thus, dummies.
3
+
4
+ module CognitiveDistance::Test
5
+
6
+ # None of this guy's methods cross into another
7
+ # Ruby class
8
+ class TracesInternal
9
+ def initialize v1=-6, v2=4, v3=9
10
+ @v1 = v1
11
+ @v2 = v2
12
+ @v3 = v3
13
+ end
14
+
15
+ def method1
16
+ 8 * (method2 + method3)
17
+ end
18
+
19
+ def method2
20
+ @v1 + method4
21
+ end
22
+
23
+ def method3
24
+ @v2
25
+ end
26
+
27
+ def method4
28
+ @v3
29
+ end
30
+
31
+ def test_throwing
32
+ catch(:tang) do
33
+ prepare_the_throwing
34
+ end
35
+ method4
36
+ end
37
+
38
+ def prepare_the_throwing
39
+ do_the_throwing
40
+ end
41
+
42
+ def do_the_throwing
43
+ throw :tang
44
+ end
45
+
46
+ def test_raising
47
+ prepare_the_raising rescue nil
48
+ method3
49
+ end
50
+
51
+ def prepare_the_raising
52
+ do_the_raising
53
+ end
54
+
55
+ def do_the_raising
56
+ raise "Suck it dipped in Tang"
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,12 @@
1
+ if ENV['SCOV']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+ end
7
+
8
+ require 'minitest/autorun'
9
+ require 'minitest/emoji'
10
+ require File.expand_path('../spec_dummies', __FILE__)
11
+ require 'cognitive_distance'
12
+
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cognitive_distance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Ian D. Eccles
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2153110480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2153110480
25
+ description: A tool for measuring locality of Ruby source. No real features yet, wait
26
+ for the non-pre version
27
+ email:
28
+ - ian.eccles@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .autotest
34
+ - .gitignore
35
+ - .travis.yml
36
+ - Gemfile
37
+ - LICENSE.md
38
+ - README.md
39
+ - Rakefile
40
+ - cognitive_distance.gemspec
41
+ - lib/cognitive_distance.rb
42
+ - lib/cognitive_distance/measurements.rb
43
+ - lib/cognitive_distance/measurements/distinct_module_hops.rb
44
+ - lib/cognitive_distance/measurements/measurement.rb
45
+ - lib/cognitive_distance/measurements/module_hops.rb
46
+ - lib/cognitive_distance/presenters.rb
47
+ - lib/cognitive_distance/presenters/graph_to_dot.rb
48
+ - lib/cognitive_distance/structures.rb
49
+ - lib/cognitive_distance/structures/call_node.rb
50
+ - lib/cognitive_distance/structures/call_node_root.rb
51
+ - lib/cognitive_distance/structures/call_tree.rb
52
+ - lib/cognitive_distance/structures/graph.rb
53
+ - lib/cognitive_distance/structures/missing_call_context.rb
54
+ - lib/cognitive_distance/tracer.rb
55
+ - lib/cognitive_distance/transforms.rb
56
+ - lib/cognitive_distance/transforms/call_tree_to_module_boundary_graph.rb
57
+ - lib/cognitive_distance/version.rb
58
+ - spec/cognitive_distance/measurements/distinct_module_hops_spec.rb
59
+ - spec/cognitive_distance/measurements/measurement_spec.rb
60
+ - spec/cognitive_distance/measurements/module_hops_spec.rb
61
+ - spec/cognitive_distance/measurements_spec.rb
62
+ - spec/cognitive_distance/presenters/graph_to_dot_spec.rb
63
+ - spec/cognitive_distance/structures/call_node_root_spec.rb
64
+ - spec/cognitive_distance/structures/call_node_spec.rb
65
+ - spec/cognitive_distance/structures/call_tree_spec.rb
66
+ - spec/cognitive_distance/structures/graph_spec.rb
67
+ - spec/cognitive_distance/structures/missing_call_context_spec.rb
68
+ - spec/cognitive_distance/tracer_spec.rb
69
+ - spec/cognitive_distance/transforms/call_tree_to_module_boundary_graph_spec.rb
70
+ - spec/spec_dummies.rb
71
+ - spec/spec_helper.rb
72
+ homepage: ''
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>'
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.1
90
+ requirements: []
91
+ rubyforge_project: cognitive_distance
92
+ rubygems_version: 1.8.12
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A (currently incomplete) measure of locality
96
+ test_files:
97
+ - spec/cognitive_distance/measurements/distinct_module_hops_spec.rb
98
+ - spec/cognitive_distance/measurements/measurement_spec.rb
99
+ - spec/cognitive_distance/measurements/module_hops_spec.rb
100
+ - spec/cognitive_distance/measurements_spec.rb
101
+ - spec/cognitive_distance/presenters/graph_to_dot_spec.rb
102
+ - spec/cognitive_distance/structures/call_node_root_spec.rb
103
+ - spec/cognitive_distance/structures/call_node_spec.rb
104
+ - spec/cognitive_distance/structures/call_tree_spec.rb
105
+ - spec/cognitive_distance/structures/graph_spec.rb
106
+ - spec/cognitive_distance/structures/missing_call_context_spec.rb
107
+ - spec/cognitive_distance/tracer_spec.rb
108
+ - spec/cognitive_distance/transforms/call_tree_to_module_boundary_graph_spec.rb
109
+ - spec/spec_dummies.rb
110
+ - spec/spec_helper.rb
111
+ has_rdoc: