laser 0.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE +661 -0
- data/README.md +158 -0
- data/Rakefile +104 -0
- data/VERSION +1 -0
- data/bin/laser +7 -0
- data/design_docs/goals.md +57 -0
- data/design_docs/object_regex.md +426 -0
- data/design_docs/type_annotations.md +80 -0
- data/ext/laser/BasicBlock.cpp +572 -0
- data/ext/laser/BasicBlock.h +118 -0
- data/ext/laser/extconf.rb +3 -0
- data/features/laser.feature +25 -0
- data/features/step_definitions/laser_steps.rb +39 -0
- data/features/support/env.rb +14 -0
- data/features/support/testdata/1_input +1 -0
- data/features/support/testdata/1_output +1 -0
- data/features/support/testdata/2_input +4 -0
- data/features/support/testdata/2_output +4 -0
- data/features/support/testdata/3_input +8 -0
- data/features/support/testdata/3_output +11 -0
- data/features/support/testdata/4_input +5 -0
- data/features/support/testdata/4_output +5 -0
- data/features/support/testdata/5_input +13 -0
- data/laser.gemspec +382 -0
- data/lib/laser.rb +98 -0
- data/lib/laser/analysis/annotations.rb +95 -0
- data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
- data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
- data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
- data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
- data/lib/laser/analysis/argument_expansion.rb +132 -0
- data/lib/laser/analysis/arity.rb +34 -0
- data/lib/laser/analysis/bindings.rb +144 -0
- data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
- data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
- data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
- data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
- data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
- data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
- data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
- data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
- data/lib/laser/analysis/comments.rb +35 -0
- data/lib/laser/analysis/control_flow.rb +28 -0
- data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
- data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
- data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
- data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
- data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
- data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
- data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
- data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
- data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
- data/lib/laser/analysis/control_flow/simulation.rb +385 -0
- data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
- data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
- data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
- data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
- data/lib/laser/analysis/errors.rb +131 -0
- data/lib/laser/analysis/laser_utils.rb +18 -0
- data/lib/laser/analysis/lexical_analysis.rb +172 -0
- data/lib/laser/analysis/method_call.rb +68 -0
- data/lib/laser/analysis/protocol_registry.rb +30 -0
- data/lib/laser/analysis/scope.rb +118 -0
- data/lib/laser/analysis/sexp.rb +159 -0
- data/lib/laser/analysis/sexp_analysis.rb +40 -0
- data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
- data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
- data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
- data/lib/laser/analysis/signature.rb +76 -0
- data/lib/laser/analysis/special_methods/send.rb +67 -0
- data/lib/laser/analysis/unused_methods.rb +21 -0
- data/lib/laser/analysis/visitor.rb +141 -0
- data/lib/laser/annotation_parser/annotations.treetop +126 -0
- data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
- data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
- data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
- data/lib/laser/annotation_parser/overload.treetop +24 -0
- data/lib/laser/annotation_parser/overload_parser.rb +167 -0
- data/lib/laser/annotation_parser/parsers.rb +6 -0
- data/lib/laser/annotation_parser/structural.treetop +37 -0
- data/lib/laser/annotation_parser/structural_parser.rb +406 -0
- data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
- data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
- data/lib/laser/rake/task.rb +46 -0
- data/lib/laser/runner.rb +189 -0
- data/lib/laser/scanner.rb +169 -0
- data/lib/laser/standard_library/_thread.rb +110 -0
- data/lib/laser/standard_library/abbrev.rb +103 -0
- data/lib/laser/standard_library/array.rb +418 -0
- data/lib/laser/standard_library/base64.rb +91 -0
- data/lib/laser/standard_library/basic_object.rb +55 -0
- data/lib/laser/standard_library/benchmark.rb +556 -0
- data/lib/laser/standard_library/bignum.rb +185 -0
- data/lib/laser/standard_library/cgi.rb +275 -0
- data/lib/laser/standard_library/cgi/cookie.rb +147 -0
- data/lib/laser/standard_library/cgi/core.rb +791 -0
- data/lib/laser/standard_library/cgi/html.rb +1021 -0
- data/lib/laser/standard_library/cgi/session.rb +537 -0
- data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
- data/lib/laser/standard_library/cgi/util.rb +188 -0
- data/lib/laser/standard_library/class_definitions.rb +333 -0
- data/lib/laser/standard_library/comparable.rb +125 -0
- data/lib/laser/standard_library/complex.rb +162 -0
- data/lib/laser/standard_library/enumerable.rb +178 -0
- data/lib/laser/standard_library/exceptions.rb +135 -0
- data/lib/laser/standard_library/fixnum.rb +188 -0
- data/lib/laser/standard_library/float.rb +180 -0
- data/lib/laser/standard_library/hash.rb +237 -0
- data/lib/laser/standard_library/integer.rb +123 -0
- data/lib/laser/standard_library/laser_magic.rb +7 -0
- data/lib/laser/standard_library/nil_false_true.rb +113 -0
- data/lib/laser/standard_library/numbers.rb +192 -0
- data/lib/laser/standard_library/proc.rb +31 -0
- data/lib/laser/standard_library/set.rb +1348 -0
- data/lib/laser/standard_library/string.rb +666 -0
- data/lib/laser/standard_library/stringio.rb +2 -0
- data/lib/laser/standard_library/symbol.rb +125 -0
- data/lib/laser/standard_library/tsort.rb +242 -0
- data/lib/laser/support/acts_as_struct.rb +66 -0
- data/lib/laser/support/frequency.rb +55 -0
- data/lib/laser/support/inheritable_attributes.rb +145 -0
- data/lib/laser/support/module_extensions.rb +94 -0
- data/lib/laser/support/placeholder_object.rb +13 -0
- data/lib/laser/third_party/rgl/adjacency.rb +221 -0
- data/lib/laser/third_party/rgl/base.rb +228 -0
- data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
- data/lib/laser/third_party/rgl/condensation.rb +47 -0
- data/lib/laser/third_party/rgl/connected_components.rb +138 -0
- data/lib/laser/third_party/rgl/control_flow.rb +170 -0
- data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
- data/lib/laser/third_party/rgl/dominators.rb +124 -0
- data/lib/laser/third_party/rgl/dot.rb +93 -0
- data/lib/laser/third_party/rgl/graphxml.rb +51 -0
- data/lib/laser/third_party/rgl/implicit.rb +174 -0
- data/lib/laser/third_party/rgl/mutable.rb +117 -0
- data/lib/laser/third_party/rgl/rdot.rb +445 -0
- data/lib/laser/third_party/rgl/topsort.rb +72 -0
- data/lib/laser/third_party/rgl/transitivity.rb +180 -0
- data/lib/laser/third_party/rgl/traversal.rb +348 -0
- data/lib/laser/types/types.rb +433 -0
- data/lib/laser/version.rb +14 -0
- data/lib/laser/warning.rb +149 -0
- data/lib/laser/warning_sets/default.yml +13 -0
- data/lib/laser/warnings/assignment_in_condition.rb +20 -0
- data/lib/laser/warnings/comment_spacing.rb +31 -0
- data/lib/laser/warnings/extra_blank_lines.rb +30 -0
- data/lib/laser/warnings/extra_whitespace.rb +16 -0
- data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
- data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
- data/lib/laser/warnings/line_length.rb +115 -0
- data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
- data/lib/laser/warnings/operator_spacing.rb +68 -0
- data/lib/laser/warnings/parens_on_declaration.rb +30 -0
- data/lib/laser/warnings/rescue_exception.rb +42 -0
- data/lib/laser/warnings/semicolon.rb +25 -0
- data/lib/laser/warnings/sexp_errors.rb +24 -0
- data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
- data/lib/laser/warnings/useless_double_quotes.rb +38 -0
- data/spec/analysis_specs/annotations_spec.rb +47 -0
- data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
- data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
- data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
- data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
- data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
- data/spec/analysis_specs/bindings_spec.rb +36 -0
- data/spec/analysis_specs/comment_spec.rb +93 -0
- data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
- data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
- data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
- data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
- data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
- data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
- data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
- data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
- data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
- data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
- data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
- data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
- data/spec/analysis_specs/error_spec.rb +30 -0
- data/spec/analysis_specs/laser_class_spec.rb +322 -0
- data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
- data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
- data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
- data/spec/analysis_specs/scope_spec.rb +126 -0
- data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
- data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
- data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
- data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
- data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
- data/spec/analysis_specs/sexp_spec.rb +167 -0
- data/spec/analysis_specs/spec_helper.rb +27 -0
- data/spec/analysis_specs/unused_methods_spec.rb +65 -0
- data/spec/analysis_specs/visitor_spec.rb +64 -0
- data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
- data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
- data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
- data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
- data/spec/annotation_parser_specs/spec_helper.rb +1 -0
- data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
- data/spec/laser_spec.rb +14 -0
- data/spec/rake_specs/spec_helper.rb +1 -0
- data/spec/rake_specs/task_spec.rb +67 -0
- data/spec/runner_spec.rb +207 -0
- data/spec/scanner_spec.rb +75 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/standard_library/exceptions_spec.rb +19 -0
- data/spec/standard_library/globals_spec.rb +14 -0
- data/spec/standard_library/set_spec.rb +31 -0
- data/spec/standard_library/spec_helper.rb +1 -0
- data/spec/standard_library/standard_library_spec.rb +302 -0
- data/spec/support_specs/acts_as_struct_spec.rb +94 -0
- data/spec/support_specs/frequency_spec.rb +23 -0
- data/spec/support_specs/module_extensions_spec.rb +117 -0
- data/spec/support_specs/spec_helper.rb +1 -0
- data/spec/type_specs/spec_helper.rb +1 -0
- data/spec/type_specs/types_spec.rb +133 -0
- data/spec/warning_spec.rb +95 -0
- data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
- data/spec/warning_specs/comment_spacing_spec.rb +65 -0
- data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
- data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
- data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
- data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
- data/spec/warning_specs/line_length_spec.rb +173 -0
- data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
- data/spec/warning_specs/operator_spacing_spec.rb +104 -0
- data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
- data/spec/warning_specs/rescue_exception_spec.rb +105 -0
- data/spec/warning_specs/semicolon_spec.rb +58 -0
- data/spec/warning_specs/spec_helper.rb +1 -0
- data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
- data/status_reports/2010/12/2010-12-14.md +163 -0
- data/status_reports/2010/12/2010-12-23.md +298 -0
- data/status_reports/2010/12/2010-12-24.md +6 -0
- data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
- data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
- data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
- data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
- data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
- data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
- data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
- data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
- data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
- data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
- data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
- data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
- data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
- data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
- data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
- metadata +470 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'laser/third_party/rgl/transitivity'
|
3
|
+
require_relative 'test_helper'
|
4
|
+
|
5
|
+
include RGL
|
6
|
+
|
7
|
+
class TestTransitiveClosure < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@dg = DirectedAdjacencyGraph.new
|
11
|
+
@dg.add_edges([1,2],[2,3],[2,4],[4,5],[1,6],[6,4])
|
12
|
+
@dg_tc = DirectedAdjacencyGraph.new
|
13
|
+
@dg_tc.add_edges(
|
14
|
+
[1,2],[1,3],[1,4],[1,5],[1,6],
|
15
|
+
[2,3],[2,4],[2,5],
|
16
|
+
[4,5],
|
17
|
+
[6,4],[6,5]
|
18
|
+
)
|
19
|
+
@dg_tr = DirectedAdjacencyGraph.new
|
20
|
+
@dg_tr.add_edges(
|
21
|
+
[1,2],[1,6],
|
22
|
+
[2,3],[2,4],
|
23
|
+
[4,5],
|
24
|
+
[6,4]
|
25
|
+
)
|
26
|
+
|
27
|
+
@dg_loner = @dg.dup
|
28
|
+
@dg_loner.add_vertices(7, 8, 9)
|
29
|
+
@dg_loner_tc = @dg_tc.dup
|
30
|
+
@dg_loner_tc.add_vertices(7, 8, 9)
|
31
|
+
@dg_loner_tr = @dg_tr.dup
|
32
|
+
@dg_loner_tr.add_vertices(7, 8, 9)
|
33
|
+
|
34
|
+
@dg_cyclic = DirectedAdjacencyGraph.new
|
35
|
+
@dg_cyclic.add_edges(
|
36
|
+
[1,1],[1,2],
|
37
|
+
[2,3],
|
38
|
+
[3,4],
|
39
|
+
[4,5],
|
40
|
+
[5,6],
|
41
|
+
[6,3]
|
42
|
+
)
|
43
|
+
@dg_cyclic_tc = DirectedAdjacencyGraph.new
|
44
|
+
@dg_cyclic_tc.add_edges(
|
45
|
+
[1,1],[1,2],[1,3],[1,4],[1,5],[1,6],
|
46
|
+
[2,3],[2,4],[2,5],[2,6],
|
47
|
+
[3,3],[3,4],[3,5],[3,6],
|
48
|
+
[4,3],[4,4],[4,5],[4,6],
|
49
|
+
[5,3],[5,4],[5,5],[5,6],
|
50
|
+
[6,3],[6,4],[6,5],[6,6]
|
51
|
+
)
|
52
|
+
@dg_cyclic_tr = DirectedAdjacencyGraph.new
|
53
|
+
@dg_cyclic_tr.add_edges(
|
54
|
+
[1,1],[1,2],
|
55
|
+
[2,3],
|
56
|
+
[3,4],
|
57
|
+
[4,5],
|
58
|
+
[5,6],
|
59
|
+
[6,3]
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_transitive_closure
|
64
|
+
# A simple graph without cycles.
|
65
|
+
assert_equal(@dg_tc, @dg.transitive_closure)
|
66
|
+
|
67
|
+
# Iterative applications of transitive closure should return the same result
|
68
|
+
# as a single application.
|
69
|
+
assert_equal(
|
70
|
+
@dg.transitive_closure,
|
71
|
+
@dg.transitive_closure.transitive_closure
|
72
|
+
)
|
73
|
+
|
74
|
+
# Compute for a graph containing vertices without edges.
|
75
|
+
assert_equal(@dg_loner_tc, @dg_loner.transitive_closure)
|
76
|
+
|
77
|
+
# Iterative applications of transitive closure should return the same result
|
78
|
+
# as a single application.
|
79
|
+
assert_equal(
|
80
|
+
@dg_loner.transitive_closure,
|
81
|
+
@dg_loner.transitive_closure.transitive_closure
|
82
|
+
)
|
83
|
+
|
84
|
+
# Compute for a graph with cycles.
|
85
|
+
assert_equal(@dg_cyclic_tc, @dg_cyclic.transitive_closure)
|
86
|
+
|
87
|
+
# Iterative applications of transitive closure should return the same result
|
88
|
+
# as a single application.
|
89
|
+
assert_equal(
|
90
|
+
@dg_cyclic.transitive_closure,
|
91
|
+
@dg_cyclic.transitive_closure.transitive_closure
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_transitive_closure_undirected
|
96
|
+
assert_raises(NotDirectedError) {AdjacencyGraph.new.transitive_closure}
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_transitive_reduction
|
100
|
+
# A simple graph without cycles.
|
101
|
+
assert_equal(@dg_tr, @dg.transitive_reduction)
|
102
|
+
|
103
|
+
# Compute for a graph containing vertices without edges.
|
104
|
+
assert_equal(@dg_loner_tr, @dg_loner.transitive_reduction)
|
105
|
+
|
106
|
+
# Compute for a graph with cycles.
|
107
|
+
assert_equal(@dg_cyclic_tr, @dg_cyclic.transitive_reduction)
|
108
|
+
|
109
|
+
# Test that the transitive closure of a transitive reduction is the same as
|
110
|
+
# the transitive closure of the original graph.
|
111
|
+
assert_equal(
|
112
|
+
@dg.transitive_closure,
|
113
|
+
@dg.transitive_reduction.transitive_closure
|
114
|
+
)
|
115
|
+
assert_equal(
|
116
|
+
@dg_loner.transitive_closure,
|
117
|
+
@dg_loner.transitive_reduction.transitive_closure
|
118
|
+
)
|
119
|
+
assert_equal(
|
120
|
+
@dg_cyclic.transitive_closure,
|
121
|
+
@dg_cyclic.transitive_reduction.transitive_closure
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_transitive_reduction_undirected
|
126
|
+
assert_raises(NotDirectedError) {AdjacencyGraph.new.transitive_reduction}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'laser/third_party/rgl/adjacency'
|
3
|
+
require 'laser/third_party/rgl/traversal'
|
4
|
+
require 'laser/third_party/rgl/topsort'
|
5
|
+
require 'laser/third_party/rgl/implicit'
|
6
|
+
|
7
|
+
require_relative 'test_helper'
|
8
|
+
|
9
|
+
include RGL
|
10
|
+
|
11
|
+
class TestTraversal < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@dg = DirectedAdjacencyGraph.new(Array)
|
15
|
+
edges = [[1,2],[2,3],[2,4],[4,5],[1,6],[6,4]]
|
16
|
+
edges.each do |(src,target)|
|
17
|
+
@dg.add_edge(src, target)
|
18
|
+
end
|
19
|
+
@bfs = @dg.bfs_iterator(1)
|
20
|
+
@dfs = @dg.dfs_iterator(1)
|
21
|
+
|
22
|
+
@ug = AdjacencyGraph.new(Array)
|
23
|
+
@ug.add_edges(*edges)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_bfs_iterator_creation
|
27
|
+
assert(@bfs.at_beginning?)
|
28
|
+
assert(!@bfs.at_end?)
|
29
|
+
assert_equal(1,@bfs.start_vertex)
|
30
|
+
assert_equal(@dg,@bfs.graph)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_bfs_visiting
|
34
|
+
expected = [1, 2, 6, 3, 4, 5]
|
35
|
+
assert_equal(expected,@bfs.to_a)
|
36
|
+
assert_equal(expected,@ug.bfs_iterator(1).to_a)
|
37
|
+
assert_equal([2, 1, 3, 4, 6, 5],@ug.bfs_iterator(2).to_a)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_bfs_event_handlers
|
41
|
+
expected =
|
42
|
+
'tree_edge : -1
|
43
|
+
examine_vertex : 1
|
44
|
+
examine_edge : 1-2
|
45
|
+
tree_edge : 1-2
|
46
|
+
examine_edge : 1-6
|
47
|
+
tree_edge : 1-6
|
48
|
+
finished_vertex: 1
|
49
|
+
examine_vertex : 2
|
50
|
+
examine_edge : 2-3
|
51
|
+
tree_edge : 2-3
|
52
|
+
examine_edge : 2-4
|
53
|
+
tree_edge : 2-4
|
54
|
+
finished_vertex: 2
|
55
|
+
examine_vertex : 6
|
56
|
+
examine_edge : 6-4
|
57
|
+
back_edge : 6-4
|
58
|
+
finished_vertex: 6
|
59
|
+
examine_vertex : 3
|
60
|
+
finished_vertex: 3
|
61
|
+
examine_vertex : 4
|
62
|
+
examine_edge : 4-5
|
63
|
+
tree_edge : 4-5
|
64
|
+
finished_vertex: 4
|
65
|
+
examine_vertex : 5
|
66
|
+
examine_edge : 5-3
|
67
|
+
forward_edge : 5-3
|
68
|
+
finished_vertex: 5
|
69
|
+
'
|
70
|
+
s = ''
|
71
|
+
@dg.add_edge 5,3 # for the forward_edge 5-3
|
72
|
+
@bfs.set_examine_vertex_event_handler { |v| s << "examine_vertex : #{v}\n"}
|
73
|
+
@bfs.set_examine_edge_event_handler { |u,v| s << "examine_edge : #{u}-#{v}\n"}
|
74
|
+
@bfs.set_tree_edge_event_handler { |u,v| s << "tree_edge : #{u}-#{v}\n"}
|
75
|
+
@bfs.set_back_edge_event_handler { |u,v| s << "back_edge : #{u}-#{v}\n"}
|
76
|
+
@bfs.set_forward_edge_event_handler { |u,v| s << "forward_edge : #{u}-#{v}\n"}
|
77
|
+
|
78
|
+
@bfs.each {|v| s << "finished_vertex: #{v}\n"}
|
79
|
+
puts "BFS: ", s if $DEBUG
|
80
|
+
assert_equal(expected,s)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_dfs_visiting
|
84
|
+
assert_equal([1, 6, 4, 5, 2, 3],@dg.dfs_iterator(1).to_a)
|
85
|
+
assert_equal([2, 4, 5, 3],@dg.dfs_iterator(2).to_a)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_dfs_event_handlers
|
89
|
+
expected =
|
90
|
+
'tree_edge : -1
|
91
|
+
examine_vertex : 1
|
92
|
+
examine_edge : 1-2
|
93
|
+
tree_edge : 1-2
|
94
|
+
examine_edge : 1-6
|
95
|
+
tree_edge : 1-6
|
96
|
+
finished_vertex: 1
|
97
|
+
examine_vertex : 6
|
98
|
+
examine_edge : 6-4
|
99
|
+
tree_edge : 6-4
|
100
|
+
finished_vertex: 6
|
101
|
+
examine_vertex : 4
|
102
|
+
examine_edge : 4-5
|
103
|
+
tree_edge : 4-5
|
104
|
+
finished_vertex: 4
|
105
|
+
examine_vertex : 5
|
106
|
+
examine_edge : 5-3
|
107
|
+
tree_edge : 5-3
|
108
|
+
finished_vertex: 5
|
109
|
+
examine_vertex : 3
|
110
|
+
finished_vertex: 3
|
111
|
+
examine_vertex : 2
|
112
|
+
examine_edge : 2-3
|
113
|
+
forward_edge : 2-3
|
114
|
+
examine_edge : 2-4
|
115
|
+
forward_edge : 2-4
|
116
|
+
finished_vertex: 2
|
117
|
+
'
|
118
|
+
s = ''
|
119
|
+
@dg.add_edge 5,3
|
120
|
+
@dfs.set_examine_vertex_event_handler { |v| s << "examine_vertex : #{v}\n"}
|
121
|
+
@dfs.set_examine_edge_event_handler { |u,v| s << "examine_edge : #{u}-#{v}\n"}
|
122
|
+
@dfs.set_tree_edge_event_handler { |u,v| s << "tree_edge : #{u}-#{v}\n"}
|
123
|
+
@dfs.set_back_edge_event_handler { |u,v| s << "back_edge : #{u}-#{v}\n"}
|
124
|
+
@dfs.set_forward_edge_event_handler { |u,v| s << "forward_edge : #{u}-#{v}\n"}
|
125
|
+
|
126
|
+
@dfs.each {|v| s << "finished_vertex: #{v}\n"}
|
127
|
+
puts "DFS: ", s if $DEBUG
|
128
|
+
assert_equal(expected,s)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_bfs_search_tree
|
132
|
+
assert_equal("(1-2)(1-6)(2-3)(2-4)(4-5)",@dg.bfs_search_tree_from(1).edges.sort.join)
|
133
|
+
end
|
134
|
+
|
135
|
+
def aux(it)
|
136
|
+
it.attach_distance_map
|
137
|
+
it.set_to_end
|
138
|
+
it.graph.vertices.sort.collect {|v|
|
139
|
+
"#{v}-#{it.distance_to_root(v)}"
|
140
|
+
}.join(', ')
|
141
|
+
end
|
142
|
+
def test_distance_map
|
143
|
+
assert_equal("1-0, 2-1, 3-2, 4-2, 5-3, 6-1",aux(@bfs))
|
144
|
+
@dg.add_edge 5,3
|
145
|
+
assert_equal("1-0, 2-1, 3-4, 4-2, 5-3, 6-1",aux(@dfs))
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_topsort
|
149
|
+
ts_it = @dg.topsort_iterator
|
150
|
+
assert(ts_it.at_beginning?)
|
151
|
+
assert_equal(@dg,ts_it.graph)
|
152
|
+
assert(!ts_it.at_end?)
|
153
|
+
ts_order = ts_it.to_a # do the traversal
|
154
|
+
assert_equal(@dg.num_vertices,ts_order.size)
|
155
|
+
|
156
|
+
# Check topsort contraint:
|
157
|
+
@dg.each_edge { |u,v|
|
158
|
+
assert(ts_order.index(u) < ts_order.index(v))
|
159
|
+
}
|
160
|
+
ts_it.set_to_begin
|
161
|
+
assert(ts_it.at_beginning?)
|
162
|
+
|
163
|
+
# Topsort on undirected graphs is empty
|
164
|
+
assert(@ug.topsort_iterator.at_end?)
|
165
|
+
end
|
166
|
+
|
167
|
+
# depth_first_search can also be used to compute a topsort!
|
168
|
+
def test_dfs_search_as_topsort
|
169
|
+
ts_order = []
|
170
|
+
@dg.depth_first_search { |v| ts_order << v }
|
171
|
+
ts_order = ts_order.reverse
|
172
|
+
@dg.each_edge { |u,v|
|
173
|
+
assert(ts_order.index(u) < ts_order.index(v))
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_acyclic
|
178
|
+
assert(@dg.acyclic?)
|
179
|
+
@dg.add_edge 5,2 # add cycle
|
180
|
+
assert(!@dg.acyclic?)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_dfs_visit
|
184
|
+
a = []
|
185
|
+
@dg.depth_first_visit(1) { |x| a << x }
|
186
|
+
assert_equal([3, 5, 4, 2, 6, 1],a)
|
187
|
+
|
188
|
+
a = []
|
189
|
+
@dg.add_edge 10,11
|
190
|
+
@dg.depth_first_visit(10) { |x| a << x }
|
191
|
+
assert_equal([11, 10],a)
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_dfs_visit_with_parens
|
195
|
+
a = ""
|
196
|
+
vis = DFSVisitor.new(@dg)
|
197
|
+
vis.set_examine_vertex_event_handler {|v| a << "(#{v} "}
|
198
|
+
vis.set_finish_vertex_event_handler {|v| a << " #{v})"}
|
199
|
+
@dg.depth_first_visit(1,vis) { |x| }
|
200
|
+
assert_equal("(1 (2 (3 3)(4 (5 5) 4) 2)(6 6) 1)",a)
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_depth_first_search_with_parens
|
204
|
+
@dg.add_edge 10,11
|
205
|
+
# We must ensure, that the order of the traversal is not dependend on the
|
206
|
+
# order of the each iterator in the hash map of the adjacency graph. Therefor we
|
207
|
+
# wrap the graph with an implicit graph that simply ensures a sort order on
|
208
|
+
# the vertices.
|
209
|
+
dg = @dg.implicit_graph {
|
210
|
+
| g |
|
211
|
+
g.vertex_iterator { |b| @dg.vertices.sort.each(&b)}
|
212
|
+
}
|
213
|
+
a = ""
|
214
|
+
vis = DFSVisitor.new(dg)
|
215
|
+
vis.set_examine_vertex_event_handler {|v| a << "(#{v} "}
|
216
|
+
vis.set_finish_vertex_event_handler {|v| a << " #{v})"}
|
217
|
+
dg.depth_first_search(vis) { |x| }
|
218
|
+
assert_equal("(1 (2 (3 3)(4 (5 5) 4) 2)(6 6) 1)(10 (11 11) 10)",a)
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'laser/third_party/rgl/adjacency'
|
3
|
+
|
4
|
+
include RGL
|
5
|
+
include RGL::Edge
|
6
|
+
|
7
|
+
class TestUnDirectedGraph < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@dg = AdjacencyGraph.new
|
11
|
+
[[1,2],[2,3],[3,2],[2,4]].each do |(src,target)|
|
12
|
+
@dg.add_edge(src, target)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_empty_graph
|
17
|
+
dg = AdjacencyGraph.new
|
18
|
+
assert(dg.empty?)
|
19
|
+
assert(!dg.directed?)
|
20
|
+
assert(!dg.has_edge?(2,1))
|
21
|
+
assert(!dg.has_vertex?(3))
|
22
|
+
# Non existend vertex result in a Name Error because each_key is
|
23
|
+
# called for nil
|
24
|
+
assert_raises(NoVertexError) {dg.out_degree(3)}
|
25
|
+
assert_equal([],dg.vertices)
|
26
|
+
assert_equal(0,dg.size)
|
27
|
+
assert_equal(0,dg.num_vertices)
|
28
|
+
assert_equal(0,dg.num_edges)
|
29
|
+
assert_equal(UnDirectedEdge,dg.edge_class)
|
30
|
+
assert([].eql?(dg.edges))
|
31
|
+
assert([].eql?(dg.to_a))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_add
|
35
|
+
dg = AdjacencyGraph.new
|
36
|
+
dg.add_edge(1,2)
|
37
|
+
assert(!dg.empty?)
|
38
|
+
assert(dg.has_edge?(1,2))
|
39
|
+
assert(dg.has_edge?(2,1), "Backwards edge not included!")
|
40
|
+
assert(dg.has_vertex?(1) && dg.has_vertex?(2))
|
41
|
+
assert(!dg.has_vertex?(3))
|
42
|
+
|
43
|
+
assert_equal([1,2],dg.vertices.sort)
|
44
|
+
assert([DirectedEdge.new(1,2)].eql?(dg.edges))
|
45
|
+
assert_equal("(1=2)",dg.edges.join)
|
46
|
+
|
47
|
+
assert_equal([2],dg.adjacent_vertices(1))
|
48
|
+
assert_equal([1],dg.adjacent_vertices(2))
|
49
|
+
|
50
|
+
assert_equal(1,dg.out_degree(1))
|
51
|
+
assert_equal(1,dg.out_degree(2))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_edges
|
55
|
+
assert_equal(3, @dg.edges.count)
|
56
|
+
edges = [[1,2],[2,3],[2,4]].map {|x| UnDirectedEdge.new(*x)}
|
57
|
+
assert_equal(edges, @dg.edges.sort)
|
58
|
+
# assert_equal([0,1,2,3], @dg.edges.map {|l| l.info}.sort)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_vertices
|
62
|
+
assert_equal([1,2,3,4], @dg.vertices.sort)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_edges_from_to?
|
66
|
+
assert @dg.has_edge?(1,2)
|
67
|
+
assert @dg.has_edge?(2,3)
|
68
|
+
assert @dg.has_edge?(3,2)
|
69
|
+
assert @dg.has_edge?(2,4)
|
70
|
+
assert @dg.has_edge?(2,1)
|
71
|
+
assert !@dg.has_edge?(3,1)
|
72
|
+
assert !@dg.has_edge?(4,1)
|
73
|
+
assert @dg.has_edge?(4,2)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_remove_edges
|
77
|
+
@dg.remove_edge 1,2
|
78
|
+
assert !@dg.has_edge?(1,2), "(1,2) should not be an edge any more."
|
79
|
+
@dg.remove_edge 1,2
|
80
|
+
assert !@dg.has_edge?(2,1)
|
81
|
+
@dg.remove_vertex 3
|
82
|
+
assert !@dg.has_vertex?(3), "3 should not be a vertex any more."
|
83
|
+
assert !@dg.has_edge?(2,3)
|
84
|
+
assert_equal([UnDirectedEdge.new(2,4)],@dg.edges)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_add_vertices
|
88
|
+
dg = AdjacencyGraph.new
|
89
|
+
dg.add_vertices 1,3,2,4
|
90
|
+
assert_equal dg.vertices.sort, [1,2,3,4]
|
91
|
+
|
92
|
+
dg.remove_vertices 1,3
|
93
|
+
assert_equal dg.vertices.sort, [2,4]
|
94
|
+
|
95
|
+
dg.remove_vertices 1,3,Object # ones again
|
96
|
+
assert_equal dg.vertices.sort, [2,4]
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_reverse
|
100
|
+
assert_equal(@dg, @dg.reverse)
|
101
|
+
end
|
102
|
+
end
|