Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed redundant each in Flay#prune. (timruffles)

[git-p4: depot-paths = "//src/flay/dev/": change = 8293]
  • Loading branch information...
commit 3aacf3fcdf2009a826b26c51dea1bc142b1ca1d1 1 parent 7994a3b
@zenspider zenspider authored
Showing with 38 additions and 4 deletions.
  1. +2 −4 lib/flay.rb
  2. +36 −0 test/test_flay.rb
View
6 lib/flay.rb
@@ -204,10 +204,8 @@ def prune
# extract all subtree hashes from all nodes
all_hashes = {}
self.hashes.values.each do |nodes|
- nodes.each do |node|
- node.all_structural_subhashes.each do |h|
- all_hashes[h] = true
- end
+ nodes.first.all_structural_subhashes.each do |h|
+ all_hashes[h] = true
end
end
View
36 test/test_flay.rb
@@ -73,6 +73,42 @@ def x(n)
end
RUBY
+ def test_prune
+ contained = s(:a, s(:b,s(:c)), s(:d,s(:e)))
+ container = s(:d, contained)
+
+ flay = Flay.new :mass => 0
+ flay.process_sexp s(:outer,contained)
+ 2.times { flay.process_sexp s(:outer,container) }
+
+ exp = [
+ [ s(:a, s(:b, s(:c)), s(:d, s(:e))),
+ s(:a, s(:b, s(:c)), s(:d, s(:e))),
+ s(:a, s(:b, s(:c)), s(:d, s(:e)))],
+ [ s(:b, s(:c)),
+ s(:b, s(:c)),
+ s(:b, s(:c))],
+ [s(:d, s(:a, s(:b, s(:c)), s(:d, s(:e)))),
+ s(:d, s(:a, s(:b, s(:c)), s(:d, s(:e))))],
+ [ s(:d, s(:e)),
+ s(:d, s(:e)),
+ s(:d, s(:e))],
+ ]
+
+ assert_equal exp, flay.hashes.values.sort_by(&:inspect)
+
+ flay.prune
+
+ exp = [
+ [s(:d, s(:a, s(:b, s(:c)), s(:d, s(:e)))),
+ s(:d, s(:a, s(:b, s(:c)), s(:d, s(:e))))]
+ ]
+
+ assert_equal exp, flay.hashes.values.sort_by(&:inspect)
+
+ refute_includes flay.hashes, contained.structural_hash
+ end
+
def test_process_sexp
flay = Flay.new
Please sign in to comment.
Something went wrong with that request. Please try again.