richunits 0.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.rdoc ADDED
@@ -0,0 +1,68 @@
1
+ = Release History
2
+
3
+ == 0.6.1 / 2010-10-04
4
+
5
+ Minor release simply add #to_int method to Duration so Time#+
6
+ and Time#- will work with Durations in Ruby 1.9.2 (Ruby 1.8.x
7
+ uses #to_f).
8
+
9
+ Changes:
10
+
11
+ * Add Duration#to_int for Ruby 1.9.2.
12
+
13
+
14
+ == 0.6.0 / 2009-10-31
15
+
16
+ This release tightens up the Duration interface a bit and fixed the
17
+ `Duration#*` method which was accidently named `#+`.
18
+
19
+ Changes:
20
+
21
+ * More robust interface for Duration class.
22
+ * Rename #+ method to #* (typo).
23
+ * Update metadata for Gem Do POM.
24
+
25
+
26
+ == 0.5.0 / 2009-05-30
27
+
28
+ This release updates some extensions to Time for use with the
29
+ Duration class, and standardizes the library on the name 'richunits',
30
+ rather than using the underscored "rich_units". This means installation
31
+ is now:
32
+
33
+ gem install richunits
34
+
35
+ and loading the library is now:
36
+
37
+ require 'richunits'
38
+
39
+ Though a backward compatible require is still present.
40
+
41
+ The previous release contains a complete rewrite of the Duration
42
+ class and integrates it into the rest of the system.
43
+
44
+ Changes:
45
+
46
+ * Rewrote Duration class and integrated into rest of system.
47
+ * Name of gem and main require will be 'richunits' (no underscore).
48
+
49
+
50
+ == 0.4.0 / 2008-09-09
51
+
52
+ * Rewrote Duration class and integrated into rest of system.
53
+
54
+
55
+ == 0.3.0 / 2008-09-08
56
+
57
+ * Encapsulated entire library in RichUnits module.
58
+
59
+
60
+ == 0.2.0 / 2008-08-01
61
+
62
+ * Reorganized repository.
63
+
64
+
65
+ == 0.1.0 / 2008-03-27
66
+
67
+ * Initial version.
68
+
data/PROFILE ADDED
@@ -0,0 +1,26 @@
1
+ ---
2
+ title : RichUnits
3
+ suite : rubyworks
4
+ summary: Simple LCD Unit System
5
+ contact: Trans <transfire@gmail.com>
6
+ license: MIT
7
+ created: 2008-02-21
8
+ authors:
9
+ - Thomas Sawyer
10
+ - Rich Kilmer
11
+
12
+ description:
13
+ A Unit system, based on Rich Kilmer's original time.rb work,
14
+ which provides english-esque methods for working with common
15
+ units, such as days and bytes and multiplers like kilo, or mega.
16
+ It does so by reducing basic measures to a lower common denominator,
17
+ such as seconds for time measures and bits for byte measures.
18
+
19
+ resources:
20
+ home: http://rubyworks.github.com/richunits
21
+ code: http://github.com/rubyworks/richunits
22
+ repo: git://github.com/rubyworks/richunits.git
23
+
24
+ copyright:
25
+ Copyright (c) 2008 Thomas Sawyer
26
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  Easy Units for Ruby
4
4
 
5
- * http://rubyworks.github.com/richunits/
5
+ * http://rubyworks.github.com/richunits
6
6
  * http://richunits.rubyforge.org/ (old site)
7
7
 
8
8
 
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ desc "run unit tests"
4
+ task :test do
5
+ $:.unshift('./lib')
6
+ Dir['test/*.rb'].each do |file|
7
+ load file
8
+ end
9
+ end
10
+
11
+ # vim: syntax=Ruby
12
+
data/VERSION ADDED
@@ -0,0 +1,7 @@
1
+ name : richunits
2
+ date : 2010-10-04
3
+ version : 0.6.1
4
+
5
+ requires:
6
+ - syckle (build)
7
+ - rspec (test)
@@ -70,6 +70,8 @@ module RichUnits
70
70
  def to_i ; @seconds.to_i ; end
71
71
  def to_f ; @seconds.to_f ; end
72
72
 
73
+ alias_method :to_int, :to_i
74
+
73
75
  public
74
76
 
75
77
  def to_a
@@ -0,0 +1,7 @@
1
+ name : richunits
2
+ date : 2010-10-04
3
+ version : 0.6.1
4
+
5
+ requires:
6
+ - syckle (build)
7
+ - rspec (test)
@@ -0,0 +1,68 @@
1
+ require 'richunits/bytes'
2
+ #require 'test/unit'
3
+
4
+ describe Numeric do
5
+
6
+ # bits
7
+
8
+ it "bits" do
9
+ 8.bits.should == 8
10
+ end
11
+
12
+ it "kilobits" do
13
+ 1.kilobit.should == 1024**1
14
+ end
15
+
16
+ it "megabits" do
17
+ 1.megabit.should == 1024**2
18
+ end
19
+
20
+ it "gigabits" do
21
+ 1.gigabit.should == 1024**3
22
+ end
23
+
24
+ it "terabits" do
25
+ 1.terabit.should == 1024**4
26
+ end
27
+
28
+ # bytes
29
+
30
+ it "bytes" do
31
+ 1024.bytes.should == 8192
32
+ end
33
+
34
+ it "kilobytes" do
35
+ 1.kilobyte.should == 1024**1*8
36
+ end
37
+
38
+ it "megabytes" do
39
+ 1.megabyte.should == 1024**2*8
40
+ end
41
+
42
+ it "gigabytes" do
43
+ 1.gigabyte.should == 1024**3*8
44
+ end
45
+
46
+ it "terabytes" do
47
+ 1.terabyte.should == 1024**4*8
48
+ end
49
+
50
+ # bits_to_s
51
+
52
+ it "strfbits" do
53
+ 1024.strfbits.should == "1.00 kb"
54
+ 1048576.strfbits.should == "1.00 mb"
55
+ 1073741824.strfbits.should == "1.00 gb"
56
+ 1099511627776.strfbits .should == "1.00 tb"
57
+ end
58
+
59
+ # bytes_to_s
60
+
61
+ it "strfbytes" do
62
+ 1024.strfbytes.should == "1.00 KB"
63
+ 1048576.strfbytes.should == "1.00 MB"
64
+ 1073741824.strfbytes.should == "1.00 GB"
65
+ 1099511627776.strfbytes.should == "1.00 TB"
66
+ end
67
+
68
+ end
@@ -1,53 +1,52 @@
1
1
  require 'richunits/duration'
2
- require 'test/unit'
3
2
 
4
- class TestDuration < Test::Unit::TestCase
3
+ describe RichUnits::Duration do
5
4
 
6
- def test_to_a
5
+ it "to_a" do
7
6
  d = RichUnits::Duration.new(24*60*60 + 1)
8
7
  r = d.to_a
9
8
  x = [1, 0, 0, 1]
10
- assert_equal(x, r)
9
+ r.should == x
11
10
 
12
11
  d = RichUnits::Duration.new(10*24*60*60 + 5)
13
12
  r = d.to_a
14
13
  x = [10, 0, 0, 5]
15
- assert_equal(x, r)
14
+ r.should == x
16
15
  end
17
16
 
18
- def test_segmented
17
+ it "segmented" do
19
18
  d = RichUnits::Duration.new(8*24*60*60 + 1)
20
19
  r = d.segmented(:week, :day, :hour, :minute, :second)
21
20
  x = [1, 1, 0, 0, 1]
22
- assert_equal(x, r.to_a)
21
+ r.to_a.should == x
23
22
  end
24
23
 
25
- def test_to_h
24
+ it "to_h" do
26
25
  d = RichUnits::Duration.new(24*60*60)
27
26
  r = d.to_h
28
27
  x = { :days=>1, :hours=>0, :minutes=>0, :seconds=>0 }
29
- assert_equal(x, r)
28
+ r.should == x
30
29
  end
31
30
 
32
- def test_repeated_numeric_days
31
+ it "repeated_numeric_days" do
33
32
  a = 10.days
34
33
  r = 10.days.days
35
34
  x = 10
36
- assert_equal(x,r)
35
+ r.should == x
37
36
  end
38
37
 
39
- def test_repeated_numeric_years
38
+ it "repeated_numeric_years" do
40
39
  a = 10.years
41
40
  r = 10.years.years
42
41
  x = 10
43
- assert_equal(x,r)
42
+ r.should == x
44
43
  end
45
44
 
46
- def test_repeated_strftime
45
+ it "repeated_strftime" do
47
46
  a = RichUnits::Duration[24*60*60 + 1]
48
47
  r = a.strftime('%d:%h:%m:%s')
49
48
  x = "1:0:0:1"
50
- assert_equal(x,r)
49
+ r.should == x
51
50
  end
52
51
 
53
52
  end
@@ -0,0 +1,98 @@
1
+ require 'richunits/multipliers'
2
+
3
+ describe "Multipliers" do
4
+
5
+ it "deka" do
6
+ 1.deka.should == 10
7
+ end
8
+
9
+ it "hecto" do
10
+ 1.hecto.should == 100
11
+ end
12
+
13
+ it "kilo" do
14
+ 1.kilo.should == 1000
15
+ end
16
+
17
+ it "mega" do
18
+ 1.mega.should == 1000000
19
+ end
20
+
21
+ it "giga" do
22
+ 1.giga.should == 1000000000
23
+ end
24
+
25
+ it "tera" do
26
+ 1.tera.should == 1000000000000
27
+ end
28
+
29
+ it "peta" do
30
+ 1.peta.should == 1000000000000000
31
+ end
32
+
33
+ it "exa" do
34
+ 1.exa.should == 1000000000000000000
35
+ end
36
+
37
+ # Fractional
38
+
39
+ it "deci" do
40
+ 1.deci.should == 0.1
41
+ end
42
+
43
+ it "centi" do
44
+ 1.centi.should == 0.01
45
+ end
46
+
47
+ it "milli" do
48
+ 1.milli.should == 0.001
49
+ end
50
+
51
+ it "milli" do
52
+ 1.micro.should == 0.000001
53
+ end
54
+
55
+ it "nano" do
56
+ 1.nano.should == 0.000000001
57
+ end
58
+
59
+ it "pico" do
60
+ 1.pico.should == 0.000000000001
61
+ end
62
+
63
+ it "femto" do
64
+ 1.femto.should == 0.000000000000001
65
+ end
66
+
67
+ it "atto" do
68
+ 1.atto.should == 0.000000000000000001
69
+ end
70
+
71
+ # SI Binary
72
+
73
+ it "kibi" do
74
+ 1.kibi.should == 1024
75
+ end
76
+
77
+ it "mebi" do
78
+ 1.mebi.should == 1024**2
79
+ end
80
+
81
+ it "gibi" do
82
+ 1.gibi.should == 1024**3
83
+ end
84
+
85
+ it "tebi" do
86
+ 1.tebi.should == 1024**4
87
+ end
88
+
89
+ it "pebi" do
90
+ 1.pebi.should == 1024**5
91
+ end
92
+
93
+ it "exbi" do
94
+ 1.exbi.should == 1024**6
95
+ end
96
+
97
+ end
98
+
@@ -0,0 +1,102 @@
1
+ require 'richunits/times'
2
+
3
+ describe "RichUnits::Times" do
4
+
5
+ #it "micro_seconds
6
+ # 1.microsecond.should == 0.000001
7
+ #end
8
+
9
+ #it "milli_seconds
10
+ # 1.millisecond.should == 0.001
11
+ #end
12
+
13
+ it "seconds" do
14
+ 1.seconds.to_i.should == 60**0
15
+ end
16
+
17
+ it "minutes" do
18
+ 1.minutes.to_i.should == 60**1
19
+ end
20
+
21
+ it "hours" do
22
+ 1.hours.to_i.should == 60**2
23
+ end
24
+
25
+ it "days" do
26
+ 1.days.to_i.should == 24*(60**2)
27
+ end
28
+
29
+ it "weeks" do
30
+ 1.weeks.to_i.should == 7*24*(60**2)
31
+ end
32
+
33
+ it "fortnights" do
34
+ 1.fortnights.to_i .should == 14*24*(60**2)
35
+ end
36
+
37
+ it "months" do
38
+ 1.months.to_i.should == 30*24*(60**2)
39
+ end
40
+
41
+ it "years" do
42
+ 1.years.to_i.should == 365*24*(60**2)
43
+ end
44
+
45
+
46
+ it "before" do
47
+ t = Time.now
48
+ 1.day.before(t).should == t - 1.day
49
+ end
50
+
51
+ it "after" do
52
+ t = Time.now
53
+ 1.day.after(t).should == t + 1.day
54
+ end
55
+
56
+ #
57
+
58
+ it "addition" do
59
+ (10.minutes + 1.minute).should == 11.minutes
60
+ (10.minutes + 1.minute).to_i.should == 11.minutes.to_i
61
+
62
+ (10.minutes + 60.seconds).should == 11.minutes
63
+ (10.minutes + 60.seconds).to_i.should == 11.minutes.to_i
64
+ end
65
+
66
+ it "multiplication" do
67
+ (10.minutes * 2).should == 20.minutes
68
+ (10.minutes * 2).to_i.should ==20.minutes.to_i
69
+ end
70
+
71
+ end
72
+
73
+ describe "Weekdays Test" do
74
+
75
+ MONDAY = Time.at(1165250000)
76
+ THURSDAY = Time.at(1165500000)
77
+ FRIDAY = Time.at(1165606025)
78
+
79
+ it "weekday after monday" do
80
+ 1.weekday.since(MONDAY).wday.should == 2
81
+ end
82
+
83
+ it "weekday after friday" do
84
+ 1.weekday.after(FRIDAY).wday.should == 1
85
+ end
86
+
87
+ it "weekdays before friday" do
88
+ 3.weekdays.before(FRIDAY).wday.should == 2
89
+ end
90
+
91
+ #it "weekday before today" do
92
+ # Time.expects(:now).returns(THURSDAY)
93
+ # 1.weekday.ago.wday.should == 3
94
+ #end
95
+
96
+ #it "weekdays after today" do
97
+ # Time.expects(:now).returns(MONDAY)
98
+ # 2.weekday.from_now.wday.should == 3
99
+ #end
100
+
101
+ end
102
+
metadata CHANGED
@@ -1,97 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: richunits
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.6"
4
+ hash: 5
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 1
10
+ version: 0.6.1
5
11
  platform: ruby
6
- authors: []
7
-
12
+ authors:
13
+ - Thomas Sawyer
14
+ - Rich Kilmer
8
15
  autorequire:
9
16
  bindir: bin
10
17
  cert_chain: []
11
18
 
12
- date: 2009-10-31 00:00:00 -04:00
19
+ date: 2010-11-04 00:00:00 -04:00
13
20
  default_executable:
14
- dependencies: []
15
-
16
- description: |-
17
- Rich Kilmer's Unit system provides english-esque methods
18
- for working with common units, such as days and bytes and
19
- multiplers like kilo, or mega. It does so by reducing basic
20
- measures to a lower common denominator, such as seconds for
21
- time measures and bits for byte measures.
22
- email: 7ransUnit <transfire@gmail.com>
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: syckle
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: A Unit system, based on Rich Kilmer's original time.rb work, which provides english-esque methods for working with common units, such as days and bytes and multiplers like kilo, or mega. It does so by reducing basic measures to a lower common denominator, such as seconds for time measures and bits for byte measures.
51
+ email: transfire@gmail.com
23
52
  executables: []
24
53
 
25
54
  extensions: []
26
55
 
27
56
  extra_rdoc_files:
28
- - README
29
- - MANIFEST
30
- - CHANGES
31
- - RELEASE
32
- - TODO
33
- - COPYING
57
+ - README.rdoc
34
58
  files:
35
- - CHANGES
36
- - COPYING
37
- - MANIFEST
38
- - README
39
- - RELEASE
40
- - TODO
41
59
  - lib/rich_units.rb
42
- - lib/richunits.rb
43
60
  - lib/richunits/bytes.rb
44
61
  - lib/richunits/duration.rb
45
62
  - lib/richunits/multipliers.rb
46
63
  - lib/richunits/times.rb
64
+ - lib/richunits/version.yml
47
65
  - lib/richunits/weekdays.rb
48
- - meta/abstract
49
- - meta/anthology
50
- - meta/contact
51
- - meta/created
52
- - meta/homepage
53
- - meta/license
54
- - meta/name
55
- - meta/repository
56
- - meta/title
57
- - meta/version
58
- - test/test_bytes.rb
59
- - test/test_duration.rb
60
- - test/test_multipliers.rb
61
- - test/test_times.rb
66
+ - lib/richunits.rb
67
+ - spec/bytes_spec.rb
68
+ - spec/duration_spec.rb
69
+ - spec/multipliers_spec.rb
70
+ - spec/times_spec.rb
71
+ - Rakefile
72
+ - HISTORY.rdoc
73
+ - PROFILE
74
+ - README.rdoc
75
+ - VERSION
76
+ - COPYING
62
77
  has_rdoc: true
63
- homepage: http://tigerops.rubyforge.org/richunits
64
- licenses: []
65
-
78
+ homepage: http://rubyworks.github.com/richunits
79
+ licenses:
80
+ - MIT
66
81
  post_install_message:
67
82
  rdoc_options:
68
83
  - --title
69
84
  - RichUnits API
70
85
  - --main
71
- - README
86
+ - README.rdoc
72
87
  require_paths:
73
88
  - lib
74
89
  required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
75
91
  requirements:
76
92
  - - ">="
77
93
  - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
78
97
  version: "0"
79
- version:
80
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
81
100
  requirements:
82
101
  - - ">="
83
102
  - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
84
106
  version: "0"
85
- version:
86
107
  requirements: []
87
108
 
88
- rubyforge_project: tigerops
89
- rubygems_version: 1.3.5
109
+ rubyforge_project: richunits
110
+ rubygems_version: 1.3.7
90
111
  signing_key:
91
112
  specification_version: 3
92
- summary: Rich Kilmer's Unit system provides english-esque methods
93
- test_files:
94
- - test/test_bytes.rb
95
- - test/test_duration.rb
96
- - test/test_multipliers.rb
97
- - test/test_times.rb
113
+ summary: Simple LCD Unit System
114
+ test_files: []
115
+
data/CHANGES DELETED
@@ -1,20 +0,0 @@
1
- === 0.5.0 / 2009-05-30
2
-
3
- * Name of gem and main require will be 'richunits' (no underscore).
4
-
5
- === 0.4.0 / 2008-09-09
6
-
7
- * Rewrote Duration class and integrated into rest of system.
8
-
9
- === 0.3.0 / 2008-09-08
10
-
11
- * Encapsulated entire library in RichUnits module.
12
-
13
- === 0.2.0 / 2008-08-01
14
-
15
- * Reorganized repository.
16
-
17
- === 0.1.0 / 2008-03-27
18
-
19
- * Initial version.
20
-
data/MANIFEST DELETED
@@ -1,28 +0,0 @@
1
- CHANGES
2
- COPYING
3
- MANIFEST
4
- README
5
- RELEASE
6
- TODO
7
- lib/rich_units.rb
8
- lib/richunits
9
- lib/richunits.rb
10
- lib/richunits/bytes.rb
11
- lib/richunits/duration.rb
12
- lib/richunits/multipliers.rb
13
- lib/richunits/times.rb
14
- lib/richunits/weekdays.rb
15
- meta/abstract
16
- meta/anthology
17
- meta/contact
18
- meta/created
19
- meta/homepage
20
- meta/license
21
- meta/name
22
- meta/repository
23
- meta/title
24
- meta/version
25
- test/test_bytes.rb
26
- test/test_duration.rb
27
- test/test_multipliers.rb
28
- test/test_times.rb
data/RELEASE DELETED
@@ -1,21 +0,0 @@
1
- This release updates some extensions to Time for use with the
2
- Duration class, and standardizes the library on the name 'richunits',
3
- rather than using the underscored "rich_units". This means installation
4
- is now:
5
-
6
- gem install richunits
7
-
8
- and loading the library is now:
9
-
10
- require 'richunits'
11
-
12
- Though a backward compatible require is still present.
13
-
14
- The previous release contains a complete rewrite of the Duration
15
- class and integrates it into the rest of the system.
16
-
17
-
18
- ### 0.5.0 / 2009-05-30
19
-
20
- * Rewrote Duration class and integrated into rest of system.
21
-
data/TODO DELETED
@@ -1,22 +0,0 @@
1
- = TODO List
2
-
3
- == Achieve 99.9% drop-in compatability with ActiveSupport.
4
-
5
- * Duration may be the big difficulty here.
6
-
7
-
8
- == Better TimeZone support
9
-
10
- * tgzinfo?
11
-
12
-
13
- == Documentation
14
-
15
- I was looking through the rdoc at
16
-
17
- http://tigerops.rubyforge.org/rich_units/rdoc/index.html
18
-
19
- and found that the names generated by rdoc for the bit and byte human readable string methods is out of synch with the examples in the documentation for each of the methods. The actual method names Numeric#strfbits and Numeric#strfbytes work but the method names Numeric#bits_to_s and Numeric#bytes_to_s that are shown in the examples for each method do not work.
20
-
21
- (from Larry Baltz)
22
-
data/meta/abstract DELETED
@@ -1,5 +0,0 @@
1
- Rich Kilmer's Unit system provides english-esque methods
2
- for working with common units, such as days and bytes and
3
- multiplers like kilo, or mega. It does so by reducing basic
4
- measures to a lower common denominator, such as seconds for
5
- time measures and bits for byte measures.
data/meta/anthology DELETED
@@ -1 +0,0 @@
1
- rubyworks
data/meta/contact DELETED
@@ -1 +0,0 @@
1
- 7ransUnit <transfire@gmail.com>
data/meta/created DELETED
@@ -1 +0,0 @@
1
- 2008-02-21
data/meta/homepage DELETED
@@ -1,2 +0,0 @@
1
- http://tigerops.rubyforge.org/richunits
2
-
data/meta/license DELETED
@@ -1 +0,0 @@
1
- MIT
data/meta/name DELETED
@@ -1 +0,0 @@
1
- richunits
data/meta/repository DELETED
@@ -1 +0,0 @@
1
- git://github.com/rubyworks/richunits.git
data/meta/title DELETED
@@ -1 +0,0 @@
1
- RichUnits
data/meta/version DELETED
@@ -1 +0,0 @@
1
- 0.6
data/test/test_bytes.rb DELETED
@@ -1,69 +0,0 @@
1
- require 'richunits/bytes'
2
- require 'test/unit'
3
-
4
- class TC_Numeric < Test::Unit::TestCase
5
-
6
- # bits
7
-
8
- def test_bits
9
- assert_equal( 8, 8.bits )
10
- end
11
-
12
- def test_kilobits
13
- assert_equal( 1024**1, 1.kilobit )
14
- end
15
-
16
- def test_megabits
17
- assert_equal( 1024**2, 1.megabit )
18
- end
19
-
20
- def test_gigabits
21
- assert_equal( 1024**3, 1.gigabit )
22
- end
23
-
24
- def test_terabits
25
- assert_equal( 1024**4, 1.terabit )
26
- end
27
-
28
- # bytes
29
-
30
- def test_bytes
31
- assert_equal( 8192, 1024.bytes )
32
- end
33
-
34
- def test_kilobytes
35
- assert_equal( 1024**1*8, 1.kilobyte )
36
- end
37
-
38
- def test_megabytes
39
- assert_equal( 1024**2*8, 1.megabyte )
40
- end
41
-
42
- def test_gigabytes
43
- assert_equal( 1024**3*8, 1.gigabyte )
44
- end
45
-
46
- def test_terabytes
47
- assert_equal( 1024**4*8, 1.terabyte )
48
- end
49
-
50
- # bits_to_s
51
-
52
- def test_strfbits
53
- assert_equal( "1.00 kb", 1024.strfbits )
54
- assert_equal( "1.00 mb", 1048576.strfbits )
55
- assert_equal( "1.00 gb", 1073741824.strfbits )
56
- assert_equal( "1.00 tb", 1099511627776.strfbits )
57
- end
58
-
59
- # bytes_to_s
60
-
61
- def test_strfbytes
62
- assert_equal( "1.00 KB", 1024.strfbytes )
63
- assert_equal( "1.00 MB", 1048576.strfbytes )
64
- assert_equal( "1.00 GB", 1073741824.strfbytes )
65
- assert_equal( "1.00 TB", 1099511627776.strfbytes )
66
- end
67
-
68
- end
69
-
@@ -1,99 +0,0 @@
1
- require 'richunits/multipliers'
2
- require 'test/unit'
3
-
4
- class TC_Multipliers < Test::Unit::TestCase
5
-
6
- def test_deka
7
- assert_equal( 10, 1.deka )
8
- end
9
-
10
- def test_hecto
11
- assert_equal( 100, 1.hecto )
12
- end
13
-
14
- def test_kilo
15
- assert_equal( 1000, 1.kilo )
16
- end
17
-
18
- def test_mega
19
- assert_equal( 1000000, 1.mega )
20
- end
21
-
22
- def test_giga
23
- assert_equal( 1000000000, 1.giga )
24
- end
25
-
26
- def test_tera
27
- assert_equal( 1000000000000, 1.tera )
28
- end
29
-
30
- def test_peta
31
- assert_equal( 1000000000000000, 1.peta )
32
- end
33
-
34
- def test_exa
35
- assert_equal( 1000000000000000000, 1.exa )
36
- end
37
-
38
- # Fractional
39
-
40
- def test_deci
41
- assert_equal( 0.1, 1.deci )
42
- end
43
-
44
- def test_centi
45
- assert_equal( 0.01, 1.centi )
46
- end
47
-
48
- def test_milli
49
- assert_equal( 0.001, 1.milli )
50
- end
51
-
52
- def test_milli
53
- assert_equal( 0.000001, 1.micro )
54
- end
55
-
56
- def test_nano
57
- assert_equal( 0.000000001, 1.nano )
58
- end
59
-
60
- def test_pico
61
- assert_equal( 0.000000000001, 1.pico )
62
- end
63
-
64
- def test_femto
65
- assert_equal( 0.000000000000001, 1.femto )
66
- end
67
-
68
- def test_atto
69
- assert_equal( 0.000000000000000001, 1.atto )
70
- end
71
-
72
- # SI Binary
73
-
74
- def test_kibi
75
- assert_equal( 1024, 1.kibi )
76
- end
77
-
78
- def test_mebi
79
- assert_equal( 1024**2, 1.mebi )
80
- end
81
-
82
- def test_gibi
83
- assert_equal( 1024**3, 1.gibi )
84
- end
85
-
86
- def test_tebi
87
- assert_equal( 1024**4, 1.tebi )
88
- end
89
-
90
- def test_pebi
91
- assert_equal( 1024**5, 1.pebi )
92
- end
93
-
94
- def test_exbi
95
- assert_equal( 1024**6, 1.exbi )
96
- end
97
-
98
- end
99
-
data/test/test_times.rb DELETED
@@ -1,103 +0,0 @@
1
- require 'richunits/times'
2
- require 'test/unit'
3
-
4
- class TC_Times < Test::Unit::TestCase
5
-
6
- #def test_micro_seconds
7
- # assert_equal( 0.000001, 1.microsecond )
8
- #end
9
-
10
- #def test_milli_seconds
11
- # assert_equal( 0.001, 1.millisecond )
12
- #end
13
-
14
- def test_seconds
15
- assert_equal( 60**0, 1.seconds.to_i )
16
- end
17
-
18
- def test_minutes
19
- assert_equal( 60**1, 1.minutes.to_i )
20
- end
21
-
22
- def test_hours
23
- assert_equal( 60**2, 1.hours.to_i )
24
- end
25
-
26
- def test_days
27
- assert_equal( 24*(60**2), 1.days.to_i )
28
- end
29
-
30
- def test_weeks
31
- assert_equal( 7*24*(60**2), 1.weeks.to_i )
32
- end
33
-
34
- def test_fortnights
35
- assert_equal( 14*24*(60**2), 1.fortnights.to_i )
36
- end
37
-
38
- def test_months
39
- assert_equal( 30*24*(60**2), 1.months.to_i )
40
- end
41
-
42
- def test_years
43
- assert_equal( 365*24*(60**2), 1.years.to_i )
44
- end
45
-
46
-
47
- def test_before
48
- t = Time.now
49
- assert_equal( t - 1.day, 1.day.before(t) )
50
- end
51
-
52
- def test_after
53
- t = Time.now
54
- assert_equal( t + 1.day, 1.day.after(t) )
55
- end
56
-
57
- #
58
-
59
- def test_addition
60
- assert_equal(11.minutes, 10.minutes + 1.minute)
61
- assert_equal(11.minutes.to_i, (10.minutes + 1.minute).to_i)
62
-
63
- assert_equal(11.minutes, 10.minutes + 60.seconds)
64
- assert_equal(11.minutes.to_i, (10.minutes + 60.seconds).to_i)
65
- end
66
-
67
- def test_multiplication
68
- assert_equal(20.minutes, 10.minutes * 2)
69
- assert_equal(20.minutes.to_i, (10.minutes * 2).to_i)
70
- end
71
-
72
- end
73
-
74
- class WeekdaysTest < Test::Unit::TestCase
75
-
76
- MONDAY = Time.at(1165250000)
77
- THURSDAY = Time.at(1165500000)
78
- FRIDAY = Time.at(1165606025)
79
-
80
- def test_weekday_after_monday
81
- assert_equal 2, 1.weekday.since(MONDAY).wday
82
- end
83
-
84
- def test_weekday_after_friday
85
- assert_equal 1, 1.weekday.after(FRIDAY).wday
86
- end
87
-
88
- def test_weekdays_before_friday
89
- assert_equal 2, 3.weekdays.before(FRIDAY).wday
90
- end
91
-
92
- #def test_weekday_before_today
93
- # Time.expects(:now).returns(THURSDAY)
94
- # assert_equal 3, 1.weekday.ago.wday
95
- #end
96
-
97
- #def test_weekdays_after_today
98
- # Time.expects(:now).returns(MONDAY)
99
- # assert_equal 3, 2.weekday.from_now.wday
100
- #end
101
-
102
- end
103
-