comp_tree 0.7.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,13 @@
1
1
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../devel'
2
3
 
3
4
  require 'test/unit'
4
5
  require 'comp_tree'
5
- #require 'benchmark'
6
6
 
7
- module TestCommon
7
+ module TestBase
8
8
  if ARGV.include?("--bench")
9
+ require 'benchmark'
10
+
9
11
  def separator
10
12
  puts
11
13
  puts "-"*60
@@ -23,7 +25,18 @@ module TestCommon
23
25
  end
24
26
  end
25
27
  else
26
- def separator() end
27
- def bench_output(desc = nil, stream = STDOUT, &block) end
28
+ module Benchmark
29
+ class << self
30
+ def measure
31
+ yield
32
+ end
33
+ end
34
+ end
35
+
36
+ def separator()
37
+ end
38
+
39
+ def bench_output(desc = nil, stream = STDOUT, &block)
40
+ end
28
41
  end
29
42
  end
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/common'
1
+ require File.dirname(__FILE__) + '/comp_tree_test_base'
2
2
 
3
3
  class TestDrain < Test::Unit::TestCase
4
- include TestCommon
4
+ include TestBase
5
5
 
6
6
  def drain
7
7
  500000.times { }
@@ -17,10 +17,9 @@ class TestDrain < Test::Unit::TestCase
17
17
  driver.define(:height, :border, &func)
18
18
  driver.define(:border, &func)
19
19
  driver.define(:offset, &func)
20
- #bench_output "number of threads: #{threads}"
21
- #bench = Benchmark.measure { driver.compute(:area, threads) }
22
- driver.compute(:area, threads)
23
- #bench_output bench
20
+ bench_output "number of threads: #{threads}"
21
+ bench = Benchmark.measure { driver.compute(:area, threads) }
22
+ bench_output bench
24
23
  }
25
24
  end
26
25
 
@@ -0,0 +1,117 @@
1
+ require File.dirname(__FILE__) + '/comp_tree_test_base'
2
+
3
+ class TestException < Test::Unit::TestCase
4
+ def test_exception
5
+ test_error = Class.new StandardError
6
+ [true, false].each { |define_all|
7
+ [true, false].each { |abort_on_exception|
8
+ (1..20).each { |num_threads|
9
+ error = (
10
+ begin
11
+ CompTree.build { |driver|
12
+ driver.define(:area, :width, :height, :offset) {
13
+ |width, height, offset|
14
+ width*height - offset
15
+ }
16
+
17
+ driver.define(:width, :border) { |border|
18
+ 2 + border
19
+ }
20
+
21
+ driver.define(:height, :border) { |border|
22
+ 3 + border
23
+ }
24
+
25
+ if define_all
26
+ driver.define(:border) {
27
+ raise test_error
28
+ }
29
+ end
30
+
31
+ driver.define(:offset) {
32
+ 7
33
+ }
34
+
35
+ begin
36
+ previous = Thread.abort_on_exception
37
+ Thread.abort_on_exception = abort_on_exception
38
+ driver.compute(:area, num_threads)
39
+ ensure
40
+ Thread.abort_on_exception = previous
41
+ end
42
+ }
43
+ nil
44
+ rescue Exception => e
45
+ e
46
+ end
47
+ )
48
+
49
+ if define_all
50
+ assert_block { error.is_a? test_error }
51
+ else
52
+ assert_block { error.is_a? CompTree::NoFunctionError }
53
+ assert_equal(
54
+ "no function was defined for node `:border'",
55
+ error.message
56
+ )
57
+ end
58
+ }
59
+ }
60
+ }
61
+ end
62
+
63
+ def test_num_threads
64
+ CompTree.build do |driver|
65
+ driver.define(:root) { }
66
+ assert_raises(RangeError) { driver.compute(:root, 0) }
67
+ assert_raises(RangeError) { driver.compute(:root, -1) }
68
+ assert_raises(RangeError) { driver.compute(:root, -11) }
69
+
70
+ assert_raises(TypeError) { driver.compute(:root, "11") }
71
+ assert_raises(TypeError) { driver.compute(:root, {}) }
72
+ assert_raises(TypeError) { driver.compute(:root, Object.new) }
73
+ assert_raises(TypeError) { driver.compute(:root, true) }
74
+ assert_raises(TypeError) { driver.compute(:root, nil) }
75
+ end
76
+ end
77
+
78
+ def test_invalid_node
79
+ (1..20).each { |num_threads|
80
+ CompTree.build do |driver|
81
+ driver.define(:root) { }
82
+ assert_nothing_raised {
83
+ driver.compute(:root, num_threads)
84
+ }
85
+
86
+ error = assert_raises(CompTree::NoNodeError) {
87
+ driver.compute(:a, num_threads)
88
+ }
89
+ assert_equal "no node named `:a'", error.message
90
+ assert_equal :a, error.node_name
91
+
92
+ error = assert_raises(CompTree::NoNodeError) {
93
+ driver.compute(nil, num_threads)
94
+ }
95
+ assert_equal nil, error.node_name
96
+ assert_equal "no node named `nil'", error.message
97
+ assert_equal "#<CompTree::NoNodeError: #{error.message}>", error.inspect
98
+ end
99
+ }
100
+ end
101
+
102
+ def test_missing_function
103
+ (1..20).each { |num_threads|
104
+ CompTree.build { |driver|
105
+ driver.define(:f, :x) { |x|
106
+ x + 33
107
+ }
108
+ error = assert_raises(CompTree::NoFunctionError) {
109
+ driver.compute(:f, num_threads)
110
+ }
111
+ msg = "no function was defined for node `:x'"
112
+ assert_equal msg, error.message
113
+ assert_equal "#<CompTree::NoFunctionError: #{msg}>", error.inspect
114
+ }
115
+ }
116
+ end
117
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/common'
1
+ require File.dirname(__FILE__) + '/comp_tree_test_base'
2
2
 
3
3
  class TestFlood < Test::Unit::TestCase
4
4
  def test_thread_flood
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '/common'
1
+ require File.dirname(__FILE__) + '/comp_tree_test_base'
2
2
 
3
3
  class TestGrind < Test::Unit::TestCase
4
- include TestCommon
4
+ include TestBase
5
5
 
6
6
  GENERATOR_DATA = {
7
7
  :level_range => 1..5,
@@ -32,7 +32,7 @@ class TestGrind < Test::Unit::TestCase
32
32
  RETURN_FLAG
33
33
  }
34
34
  build_tree = lambda { |parent, children, level|
35
- #trace "building #{parent} --> #{children.join(' ')}"
35
+ #puts "building #{parent} --> #{children.join(' ')}"
36
36
 
37
37
  driver.define(parent, *children, &drain)
38
38
 
@@ -55,22 +55,21 @@ class TestGrind < Test::Unit::TestCase
55
55
  args[:level_range].each { |num_levels|
56
56
  args[:children_range].each { |num_children|
57
57
  separator
58
- #bench_output {%{num_levels}}
59
- #bench_output {%{num_children}}
58
+ bench_output {%{num_levels}}
59
+ bench_output {%{num_children}}
60
60
  driver = generate_comp_tree(
61
61
  num_levels,
62
62
  num_children,
63
63
  args[:drain_iterations])
64
64
  args[:thread_range].each { |threads|
65
- #bench_output {%{threads}}
65
+ bench_output {%{threads}}
66
66
  2.times {
67
67
  driver.reset(ROOT)
68
- #result = nil
69
- #bench = Benchmark.measure {
70
- # result = driver.compute(ROOT, threads)
71
- #}
72
- result = driver.compute(ROOT, threads)
73
- #bench_output bench
68
+ result = nil
69
+ bench = Benchmark.measure {
70
+ result = driver.compute(ROOT, threads)
71
+ }
72
+ bench_output bench
74
73
  assert_equal(result, RETURN_FLAG)
75
74
  }
76
75
  }
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + "/comp_tree_test_base"
2
+
3
+ require "jumpstart"
4
+
5
+ Jumpstart.doc_to_test("README.rdoc", "Synopsis")
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/common'
1
+ require File.dirname(__FILE__) + '/comp_tree_test_base'
2
2
 
3
3
  class TestSequential < Test::Unit::TestCase
4
4
  def test_sequential
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/common'
1
+ require File.dirname(__FILE__) + '/comp_tree_test_base'
2
2
 
3
3
  class TestThrow < Test::Unit::TestCase
4
4
  EXPECTED = RUBY_VERSION >= "1.9.0" ? ArgumentError : ThreadError
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comp_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James M. Lawrence
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-21 00:00:00 -04:00
12
+ date: 2009-09-13 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: CompTree is a framework for parallelizing interrelated computations.
16
+ description: CompTree is parallel computation tree structure based upon concepts from pure functional programming.
17
17
  email:
18
18
  - quixoticsycophant@gmail.com
19
19
  executables: []
@@ -24,85 +24,84 @@ extra_rdoc_files:
24
24
  - README.rdoc
25
25
  files:
26
26
  - CHANGES.rdoc
27
- - MANIFEST
28
27
  - README.rdoc
29
28
  - Rakefile
30
29
  - devel/jumpstart.rb
31
- - devel/jumpstart/lazy_attribute.rb
32
- - devel/jumpstart/ruby.rb
33
- - devel/jumpstart/simple_installer.rb
34
30
  - install.rb
35
31
  - lib/comp_tree.rb
36
32
  - lib/comp_tree/algorithm.rb
33
+ - lib/comp_tree/comp_tree.rb
37
34
  - lib/comp_tree/driver.rb
38
35
  - lib/comp_tree/error.rb
39
36
  - lib/comp_tree/node.rb
40
- - lib/comp_tree/queue.rb
41
- - lib/comp_tree/queue_new.rb
42
- - lib/comp_tree/queue_old.rb
43
- - test/common.rb
44
- - test/test_basic.rb
45
- - test/test_circular.rb
46
- - test/test_drain.rb
47
- - test/test_exception.rb
48
- - test/test_flood.rb
49
- - test/test_grind.rb
50
- - test/test_sequential.rb
51
- - test/test_throw.rb
37
+ - lib/comp_tree/queue/queue.rb
38
+ - lib/comp_tree/queue/queue_18.rb
39
+ - lib/comp_tree/queue/queue_19.rb
40
+ - test/basic_test.rb
41
+ - test/circular_test.rb
42
+ - test/comp_tree_test_base.rb
43
+ - test/drain_test.rb
44
+ - test/exception_test.rb
45
+ - test/flood_test.rb
46
+ - test/grind_test.rb
47
+ - test/readme_test.rb
48
+ - test/sequential_test.rb
49
+ - test/throw_test.rb
50
+ - MANIFEST
52
51
  has_rdoc: true
53
52
  homepage: http://comptree.rubyforge.org
53
+ licenses: []
54
+
54
55
  post_install_message:
55
56
  rdoc_options:
56
57
  - --main
57
58
  - README.rdoc
58
59
  - --title
59
- - "comp_tree: Automatic parallelism and lazy evaluation via pure functional programming."
60
+ - "comp_tree: A simple framework for parallelizing computations."
60
61
  - --exclude
61
62
  - CHANGES.rdoc
62
63
  - --exclude
63
- - MANIFEST
64
- - --exclude
65
64
  - README.rdoc
66
65
  - --exclude
67
66
  - Rakefile
68
67
  - --exclude
69
68
  - devel/jumpstart.rb
70
69
  - --exclude
71
- - devel/jumpstart/lazy_attribute.rb
72
- - --exclude
73
- - devel/jumpstart/ruby.rb
74
- - --exclude
75
- - devel/jumpstart/simple_installer.rb
76
- - --exclude
77
70
  - install.rb
78
71
  - --exclude
72
+ - lib/comp_tree.rb
73
+ - --exclude
79
74
  - lib/comp_tree/algorithm.rb
80
75
  - --exclude
81
76
  - lib/comp_tree/node.rb
82
77
  - --exclude
83
- - lib/comp_tree/queue.rb
78
+ - lib/comp_tree/queue/queue.rb
84
79
  - --exclude
85
- - lib/comp_tree/queue_new.rb
80
+ - lib/comp_tree/queue/queue_18.rb
86
81
  - --exclude
87
- - lib/comp_tree/queue_old.rb
82
+ - lib/comp_tree/queue/queue_19.rb
88
83
  - --exclude
89
- - test/common.rb
84
+ - test/basic_test.rb
90
85
  - --exclude
91
- - test/test_basic.rb
86
+ - test/circular_test.rb
92
87
  - --exclude
93
- - test/test_circular.rb
88
+ - test/comp_tree_test_base.rb
94
89
  - --exclude
95
- - test/test_drain.rb
90
+ - test/drain_test.rb
96
91
  - --exclude
97
- - test/test_exception.rb
92
+ - test/exception_test.rb
98
93
  - --exclude
99
- - test/test_flood.rb
94
+ - test/flood_test.rb
100
95
  - --exclude
101
- - test/test_grind.rb
96
+ - test/grind_test.rb
102
97
  - --exclude
103
- - test/test_sequential.rb
98
+ - test/readme_test.rb
104
99
  - --exclude
105
- - test/test_throw.rb
100
+ - test/sequential_test.rb
101
+ - --exclude
102
+ - test/throw_test.rb
103
+ - --exclude
104
+ - MANIFEST
106
105
  require_paths:
107
106
  - lib
108
107
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -120,9 +119,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
119
  requirements: []
121
120
 
122
121
  rubyforge_project: comptree
123
- rubygems_version: 1.3.1
122
+ rubygems_version: 1.3.5
124
123
  signing_key:
125
- specification_version: 2
126
- summary: Automatic parallelism and lazy evaluation via pure functional programming.
124
+ specification_version: 3
125
+ summary: A simple framework for parallelizing computations.
127
126
  test_files: []
128
127
 
@@ -1,38 +0,0 @@
1
-
2
- class Jumpstart
3
- #
4
- # Mixin for lazily-evaluated attributes.
5
- #
6
- module LazyAttribute
7
- #
8
- # &block is evaluated when this attribute is requested. The same
9
- # result is returned for subsequent calls until the attribute is
10
- # assigned a different value.
11
- #
12
- def attribute(reader, &block)
13
- writer = "#{reader}="
14
-
15
- singleton = (class << self ; self ; end)
16
-
17
- define_evaluated_reader = lambda { |value|
18
- singleton.class_eval {
19
- remove_method(reader)
20
- define_method(reader) { value }
21
- }
22
- }
23
-
24
- singleton.class_eval {
25
- define_method(reader) {
26
- value = block.call
27
- define_evaluated_reader.call(value)
28
- value
29
- }
30
-
31
- define_method(writer) { |value|
32
- define_evaluated_reader.call(value)
33
- value
34
- }
35
- }
36
- end
37
- end
38
- end
@@ -1,44 +0,0 @@
1
-
2
- require 'rbconfig'
3
-
4
- class Jumpstart
5
- module Ruby
6
- EXECUTABLE = lambda {
7
- name = File.join(
8
- Config::CONFIG["bindir"],
9
- Config::CONFIG["RUBY_INSTALL_NAME"]
10
- )
11
-
12
- if Config::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
13
- File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
14
- name + Config::CONFIG["EXEEXT"]
15
- else
16
- name
17
- end
18
- }.call
19
-
20
- class << self
21
- def run(*args)
22
- cmd = [EXECUTABLE, *args]
23
- unless system(*cmd)
24
- cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
25
- raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
26
- end
27
- end
28
-
29
- def with_warnings(value = true)
30
- previous = $VERBOSE
31
- $VERBOSE = value
32
- begin
33
- yield
34
- ensure
35
- $VERBOSE = previous
36
- end
37
- end
38
-
39
- def no_warnings(&block)
40
- with_warnings(false, &block)
41
- end
42
- end
43
- end
44
- end
@@ -1,85 +0,0 @@
1
-
2
- require 'rbconfig'
3
- require 'fileutils'
4
- require 'find'
5
-
6
- class Jumpstart
7
- class SimpleInstaller
8
- def initialize
9
- dest_root = Config::CONFIG["sitelibdir"]
10
- sources = []
11
- Find.find("./lib") { |source|
12
- if install_file?(source)
13
- sources << source
14
- end
15
- }
16
- @spec = sources.inject(Array.new) { |acc, source|
17
- if source == "./lib"
18
- acc
19
- else
20
- dest = File.join(dest_root, source.sub(%r!\A\./lib!, ""))
21
-
22
- install = lambda {
23
- if File.directory?(source)
24
- unless File.directory?(dest)
25
- puts "mkdir #{dest}"
26
- FileUtils.mkdir(dest)
27
- end
28
- else
29
- puts "install #{source} --> #{dest}"
30
- FileUtils.install(source, dest)
31
- end
32
- }
33
-
34
- uninstall = lambda {
35
- if File.directory?(source)
36
- if File.directory?(dest)
37
- puts "rmdir #{dest}"
38
- FileUtils.rmdir(dest)
39
- end
40
- else
41
- if File.file?(dest)
42
- puts "rm #{dest}"
43
- FileUtils.rm(dest)
44
- end
45
- end
46
- }
47
-
48
- acc << {
49
- :source => source,
50
- :dest => dest,
51
- :install => install,
52
- :uninstall => uninstall,
53
- }
54
- end
55
- }
56
- end
57
-
58
- def install_file?(source)
59
- File.directory?(source) or
60
- (File.file?(source) and File.extname(source) == ".rb")
61
- end
62
-
63
- def install
64
- @spec.each { |entry|
65
- entry[:install].call
66
- }
67
- end
68
-
69
- def uninstall
70
- @spec.reverse.each { |entry|
71
- entry[:uninstall].call
72
- }
73
- end
74
-
75
- def run(args = ARGV)
76
- if args.empty?
77
- install
78
- elsif args.size == 1 and args.first == "--uninstall"
79
- uninstall
80
- else
81
- raise "unrecognized arguments: #{args.inspect}"
82
- end
83
- end
84
- end
85
- end
@@ -1 +0,0 @@
1
- require "comp_tree/queue_" + (RUBY_VERSION < "1.9.0" ? "old" : "new")
@@ -1,84 +0,0 @@
1
- require File.dirname(__FILE__) + '/common'
2
-
3
- class TestException < Test::Unit::TestCase
4
- def test_exception
5
- test_error = Class.new StandardError
6
- [true, false].each { |define_all|
7
- [true, false].each { |abort_on_exception|
8
- error = (
9
- begin
10
- CompTree.build { |driver|
11
- driver.define(:area, :width, :height, :offset) {
12
- |width, height, offset|
13
- width*height - offset
14
- }
15
-
16
- driver.define(:width, :border) { |border|
17
- 2 + border
18
- }
19
-
20
- driver.define(:height, :border) { |border|
21
- 3 + border
22
- }
23
-
24
- if define_all
25
- driver.define(:border) {
26
- raise test_error
27
- }
28
- end
29
-
30
- driver.define(:offset) {
31
- 7
32
- }
33
-
34
- begin
35
- previous = Thread.abort_on_exception
36
- Thread.abort_on_exception = abort_on_exception
37
- driver.compute(:area, 99)
38
- ensure
39
- Thread.abort_on_exception = previous
40
- end
41
- }
42
- nil
43
- rescue => e
44
- e
45
- end
46
- )
47
-
48
- if define_all
49
- assert_block { error.is_a? test_error }
50
- else
51
- assert_block { error.is_a? CompTree::NoFunctionError }
52
- end
53
- }
54
- }
55
- end
56
-
57
- def test_num_threads
58
- CompTree.build do |driver|
59
- driver.define(:root) { }
60
- error = CompTree::ArgumentError
61
- assert_raises(error) { driver.compute(:root, 0) }
62
- assert_raises(error) { driver.compute(:root, :threads => 0) }
63
- assert_raises(error) { driver.compute(:root, -1) }
64
- assert_raises(error) { driver.compute(:root, :threads => -1) }
65
- assert_raises(error) { driver.compute(:root, -11) }
66
- assert_raises(error) { driver.compute(:root, :threads => -11) }
67
- end
68
- end
69
-
70
- def test_invalid_node
71
- CompTree.build do |driver|
72
- driver.define(:root) { }
73
- assert_nothing_raised {
74
- driver.compute(:root, 33)
75
- }
76
- assert_raises(CompTree::ArgumentError) {
77
- driver.compute(:a, 33)
78
- }
79
- assert_raises(CompTree::ArgumentError) {
80
- driver.compute(nil, 33)
81
- }
82
- end
83
- end
84
- end