Permalink
Browse files

Upgraded tryouts to 2.0 syntax

  • Loading branch information...
1 parent be3c95c commit ba5305499176f9c68928326ae77fdf36661f7b9d @delano committed Sep 4, 2010
View
110 tryouts/10_stats_tryouts.rb
@@ -1,66 +1,50 @@
+require 'benelux'
-group "Benelux"
+@base = Benelux::Stats::Calculator.new
+@stat_names = [:execute, :request, :first_byte]
-library :benelux, 'lib'
-tryouts "Calculator" do
- set :base, Benelux::Stats::Calculator.new
- dream :class, Benelux::Stats::Calculator
- dream :n, 10
- dream :sum, 45
- dream :sumsq, 285
- dream :min, 0
- dream :max, 9
- dream :proc, lambda { |calc| calc.sd.to_i == 3 }
- drill "can keep stats" do
- 10.times { |i| base.sample(i) }
- base
- end
-
- dream true
- drill "can add stats" do
- by_sample = Benelux::Stats::Calculator.new
- 10.times { |i| by_sample.sample(i) }
- by_sample += base
- by_merge = Benelux::Stats::Calculator.new
- by_merge.merge! base
- by_merge.merge! base
- stash :sample, by_sample
- stash :merge, by_merge
- by_sample == by_merge
- end
-
-end
+## "can keep stats"
+10.times { |i| @base.sample(i) }
+@base.sum
+#=> 45
-tryouts "Stats" do
- set :stat_names, [:execute, :request, :first_byte]
-
- dream stat_names
- drill "knows stats names" do
- stats = Benelux::Stats.new(stat_names)
- stats.names
- end
-
- drill "can keep multiple stats", true do
- stats = Benelux::Stats.new(stat_names)
- stats.execute.sample(rand)
- stats.request.sample(rand*-1)
- stats.execute != stats.request
- end
-
- dream [true, true, true]
- drill "can keep stats with tags" do
- stats = Benelux::Stats.new(stat_names)
- 3.times { |i|
- stats.execute.sample(rand, :usecase => '11')
- stats.execute.sample(rand, :usecase => '11', :request => '22')
- stats.execute.sample(rand, :request => '22')
- }
- stash :execute_stats, stats.execute
- [
- stats.execute['11'] == stats.execute[:usecase => '11'],
- stats.execute['22'] == stats.execute[:request => '22'],
- stats.execute['22','11'] == stats.execute[:usecase => '11', :request => '22']
- ]
- end
-
-end
+## "can add stats"
+by_sample = Benelux::Stats::Calculator.new
+10.times { |i| by_sample.sample(i) }
+by_sample += @base
+by_merge = Benelux::Stats::Calculator.new
+by_merge.merge! @base
+by_merge.merge! @base
+p [:sample, by_sample]
+p [:merge, by_merge]
+by_sample == by_merge
+#=> true
+
+
+## "knows stats names"
+stats = Benelux::Stats.new(@stat_names)
+stats.names
+#=> @stat_names
+
+
+## "can keep multiple stats"
+stats = Benelux::Stats.new(@stat_names)
+stats.execute.sample(rand)
+stats.request.sample(rand*-1)
+stats.execute != stats.request
+#=> true
+
+
+## "can keep stats with tags"
+stats = Benelux::Stats.new(@stat_names)
+3.times { |i|
+ stats.execute.sample(rand, :usecase => '11')
+ stats.execute.sample(rand, :usecase => '11', :request => '22')
+ stats.execute.sample(rand, :request => '22')
+}
+[
+ stats.execute['11'] == stats.execute[:usecase => '11'],
+ stats.execute['22'] == stats.execute[:request => '22'],
+ stats.execute['22','11'] == stats.execute[:usecase => '11', :request => '22']
+]
+#=> [true, true, true]
View
150 tryouts/11_selectable_tryouts.rb
@@ -1,92 +1,78 @@
+require 'benelux'
-group "Benelux"
+@base = SelectableArray.new
+@tags = Selectable::Tags[:a => 1, :b => 2]
-library :benelux, 'lib'
-tryouts "Selectable" do
- set :base, SelectableArray.new
-
- setup do
- class ::TaggedItems
- include Selectable::Object
- end
- 10.times { |i|
- obj = TaggedItems.new
- obj.add_tags :index => i, :even => (i%2 == 0)
- base << obj
- }
- end
-
- dream :class, SelectableArray
- dream :size, 5
- drill "filter returns a new instance of the same object" do
- base.filter(:even => true)
- end
-
- dream :class, SelectableArray
- dream :object_id, base.object_id
- dream :size, 5
- drill "filter! makes permanent changes to itself" do
- base.filter! :even => true
- end
-
+class ::TaggedItems
+ include Selectable::Object
end
+10.times { |i|
+ obj = TaggedItems.new
+ obj.add_tags :index => i, :even => (i%2 == 0)
+ @base << obj
+}
-tryouts "Tags" do
- set :base, Selectable::Tags[:a => 1, :b => 2]
-
- drill "Can equal a Hash with the same keys/values", true do
- base == {:a => 1, :b => 2}
- end
-
- drill "Implements a comparison operator", true do
- base.respond_to? :'<=>'
- end
-
- drill "Comparison operator returns 0 for same values", 0 do
- base <=> {:a => 1, :b => 2}
- end
-
- drill "Comparison operator returns 1 when it's a superset of other", 1 do
- base <=> {:a => 1}
- end
+## filter returns a new instance of the same object
+ret = @base.filter(:even => true)
+ret.class
+#=> SelectableArray
+
+## filter! makes permanent changes to itself
+ret = @base.filter! :even => true
+ret.object_id
+#=> @base.object_id
- drill "Comparison operator returns -1 when it's a subset of other", -1 do
- base <=> {:a => 1, :b => 2, :c => 3}
- end
-
- drill "> returns false when compared to a hash with more key value pairs", false do
- base > {:a => 1, :b => 2, :c => 3}
- end
-
- drill "> returns true when compared to a hash with fewer key value pairs", true do
- base > {:b => 2}
- end
- drill "< returns true when compared to a hash with more key value pairs", true do
- base < {:a => 1, :b => 2, :c => 3}
- end
-
- drill "< returns false when compared to a hash with fewer key value pairs", false do
- base < {:b => 2}
- end
-
- drill "< returns false when compared to a hash with same values", false do
- base < {:a => 1, :b => 2}
- end
+## Can equal a Hash with the same keys/values
+@tags == {:a => 1, :b => 2}
+#=> true
- drill "<= returns true when compared to a hash with same values", true do
- base <= {:b => 2, :a => 1}
- end
-
- drill "< returns false when compared to an array with same values", false do
- base < [1, 2]
- end
-
- drill "<= returns true when compared to an array with same values", true do
- base <= [2, 1]
- end
-
-end
+## Implements a comparison operator
+@tags.respond_to? :'<=>'
+#=> true
+
+## Comparison operator returns 0 for same values
+@tags <=> {:a => 1, :b => 2}
+#=> 0
+
+## Comparison operator returns 1 when it's a superset of other
+@tags <=> {:a => 1}
+#=> 1
+
+## Comparison operator returns -1 when it's a subset of other
+@tags <=> {:a => 1, :b => 2, :c => 3}
+#=> -1
+
+## > returns false when compared to a hash with more key value pairs
+@tags > {:a => 1, :b => 2, :c => 3}
+#=> false
+
+## > returns true when compared to a hash with fewer key value pairs
+@tags > {:b => 2}
+#=> true
+
+## < returns true when compared to a hash with more key value pairs
+@tags < {:a => 1, :b => 2, :c => 3}
+#=> true
+
+## < returns false when compared to a hash with fewer key value pairs
+@tags < {:b => 2}
+#=> false
+
+## < returns false when compared to a hash with same values
+@tags < {:a => 1, :b => 2}
+#=> false
+
+## <= returns true when compared to a hash with same values
+@tags <= {:b => 2, :a => 1}
+#=> true
+
+## < returns false when compared to an array with same values
+@tags < [1, 2]
+#=> false
+## <= returns true when compared to an array with same values
+@tags <= [2, 1]
+#=> true
View
39 tryouts/20_tracks_tryouts.rb
@@ -1,22 +1,21 @@
-group "Benelux"
+require 'benelux'
-library :benelux, 'lib'
-tryouts "Tracks" do
-
- dream [:track1, :track1]
- drill "Can specify current track" do
- Benelux.current_track :track1
- [Thread.current.track_name, Benelux.current_track.name]
- end
-
- dream :class, Benelux::Timeline
- drill "Track has a timeline" do
- Benelux.current_track.timeline
- end
-
- dream :exception, Benelux::UnknownTrack
- drill "raises exception when unknown track specified" do
- Benelux.track :name
- end
-
+
+## Can specify current track" do
+Benelux.current_track :track1
+[Thread.current.track_name, Benelux.current_track.name]
+#=> [:track1, :track1]
+
+## Track has a timeline" do
+tl = Benelux.current_track.timeline
+tl.class
+#=> Benelux::Timeline
+
+
+## raises exception when unknown track specified" do
+begin
+ Benelux.track :name
+rescue Benelux::UnknownTrack
+ :success
end
+#=> :success
View
34 tryouts/30_reporter_tryouts.rb
@@ -1,34 +0,0 @@
-group "Benelux"
-
-library :benelux, 'lib'
-xtryouts "Reporter" do
- set :reporter, Benelux::Reporter.new
-
- drill "1", true do
- p Benelux
- end
-
- dream :exception, Benelux::BadRecursion
- xdrill "will not report on itself" do
- reporter.add_threads Thread.current
- end
-
- dream :class, ThreadsWait
- dream :empty?, false
- xdrill "can add threads" do
- 2.times {
- t = Thread.new do
- 3.times { sleep 1; }
- end
- reporter.add_thread t
- }
- reporter.thwait
- end
-
- dream true
- xdrill "will wait for known threads" do
- reporter.start
- reporter
- end
-
-end
View
60 tryouts/30_timeline_tryouts.rb
@@ -1,60 +0,0 @@
-
-
-__END__
-# OLD (0.3):
-
-group "Benelux"
-
-library :benelux, 'lib'
-tryouts "Timelines" do
- set :tl, Benelux::Timeline.new
-
- setup do
- class ::Sleeper
- def do_something() sleep rand/3 end
- def another_method(t) t*2 end
- end
- end
-
- drill "Can set thread track", :track1 do
- Benelux.current_track :track1
-# Thread.current.track
- end
-
- drill "Add timers to existing objects", true do
- Benelux.add_timer Sleeper, :do_something
- Sleeper.new.respond_to? :timeline
- end
-
- dream :class, Benelux::Timeline
- dream :size, 3
- drill "create timeline with marks" do
- tl.add_default_tags :a => :frog
- tl.add_mark(:one)
- tl.add_default_tags :b => :rest
- tl.add_mark(:two)
- tl.add_default_tags :c => :tilt
- tl.add_mark(:three)
- tl.marks
- end
-
- dream :size, 2
- drill "select marks based on tags" do
- tl[:frog][:b => :rest]
- end
-
- dream :class, Benelux::Timeline
- dream :size, 10 # 5 * 2 = 10
- drill "Creates a timeline for the thread" do
- sleeper = Sleeper.new
- 5.times { sleeper.do_something }
- Benelux.thread_timeline
- end
-
- dream :class, Benelux::Timeline
- dream :size, 10
- drill "Creates a global timeline" do
- Benelux.update_all_track_timelines
- Benelux.timeline
- end
-end

0 comments on commit ba53054

Please sign in to comment.