darkhelmet-darkext 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/darkext/beagle.rb +2 -1
- data/lib/darkext/float.rb +1 -3
- data/lib/darkext/integer.rb +1 -1
- data/lib/darkext/net.rb +2 -2
- data/lib/darkext/sitemap_generator.rb +2 -2
- data/lib/darkext/statistics.rb +22 -6
- data/lib/darkext/string.rb +3 -5
- data/lib/darkext.rb +10 -4
- data/spec/array_spec.rb +57 -0
- data/spec/beagle_spec.rb +42 -0
- data/spec/boolean_spec.rb +31 -0
- data/spec/fiber_spec.rb +21 -0
- data/spec/float_spec.rb +11 -0
- data/spec/hash_spec.rb +11 -0
- data/spec/integer_spec.rb +15 -0
- data/spec/io_spec.rb +30 -0
- data/spec/net_spec.rb +23 -0
- data/spec/numeric_spec.rb +17 -0
- data/spec/object_spec.rb +16 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/statistics_spec.rb +56 -0
- data/spec/string_spec.rb +29 -0
- data/spec/symbol_spec.rb +11 -0
- metadata +17 -2
data/VERSION.yml
CHANGED
data/lib/darkext/beagle.rb
CHANGED
@@ -77,7 +77,8 @@ module Beagle
|
|
77
77
|
|
78
78
|
def self.running?
|
79
79
|
raise BeagleError, "Beagle.home (BEAGLE_HOME) not set!" if home.nil?
|
80
|
-
|
80
|
+
s = status
|
81
|
+
return false if s.include?("Could not connect") || s.empty?
|
81
82
|
return true
|
82
83
|
end
|
83
84
|
|
data/lib/darkext/float.rb
CHANGED
data/lib/darkext/integer.rb
CHANGED
@@ -3,7 +3,7 @@ require 'darkext/array'
|
|
3
3
|
class Integer
|
4
4
|
# Computes the factorial of the Integer
|
5
5
|
def fact
|
6
|
-
raise ArgumentError.new(
|
6
|
+
raise ArgumentError.new('Cannot compute factorial of negative number') if 0 > self
|
7
7
|
return 1 if self.zero?
|
8
8
|
return (1..self).to_a.product
|
9
9
|
end
|
data/lib/darkext/net.rb
CHANGED
@@ -11,8 +11,7 @@ module Net
|
|
11
11
|
case resp
|
12
12
|
when Net::HTTPSuccess then resp
|
13
13
|
when Net::HTTPRedirection then download(resp['location'], limit - 1)
|
14
|
-
else
|
15
|
-
resp.error!
|
14
|
+
else resp.error!
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -22,6 +21,7 @@ module Net
|
|
22
21
|
else
|
23
22
|
path = File.expand_path(path)
|
24
23
|
end
|
24
|
+
raise ArgumentError.new('Save path is a directory') if File.directory?(path)
|
25
25
|
resp = download(url)
|
26
26
|
open(path,'w') { |file| file.write(resp.body) } if resp.is_a?(Net::HTTPSuccess)
|
27
27
|
end
|
@@ -43,7 +43,7 @@ module Darkext
|
|
43
43
|
def index(url, target = $stdout)
|
44
44
|
@pages << url
|
45
45
|
|
46
|
-
root = open(url)
|
46
|
+
root = Hpricot(open(url))
|
47
47
|
(root/"a.#{@options.nested_find(:forum,:class)}").each do |link|
|
48
48
|
index_forum(link.attributes['href'].to_s)
|
49
49
|
end
|
@@ -77,7 +77,7 @@ module Darkext
|
|
77
77
|
|
78
78
|
private
|
79
79
|
def index_forum(href)
|
80
|
-
root = open(href)
|
80
|
+
root = Hpricot(open(href))
|
81
81
|
(root/"a.#{@options.nested_find(:forum,:class)}").each do |link|
|
82
82
|
index_forum(link.attributes['href'].to_s)
|
83
83
|
end
|
data/lib/darkext/statistics.rb
CHANGED
@@ -7,27 +7,30 @@ require 'darkext/symbol'
|
|
7
7
|
class Array
|
8
8
|
# Finds the mean of the array
|
9
9
|
def mean
|
10
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
10
11
|
self.sum / self.size.to_f
|
11
12
|
end
|
12
13
|
alias :average :mean
|
13
14
|
alias :ave :mean
|
14
15
|
|
15
16
|
def harmonic_mean
|
17
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
16
18
|
self.size.to_f / self.map { |i| 1 / i.to_f }.sum
|
17
19
|
end
|
18
20
|
alias :h_mean :harmonic_mean
|
19
21
|
|
20
22
|
def geometric_mean
|
23
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
21
24
|
self.product.root(self.size)
|
22
25
|
end
|
23
26
|
alias :g_mean :geometric_mean
|
24
27
|
|
25
28
|
# Finds the median of the array
|
26
29
|
def median
|
27
|
-
|
30
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
28
31
|
case self.size % 2
|
29
32
|
when 0
|
30
|
-
return self.sort[self.size /
|
33
|
+
return self.sort[(self.size / 2) - 1, 2].mean
|
31
34
|
when 1
|
32
35
|
return self.sort[self.size / 2]
|
33
36
|
end
|
@@ -43,6 +46,7 @@ class Array
|
|
43
46
|
|
44
47
|
# Finds the mode of the array
|
45
48
|
def mode
|
49
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
46
50
|
map = self.histogram
|
47
51
|
max = map.values.max
|
48
52
|
map.keys.select { |x| map[x] == max }
|
@@ -50,23 +54,28 @@ class Array
|
|
50
54
|
|
51
55
|
# Variance
|
52
56
|
def population_variance
|
57
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
53
58
|
self.sum_of_squares.to_f / (self.size).to_f
|
54
59
|
end
|
55
60
|
|
56
61
|
def sample_variance
|
62
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
57
63
|
self.sum_of_squares.to_f / (self.size - 1).to_f
|
58
64
|
end
|
59
65
|
|
60
66
|
# Standard deviation
|
61
67
|
def population_deviation
|
68
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
62
69
|
self.population_variance.abs.sqrt
|
63
70
|
end
|
64
71
|
|
65
72
|
def sample_deviation
|
73
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
66
74
|
self.sample_variance.abs.sqrt
|
67
75
|
end
|
68
76
|
|
69
77
|
def geometric_deviation
|
78
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
70
79
|
gmean = self.g_mean
|
71
80
|
Math.exp((self.map { |x| (x.ln - gmean.ln).square }.sum.to_f / self.size.to_f).sqrt)
|
72
81
|
end
|
@@ -79,7 +88,10 @@ class Array
|
|
79
88
|
|
80
89
|
# Generates a confidence interval
|
81
90
|
def ci(opts = { })
|
91
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
82
92
|
opts.with_defaults!({ :percent => 0.95, :rho => 1, :type => :center })
|
93
|
+
percent = opts[:percent]
|
94
|
+
rho = opts[:rho]
|
83
95
|
m = self.mean
|
84
96
|
ret = Array.new
|
85
97
|
div = (opts[:type] == :center ? 2 : 1)
|
@@ -110,6 +122,7 @@ class Array
|
|
110
122
|
end
|
111
123
|
|
112
124
|
def sum_of_squares
|
125
|
+
raise ArgumentError.new('Array size must be > 0') if self.size.zero?
|
113
126
|
m = self.mean
|
114
127
|
self.map { |v| v - m }.squares.sum
|
115
128
|
end
|
@@ -173,9 +186,10 @@ module Darkext
|
|
173
186
|
# * R (:r)
|
174
187
|
# * unbiased estimator (:estimator)
|
175
188
|
# * the equation as a lambda (:equation)
|
176
|
-
# Raises an argument error if the arguments are not the same size
|
189
|
+
# Raises an argument error if the arguments are not the same size or either is zero
|
177
190
|
def self.least_squares(xs,ys)
|
178
|
-
raise ArgumentError(
|
191
|
+
raise ArgumentError.new('Arrays must have size > 0') if xs.size.zero? || ys.size.zero?
|
192
|
+
raise ArgumentError.new('Arrays must be of equal size') if xs.size != ys.size
|
179
193
|
n = xs.size
|
180
194
|
b_1 = (xs.zip(ys).map(&:product).sum - ((ys.sum * xs.sum)/n))/(xs.map(&:square).sum - (xs.sum.square/n))
|
181
195
|
b_0 = ys.mean - b_1 * xs.mean
|
@@ -187,7 +201,8 @@ module Darkext
|
|
187
201
|
estimator = ss_e/(n - 2)
|
188
202
|
r_2 = 1 - (ss_e/ss_t)
|
189
203
|
r = r_2.sqrt
|
190
|
-
reg = {
|
204
|
+
reg = {
|
205
|
+
:n => n,
|
191
206
|
:b_1 => b_1,
|
192
207
|
:b_0 => b_0,
|
193
208
|
:predicted => predicted,
|
@@ -197,7 +212,8 @@ module Darkext
|
|
197
212
|
:estimator => estimator,
|
198
213
|
:equation => equation,
|
199
214
|
:r_2 => r_2,
|
200
|
-
:r => r
|
215
|
+
:r => r
|
216
|
+
}
|
201
217
|
return reg
|
202
218
|
end
|
203
219
|
end
|
data/lib/darkext/string.rb
CHANGED
@@ -27,11 +27,9 @@ class String
|
|
27
27
|
# * :capture => true to capture the output. If :capture => true, background is voided
|
28
28
|
def exec(opts = {})
|
29
29
|
opts.with_defaults!(:background => false, :capture => false)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
return system(cmd) if !opts[:capture]
|
34
|
-
return `#{cmd}` if opts[:capture]
|
30
|
+
return `#{self}` if opts[:capture]
|
31
|
+
return fork { system(self) } if opts[:background]
|
32
|
+
return system(self)
|
35
33
|
end
|
36
34
|
|
37
35
|
# Prints the String using print
|
data/lib/darkext.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
Dir[File.join(File.join(File.dirname(__FILE__), 'darkext'), '*.rb')]
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
libs = Dir[File.join(File.join(File.dirname(__FILE__), 'darkext'), '*.rb')]
|
5
|
+
|
6
|
+
# Don't load these by default
|
7
|
+
other_libs = libs.reject! { |lib| lib.include?('sinatra') || lib.include?('sitemap') }
|
8
|
+
|
9
|
+
libs.reject! { |lib| lib.include?('beagle') }.first
|
10
|
+
libs.each { |lib| require lib }
|
11
|
+
|
12
|
+
# autoload beagle
|
13
|
+
autoload(:Beagle, 'darkext/beagle')
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
before(:each) do
|
5
|
+
@a = [1,2,3,4,5,6,7,8,9,10]
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should respond to all the new methods' do
|
9
|
+
%w(rotate rotate_reverse sum product squares squares! random pick randomize randomize!).each { |method| [1].methods.include?(method).should == true }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not remove or add elements when randomizing' do
|
13
|
+
@a.randomize.size.should == @a.size
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should rotate back to normal' do
|
17
|
+
b = @a.clone
|
18
|
+
b.rotate(b.size)
|
19
|
+
b.should == @a
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should rotate reverse back to normal' do
|
23
|
+
b = @a.clone
|
24
|
+
b.rotate_reverse(b.size)
|
25
|
+
b.should == @a
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return a Numeric from sum and sum' do
|
29
|
+
@a.sum.should be_a_kind_of(Numeric)
|
30
|
+
@a.product.should be_a_kind_of(Numeric)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return an array of equal size from squares' do
|
34
|
+
squares = @a.squares
|
35
|
+
squares.should be_a_kind_of(Array)
|
36
|
+
squares.size.should == @a.size
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should destructively collect squares' do
|
40
|
+
b = @a.clone
|
41
|
+
b.squares!.should == @a.squares
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should pick randomly' do
|
45
|
+
counts = [0,0,0,0,0,0,0,0,0,0]
|
46
|
+
count = 1000000
|
47
|
+
count.times do
|
48
|
+
r = @a.random
|
49
|
+
counts[r - 1] += 1
|
50
|
+
end
|
51
|
+
counts.each { |v| (v/count.to_f).should be_close(1/counts.size.to_f,0.001) }
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return an Array from randomize' do
|
55
|
+
@a.randomize.should be_a_kind_of(Array)
|
56
|
+
end
|
57
|
+
end
|
data/spec/beagle_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Beagle do
|
4
|
+
it 'should respond to all the methods' do
|
5
|
+
Beagle.should respond_to(*%w(home home= start stop status query running?))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should not work if Beagle.home is nil' do
|
9
|
+
Beagle.home = nil
|
10
|
+
lambda { Beagle.start }.should raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return a true or false value from running' do
|
14
|
+
# TODO: use temp dir
|
15
|
+
Beagle.home = '/balls'
|
16
|
+
Beagle.running?.is_boolean?.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should probably not be running for a random directory' do
|
20
|
+
# TODO: use temp dir
|
21
|
+
Beagle.home = '/balls'
|
22
|
+
Beagle.running?.should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return a String for the status' do
|
26
|
+
# TODO: use temp dir
|
27
|
+
Beagle.home = '/balls'
|
28
|
+
Beagle.status.should be_a_kind_of(String)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should return a true or false value from start' do
|
32
|
+
# TODO: use temp dir
|
33
|
+
Beagle.home = '/usr'
|
34
|
+
Beagle.start.is_boolean?.should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return a true or false value from stop' do
|
38
|
+
# TODO: use temp dir
|
39
|
+
Beagle.home = '/usr'
|
40
|
+
Beagle.stop.is_boolean?.should be_true
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
it 'should respond to the new method' do
|
5
|
+
Object.new.should respond_to(*%w(is_boolean?))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return a boolean from is_boolean' do
|
9
|
+
true.is_boolean?.is_boolean?.should be_true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe TrueClass do
|
14
|
+
it 'should respond to the new method' do
|
15
|
+
true.should respond_to(*%w(intern))
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return a symbol from intern' do
|
19
|
+
true.intern.should be_a_kind_of(Symbol)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe FalseClass do
|
24
|
+
it 'should respond to the new method' do
|
25
|
+
false.should respond_to(*%w(intern))
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return a symbol from intern' do
|
29
|
+
false.intern.should be_a_kind_of(Symbol)
|
30
|
+
end
|
31
|
+
end
|
data/spec/fiber_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Fiber do
|
4
|
+
before(:each) do
|
5
|
+
@fiber = Fiber.new do
|
6
|
+
(1..10).each { |i| Fiber.yield }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should respond to all the class methods' do
|
11
|
+
Fiber.should respond_to(*%w(yield current))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should respond to all the instance methods' do
|
15
|
+
@fiber.should respond_to(*%w(resume yield))
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should raise an error when it is done' do
|
19
|
+
lambda { 100.times { @fiber.resume } }.should raise_error
|
20
|
+
end
|
21
|
+
end
|
data/spec/float_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Float do
|
4
|
+
it 'should respond to the new methods' do
|
5
|
+
1.0.should respond_to(*%w(equals?))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return a boolean from equals?' do
|
9
|
+
1.0.equals?(1.0000001).is_boolean?.should be_true
|
10
|
+
end
|
11
|
+
end
|
data/spec/hash_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
it 'should respond to all the new methods' do
|
5
|
+
Hash.new.should respond_to(*%w(with_defaults with_defaults! nested_find deep_merge! nested_hash merge_nested_hash!))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return a hash from with_defaults' do
|
9
|
+
Hash.new.with_defaults(:foo => :bar).should be_a_kind_of(Hash)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
it 'should respond to the new methods' do
|
5
|
+
10.should respond_to(*%w(fact))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should not calculate the factorial of negative numbers' do
|
9
|
+
lambda { -10.fact }.should raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return an Integer from factorial' do
|
13
|
+
10.fact.should be_a_kind_of(Integer)
|
14
|
+
end
|
15
|
+
end
|
data/spec/io_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe DarkIO do
|
4
|
+
it 'should return an array of size 2 when capturing both stdout and stderr' do
|
5
|
+
out = DarkIO::capture_output(:stderr => true, :stdout => true) do
|
6
|
+
STDOUT.print('Hello, World!')
|
7
|
+
STDERR.print('Hello, World!')
|
8
|
+
end
|
9
|
+
out.should be_a_kind_of(Array)
|
10
|
+
out.size.should == 2
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return a string when capturing either stdout or stderr' do
|
14
|
+
out = DarkIO::capture_output(:stderr => true, :stdout => false) do
|
15
|
+
STDERR.print('Hello, World!')
|
16
|
+
end
|
17
|
+
out.should be_a_kind_of(String)
|
18
|
+
out = DarkIO::capture_output(:stdout => true, :stderr => false) do
|
19
|
+
STDOUT.print('Hello, World!')
|
20
|
+
end
|
21
|
+
out.should be_a_kind_of(String)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return nil if not capturing anything' do
|
25
|
+
DarkIO::capture_output(:stderr => false, :stdout => false) do
|
26
|
+
STDOUT.print('Hello, World!')
|
27
|
+
STDERR.print('Hello, World!')
|
28
|
+
end.nil?.should == true
|
29
|
+
end
|
30
|
+
end
|
data/spec/net_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Net do
|
4
|
+
it 'should respond to the new methods' do
|
5
|
+
Net.should respond_to(*%w(download download_and_save))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should raise an exception on 404' do
|
9
|
+
lambda { Net::download('http://www.google.com/pickles.html') }.should raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should raise an exception when trying to save an empty path' do
|
13
|
+
lambda { Net::download_and_save('http://www.google.com/','') }.should raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not write anything to the disk if not success' do
|
17
|
+
begin
|
18
|
+
Net::download_and_save('http://www.google.com/pickles.html')
|
19
|
+
rescue
|
20
|
+
end
|
21
|
+
File.exists?('pickles.html').should be_false
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Numeric do
|
4
|
+
it 'should respond to the new methods' do
|
5
|
+
[10,10.5].each do |num|
|
6
|
+
num.should respond_to(*%w(square cube sqrt root ln log))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return Numeric from most new methods' do
|
11
|
+
%w(square cube sqrt root ln log).each do |method|
|
12
|
+
[10,10.5].each do |num|
|
13
|
+
num.send(method.intern).should be_a_kind_of(Numeric)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
it 'should respond to the new methods' do
|
5
|
+
Object.new.should respond_to(*%w(try tap))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return itself from tap' do
|
9
|
+
a = Object.new
|
10
|
+
a.tap { |s| }.should equal(a)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return nil from try if called on nil' do
|
14
|
+
nil.try(1) { |a| }.should be_nil
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
# gem install redgreen for colored test output
|
5
|
+
begin require 'redgreen' unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
|
6
|
+
|
7
|
+
path = File.expand_path(File.dirname(__FILE__) + '/../lib/')
|
8
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
9
|
+
|
10
|
+
require 'lib/darkext'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
before(:each) do
|
5
|
+
@a = [1,2,3,4,5,6,7,8,9,10]
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should respond to all the new methods' do
|
9
|
+
Array.new.should respond_to(*%w(mean average ave harmonic_mean h_mean geometric_mean g_mean median histogram mode population_variance sample_variance population_deviation sample_deviation geometric_deviation gstddev sample ci standardize standardize! sum_of_squares normalize normalize!))
|
10
|
+
Darkext::Statistics.should respond_to(*%w(prob zscore p_val))
|
11
|
+
Darkext::Statistics::Regression.should respond_to(*%w(least_squares))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return a Numeric from mean, harmonic_mean, geometric_mean, median, population_variance, sample_variance, population_deviation, sample_deviation, geometric_deviation, and sum_of_squares' do
|
15
|
+
%w(mean harmonic_mean geometric_mean median population_variance sample_variance population_deviation sample_deviation geometric_deviation sum_of_squares).each do |method|
|
16
|
+
@a.send(method.intern).should be_a_kind_of(Numeric)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return a hash from histogram' do
|
21
|
+
@a.histogram.should be_a_kind_of(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return an array from mode, sample, ci, standardize, and normalize' do
|
25
|
+
%w(mode sample ci standardize normalize).each do |method|
|
26
|
+
@a.send(method.intern).should be_a_kind_of(Array)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should raise and erro from mean, harmonic_mean, geometric_mean, median, mode, population_variance, sample_variance, population_deviation, sample_deviation, geometric_deviation, ci, and sum_of_squares if size is zero' do
|
31
|
+
%w(mean harmonic_mean geometric_mean median mode population_variance sample_variance population_deviation sample_deviation geometric_deviation ci sum_of_squares).each do |method|
|
32
|
+
lambda { Array.new.send(method.intern) }.should raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return a Numeric from prob and zscore' do
|
37
|
+
Darkext::Statistics::prob(1).should be_a_kind_of(Numeric)
|
38
|
+
Darkext::Statistics::zscore(0.9).should be_a_kind_of(Numeric)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should return a Numeric from p_val' do
|
42
|
+
Darkext::Statistics::p_val(@a).should be_a_kind_of(Numeric)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return a Hash from least_squares' do
|
46
|
+
Darkext::Statistics::Regression::least_squares([1,2,4,5],[2,3,6,10]).should be_a_kind_of(Hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should raise an error if the arguments to least_squares have different sizes' do
|
50
|
+
lambda { Darkext::Statistics::Regression::least_squares(@a,[1,2,3]) }.should raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should raise an error if either argument has size.zero?' do
|
54
|
+
lambda { Darkext::Statistics::Regression::least_squares(@a,Array.new) }.should raise_error
|
55
|
+
end
|
56
|
+
end
|
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
it 'should respond to the new methods' do
|
5
|
+
'foo'.should respond_to(*%w(to_range exec print printn true? false? starts_with? ends_with? /))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return a boolean from starts_with? and ends_with?' do
|
9
|
+
'foo'.starts_with?('fo').is_boolean?.should be_true
|
10
|
+
'foo'.ends_with?('oo').is_boolean?.should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return a boolean from true? and false?' do
|
14
|
+
'true'.true?.is_boolean?.should be_true
|
15
|
+
'false'.false?.is_boolean?.should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return the same thing from / as split' do
|
19
|
+
'f.o.o'.split('.').should eql('f.o.o' / '.')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return a range from to_range if it works' do
|
23
|
+
'1..5'.to_range.should be_a_kind_of(Range)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return nil if the range is not a valid format' do
|
27
|
+
'nipples'.to_range.should be_nil
|
28
|
+
end
|
29
|
+
end
|
data/spec/symbol_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Symbol do
|
4
|
+
it 'should respond to the new methods' do
|
5
|
+
Proc.new{ }.should respond_to(*%w(to_proc))
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return a Proc from to_proc' do
|
9
|
+
:foo.to_proc.should be_a_kind_of(Proc)
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darkhelmet-darkext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Huckstep
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-28 00:00:00 -07:00
|
13
13
|
default_executable: sinatra-app
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -54,6 +54,21 @@ files:
|
|
54
54
|
- test/helper.rb
|
55
55
|
- test/darkext_test.rb
|
56
56
|
- spec/spec.opts
|
57
|
+
- spec/array_spec.rb
|
58
|
+
- spec/beagle_spec.rb
|
59
|
+
- spec/boolean_spec.rb
|
60
|
+
- spec/fiber_spec.rb
|
61
|
+
- spec/float_spec.rb
|
62
|
+
- spec/hash_spec.rb
|
63
|
+
- spec/integer_spec.rb
|
64
|
+
- spec/io_spec.rb
|
65
|
+
- spec/net_spec.rb
|
66
|
+
- spec/numeric_spec.rb
|
67
|
+
- spec/object_spec.rb
|
68
|
+
- spec/statistics_spec.rb
|
69
|
+
- spec/string_spec.rb
|
70
|
+
- spec/symbol_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
57
72
|
has_rdoc: true
|
58
73
|
homepage: http://github.com/darkhelmet/darkext
|
59
74
|
post_install_message:
|