rubyonacid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +6 -0
  2. data/LICENSE +20 -0
  3. data/README.textile +21 -0
  4. data/Rakefile +63 -0
  5. data/VERSION +1 -0
  6. data/examples/midi.rb +57 -0
  7. data/examples/permutations.rb +40 -0
  8. data/examples/raw_audio.rb +54 -0
  9. data/examples/rinda_agent.rb +81 -0
  10. data/examples/rmagick.rb +59 -0
  11. data/examples/test.rb +95 -0
  12. data/examples/test2.rb +85 -0
  13. data/examples/test3.rb +108 -0
  14. data/features/rubyonacid.feature +9 -0
  15. data/features/step_definitions/rubyonacid_steps.rb +0 -0
  16. data/features/support/env.rb +4 -0
  17. data/lib/rubyonacid/factories/constant.rb +25 -0
  18. data/lib/rubyonacid/factories/flash.rb +32 -0
  19. data/lib/rubyonacid/factories/increment.rb +32 -0
  20. data/lib/rubyonacid/factories/loop.rb +30 -0
  21. data/lib/rubyonacid/factories/meta.rb +31 -0
  22. data/lib/rubyonacid/factories/modulo.rb +25 -0
  23. data/lib/rubyonacid/factories/random.rb +15 -0
  24. data/lib/rubyonacid/factories/repeat.rb +35 -0
  25. data/lib/rubyonacid/factories/rinda.rb +40 -0
  26. data/lib/rubyonacid/factories/sine.rb +24 -0
  27. data/lib/rubyonacid/factories/skip.rb +23 -0
  28. data/lib/rubyonacid/factory.rb +29 -0
  29. data/lib/rubyonacid.rb +0 -0
  30. data/spec/generators/constant_spec.rb +24 -0
  31. data/spec/generators/flash_spec.rb +49 -0
  32. data/spec/generators/increment_spec.rb +43 -0
  33. data/spec/generators/loop_spec.rb +43 -0
  34. data/spec/generators/meta_spec.rb +20 -0
  35. data/spec/generators/modulo_spec.rb +33 -0
  36. data/spec/generators/random_spec.rb +20 -0
  37. data/spec/generators/repeat_spec.rb +37 -0
  38. data/spec/generators/rinda_spec.rb +32 -0
  39. data/spec/generators/sine_spec.rb +43 -0
  40. data/spec/generators/skip_spec.rb +25 -0
  41. data/spec/shared_factory_specs.rb +79 -0
  42. data/spec/spec_helper.rb +9 -0
  43. metadata +122 -0
data/examples/test3.rb ADDED
@@ -0,0 +1,108 @@
1
+ require 'rubygems'
2
+ require 'wx'
3
+ require 'rubyonacid/factories/meta'
4
+ require 'rubyonacid/factories/constant'
5
+ require 'rubyonacid/factories/flash'
6
+ require 'rubyonacid/factories/increment'
7
+ require 'rubyonacid/factories/loop'
8
+ require 'rubyonacid/factories/modulo'
9
+ require 'rubyonacid/factories/random'
10
+ require 'rubyonacid/factories/repeat'
11
+ require 'rubyonacid/factories/sine'
12
+ require 'rubyonacid/factories/skip'
13
+
14
+
15
+
16
+ class MyApp < Wx::App
17
+
18
+ WIDTH = 320
19
+ HEIGHT = 320
20
+
21
+ def on_init
22
+
23
+ random_factory = RubyOnAcid::RandomFactory.new
24
+
25
+ (1..1000).each do |file_number|
26
+
27
+ file_name = sprintf("%05d_random.png", file_number)
28
+
29
+ #The MetaFactory assigns factories to requested value types.
30
+ @f = RubyOnAcid::MetaFactory.new
31
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
32
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
33
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
34
+ @f.factory_pool << RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1))
35
+ @f.factory_pool << RubyOnAcid::ConstantFactory.new(random_factory.within(:constant, 0.0, 1.0))
36
+ @f.factory_pool << RubyOnAcid::FlashFactory.new(random_factory.within(:interval, 2, 100))
37
+ @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
38
+ @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
39
+ @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
40
+ @f.factory_pool << RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1))
41
+ @f.factory_pool << RubyOnAcid::RepeatFactory.new(
42
+ RubyOnAcid::LoopFactory.new(random_factory.within(:increment, -0.1, 0.1)),
43
+ random_factory.within(:interval, 2, 100)
44
+ )
45
+ @f.factory_pool << RubyOnAcid::RepeatFactory.new(
46
+ RubyOnAcid::RandomFactory.new,
47
+ random_factory.within(:interval, 2, 1000)
48
+ )
49
+ @f.factory_pool << RubyOnAcid::RepeatFactory.new(
50
+ RubyOnAcid::SineFactory.new(random_factory.within(:increment, -0.1, 0.1)),
51
+ random_factory.within(:interval, 2, 100)
52
+ )
53
+ @f.factory_pool << RubyOnAcid::ModuloFactory.new(RubyOnAcid::LoopFactory.new(0.00001))
54
+
55
+ frame = Wx::Frame.new(nil, :size => [WIDTH, HEIGHT])
56
+
57
+ bitmap = Wx::Bitmap.new(WIDTH, HEIGHT)
58
+ bitmap.draw do |surface|
59
+ # surface.pen = black_pen
60
+ surface.brush = Wx::BLACK_BRUSH
61
+ surface.draw_rectangle(0, 0, WIDTH, HEIGHT)
62
+ end
63
+ random_factory.within(:iterations, 10, 10000).to_i.times do
64
+ bitmap.draw {|surface| render(surface)}
65
+ end
66
+ bitmap.draw do |surface|
67
+ surface.text_foreground = Wx::Colour.new(255, 255, 255, 255)
68
+ y = 0
69
+ @f.to_yaml.split("\n").each do |line|
70
+ surface.draw_text(line, 0, y)
71
+ y += 10
72
+ end
73
+ end
74
+
75
+ File.open(file_name + ".yml", "w") do |file|
76
+ YAML.dump(@f, file)
77
+ end
78
+
79
+ bitmap.save_file(file_name, Wx::BITMAP_TYPE_PNG)
80
+
81
+ end
82
+
83
+ exit
84
+
85
+ end
86
+
87
+ def render(surface)
88
+ surface.pen = Wx::Pen.new(
89
+ Wx::Colour.new(
90
+ @f.within(:red, 0, 255).to_i,
91
+ @f.within(:green, 0, 255).to_i,
92
+ @f.within(:blue, 0, 255).to_i,
93
+ @f.within(:alpha, 50, 255).to_i
94
+ ),
95
+ @f.within(:width, 1, 5).to_i
96
+ )
97
+ surface.draw_line(
98
+ @f.within(:x, 0, WIDTH).to_i,
99
+ @f.within(:y, 0, HEIGHT).to_i,
100
+ @f.within(:x2, 0, WIDTH).to_i,
101
+ @f.within(:y2, 0, HEIGHT).to_i
102
+ )
103
+ end
104
+
105
+ end
106
+
107
+ app = MyApp.new
108
+ app.main_loop
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
File without changes
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'rubyonacid'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,25 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class ConstantFactory < Factory
6
+
7
+ attr_accessor :value
8
+ def value=(value)
9
+ raise "assigned #{value} to value, must be between -1 and 1" if value < -1 or value > 1
10
+ @value = value
11
+ end
12
+
13
+ def initialize(value = 0.5)
14
+ super
15
+ @value = value
16
+ end
17
+
18
+ #Increment counter for key, looping it around to opposite side if it exits boundary.
19
+ def get_unit(key)
20
+ @value
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class FlashFactory < Factory
6
+
7
+ attr_accessor :interval
8
+
9
+ def initialize(interval = 3)
10
+ super
11
+ @counters = {}
12
+ @values = {}
13
+ @interval = interval
14
+ end
15
+
16
+ #If key is over threshold, flip to other value and reset counter.
17
+ def get_unit(key)
18
+ @counters[key] ||= 0
19
+ @values[key] ||= 1.0
20
+ if @counters[key] >= @interval
21
+ @values[key] = (@values[key] == 1.0 ? 0.0 : 1.0)
22
+ @counters[key] = 0
23
+ end
24
+ #Increment counter.
25
+ @counters[key] += 1
26
+ #Return value.
27
+ @values[key]
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class IncrementFactory < Factory
6
+
7
+ attr_accessor :interval
8
+ def interval=(value)
9
+ @interval = value
10
+ @start_value = (@interval < 0.0 ? 1.0 : 0.0)
11
+ @counters.each_key{|k| @counters[k] = @start_value}
12
+ end
13
+
14
+ def initialize(interval = 0.001)
15
+ super
16
+ @start_value = 0.0
17
+ @counters = {}
18
+ @interval = interval
19
+ end
20
+
21
+ #Increment counter for key and get its sine, then scale it between 0 and 1.
22
+ def get_unit(key)
23
+ @counters[key] ||= @start_value
24
+ @counters[key] += @interval
25
+ @counters[key] = 1.0 if @counters[key] > 1.0
26
+ @counters[key] = 0.0 if @counters[key] < 0.0
27
+ @counters[key]
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class LoopFactory < Factory
6
+
7
+ attr_accessor :interval
8
+ def interval=(value)
9
+ raise "assigned #{value} to interval, must be between -1 and 1" if value < -1 or value > 1
10
+ @interval = value
11
+ end
12
+
13
+ def initialize(interval = 0.01)
14
+ super
15
+ @counters = {}
16
+ @interval = interval
17
+ end
18
+
19
+ #Increment counter for key, looping it around to opposite side if it exits boundary.
20
+ def get_unit(key)
21
+ @counters[key] ||= 0
22
+ @counters[key] += @interval
23
+ @counters[key] = @counters[key] - 1.0 if @counters[key] > 1
24
+ @counters[key] = @counters[key] + 1.0 if @counters[key] < 0
25
+ @counters[key]
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class MetaFactory < Factory
6
+
7
+ attr_accessor :factory_pool
8
+ attr_accessor :assigned_factories
9
+
10
+ def initialize(factory_pool = [])
11
+ super
12
+ @factory_pool = factory_pool
13
+ @assigned_factories = {}
14
+ end
15
+
16
+ def assign_factory(key, factory)
17
+ @assigned_factories[key] = factory
18
+ end
19
+
20
+ def get_unit(key)
21
+ @assigned_factories[key] ||= @factory_pool[rand(@factory_pool.length)]
22
+ @assigned_factories[key].get_unit(key)
23
+ end
24
+
25
+ def reset_assignments
26
+ @assigned_factories.clear
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ #Gets values from a source factory and returns the same value the given number of times before getting a fresh value.
6
+ class ModuloFactory < Factory
7
+
8
+ #Factory to get values from.
9
+ attr_accessor :source_factory
10
+
11
+ def initialize(source_factory = nil)
12
+ super
13
+ @source_factory = source_factory
14
+ @prior_values = {}
15
+ end
16
+
17
+ #Returns the value of get_unit on the source factory the assigned number of times.
18
+ def get_unit(key)
19
+ @prior_values[key] ||= 0
20
+ @prior_values[key] = (@prior_values[key] + @source_factory.get_unit(key)) % 1
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class RandomFactory < Factory
6
+
7
+ #Returns a random value between 0 and 1.
8
+ def get_unit(key)
9
+ rand
10
+ end
11
+
12
+ end
13
+
14
+
15
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ #Gets values from a source factory and returns the same value the given number of times before getting a fresh value.
6
+ class RepeatFactory < Factory
7
+
8
+ #Factory to get values from.
9
+ attr_accessor :source_factory
10
+ #The number of times to repeat a value for a given key.
11
+ attr_accessor :repeat_count
12
+
13
+ def initialize(source_factory = nil, repeat_count = 2)
14
+ super
15
+ @source_factory = source_factory
16
+ @repeat_count = repeat_count
17
+ @repeat_counts = {}
18
+ @values = {}
19
+ end
20
+
21
+ #Returns the value of get_unit on the source factory the assigned number of times.
22
+ def get_unit(key)
23
+ @repeat_counts[key] ||= 0
24
+ if @repeat_counts[key] >= @repeat_count
25
+ @values[key] = nil
26
+ @repeat_counts[key] = 0
27
+ end
28
+ @values[key] ||= @source_factory.get_unit(key)
29
+ @repeat_counts[key] += 1
30
+ @values[key]
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,40 @@
1
+ require 'rinda/rinda'
2
+ require 'rubyonacid/factory'
3
+
4
+ module RubyOnAcid
5
+
6
+ class RindaFactory < Factory
7
+
8
+ #Time in seconds to wait for a value before giving up and returning the last retrieved value for the given key.
9
+ #Default is 0, which will return immediately.
10
+ attr_accessor :timeout
11
+ #The URI to connect to. Default is "druby://127.0.0.1:7632" (7632 == RNDA).
12
+ attr_accessor :uri
13
+
14
+ def initialize(uri = "druby://127.0.0.1:7632", timeout = 0)
15
+ super
16
+ @uri = uri
17
+ @timeout = timeout
18
+ @prior_values = {}
19
+ end
20
+
21
+ def start_service
22
+ DRb.start_service
23
+ @space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, @uri))
24
+ end
25
+
26
+ #Get key from Rinda server.
27
+ def get_unit(key)
28
+ @prior_values[key] ||= 0.0
29
+ begin
30
+ key, value = @space.take([key, Float], @timeout)
31
+ @prior_values[key] = value
32
+ rescue Rinda::RequestExpiredError => exception
33
+ value = @prior_values[key]
34
+ end
35
+ value
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class SineFactory < Factory
6
+
7
+ attr_accessor :interval
8
+
9
+ def initialize(interval = 0.1)
10
+ super
11
+ @counters = {}
12
+ @interval = interval
13
+ end
14
+
15
+ #Increment counter for key and get its sine, then scale it between 0 and 1.
16
+ def get_unit(key)
17
+ @counters[key] ||= 0
18
+ @counters[key] += @interval
19
+ (Math.sin(@counters[key]) + 1) / 2
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubyonacid/factory'
2
+
3
+ module RubyOnAcid
4
+
5
+ class SkipFactory < Factory
6
+
7
+ #The percentage odds that the factory will return 0 instead of 1.
8
+ attr_accessor :odds
9
+
10
+ def initialize(odds = 0.1)
11
+ super
12
+ @odds = odds
13
+ end
14
+
15
+ #If a random number between 0 and 1 is less than the assigned odds value, will return 0 (a "skip").
16
+ #Otherwise returns 1.
17
+ def get_unit(key)
18
+ rand < @odds ? 0.0 : 1.0
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,29 @@
1
+ module RubyOnAcid
2
+
3
+ class Factory
4
+
5
+ def initialize(*args)
6
+ @minimums = {}
7
+ @maximums = {}
8
+ end
9
+
10
+ #Calls get_unit with key to get value between 0.0 and 1.0, then converts that value to be between given minimum and maximum.
11
+ def within(key, minimum, maximum)
12
+ get_unit(key) * (maximum - minimum) + minimum
13
+ end
14
+
15
+ #Calls get_unit with key to get value between 0.0 and 1.0, then converts that value to be between given minimum and maximum.
16
+ def get(key, options = {})
17
+ @minimums[key] = (options[:min] || @minimums[key] || 0.0)
18
+ @maximums[key] = (options[:max] || @maximums[key] || @minimums[key] > 1.0 ? @minimums[key] + 1.0 : 1.0)
19
+ get_unit(key) * (@maximums[key] - @minimums[key]) + @minimums[key]
20
+ end
21
+
22
+ #Returns true if get_unit(key) returns greater than 0.5.
23
+ def boolean(key)
24
+ get_unit(key) >= 0.5
25
+ end
26
+
27
+ end
28
+
29
+ end
data/lib/rubyonacid.rb ADDED
File without changes
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require "shared_factory_specs"
3
+ require 'rubyonacid/factories/constant'
4
+
5
+ include RubyOnAcid
6
+
7
+ describe ConstantFactory do
8
+
9
+ MARGIN = 0.01
10
+
11
+ before :each do
12
+ @it = ConstantFactory.new
13
+ end
14
+
15
+ it_should_behave_like "a factory"
16
+
17
+
18
+ it "always returns the same value" do
19
+ @it.value = 0.1
20
+ @it.get_unit(:x).should == 0.1
21
+ @it.get_unit(:x).should == 0.1
22
+ end
23
+
24
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require "shared_factory_specs"
3
+ require 'rubyonacid/factories/flash'
4
+
5
+ include RubyOnAcid
6
+
7
+ describe FlashFactory do
8
+
9
+ before :each do
10
+ @it = FlashFactory.new
11
+ end
12
+
13
+ it_should_behave_like "a factory"
14
+
15
+ it "returns 1.0 three times, then 0.0 three times, then loops" do
16
+ @it.get_unit(:x).should == 1.0
17
+ @it.get_unit(:x).should == 1.0
18
+ @it.get_unit(:x).should == 1.0
19
+ @it.get_unit(:x).should == 0.0
20
+ @it.get_unit(:x).should == 0.0
21
+ @it.get_unit(:x).should == 0.0
22
+ @it.get_unit(:x).should == 1.0
23
+ @it.get_unit(:x).should == 1.0
24
+ @it.get_unit(:x).should == 1.0
25
+ @it.get_unit(:x).should == 0.0
26
+ @it.get_unit(:x).should == 0.0
27
+ @it.get_unit(:x).should == 0.0
28
+ end
29
+
30
+ it "can take a different interval" do
31
+ @it.interval = 2
32
+ @it.get_unit(:x).should == 1.0
33
+ @it.get_unit(:x).should == 1.0
34
+ @it.get_unit(:x).should == 0.0
35
+ @it.get_unit(:x).should == 0.0
36
+ @it.get_unit(:x).should == 1.0
37
+ end
38
+
39
+ it "handles multiple keys" do
40
+ @it.interval = 2
41
+ @it.get_unit(:x).should == 1.0
42
+ @it.get_unit(:y).should == 1.0
43
+ @it.get_unit(:x).should == 1.0
44
+ @it.get_unit(:y).should == 1.0
45
+ @it.get_unit(:x).should == 0.0
46
+ @it.get_unit(:y).should == 0.0
47
+ end
48
+
49
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require "shared_factory_specs"
3
+ require 'rubyonacid/factories/increment'
4
+
5
+ include RubyOnAcid
6
+
7
+ describe IncrementFactory do
8
+
9
+ MARGIN = 0.01
10
+
11
+ before :each do
12
+ @it = IncrementFactory.new
13
+ end
14
+
15
+ it_should_behave_like "a factory"
16
+
17
+ it "Stops at 1 if increment is positive" do
18
+ @it.interval = 0.3
19
+ @it.get_unit(:x).should be_close(0.3, MARGIN)
20
+ @it.get_unit(:x).should be_close(0.6, MARGIN)
21
+ @it.get_unit(:x).should be_close(0.9, MARGIN)
22
+ @it.get_unit(:x).should be_close(1.0, MARGIN)
23
+ @it.get_unit(:x).should be_close(1.0, MARGIN)
24
+ end
25
+
26
+ it "Stops at 0 if increment is negative" do
27
+ @it.interval = -0.3
28
+ @it.get_unit(:x).should be_close(0.7, MARGIN)
29
+ @it.get_unit(:x).should be_close(0.4, MARGIN)
30
+ @it.get_unit(:x).should be_close(0.1, MARGIN)
31
+ @it.get_unit(:x).should be_close(0.0, MARGIN)
32
+ @it.get_unit(:x).should be_close(0.0, MARGIN)
33
+ end
34
+
35
+ it "handles multiple keys" do
36
+ @it.interval = 0.3
37
+ @it.get_unit(:x).should be_close(0.3, MARGIN)
38
+ @it.get_unit(:y).should be_close(0.3, MARGIN)
39
+ @it.get_unit(:x).should be_close(0.6, MARGIN)
40
+ @it.get_unit(:y).should be_close(0.6, MARGIN)
41
+ end
42
+
43
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require "shared_factory_specs"
3
+ require 'rubyonacid/factories/loop'
4
+
5
+ include RubyOnAcid
6
+
7
+ describe LoopFactory do
8
+
9
+ MARGIN = 0.01
10
+
11
+ before :each do
12
+ @it = LoopFactory.new
13
+ end
14
+
15
+ it_should_behave_like "a factory"
16
+
17
+ it "Loops to 0 if increment is positive" do
18
+ @it.interval = 0.3
19
+ @it.get_unit(:x).should be_close(0.3, MARGIN)
20
+ @it.get_unit(:x).should be_close(0.6, MARGIN)
21
+ @it.get_unit(:x).should be_close(0.9, MARGIN)
22
+ @it.get_unit(:x).should be_close(0.2, MARGIN)
23
+ @it.get_unit(:x).should be_close(0.5, MARGIN)
24
+ end
25
+
26
+ it "Loops to 1 if increment is negative" do
27
+ @it.interval = -0.3
28
+ @it.get_unit(:x).should be_close(0.7, MARGIN)
29
+ @it.get_unit(:x).should be_close(0.4, MARGIN)
30
+ @it.get_unit(:x).should be_close(0.1, MARGIN)
31
+ @it.get_unit(:x).should be_close(0.8, MARGIN)
32
+ @it.get_unit(:x).should be_close(0.5, MARGIN)
33
+ end
34
+
35
+ it "handles multiple keys" do
36
+ @it.interval = 0.3
37
+ @it.get_unit(:x).should be_close(0.3, MARGIN)
38
+ @it.get_unit(:y).should be_close(0.3, MARGIN)
39
+ @it.get_unit(:x).should be_close(0.6, MARGIN)
40
+ @it.get_unit(:y).should be_close(0.6, MARGIN)
41
+ end
42
+
43
+ end
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+ require 'rubyonacid/factories/meta'
3
+
4
+ include RubyOnAcid
5
+
6
+ describe MetaFactory do
7
+
8
+ before :each do
9
+ @it = MetaFactory.new
10
+ end
11
+
12
+ it "takes a list of factories, then randomly and permanently assigns a factory to each requested key" do
13
+ @it.factory_pool << mock('FactoryZero', :get_unit => 0.0)
14
+ @it.factory_pool << mock('FactoryOne', :get_unit => 1.0)
15
+ ('a'..'z').each do |key|
16
+ @it.get_unit(key.to_sym).should == @it.get_unit(key.to_sym)
17
+ end
18
+ end
19
+
20
+ end