hitimes 1.1.1-x86-mingw32 → 1.2.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.travis.yml +10 -0
  2. data/CONTRIBUTING.md +45 -0
  3. data/{HISTORY → HISTORY.md} +42 -18
  4. data/LICENSE +11 -8
  5. data/Manifest.txt +45 -0
  6. data/README.md +163 -0
  7. data/Rakefile +23 -62
  8. data/ext/hitimes/c/extconf.rb +24 -0
  9. data/ext/hitimes/{hitimes_ext.c → c/hitimes.c} +1 -1
  10. data/ext/hitimes/{hitimes_instant_clock_gettime.c → c/hitimes_instant_clock_gettime.c} +0 -0
  11. data/ext/hitimes/c/hitimes_instant_osx.c +45 -0
  12. data/ext/hitimes/{hitimes_instant_windows.c → c/hitimes_instant_windows.c} +0 -0
  13. data/ext/hitimes/{hitimes_interval.c → c/hitimes_interval.c} +15 -7
  14. data/ext/hitimes/{hitimes_interval.h → c/hitimes_interval.h} +5 -5
  15. data/ext/hitimes/{hitimes_stats.c → c/hitimes_stats.c} +0 -0
  16. data/ext/hitimes/{hitimes_stats.h → c/hitimes_stats.h} +0 -0
  17. data/ext/hitimes/java/src/hitimes/Hitimes.java +54 -0
  18. data/ext/hitimes/java/src/hitimes/HitimesInterval.java +181 -0
  19. data/ext/hitimes/java/src/hitimes/HitimesService.java +16 -0
  20. data/ext/hitimes/java/src/hitimes/HitimesStats.java +112 -0
  21. data/lib/hitimes.rb +15 -5
  22. data/lib/hitimes/1.9/hitimes.so +0 -0
  23. data/lib/hitimes/2.0/hitimes.so +0 -0
  24. data/lib/hitimes/2.1/hitimes.so +0 -0
  25. data/lib/hitimes/version.rb +1 -50
  26. data/spec/hitimes_spec.rb +14 -0
  27. data/spec/interval_spec.rb +40 -37
  28. data/spec/metric_spec.rb +8 -10
  29. data/spec/mutex_stats_spec.rb +10 -8
  30. data/spec/paths_spec.rb +3 -5
  31. data/spec/spec_helper.rb +9 -3
  32. data/spec/stats_spec.rb +28 -30
  33. data/spec/timed_metric_spec.rb +42 -42
  34. data/spec/timed_value_metric_spec.rb +54 -55
  35. data/spec/value_metric_spec.rb +26 -28
  36. data/spec/version_spec.rb +4 -30
  37. data/tasks/default.rake +242 -0
  38. data/tasks/extension.rake +31 -101
  39. data/tasks/this.rb +206 -0
  40. metadata +158 -145
  41. data/README +0 -135
  42. data/ext/hitimes/extconf.rb +0 -17
  43. data/ext/hitimes/hitimes_instant_osx.c +0 -16
  44. data/gemspec.rb +0 -64
  45. data/lib/hitimes/1.8/hitimes_ext.so +0 -0
  46. data/lib/hitimes/1.9/hitimes_ext.so +0 -0
  47. data/tasks/announce.rake +0 -42
  48. data/tasks/config.rb +0 -109
  49. data/tasks/distribution.rake +0 -93
  50. data/tasks/documentation.rake +0 -32
  51. data/tasks/rspec.rake +0 -33
  52. data/tasks/rubyforge.rake +0 -55
  53. data/tasks/utils.rb +0 -80
@@ -1,13 +1,11 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/paths'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Hitimes::Paths do
6
4
  it "can access the root dir of the project" do
7
- Hitimes::Paths.root_dir.should == File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
5
+ Hitimes::Paths.root_dir.must_equal File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
8
6
  end
9
7
 
10
8
  it "can access the lib path of the project" do
11
- Hitimes::Paths.lib_path.should == File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) ) + ::File::SEPARATOR
9
+ Hitimes::Paths.lib_path.must_equal File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) ) + ::File::SEPARATOR
12
10
  end
13
11
  end
@@ -1,5 +1,11 @@
1
- require 'rubygems'
2
- require 'spec'
1
+ if RUBY_VERSION >= '1.9.2' then
2
+ require 'simplecov'
3
+ puts "Using coverage!"
4
+ SimpleCov.start if ENV['COVERAGE']
5
+ end
3
6
 
4
- $: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
7
+ gem 'minitest'
8
+ require 'hitimes'
9
+ require 'minitest/autorun'
10
+ require 'minitest/pride'
5
11
 
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/stats'
1
+ require 'spec_helper'
4
2
  require 'json'
5
3
 
6
4
  describe Hitimes::Stats do
@@ -12,64 +10,64 @@ describe Hitimes::Stats do
12
10
  end
13
11
 
14
12
  it "is initialized with 0 values" do
15
- @stats.count.should == 0
16
- @stats.min.should == 0.0
17
- @stats.max.should == 0.0
18
- @stats.sum.should == 0.0
19
- @stats.rate.should == 0.0
13
+ @stats.count.must_equal 0
14
+ @stats.min.must_equal 0.0
15
+ @stats.max.must_equal 0.0
16
+ @stats.sum.must_equal 0.0
17
+ @stats.rate.must_equal 0.0
20
18
  end
21
19
 
22
20
  it "calculates the mean correctly" do
23
- @full_stats.mean.should == 2.0
21
+ @full_stats.mean.must_equal 2.0
24
22
  end
25
23
 
26
24
  it "calculates the rate correctly" do
27
- @full_stats.rate.should == 0.5
25
+ @full_stats.rate.must_equal 0.5
28
26
  end
29
27
 
30
28
  it "tracks the maximum value" do
31
- @full_stats.max.should == 3.0
29
+ @full_stats.max.must_equal 3.0
32
30
  end
33
31
 
34
32
  it "tracks the minimum value" do
35
- @full_stats.min.should == 1.0
33
+ @full_stats.min.must_equal 1.0
36
34
  end
37
35
 
38
36
  it "tracks the count" do
39
- @full_stats.count.should == 3
37
+ @full_stats.count.must_equal 3
40
38
  end
41
39
 
42
40
  it "tracks the sum" do
43
- @full_stats.sum.should == 6.0
41
+ @full_stats.sum.must_equal 6.0
44
42
  end
45
43
 
46
44
  it "calculates the standard deviation" do
47
- @full_stats.stddev.should == 1.0
45
+ @full_stats.stddev.must_equal 1.0
48
46
  end
49
47
 
50
48
  it "calculates the sum of squares " do
51
- @full_stats.sumsq.should == 14.0
49
+ @full_stats.sumsq.must_equal 14.0
52
50
  end
53
51
 
54
52
  describe "#to_hash " do
55
53
  it "converts to a Hash" do
56
54
  h = @full_stats.to_hash
57
- h.size.should == ::Hitimes::Stats::STATS.size
58
- h.keys.sort.should == ::Hitimes::Stats::STATS
55
+ h.size.must_equal ::Hitimes::Stats::STATS.size
56
+ h.keys.sort.must_equal ::Hitimes::Stats::STATS
59
57
  end
60
58
 
61
59
  it "converts to a limited Hash if given arguments" do
62
60
  h = @full_stats.to_hash( "min", "max", "mean" )
63
- h.size.should == 3
64
- h.keys.sort.should == %w[ max mean min ]
61
+ h.size.must_equal 3
62
+ h.keys.sort.must_equal %w[ max mean min ]
65
63
 
66
64
  h = @full_stats.to_hash( %w[ count rate ] )
67
- h.size.should == 2
68
- h.keys.sort.should == %w[ count rate ]
65
+ h.size.must_equal 2
66
+ h.keys.sort.must_equal %w[ count rate ]
69
67
  end
70
68
 
71
69
  it "raises NoMethodError if an invalid stat is used" do
72
- lambda { @full_stats.to_hash( "wibble" ) }.should raise_error( NoMethodError )
70
+ lambda { @full_stats.to_hash( "wibble" ) }.must_raise( NoMethodError )
73
71
  end
74
72
  end
75
73
 
@@ -77,24 +75,24 @@ describe Hitimes::Stats do
77
75
  it "converts to a json string" do
78
76
  j = @full_stats.to_json
79
77
  h = JSON.parse( j )
80
- h.size.should == ::Hitimes::Stats::STATS.size
81
- h.keys.sort.should == ::Hitimes::Stats::STATS
78
+ h.size.must_equal ::Hitimes::Stats::STATS.size
79
+ h.keys.sort.must_equal ::Hitimes::Stats::STATS
82
80
  end
83
81
 
84
82
  it "converts to a limited Hash if given arguments" do
85
83
  j = @full_stats.to_json( "min", "max", "mean" )
86
84
  h = JSON.parse( j )
87
- h.size.should == 3
88
- h.keys.sort.should == %w[ max mean min ]
85
+ h.size.must_equal 3
86
+ h.keys.sort.must_equal %w[ max mean min ]
89
87
 
90
88
  j = @full_stats.to_json( %w[ count rate ] )
91
89
  h = JSON.parse( j )
92
- h.size.should == 2
93
- h.keys.sort.should == %w[ count rate ]
90
+ h.size.must_equal 2
91
+ h.keys.sort.must_equal %w[ count rate ]
94
92
  end
95
93
 
96
94
  it "raises NoMethodError if an invalid stat is used" do
97
- lambda { @full_stats.to_json( "wibble" ) }.should raise_error( NoMethodError )
95
+ lambda { @full_stats.to_json( "wibble" ) }.must_raise( NoMethodError )
98
96
  end
99
97
  end
100
98
  end
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/timed_metric'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Hitimes::TimedMetric do
6
4
  before( :each ) do
@@ -8,147 +6,149 @@ describe Hitimes::TimedMetric do
8
6
  end
9
7
 
10
8
  it "knows if it is running or not" do
11
- @tm.should_not be_running
9
+ @tm.running?.must_equal false
12
10
  @tm.start
13
- @tm.should be_running
11
+ @tm.running?.must_equal true
14
12
  @tm.stop
15
- @tm.should_not be_running
13
+ @tm.running?.must_equal false
16
14
  end
17
15
 
18
16
  it "#split returns the last duration and the timer is still running" do
19
17
  @tm.start
20
18
  d = @tm.split
21
- @tm.should be_running
22
- d.should > 0
23
- @tm.count.should == 1
24
- @tm.duration.should == d
19
+ @tm.running?.must_equal true
20
+ d.must_be :>, 0
21
+ @tm.count.must_equal 1
22
+ @tm.duration.must_equal d
25
23
  end
26
24
 
27
25
  it "#stop returns false if called more than once in a row" do
28
26
  @tm.start
29
- @tm.stop.should > 0
30
- @tm.stop.should == false
27
+ @tm.stop.must_be :>, 0
28
+ @tm.stop.must_equal false
31
29
  end
32
30
 
33
31
  it "does not count a currently running interval as an interval in calculations" do
34
32
  @tm.start
35
- @tm.count.should == 0
33
+ @tm.count.must_equal 0
36
34
  @tm.split
37
- @tm.count.should == 1
35
+ @tm.count.must_equal 1
38
36
  end
39
37
 
40
38
  it "#split called on a stopped timer does nothing" do
41
39
  @tm.start
42
40
  @tm.stop
43
- @tm.split.should == false
41
+ @tm.split.must_equal false
44
42
  end
45
43
 
46
44
  it "calculates the mean of the durations" do
47
45
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
48
- @tm.mean.should be_close( 0.05, 0.01 )
46
+ @tm.mean.must_be_close_to(0.05, 0.002)
49
47
  end
50
48
 
51
49
  it "calculates the rate of the counts " do
52
50
  5.times { @tm.start ; sleep 0.05 ; @tm.stop }
53
- @tm.rate.should be_close( 20.00, 0.1 )
51
+ @tm.rate.must_be_close_to(20.00, 0.5)
54
52
  end
55
53
 
56
54
 
57
55
  it "calculates the stddev of the durations" do
58
- 3.times { |x| @tm.start ; sleep (0.05 * x) ; @tm.stop }
59
- @tm.stddev.should be_close( 0.05, 0.001)
56
+ 3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop }
57
+ @tm.stddev.must_be_close_to(0.05)
60
58
  end
61
59
 
62
60
  it "returns 0.0 for stddev if there is no data" do
63
- @tm.stddev.should == 0.0
61
+ @tm.stddev.must_equal 0.0
64
62
  end
65
63
 
66
64
  it "keeps track of the min value" do
67
65
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
68
- @tm.min.should be_close( 0.05, 0.002 )
66
+ @tm.min.must_be_close_to(0.05, 0.01)
69
67
  end
70
68
 
71
69
  it "keeps track of the max value" do
72
70
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
73
- @tm.max.should be_close( 0.05, 0.002 )
71
+ @tm.max.must_be_close_to(0.05, 0.01)
74
72
  end
75
73
 
76
74
  it "keeps track of the sum value" do
77
75
  2.times { @tm.start ; sleep 0.05 ; @tm.stop }
78
- @tm.sum.should be_close( 0.10, 0.002 )
76
+ @tm.sum.must_be_close_to(0.10, 0.01)
79
77
  end
80
-
78
+
81
79
  it "keeps track of the sum of squars value" do
82
80
  3.times { @tm.start ; sleep 0.05 ; @tm.stop }
83
- @tm.sumsq.should be_close( 0.0075, 0.0001 )
81
+ @tm.sumsq.must_be_close_to(0.0075)
84
82
  end
85
83
 
86
84
  it "keeps track of the minimum start time of all the intervals" do
87
85
  f1 = Time.now.gmtime.to_f * 1_000_000
88
86
  5.times { @tm.start ; sleep 0.05 ; @tm.stop }
89
87
  f2 = Time.now.gmtime.to_f * 1_000_000
90
- @tm.sampling_start_time.should >= f1
91
- @tm.sampling_start_time.should < f2
88
+ @tm.sampling_start_time.must_be :>=, f1
89
+ @tm.sampling_start_time.must_be :<, f2
92
90
  # distance from now to start time should be greater than the distance from
93
91
  # the start to the min start_time
94
- (f2 - @tm.sampling_start_time).should > ( @tm.sampling_start_time - f1 )
92
+ (f2 - @tm.sampling_start_time).must_be :>, ( @tm.sampling_start_time - f1 )
95
93
  end
96
94
 
97
95
  it "keeps track of the last stop time of all the intervals" do
98
96
  f1 = Time.now.gmtime.to_f * 1_000_000
97
+ sleep 0.01
99
98
  5.times { @tm.start ; sleep 0.05 ; @tm.stop }
99
+ sleep 0.01
100
100
  f2 = Time.now.gmtime.to_f * 1_000_000
101
- @tm.sampling_stop_time.should > f1
102
- @tm.sampling_stop_time.should <= f2
101
+ @tm.sampling_stop_time.must_be :>, f1
102
+ @tm.sampling_stop_time.must_be :<=, f2
103
103
  # distance from now to max stop time time should be less than the distance
104
104
  # from the start to the max stop time
105
- (f2 - @tm.sampling_stop_time).should < ( @tm.sampling_stop_time - f1 )
105
+ (f2 - @tm.sampling_stop_time).must_be :<, ( @tm.sampling_stop_time - f1 )
106
106
  end
107
107
 
108
108
  it "can create an already running timer" do
109
109
  t = Hitimes::TimedMetric.now( 'already-running' )
110
- t.should be_running
110
+ t.running?.must_equal true
111
111
  end
112
112
 
113
113
  it "can measure a block of code from an instance" do
114
114
  t = Hitimes::TimedMetric.new( 'measure a block' )
115
115
  3.times { t.measure { sleep 0.05 } }
116
- t.duration.should be_close( 0.15, 0.001 )
117
- t.count.should == 3
116
+ t.duration.must_be_close_to(0.15, 0.01)
117
+ t.count.must_equal 3
118
118
  end
119
119
 
120
120
  it "returns the value of the block when measuring" do
121
121
  t = Hitimes::TimedMetric.new( 'measure a block' )
122
122
  x = t.measure { sleep 0.05; 42 }
123
- t.duration.should be_close( 0.05, 0.001 )
124
- x.should == 42
123
+ t.duration.must_be_close_to(0.05, 0.002)
124
+ x.must_equal 42
125
125
  end
126
126
 
127
127
  describe "#to_hash" do
128
128
 
129
129
  it "has name value" do
130
130
  h = @tm.to_hash
131
- h['name'].should == "test-timed-metric"
131
+ h['name'].must_equal "test-timed-metric"
132
132
  end
133
133
 
134
134
  it "has an empty hash for additional_data" do
135
135
  h = @tm.to_hash
136
- h['additional_data'].should == Hash.new
137
- h['additional_data'].size.should == 0
136
+ h['additional_data'].must_equal Hash.new
137
+ h['additional_data'].size.must_equal 0
138
138
  end
139
139
 
140
140
  it "has the right sum" do
141
141
  10.times { |x| @tm.measure { sleep 0.01*x } }
142
142
  h = @tm.to_hash
143
- h['sum'].should be_close( 0.45, 0.003 )
143
+ h['sum'].must_be_close_to(0.45, 0.01)
144
144
  end
145
145
 
146
146
  fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]
147
147
  fields.each do |f|
148
- it "should have a value for #{f}" do
148
+ it "has a value for #{f}" do
149
149
  @tm.measure { sleep 0.001 }
150
150
  h = @tm.to_hash
151
- h[f].should_not be_nil
151
+ h[f].wont_be_nil
152
152
  end
153
153
  end
154
154
  end
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/timed_value_metric'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Hitimes::TimedValueMetric do
6
4
  before( :each ) do
@@ -8,164 +6,165 @@ describe Hitimes::TimedValueMetric do
8
6
  end
9
7
 
10
8
  it "knows if it is running or not" do
11
- @tm.should_not be_running
9
+ @tm.running?.must_equal false
12
10
  @tm.start
13
- @tm.should be_running
11
+ @tm.running?.must_equal true
14
12
  @tm.stop( 1 )
15
- @tm.should_not be_running
13
+ @tm.running?.must_equal false
16
14
  end
17
15
 
18
16
  it "#split returns the last duration and the timer is still running" do
19
17
  @tm.start
20
18
  d = @tm.split( 1 )
21
- @tm.should be_running
22
- d.should > 0
23
- @tm.value_stats.count.should == 1
24
- @tm.timed_stats.count.should == 1
25
- @tm.duration.should == d
19
+ @tm.running?.must_equal true
20
+ d.must_be :>, 0
21
+ @tm.value_stats.count.must_equal 1
22
+ @tm.timed_stats.count.must_equal 1
23
+ @tm.duration.must_equal d
26
24
  end
27
25
 
28
26
  it "#stop returns false if called more than once in a row" do
29
27
  @tm.start
30
- @tm.stop( 1 ).should > 0
31
- @tm.stop( 1 ).should == false
28
+ @tm.stop( 1 ).must_be :>, 0
29
+ @tm.stop( 1 ).must_equal false
32
30
  end
33
31
 
34
32
  it "does not count a currently running interval as an interval in calculations" do
35
33
  @tm.start
36
- @tm.value_stats.count.should == 0
37
- @tm.timed_stats.count.should == 0
34
+ @tm.value_stats.count.must_equal 0
35
+ @tm.timed_stats.count.must_equal 0
38
36
  @tm.split( 1 )
39
- @tm.value_stats.count.should == 1
40
- @tm.timed_stats.count.should == 1
37
+ @tm.value_stats.count.must_equal 1
38
+ @tm.timed_stats.count.must_equal 1
41
39
  end
42
40
 
43
41
  it "#split called on a stopped timer does nothing" do
44
42
  @tm.start
45
43
  @tm.stop( 1 )
46
- @tm.split( 1 ).should == false
44
+ @tm.split( 1 ).must_equal false
47
45
  end
48
46
 
49
47
  it "calculates the mean of the durations" do
50
48
  3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop(x) }
51
- @tm.timed_stats.mean.should be_close( 0.05, 0.01 )
52
- @tm.value_stats.mean.should == 1.00
49
+ @tm.timed_stats.mean.must_be_close_to(0.05, 0.01)
50
+ @tm.value_stats.mean.must_equal 1.00
53
51
  end
54
52
 
55
53
  it "calculates the rate of the counts " do
56
54
  5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
57
- @tm.rate.should be_close( 40.0, 0.2)
55
+ @tm.rate.must_be_close_to(40.0, 1.0)
58
56
  end
59
57
 
60
58
 
61
59
  it "calculates the stddev of the durations" do
62
- 3.times { |x| @tm.start ; sleep (0.05 * x) ; @tm.stop(x) }
63
- @tm.timed_stats.stddev.should be_close( 0.05, 0.001)
64
- @tm.value_stats.stddev.should == 1.0
60
+ 3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop(x) }
61
+ @tm.timed_stats.stddev.must_be_close_to(0.05, 0.001)
62
+ @tm.value_stats.stddev.must_equal 1.0
65
63
  end
66
64
 
67
65
  it "returns 0.0 for stddev if there is no data" do
68
- @tm.timed_stats.stddev.should == 0.0
69
- @tm.value_stats.stddev.should == 0.0
66
+ @tm.timed_stats.stddev.must_equal 0.0
67
+ @tm.value_stats.stddev.must_equal 0.0
70
68
  end
71
69
 
72
70
  it "keeps track of the min value" do
73
71
  3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
74
- @tm.timed_stats.min.should be_close( 0.05, 0.001 )
75
- @tm.value_stats.min.should == 0
72
+ @tm.timed_stats.min.must_be_close_to( 0.05, 0.003 )
73
+ @tm.value_stats.min.must_equal 0
76
74
  end
77
75
 
78
76
  it "keeps track of the max value" do
79
77
  3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
80
- @tm.timed_stats.max.should be_close( 0.05, 0.001)
81
- @tm.value_stats.max.should == 2
78
+ @tm.timed_stats.max.must_be_close_to( 0.05, 0.003 )
79
+ @tm.value_stats.max.must_equal 2
82
80
  end
83
81
 
84
82
  it "keeps track of the sum value" do
85
83
  3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
86
- @tm.timed_stats.sum.should be_close( 0.15, 0.01 )
87
- @tm.value_stats.sum.should == 3
84
+ @tm.timed_stats.sum.must_be_close_to( 0.15, 0.01 )
85
+ @tm.value_stats.sum.must_equal 3
88
86
  end
89
87
 
90
88
  it "keeps track of the sum of squares value" do
91
89
  3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
92
- @tm.timed_stats.sumsq.should be_close( 0.0075, 0.0001 )
93
- @tm.value_stats.sumsq.should == 5
90
+ @tm.timed_stats.sumsq.must_be_close_to(0.0075, 0.0005)
91
+ @tm.value_stats.sumsq.must_equal 5
94
92
  end
95
93
 
96
94
  it "keeps track of the minimum start time of all the intervals" do
97
95
  f1 = Time.now.gmtime.to_f * 1000000
98
96
  5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
99
97
  f2 = Time.now.gmtime.to_f * 1000000
100
- @tm.sampling_start_time.should >= f1
101
- @tm.sampling_start_time.should < f2
98
+ @tm.sampling_start_time.must_be :>=, f1
99
+ @tm.sampling_start_time.must_be :<, f2
102
100
  # distance from now to start time should be greater than the distance from
103
101
  # the start to the min start_time
104
- (f2 - @tm.sampling_start_time).should > ( @tm.sampling_start_time - f1 )
102
+ (f2 - @tm.sampling_start_time).must_be :>, ( @tm.sampling_start_time - f1 )
105
103
  end
106
104
 
107
105
  it "keeps track of the last stop time of all the intervals" do
108
- f1 = Time.now.gmtime.to_f * 1000000
106
+ f1 = Time.now.gmtime.to_f * 1_000_000
109
107
  5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
110
- f2 = Time.now.gmtime.to_f * 1000000
111
- @tm.sampling_stop_time.should > f1
112
- @tm.sampling_stop_time.should <= f2
108
+ sleep 0.05
109
+ f2 = Time.now.gmtime.to_f * 1_000_000
110
+ @tm.sampling_stop_time.must_be :>, f1
111
+ @tm.sampling_stop_time.must_be :<=, f2
113
112
  # distance from now to max stop time time should be less than the distance
114
113
  # from the start to the max stop time
115
- (f2 - @tm.sampling_stop_time).should < ( @tm.sampling_stop_time - f1 )
114
+ (f2 - @tm.sampling_stop_time).must_be :<, ( @tm.sampling_stop_time - f1 )
116
115
  end
117
116
 
118
117
  it "can create an already running timer" do
119
118
  t = Hitimes::TimedValueMetric.now( 'already-running' )
120
- t.should be_running
119
+ t.running?.must_equal true
121
120
  end
122
121
 
123
122
  it "can measure a block of code from an instance" do
124
123
  t = Hitimes::TimedValueMetric.new( 'measure a block' )
125
124
  3.times { t.measure( 1 ) { sleep 0.05 } }
126
- t.duration.should be_close( 0.15, 0.001 )
127
- t.timed_stats.count.should == 3
128
- t.value_stats.count.should == 3
125
+ t.duration.must_be_close_to(0.15, 0.004)
126
+ t.timed_stats.count.must_equal 3
127
+ t.value_stats.count.must_equal 3
129
128
  end
130
129
 
131
130
  it "returns the value of the block when measuring" do
132
131
  t = Hitimes::TimedValueMetric.new( 'measure a block' )
133
132
  x = t.measure( 42 ) { sleep 0.05; 42 }
134
- t.duration.should be_close( 0.05, 0.001 )
135
- x.should == 42
133
+ t.duration.must_be_close_to(0.05, 0.002)
134
+ x.must_equal 42
136
135
  end
137
136
 
138
137
  describe "#to_hash" do
139
138
 
140
139
  it "has name value" do
141
140
  h = @tm.to_hash
142
- h['name'].should == "test-timed-value-metric"
141
+ h['name'].must_equal "test-timed-value-metric"
143
142
  end
144
143
 
145
144
  it "has an empty has for additional_data" do
146
145
  h = @tm.to_hash
147
- h['additional_data'].should == Hash.new
148
- h['additional_data'].size.should == 0
146
+ h['additional_data'].must_equal Hash.new
147
+ h['additional_data'].size.must_equal 0
149
148
  end
150
149
 
151
150
  it "has a rate" do
152
151
  5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
153
152
  h = @tm.to_hash
154
- h['rate'].should be_close( 40.0, 0.3 )
153
+ h['rate'].must_be_close_to(40.0, 1.0)
155
154
  end
156
155
 
157
156
  it "has a unit_count" do
158
157
  5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
159
158
  h = @tm.to_hash
160
- h['unit_count'].should == 10
159
+ h['unit_count'].must_equal 10
161
160
  end
162
161
 
163
162
  fields = %w[ name additional_data sampling_start_time sampling_stop_time value_stats timed_stats rate unit_count ]
164
163
  fields.each do |f|
165
- it "should have a value for #{f}" do
164
+ it "has a value for #{f}" do
166
165
  3.times { |x| @tm.measure(x) { sleep 0.001 } }
167
166
  h = @tm.to_hash
168
- h[f].should_not be_nil
167
+ h[f].wont_be_nil
169
168
  end
170
169
  end
171
170
  end