flori-bullshit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/Rakefile +95 -0
- data/VERSION +1 -0
- data/bullshit.gemspec +25 -0
- data/examples/compare.rb +11 -0
- data/examples/fibonacci.rb +75 -0
- data/examples/iteration.rb +116 -0
- data/examples/josephus.rb +136 -0
- data/examples/sorting.rb +363 -0
- data/install.rb +15 -0
- data/lib/bullshit.rb +2244 -0
- data/lib/bullshit/version.rb +8 -0
- data/make_doc.rb +4 -0
- data/tests/test_analysis.rb +321 -0
- data/tests/test_bullshit.rb +222 -0
- data/tests/test_continued_fraction.rb +40 -0
- data/tests/test_distribution.rb +69 -0
- data/tests/test_functions.rb +33 -0
- data/tests/test_newton_bisection.rb +28 -0
- data/tests/test_window.rb +34 -0
- metadata +94 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'bullshit'
|
5
|
+
|
6
|
+
class TestContinuedFraction < Test::Unit::TestCase
|
7
|
+
include Bullshit
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@none1 = ContinuedFraction.for_a proc {}
|
11
|
+
@none2 = ContinuedFraction.for_a {}
|
12
|
+
@phi = ContinuedFraction.new
|
13
|
+
@finite = ContinuedFraction.for_a [3, 4, 12, 3, 1]
|
14
|
+
@sqrt_2 = ContinuedFraction.for_a { |n| n == 0 ? 1 : 2 }
|
15
|
+
@pi_finite = ContinuedFraction.for_a [3, 7, 15, 1, 292, 1, 1, 1, 2]
|
16
|
+
@e = ContinuedFraction.for_a { |n| (n + 1) }.for_b { |n| (n + 1) }
|
17
|
+
@a113011 = ContinuedFraction.for_a { |n| 2 * n + 1 }.for_b { |n| 2 * n }
|
18
|
+
@a073333 = ContinuedFraction.for_a { |n| n }.for_b { |n| n }
|
19
|
+
@atan = ContinuedFraction.for_a do |n, x|
|
20
|
+
n == 0 ? 0 : 2 * n - 1
|
21
|
+
end.for_b do |n, x|
|
22
|
+
n <= 1 ? x : ((n - 1) * x) ** 2
|
23
|
+
end
|
24
|
+
@pi = lambda { 4 * @atan[1] }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_continued_fractions
|
28
|
+
assert @none1[1].nan?
|
29
|
+
assert @none2[1].nan?
|
30
|
+
assert_in_delta 1.618033, @phi[], 1E-6
|
31
|
+
assert_in_delta 3.245, @finite[], 1E-4
|
32
|
+
assert_in_delta Math.sqrt(2), @sqrt_2[], 1E-10
|
33
|
+
assert_in_delta Math::PI, @pi_finite[], 1E-10
|
34
|
+
assert_in_delta Math::E, 1 + @e[], 1E-10
|
35
|
+
assert_in_delta 1.541494, @a113011[], 1E-6
|
36
|
+
assert_in_delta 0.581976, @a073333[], 1E-6
|
37
|
+
assert_in_delta Math.atan(0.5), @atan[0.5], 1E-10
|
38
|
+
assert_in_delta Math::PI, @pi[], 1E-10
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'bullshit'
|
5
|
+
|
6
|
+
class TestDistribution < Test::Unit::TestCase
|
7
|
+
include Bullshit
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@td23 = TDistribution.new 23
|
11
|
+
@td100 = TDistribution.new 100
|
12
|
+
@chi23 = ChiSquareDistribution.new 23
|
13
|
+
@chi100 = ChiSquareDistribution.new 100
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_tdistribution
|
17
|
+
xs = [ 75, 80, 85, 90, 95, 97.5, 99, 99.5, 99.75, 99.9, 99.95 ].map { |x|
|
18
|
+
x / 100.0 }
|
19
|
+
ys = [ 0.685, 0.858, 1.060, 1.319, 1.714, 2.069, 2.500, 2.807, 3.104,
|
20
|
+
3.485, 3.767 ]
|
21
|
+
xs.zip(ys) do |x, y|
|
22
|
+
assert_in_delta y, @td23.inverse_probability(x), 1E-2
|
23
|
+
end
|
24
|
+
assert_equal @td23.inverse_probability(-0.1), -1 / 0.0
|
25
|
+
assert_equal @td23.inverse_probability(1.1), 1 / 0.0
|
26
|
+
ys = [ 0.677, 0.845, 1.042, 1.290, 1.660, 1.984, 2.364, 2.626, 2.871,
|
27
|
+
3.174, 3.390 ]
|
28
|
+
xs.zip(ys) do |x, y|
|
29
|
+
assert_in_delta y, @td100.inverse_probability(x), 1E-2
|
30
|
+
end
|
31
|
+
assert_equal @td100.inverse_probability(-0.1), -1 / 0.0
|
32
|
+
assert_equal @td100.inverse_probability(1.1), 1 / 0.0
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_standard_normal_distribution
|
36
|
+
std = STD_NORMAL_DISTRIBUTION
|
37
|
+
ps = [ 0.001, 0.005, 0.010, 0.025, 0.050, 0.100 ]
|
38
|
+
zs = [ -3.090, -2.576, -2.326, -1.960, -1.645, -1.282 ]
|
39
|
+
ps.zip(zs) do |p, z|
|
40
|
+
assert_in_delta z, std.inverse_probability(p), 1E-2
|
41
|
+
end
|
42
|
+
assert_equal std.inverse_probability(-0.1), -1 / 0.0
|
43
|
+
assert_equal std.inverse_probability(1.1), 1 / 0.0
|
44
|
+
ps.zip(zs) do |p, z|
|
45
|
+
assert_in_delta(-z, std.inverse_probability(1 - p), 1E-2)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_chisquaredistribution
|
50
|
+
xs = [ 0.0, 1, 9.260, 11.689, 28.429, 32.007, 35.172, 38.076, 38.968, 41.638,
|
51
|
+
44.181, 47.391, 49.728 ]
|
52
|
+
ys = [ 0.0, 1.593887e-12, 0.004998304, 0.025006129, 0.800007427, 0.900002084, 0.949994698,
|
53
|
+
0.975002306, 0.979998428, 0.989998939, 0.994999617, 0.997999729,
|
54
|
+
0.998999930 ]
|
55
|
+
xs.zip(ys) do |x, y|
|
56
|
+
assert_in_delta y, @chi23.probability(x), 1E-6
|
57
|
+
assert_in_delta x, @chi23.inverse_probability(y), 1E-6
|
58
|
+
end
|
59
|
+
assert_in_delta @chi23.probability(-0.1), 0.0, 1E-6
|
60
|
+
ys = [ 0.0, 1.788777e-80, 6.705663e-34, 2.337654e-29, 1.321036e-13, 8.695875e-12,
|
61
|
+
2.085529e-10, 2.691731e-09, 5.559949e-09, 4.192445e-08, 2.373762e-07,
|
62
|
+
1.678744e-06, 6.034997e-06 ]
|
63
|
+
xs.zip(ys) do |x, y|
|
64
|
+
assert_in_delta y, @chi100.probability(x), 1E-6
|
65
|
+
assert_in_delta x, @chi100.inverse_probability(y), 1E-6
|
66
|
+
end
|
67
|
+
assert_in_delta @chi100.probability(-0.1), 0.0, 1E-6
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'bullshit'
|
5
|
+
|
6
|
+
class TestFunctions < Test::Unit::TestCase
|
7
|
+
include Bullshit::Functions
|
8
|
+
|
9
|
+
def gammaP5_2(x)
|
10
|
+
gammaP_regularized(x, 5 / 2.0)
|
11
|
+
end
|
12
|
+
|
13
|
+
def gammaQ5_2(x)
|
14
|
+
gammaQ_regularized(x, 5 / 2.0)
|
15
|
+
end
|
16
|
+
|
17
|
+
X1 = [ 0.0, 0.1, 0.5, 0.9, 0.95, 0.995, 1.0, 2, 3, 5, 10, 100 ]
|
18
|
+
|
19
|
+
Y1 = [ 0.0000000000, 0.0008861388, 0.0374342268, 0.1239315997, 0.1371982774,
|
20
|
+
0.1494730091, 0.1508549639, 0.4505840486, 0.6937810816, 0.9247647539,
|
21
|
+
0.9987502694, 1.0000000000 ]
|
22
|
+
|
23
|
+
def test_gammaPQ
|
24
|
+
assert gammaQ_regularized(1, -1).nan?
|
25
|
+
assert gammaP_regularized(1, -1).nan?
|
26
|
+
assert gammaP5_2(-1).nan?
|
27
|
+
assert gammaQ5_2(-1).nan?
|
28
|
+
X1.zip(Y1) do |x, y|
|
29
|
+
assert_in_delta y, gammaP5_2(x), 1E-10
|
30
|
+
assert_in_delta y, 1 - gammaQ5_2(x), 1E-10
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'bullshit'
|
5
|
+
|
6
|
+
class TestNewtonBisection < Test::Unit::TestCase
|
7
|
+
include Bullshit
|
8
|
+
|
9
|
+
def test_bracket
|
10
|
+
solver = NewtonBisection.new { |x| x ** 2 - 3 }
|
11
|
+
assert_raises(ArgumentError) { solver.bracket(1..1) }
|
12
|
+
assert_raises(ArgumentError) { solver.bracket(1..-1) }
|
13
|
+
range = solver.bracket(0..0.1)
|
14
|
+
assert_in_delta range.first, 0, 1E-6
|
15
|
+
assert_in_delta range.last, 1.7576, 1E-6
|
16
|
+
range = solver.bracket(2..3)
|
17
|
+
assert_in_delta range.first, 0.4, 1E-6
|
18
|
+
assert_in_delta range.last, 3, 1E-6
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_zero
|
22
|
+
solver = NewtonBisection.new { |x| x ** 2 - 3 }
|
23
|
+
assert_in_delta 1.73205, solver.solve, 1E-6
|
24
|
+
assert_in_delta(-1.73205, solver.solve(-5..-1), 1E-6)
|
25
|
+
assert_in_delta 1.73205, solver.solve(solver.bracket(0..0.1)), 1E-6
|
26
|
+
assert_in_delta 1.73205, solver.solve(solver.bracket(2..3)), 1E-6
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'bullshit'
|
5
|
+
|
6
|
+
class TestWindow < Test::Unit::TestCase
|
7
|
+
include Bullshit::ModuleFunctions
|
8
|
+
|
9
|
+
def array_windows(array, window_size)
|
10
|
+
result = []
|
11
|
+
array_window(array, window_size) do |a|
|
12
|
+
result << a
|
13
|
+
end
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
@e = []
|
19
|
+
@a = (1..5).to_a
|
20
|
+
@b = (1..2).to_a
|
21
|
+
@c = (1..6).to_a
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_array_windows
|
25
|
+
assert_equal [], array_windows(@e, 3)
|
26
|
+
assert_equal [ [ 1.5, 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ], [ 4, 5, 4.5 ] ],
|
27
|
+
array_windows(@a, 3)
|
28
|
+
assert_equal [ [ 1.5, 1, 2 ], [ 1, 2, 1.5 ] ], array_windows(@b, 3)
|
29
|
+
assert_equal [ [ 1.5, 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 4, 5 ], [ 4, 5, 4.5 ] ],
|
30
|
+
array_windows(@a, 3)
|
31
|
+
assert_equal [ [ 2.0, 2.0, 1, 2, 3 ], [ 2.5, 1, 2, 3, 4 ], [ 1, 2, 3, 4, 5 ],
|
32
|
+
[ 2, 3, 4, 5, 6 ], [ 3, 4, 5, 6, 4.5 ], [ 4, 5, 6, 5.0, 5.0 ] ], array_windows(@c, 5)
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flori-bullshit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Florian Frank
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-08 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dslkit
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.5
|
24
|
+
version:
|
25
|
+
description: ""
|
26
|
+
email: flori@ping.de
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- tests
|
35
|
+
- tests/test_analysis.rb
|
36
|
+
- tests/test_functions.rb
|
37
|
+
- tests/test_distribution.rb
|
38
|
+
- tests/test_window.rb
|
39
|
+
- tests/test_continued_fraction.rb
|
40
|
+
- tests/test_bullshit.rb
|
41
|
+
- tests/test_newton_bisection.rb
|
42
|
+
- install.rb
|
43
|
+
- VERSION
|
44
|
+
- lib
|
45
|
+
- lib/bullshit.rb
|
46
|
+
- lib/bullshit
|
47
|
+
- lib/bullshit/version.rb
|
48
|
+
- make_doc.rb
|
49
|
+
- examples
|
50
|
+
- examples/compare.rb
|
51
|
+
- examples/josephus.rb
|
52
|
+
- examples/fibonacci.rb
|
53
|
+
- examples/sorting.rb
|
54
|
+
- examples/iteration.rb
|
55
|
+
- data
|
56
|
+
- bullshit.gemspec
|
57
|
+
- COPYING
|
58
|
+
- Rakefile
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://bullshit.rubyforge.org
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --title
|
64
|
+
- Bullshit -- Benchmarking in Ruby
|
65
|
+
- --line-numbers
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: bullshit
|
83
|
+
rubygems_version: 1.2.0
|
84
|
+
signing_key:
|
85
|
+
specification_version: 2
|
86
|
+
summary: Benchmarking is Bullshit
|
87
|
+
test_files:
|
88
|
+
- tests/test_analysis.rb
|
89
|
+
- tests/test_functions.rb
|
90
|
+
- tests/test_distribution.rb
|
91
|
+
- tests/test_window.rb
|
92
|
+
- tests/test_continued_fraction.rb
|
93
|
+
- tests/test_bullshit.rb
|
94
|
+
- tests/test_newton_bisection.rb
|