facets 2.9.0.pre.1 → 2.9.0.pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. data/AUTHORS +1 -0
  2. data/COPYING +1 -2
  3. data/HISTORY.rdoc +16 -8
  4. data/lib/core/facets/hash/subset.rb +24 -0
  5. data/lib/core/facets/hash/zip.rb +18 -0
  6. data/lib/core/facets/kernel/try.rb +3 -3
  7. data/lib/core/facets/module/home.rb +90 -0
  8. data/lib/core/facets/module/homename.rb +1 -0
  9. data/lib/core/facets/module/housing.rb +1 -0
  10. data/lib/core/facets/module/modname.rb +1 -22
  11. data/lib/core/facets/na.rb +11 -5
  12. data/lib/core/facets/object/clone.rb +1 -0
  13. data/lib/core/facets/{kernel/try_dup.rb → object/dup.rb} +41 -35
  14. data/lib/core/facets/{kernel → object}/object_state.rb +15 -18
  15. data/lib/core/facets/object/replace.rb +43 -0
  16. data/lib/core/facets/object/try_dup.rb +1 -0
  17. data/lib/core/facets/string/cleanlines.rb +2 -0
  18. data/lib/core/facets/time/ago.rb +1 -1
  19. data/lib/core/facets/time/in.rb +1 -93
  20. data/lib/core/facets/time/less.rb +1 -0
  21. data/lib/core/facets/time/shift.rb +95 -0
  22. data/lib/more/facets/interval.rb +284 -0
  23. data/lib/more/facets/math.rb +6 -0
  24. data/lib/more/facets/math/abs.rb +8 -0
  25. data/lib/more/facets/math/acot.rb +8 -0
  26. data/lib/more/facets/math/acoth.rb +8 -0
  27. data/lib/more/facets/math/acsc.rb +8 -0
  28. data/lib/more/facets/math/acsch.rb +8 -0
  29. data/lib/more/facets/math/amd.rb +17 -0
  30. data/lib/more/facets/math/approx_equal.rb +15 -0
  31. data/lib/more/facets/math/asec.rb +8 -0
  32. data/lib/more/facets/math/asech.rb +8 -0
  33. data/lib/more/facets/math/atkinson_index.rb +16 -0
  34. data/lib/more/facets/math/beta.rb +9 -0
  35. data/lib/more/facets/math/cdf.rb +10 -0
  36. data/lib/more/facets/math/ceil.rb +8 -0
  37. data/lib/more/facets/math/cot.rb +8 -0
  38. data/lib/more/facets/math/coth.rb +8 -0
  39. data/lib/more/facets/math/csc.rb +8 -0
  40. data/lib/more/facets/math/csch.rb +8 -0
  41. data/lib/more/facets/math/delta.rb +8 -0
  42. data/lib/more/facets/math/epsilon.rb +21 -0
  43. data/lib/more/facets/math/exp10.rb +8 -0
  44. data/lib/more/facets/math/exp2.rb +8 -0
  45. data/lib/more/facets/math/factorial.rb +37 -0
  46. data/lib/more/facets/math/floor.rb +8 -0
  47. data/lib/more/facets/math/gamma.rb +12 -0
  48. data/lib/more/facets/math/gcd.rb +23 -0
  49. data/lib/more/facets/math/gini_coefficient.rb +33 -0
  50. data/lib/more/facets/math/kldivergence.rb +19 -0
  51. data/lib/more/facets/math/lcm.rb +15 -0
  52. data/lib/more/facets/math/lgamma.rb +21 -0
  53. data/lib/more/facets/math/linsolve.rb +10 -0
  54. data/lib/more/facets/math/log2.rb +14 -0
  55. data/lib/more/facets/math/max.rb +1 -0
  56. data/lib/more/facets/math/mean.rb +16 -0
  57. data/lib/more/facets/math/median.rb +15 -0
  58. data/lib/more/facets/math/min.rb +35 -0
  59. data/lib/more/facets/math/pow.rb +8 -0
  60. data/lib/more/facets/math/pstd.rb +1 -0
  61. data/lib/more/facets/math/pvariance.rb +1 -0
  62. data/lib/more/facets/math/rmd.rb +16 -0
  63. data/lib/more/facets/math/root.rb +8 -0
  64. data/lib/more/facets/math/sec.rb +8 -0
  65. data/lib/more/facets/math/sech.rb +8 -0
  66. data/lib/more/facets/math/sign.rb +9 -0
  67. data/lib/more/facets/math/sinc.rb +8 -0
  68. data/lib/more/facets/math/sqr.rb +8 -0
  69. data/lib/more/facets/math/sqsolve.rb +53 -0
  70. data/lib/more/facets/math/std.rb +27 -0
  71. data/lib/more/facets/math/stderr.rb +1 -0
  72. data/lib/more/facets/math/sum.rb +16 -0
  73. data/lib/more/facets/math/summed_sqdevs.rb +14 -0
  74. data/lib/more/facets/math/theil_index.rb +24 -0
  75. data/lib/more/facets/math/variance.rb +31 -0
  76. data/lib/more/facets/thread.rb +24 -0
  77. data/lib/tour/facets/array/op_pow.rb +5 -0
  78. data/lib/tour/facets/module/enclosure.rb +15 -1
  79. data/lib/tour/facets/module/preextend.rb +26 -0
  80. data/lib/tour/facets/module/prepend.rb +39 -13
  81. data/meta/gemfile +1 -1
  82. data/qed/core/binding/caller.rdoc +1 -3
  83. data/test/core/array/test_after.rb +1 -1
  84. data/test/core/array/test_before.rb +1 -1
  85. data/test/core/array/test_conjoin.rb +1 -1
  86. data/test/core/array/test_store.rb +1 -1
  87. data/test/core/hash/test_argumentize.rb +1 -1
  88. data/test/core/hash/test_join.rb +1 -1
  89. data/test/core/kernel/test_dup.rb +1 -1
  90. data/test/core/kernel/test_get.rb +1 -1
  91. data/test/core/kernel/test_qua_class.rb +1 -1
  92. data/test/core/time/test_ago.rb +5 -117
  93. data/test/core/time/test_hence.rb +2 -2
  94. data/test/core/time/test_in.rb +4 -115
  95. data/test/core/time/test_less.rb +137 -0
  96. data/test/core/time/test_set.rb +1 -1
  97. data/test/core/time/test_shift.rb +126 -0
  98. data/test/more/test_date.rb +1 -1
  99. data/test/tour/module/test_cattr.rb +1 -1
  100. data/test/tour/module/test_class_extend.rb +1 -1
  101. data/test/tour/module/test_instance_function.rb +1 -1
  102. data/test/tour/module/test_method_space.rb +1 -1
  103. metadata +76 -10
  104. data/lib/core/facets/hash/zipnew.rb +0 -18
  105. data/lib/core/facets/kernel/clone.rb +0 -1
  106. data/lib/core/facets/kernel/dup.rb +0 -34
  107. data/lib/core/facets/kernel/replace.rb +0 -1
@@ -1,25 +1,51 @@
1
+ module Prependable
2
+
3
+ def self.included(base)
4
+ base.extend Self
5
+ base.instance_methods(false).each do |meth|
6
+ base.method_added(meth)
7
+ end
8
+ end
9
+
10
+ module Self
11
+ def prepend_module
12
+ @_prepend_module ||= Module.new
13
+ end
14
+
15
+ def method_added(meth)
16
+ return if meth.to_s[-2,2] == ':-'
17
+ alias_method "#{meth}:-", meth
18
+ remove_method(meth)
19
+ prepend_module.module_eval %{
20
+ def #{meth}(*a,&b); __send__("#{meth}:-",*a,&b); end
21
+ }
22
+ include prepend_module
23
+ end
24
+ end
25
+
26
+ end
27
+
1
28
  class Module
2
29
 
3
- # Prepend an +aspect+ module to a module.
4
- # This only works at the module level.
30
+ # Prepend module.
5
31
  #
6
- # module ::PreX
7
- # def x; "x"; end
32
+ # class X
33
+ # def a; "Xa"; end
8
34
  # end
9
35
  #
10
- # module ::PreU
11
- # def x; '{' + super + '}'; end
36
+ # module M
37
+ # def a; "M" + super ; end
12
38
  # end
13
39
  #
14
- # PreX.prepend(PreU)
40
+ # class X
41
+ # prepend M
42
+ # end
15
43
  #
16
- # PreX.x # => "{x}"
44
+ # X.new.a #=> MXa
17
45
  #
18
- # CREDIT Trans
19
-
20
- def prepend(aspect)
21
- aspect.__send__(:include, self)
22
- extend aspect
46
+ def prepend(mod)
47
+ include Prependable
48
+ include mod
23
49
  end
24
50
 
25
51
  end
@@ -1,5 +1,5 @@
1
1
  name: facets
2
- version: 2.9.0.pre.1
2
+ version: 2.9.0.pre.2
3
3
  date: 2010-09-01
4
4
  path: [lib/core, lib/more, lib/tour]
5
5
 
@@ -13,9 +13,7 @@ We will use the following code to demonstrate their use.
13
13
 
14
14
  == Binding#caller
15
15
 
16
- Exception.refute.raised? do
17
- @bind.caller
18
- end
16
+ @bind.caller
19
17
 
20
18
  == Binding#callstack
21
19
 
@@ -2,7 +2,7 @@ covers 'facets/array/after'
2
2
 
3
3
  testcase Array do
4
4
 
5
- instance do
5
+ setup do
6
6
  ['a', 'b', 'c']
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ covers 'facets/array/before'
2
2
 
3
3
  testcase Array do
4
4
 
5
- instance do
5
+ setup do
6
6
  ['a', 'b', 'c']
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ covers 'facets/array/conjoin'
2
2
 
3
3
  testcase Array do
4
4
 
5
- instance "any array" do
5
+ setup "any array" do
6
6
  [1,2,3,4]
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ covers 'facets/array/store'
2
2
 
3
3
  testcase Array do
4
4
 
5
- instance do
5
+ setup do
6
6
  [1,2,3,4,5]
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ covers 'facets/hash/argumentize'
2
2
 
3
3
  testcase Hash do
4
4
 
5
- instance do
5
+ setup do
6
6
  { :list => [1,2], :base => "HI" }
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ covers 'facets/hash/join'
2
2
 
3
3
  tests Hash do
4
4
 
5
- instance do
5
+ setup do
6
6
  {:a=>1, :b=>2}
7
7
  end
8
8
 
@@ -1,7 +1,7 @@
1
1
  covers 'facets/kernel/dup'
2
2
 
3
3
  tests Object do
4
- instance "ordinary object" do
4
+ setup "ordinary object" do
5
5
  Object.new
6
6
  end
7
7
 
@@ -3,7 +3,7 @@ covers 'facets/kernel/__set__'
3
3
 
4
4
  tests Kernel do
5
5
 
6
- instance "an object with an instance variable" do
6
+ setup "an object with an instance variable" do
7
7
  c = Class.new do
8
8
  attr :a
9
9
  def initialize
@@ -2,7 +2,7 @@ covers 'facets/kernel/qua_class'
2
2
 
3
3
  tests Kernel do
4
4
 
5
- instance "any object" do
5
+ setup "any object" do
6
6
  Object.new
7
7
  end
8
8
 
@@ -1,127 +1,15 @@
1
1
  covers 'facets/time/ago'
2
2
 
3
- testcase Time do
3
+ tests Time do
4
4
 
5
- instance "January 20th 2010 at Noon" do
6
- Time.utc(2010,01,20,12,00,00)
7
- end
5
+ # We do not need to test #ago b/c it is an alias for #less.
6
+ # One test is provided to add to coverage report.
8
7
 
9
- unit :ago => 'years' do |t|
8
+ unit :ago => "is an alias of #less" do
9
+ t = Time.utc(2010,01,20,12,00,00)
10
10
  t.ago(1, :year).year.assert = 2009
11
11
  t.ago(2, :years).year.assert = 2008
12
12
  end
13
13
 
14
- unit :ago => 'weeks' do |t|
15
- t.ago(1, :week).day.assert == 13
16
- t.ago(2, :weeks).day.assert == 6
17
- end
18
-
19
- unit :ago => 'days' do |t|
20
- t.ago(1, :day).day.assert == 19
21
- t.ago(2, :days).day.assert == 18
22
- end
23
-
24
- unit :ago => 'hours' do |t|
25
- t.ago(1, :hour).hour.assert == 11
26
- t.ago(2, :hours).hour.assert == 10
27
- t.ago(12, :hours).hour.assert == 0
28
- end
29
-
30
- unit :ago => 'minutes' do |t|
31
- t.ago(1, :minute).min.assert == 59
32
- t.ago(2, :minutes).min.assert == 58
33
- t.ago(60, :minutes).min.assert == 0
34
- end
35
-
36
- unit :ago => 'seconds' do |t|
37
- t.ago(1, :second).sec.assert == 59
38
- t.ago(2, :seconds).sec.assert == 58
39
- t.ago(60, :seconds).sec.assert == 0
40
- end
41
-
42
- #
43
-
44
- unit :ago => "change years" do
45
- e = Time.utc(2007,11, 1, 18,30,57)
46
- r = Time.utc(2008,11, 1, 18,30,57).ago(1, :years)
47
- r.assert == e
48
- end
49
-
50
- unit :ago => "change weeks" do
51
- e = Time.utc(2008,11,24, 18,30,57)
52
- r = Time.utc(2008,12, 1, 18,30,57).ago(1, :weeks)
53
- r.assert == e
54
- end
55
-
56
- unit :ago => "change days" do
57
- e = Time.utc(2008,11,30, 18,30,57)
58
- r = Time.utc(2008,12, 1, 18,30,57).ago(1, :days)
59
- r.assert == e
60
- end
61
-
62
- unit :ago => "change hours" do
63
- e = Time.utc(2008,11,30, 23,30,57)
64
- r = Time.utc(2008,12, 1, 0,30,57).ago(1, :hours)
65
- r.assert == e
66
- end
67
-
68
- unit :ago => "change minutes" do
69
- e = Time.utc(2008,11,30, 23,58,57)
70
- r = Time.utc(2008,12, 1, 0, 0,57).ago(2, :minutes)
71
- r.assert == e
72
- end
73
-
74
- unit :ago => "change seconds" do
75
- e = Time.utc(2008,11,30, 23,59,57)
76
- r = Time.utc(2008,12, 1, 0, 0, 1).ago(4, :seconds)
77
- r.assert == e
78
- end
79
-
80
- context "Months are the tricky one, so they get their own section"
81
-
82
- unit :ago => "change month no year wrap" do
83
- e = Time.utc(2008,11, 1)
84
- r = Time.utc(2008,12, 1).ago(1, :months)
85
- r.assert == e
86
- end
87
-
88
- unit :ago => "change month with year wrap due to month" do
89
- e = Time.utc(2007,12, 1)
90
- r = Time.utc(2008, 1, 1).ago(1, :months)
91
- r.assert == e
92
- end
93
-
94
- unit :ago => "change month with 12 or more converts extra months into a year adjustment" do
95
- e = Time.utc(2007, 1, 1)
96
- r = Time.utc(2008, 1, 1).ago(12, :months)
97
- r.assert == e
98
-
99
- e = Time.utc(2006,11, 1)
100
- r = Time.utc(2008,12, 1).ago(25, :months)
101
- r.assert == e
102
- end
103
-
104
- # 13 months = 1 year + 1 month AND month changing from 12 to 1 when going backward means go back 1 extra year
105
- unit :ago => "change month with 12 or more AND year wrap due to month" do
106
- e = Time.utc(2006,12, 1)
107
- r = Time.utc(2008, 1, 1).ago(13, :months)
108
- r.assert == e
109
- end
110
-
111
- unit :ago => "smaller units should remain unchanged" do
112
- e = Time.utc(2005, 8,20, 15,37,59)
113
- r = Time.utc(2006, 1,20, 15,37,59).ago(5, :months)
114
- r.assert == e
115
- end
116
-
117
- unit :ago => "passing a negative number to ago should be same as a positive number to hence" do
118
- e = Time.utc(2008, 1, 1)
119
- r = Time.utc(2006,12, 1).ago(-13, :months)
120
- r.assert == e
121
-
122
- r = Time.utc(2006,12, 1).hence(13, :months)
123
- r.assert == e
124
- end
125
-
126
14
  end
127
15
 
@@ -2,8 +2,8 @@ covers 'facets/time/hence'
2
2
 
3
3
  tests Time do
4
4
 
5
- # we don't need to hence b/c it is an alias for #in
6
- # one test is provided to add to coverage report
5
+ # We do not need to test #hence b/c it is an alias for #shift.
6
+ # One test is provided to add to coverage report.
7
7
 
8
8
  unit :hence do
9
9
  e = Time.utc(2008,11, 1, 18,30,57)
@@ -1,126 +1,15 @@
1
- covers 'facets/time/in'
1
+ covers 'facets/time/ago'
2
2
 
3
3
  tests Time do
4
4
 
5
- instance "January 1st 2010 at Noon" do
6
- Time.utc(2010,01,01, 12,00,00)
7
- end
8
-
9
- unit :in => 'years' do |t|
10
- t.in(1, :year).year.assert = 2011
11
- t.in(2, :years).year.assert = 2012
12
- end
13
-
14
- unit :in => 'weeks' do |t|
15
- t.in(1, :week).day.assert == 8
16
- t.in(2, :weeks).day.assert == 15
17
- end
18
-
19
- unit :in => 'days' do |t|
20
- t.in(1, :day).day.assert == 2
21
- t.in(2, :days).day.assert == 3
22
- end
23
-
24
- unit :in => 'hours' do |t|
25
- t.in(1, :hour).hour.assert == 13
26
- t.in(2, :hours).hour.assert == 14
27
- t.in(12, :hours).hour.assert == 0
28
- end
29
-
30
- unit :in => 'minutes' do |t|
31
- t.in(1, :minute).min.assert == 1
32
- t.in(2, :minutes).min.assert == 2
33
- t.in(60, :minutes).min.assert == 0
34
- end
35
-
36
- unit :in => 'seconds' do |t|
37
- t.in(1, :second).sec.assert == 1
38
- t.in(2, :seconds).sec.assert == 2
39
- t.in(60, :seconds).sec.assert == 0
40
- end
5
+ # We do not need to test #in b/c it is an alias for #shift.
6
+ # One test is provided to add to coverage report.
41
7
 
42
-
43
- unit :in => "change_years" do
8
+ unit :in do
44
9
  e = Time.utc(2008,11, 1, 18,30,57)
45
10
  r = Time.utc(2007,11, 1, 18,30,57).in(1, :years)
46
11
  r.assert == e
47
12
  end
48
13
 
49
- unit :in => "change weeks" do
50
- e = Time.utc(2008,12, 1, 18,30,57)
51
- r = Time.utc(2008,11,24, 18,30,57).in(1, :weeks)
52
- r.assert == e
53
- end
54
-
55
- unit :in => "change days" do
56
- e = Time.utc(2008,12, 1, 18,30,57)
57
- r = Time.utc(2008,11,30, 18,30,57).in(1, :days)
58
- r.assert == e
59
- end
60
-
61
- unit :in => "change hours" do
62
- e = Time.utc(2008,12, 1, 0,30,57)
63
- r = Time.utc(2008,11,30, 23,30,57).in(1, :hours)
64
- r.assert == e
65
- end
66
-
67
- unit :in => "change minutes" do
68
- e = Time.utc(2008,12, 1, 0, 0,57)
69
- r = Time.utc(2008,11,30, 23,58,57).in(2, :minutes)
70
- r.assert == e
71
- end
72
-
73
- unit :in => "change seconds" do
74
- e = Time.utc(2008,12, 1, 0, 0, 1)
75
- r = Time.utc(2008,11,30, 23,59,57).in(4, :seconds)
76
- r.assert == e
77
- end
78
-
79
-
80
- concern "months are more difficult, so they get their own section"
81
-
82
- unit :in => "change month no year wrap" do
83
- e = Time.utc(2008,12, 1)
84
- r = Time.utc(2008,11, 1).in(1, :months)
85
- r.assert == e
86
- end
87
-
88
- unit :in => "change month with year wrap due to month" do
89
- e = Time.utc(2008, 1, 1)
90
- r = Time.utc(2007,12, 1).in(1, :months)
91
- r.assert == e
92
- end
93
-
94
- unit :in => "change month with 12 or more converts extra months into a year adjustment" do
95
- e = Time.utc(2008, 1, 1)
96
- r = Time.utc(2007, 1, 1).in(12, :months)
97
- r.assert == e
98
-
99
- e = Time.utc(2008,12, 1)
100
- r = Time.utc(2006,11, 1).in(25, :months)
101
- r.assert == e
102
- end
103
-
104
- unit :in => "change month with 12 or more AND year wrap due to month" do
105
- e = Time.utc(2008, 1, 1)
106
- r = Time.utc(2006,12, 1).in(13, :months)
107
- r.assert == e
108
- end
109
-
110
- unit :in => "smaller units should remain unchanged" do
111
- e = Time.utc(2006, 1,20, 15,37,59)
112
- r = Time.utc(2005, 8,20, 15,37,59).in(5, :months)
113
- r.assert == e
114
- end
115
-
116
- unit :in => "passing a negative number to #in should be same as a positive number to #ago" do
117
- e = Time.utc(2005, 8,20)
118
- r = Time.utc(2006, 1,20).in(-5, :months)
119
- r.assert == e
120
-
121
- r = Time.utc(2006, 1,20).ago(5, :months)
122
- r.assert == e
123
- end
124
-
125
14
  end
126
15