sy 2.0.7 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 672ba8a0946d6df05bb65ff2e23100e0419fdec2
4
- data.tar.gz: 19dbf53c658806b0052809bda3e975b8ba7a29df
3
+ metadata.gz: fbbae1ea1d66b6976a9dbff702b83e891d0a2e71
4
+ data.tar.gz: 45b1ac5ddb4e8394d96ae22ad4a2e9946e23ec11
5
5
  SHA512:
6
- metadata.gz: 98ca4cb0b79fc7c73b3ca6a6748415b152ef2e78d291f4775b98832e15c7647e0e613ee9787fde0fa2d7782030be2deeb782debb9280bd0549751453e29bed5f
7
- data.tar.gz: c21b90522fe5268c2a9438964dedb51cb07d5813fa237d365fa12869817eb8f51f5a0d8541b73fdbc37f7e66053c22105ea7847c3557f20dafc07e8d5ae72cc5
6
+ metadata.gz: 61cd30896408251b6611e1d616476e3666fd6d1c006140b4f9472ce15f11dfb29cf47b59a631614b9a8d1c5c74d282562ef70d588abacd3571aba063312ed5bb
7
+ data.tar.gz: 2c6553261eebeacdf3ab6f9a29094bc855800845d2cf44a3c9d62b19dd86b09c25ce796ad4a50a7de9cc5f070b484c20b2a1a53ec2a6241b7a17ab9f67933d50
data/lib/sy.rb CHANGED
@@ -66,7 +66,9 @@ module SY
66
66
  # of the constant "UNIT" implies, via YSupport's NameMagic mixin, that the
67
67
  # name of the object becomes :unit and that it is possible to use syntax
68
68
  # such as 42.unit to create magnitudes of SY::Amount.
69
+ puts "About to construct UNIT." if SY::DEBUG
69
70
  UNIT = Unit.standard of: Amount
71
+ puts "UNIT constructed. SY::Unit instances are #{SY::Unit.instance_names}" if SY::DEBUG
70
72
 
71
73
  # AVOGADRO_CONSTANT (Nᴀ) is a certain well-known amount of things:
72
74
  Nᴀ = AVOGADRO_CONSTANT = 6.02214e23
@@ -75,7 +77,10 @@ module SY
75
77
  MoleAmount = Quantity.dimensionless coerces: Amount
76
78
 
77
79
  # And let SY::MOLE be its standard unit, related to SY::Amount via Nᴀ:
80
+ puts "About to construct MOLE." if SY::DEBUG
78
81
  MOLE = Unit.standard of: MoleAmount, short: "mol", amount: Nᴀ.unit
82
+ puts SY::Unit.__instances__ if SY::DEBUG
83
+ puts "MOLE constructed. SY::Unit instances are #{SY::Unit.instance_names}" if SY::DEBUG
79
84
 
80
85
  # === Basic dimension L (length)
81
86
 
@@ -141,18 +146,49 @@ module SY
141
146
  CELSIUS = Unit.standard( of: CelsiusTemperature,
142
147
  short: '°C', measure: CELSIUS_MEASURE )
143
148
 
144
- class << CelsiusTemperature
145
- # FIXME: Patch CelsiusTemperature to make it work with SY::Temperature
146
- # 1.°C + 1.K #=> 2.°C
147
- # 1.°C - 1.°C #=> 0.K (unambiguous)
148
- # 1.°C + 1.°C #=> QuantityError (ambiguous)
149
- # 1.K +- 1.°C #=> QuantityError (ambiguous)
150
- # 1.°C +- 1.K #=> 2.°C
151
- # 1.mm.°C⁻¹ #=> 1.mm.K⁻¹ etc.
152
- # 1.mm.°C #=> 1.mm.K etc.
153
- # 1.mm */ 1.°C #=> QuantityError (ambiguous)
149
+ module CelsiusMagnitude
150
+ def + m2
151
+ puts "CelsiusMagnitude#+ method with #{m2}" # FIXME: This message doesn't show.
152
+ return magnitude amount + m2.amount if
153
+ m2.quantity == SY::Temperature ||
154
+ m2.quantity.colleague == SY::Temperature
155
+ raise QuantityError, "Addition of Celsius temepratures is ambiguous!" if
156
+ m2.quantity == SY::CelsiusTemperature
157
+ super
158
+ end
159
+
160
+ def - m2
161
+ puts "CelsiusMagnitude#- method with #{m2}" # FIXME: This message doesn't show.
162
+ return magnitude amount - m2.amount if
163
+ m2.quantity == SY::Temperature ||
164
+ m2.quantity.colleague == SY::Temperature
165
+ return super.( SY::Temperature ) if m2.quantity == SY::CelsiusTemperature
166
+ super
167
+ end
168
+
169
+ # FIXME: #% method etc
154
170
  end
155
171
 
172
+ # Making sure that for Celsius temperature, #°C returns absolute magnitude.
173
+ #
174
+ class Numeric
175
+ def °C
176
+ SY::CelsiusTemperature.absolute.magnitude self
177
+ end
178
+ end
179
+ # FIXME: Make this more systematic.
180
+ # FIXME: Make sure that SI prefixes may not be used with Celsius
181
+ # FIXME: Make sure that highly unusual SI prefixes may not be used
182
+
183
+ class << CelsiusTemperature.send( :Magnitude )
184
+ include SY::CelsiusMagnitude
185
+ end
186
+
187
+ class << CelsiusTemperature.relative.send( :Magnitude )
188
+ include SY::CelsiusMagnitude
189
+ end
190
+
191
+
156
192
  # alias :°C :celsius # with U+00B0 DEGREE SIGN
157
193
  # alias :˚C :celsius # with U+02DA RING ABOVE
158
194
  # alias :℃ :celsius # U+2103 DEGREE CELSIUS
@@ -43,6 +43,8 @@ module SY::AbsoluteMagnitude
43
43
  # For absolute magnitudes, #+ method always returns a result framed in
44
44
  # corresponding relative quantity.
45
45
  #
46
+ # TODO: Figure out which module comes on the top in Quantity@Magnitude, whether Magnitude
47
+ # or SignedMagnitude, and therefore, whether it is necessary to adjust this method.
46
48
  def + m2
47
49
  return magnitude amount + m2.amount if m2.quantity == quantity.relative
48
50
  return quantity.relative.magnitude( amount + m2.amount ) if
@@ -67,6 +69,8 @@ module SY::AbsoluteMagnitude
67
69
  # For absolute magnitudes, #- method always returns a result framed in
68
70
  # corresponding relative quantity.
69
71
  #
72
+ # TODO: Figure out which module comes on the top in Quantity@Magnitude, whether Magnitude
73
+ # or SignedMagnitude, and therefore, whether it is necessary to adjust this method.
70
74
  def - m2
71
75
  return magnitude amount - m2.amount if m2.quantity == quantity.relative
72
76
  return quantity.relative.magnitude( amount - m2.amount ) if
@@ -68,19 +68,24 @@ module SY::ExpressibleInUnits
68
68
  @included_in ||= []
69
69
  end
70
70
 
71
+ # Unit namespace.
72
+ #
73
+ def unit_namespace
74
+ begin
75
+ SY::Unit
76
+ rescue NameError # no SY::Unit defined yet
77
+ end
78
+ end
79
+
71
80
  # Currently defined unit instances, if any.
72
81
  #
73
82
  def known_units
74
- unit_namespace = begin
75
- SY::Unit
76
- rescue NameError
77
- return [] # no SY::Unit yet
78
- end
79
83
  begin
80
84
  unit_namespace.instances
81
85
  rescue NoMethodError
82
86
  [] # no #instances method defined yet
83
87
  end
88
+ .tap { |r| puts "Known units are #{r}" if SY::DEBUG }
84
89
  end
85
90
 
86
91
  # All methods defined by this mixin.
@@ -92,7 +97,12 @@ module SY::ExpressibleInUnits
92
97
  # Find unit based on name / abbreviation.
93
98
  #
94
99
  def find_unit ς
95
- known_units.find { |u| u.name.to_s == ς || u.short.to_s == ς }
100
+ puts "searching for unit #{ς}" if SY::DEBUG
101
+ known_units.find do |u|
102
+ u.name.to_s.downcase == ς.downcase &&
103
+ ( ς == ς.downcase || ς == ς.upcase ) ||
104
+ u.short.to_s == ς
105
+ end
96
106
  end
97
107
 
98
108
  # Return prefix method or empty string, if prefix method not necessary.
@@ -121,6 +131,7 @@ module SY::ExpressibleInUnits
121
131
  # I'D HAVE TO PERFORM THE COLLISION CHECK HERE
122
132
  # IF NO COLLISION, INFORM THE SUBSEQUENT METHOD DEFINED CALL ON
123
133
  # SELF.CLASS
134
+ puts "parsed" if SY::DEBUG
124
135
  self.class.instance_variable_set "@no_collision", ß # FIXME: This is too clumsy
125
136
  self.class.module_eval write_unit_method( ß, prefixes, units, exps )
126
137
  SY::ExpressibleInUnits.method_family << self.class.instance_method( ß )
@@ -155,6 +166,7 @@ module SY::ExpressibleInUnits
155
166
  # figures out which SY units it represents, along with prefixes and exponents.
156
167
  #
157
168
  def parse_unit_symbol ß
169
+ puts "About to parse #{ß} using all prefixes" if SY::DEBUG
158
170
  SY::Unit.parse_sps_using_all_prefixes( ß ) # rely on SY::Unit
159
171
  end
160
172
 
@@ -163,10 +175,12 @@ module SY::ExpressibleInUnits
163
175
  # Arrays must be of equal length. (Note: 'ß' is 'symbol', 'ς' is 'string')
164
176
  #
165
177
  def write_unit_method ß, prefixes, units, exponents
178
+ puts "writing unit method #{ß}" if SY::DEBUG
166
179
  # Prepare prefix / unit / exponent triples for making factor strings:
167
180
  triples = [ prefixes, units, exponents ].transpose
168
181
  # A procedure for triple processing before use:
169
182
  process_triple = lambda do |pfx, unit_ς, exp|
183
+ puts "Processing triple #{pfx}, #{unit_ς}, #{exp}." if SY::DEBUG
170
184
  [ ::SY::ExpressibleInUnits.find_unit( unit_ς ).name.to_s.upcase,
171
185
  ::SY::ExpressibleInUnits.prefix_method_string( pfx ),
172
186
  ::SY::ExpressibleInUnits.exponentiation_string( exp ) ]
@@ -157,14 +157,16 @@ module SY::Magnitude
157
157
 
158
158
  # Same magnitudes <em>and</em> same (#eql) quantities.
159
159
  #
160
- def eql other
161
- raise NotImplementedError
160
+ def eql? other
161
+ quantity == other.quantity && amount == other.amount
162
162
  end
163
163
 
164
164
  # Percent operator (remainder after division)
165
165
  #
166
- def %
167
- raise NotImplementedError
166
+ def % m2
167
+ return magnitude amount % m2.amount if quantity == m2.quantity
168
+ return self % m2.( quantity ) if quantity.coerces? m2.quantity
169
+ apply_through_coerce :%, m2
168
170
  end
169
171
 
170
172
  # Type coercion for magnitudes.
@@ -261,7 +261,7 @@ class SY::Quantity
261
261
  Unit().standard
262
262
  end
263
263
 
264
- # Constructs a new absolute magnitude of this quantity.
264
+ # Constructs a absolute magnitude of this quantity.
265
265
  #
266
266
  def magnitude amount
267
267
  puts "Constructing #{self}#magnitude with amount #{amount}." if SY::DEBUG
@@ -436,8 +436,8 @@ class SY::Quantity
436
436
  qnt = self
437
437
  ɴλ = -> { name ? "#{name}@%s" : "#<Quantity:#{object_id}@%s>" }
438
438
 
439
- Class.new Magnitude() do # Unit class.
440
- include SY::Unit
439
+ Class.new Magnitude() do puts "Creating @Unit class!" if SY::DEBUG
440
+ include SY::Unit; puts "Included SY::Unit" if SY::DEBUG
441
441
 
442
442
  singleton_class.class_exec do
443
443
  define_method :standard do |**nn| # Customized #standard.
@@ -449,8 +449,12 @@ class SY::Quantity
449
449
  ɴλ.call % "Unit" # as for @Magnitude applies.)
450
450
  end
451
451
  end
452
- end
453
- end )
452
+ end.namespace! SY::Unit
453
+ end ).tap do |u|
454
+ puts "@Unit constructed, its namespace is #{u.namespace}" if SY::DEBUG
455
+ puts "its instances are #{u.namespace.instances}" if SY::DEBUG
456
+ puts "its instance names are #{u.namespace.instance_names}" if SY::DEBUG
457
+ end
454
458
  end
455
459
 
456
460
  private
@@ -29,6 +29,8 @@ module SY::SignedMagnitude
29
29
 
30
30
  # Addition.
31
31
  #
32
+ # TODO: Figure out which module comes on the top in Quantity@Magnitude, whether Magnitude
33
+ # or SignedMagnitude, and therefore, whether it is necessary to adjust this method.
32
34
  def + m2
33
35
  return magnitude( amount + m2.amount ) if quantity == m2.quantity
34
36
  return quantity.absolute.magnitude( amount + m2.amount ) if
@@ -38,7 +40,8 @@ module SY::SignedMagnitude
38
40
  end
39
41
 
40
42
  # Subtraction.
41
- #
43
+ #
44
+ # TODO: ditto
42
45
  def - m2
43
46
  return magnitude( amount - m2.amount ) if m2.quantity == quantity.relative
44
47
  return quantity.relative.magnitude( amount - m2.amount ) if
@@ -6,86 +6,61 @@
6
6
  module SY::Unit
7
7
  PROTECTED_NAMES = [ "kilogram" ]
8
8
 
9
- def self.pre_included target
10
- class << target
11
- # Overriding this method from NameMagic mixin ensures, that all Unit
12
- # subclasses use common namespace (Unit), rather than each their own.
13
- #
14
- def namespace
15
- SY::Unit
16
- end
17
- end
18
- end # def self.pre_included
19
-
20
- # Tweaking instance accessor from NameMagic to make it accept unit
21
- # abbreviations and unit names regardless of capitalization
22
- #
23
- def self.instance arg
24
- puts "SY::Unit module #instance method activated" if SY::DEBUG
25
- begin
26
- super # let's first try the original method
27
- .tap { puts "original #instance method provided by NameMagic succeeded" if SY::DEBUG }
28
- rescue NameError # if we fail...
29
- puts "original #instance method provided by NameMagic returned NameError" if SY::DEBUG
30
- begin # second in order, let's try whether it's an abbreviation
31
- puts "trying whether the argument is an abbreviation" if SY::DEBUG
32
- rslt = instances.find { |unit_inst|
33
- if unit_inst.abbreviation then
34
- if unit_inst.abbreviation.to_s == arg.to_s then
35
- puts "For supplied argument #{arg} (#{arg.class}), it seems that " +
36
- "unit #{unit_inst} of quantity #{unit_inst.quantity} has abbreviation " +
37
- "#{unit_inst.abbreviation} matching it." if SY::DEBUG
38
- true
39
- else
40
- false
41
- end
9
+ class << self
10
+ # Make Unit#instance ignore capitalization and accept abbreviations.
11
+ #
12
+ def instance arg
13
+ begin
14
+ super # let's first try the original method
15
+ rescue NameError # if we fail...
16
+ begin # ... let's try the abbreviation
17
+ super instances.find { |unit_inst|
18
+ unit_inst.short.to_s == arg.to_s if unit_inst.short
19
+ }.tap { |rslt| fail NameError if rslt.nil? } # fail if nothing found
20
+ rescue NameError, TypeError
21
+ begin # Let's to try upcase if we have all-downcase arg
22
+ super arg.to_s.upcase
23
+ rescue NameError # if not, tough luck
24
+ raise NameError, "Unknown unit symbol: #{arg}"
42
25
  end
43
- # inst.abbreviation.to_s == arg.to_s if inst.abbreviation
44
- }
45
- fail NameError if rslt.nil? # if nothing found, super need not be called
46
- super rslt
47
- rescue NameError, TypeError
48
- puts "failed, we'll now try to upcase the argument in case of all-downcase argument" if SY::DEBUG
49
- begin # finally, let's try upcase if we have all-downcase arg
50
- super arg.to_s.upcase
51
- rescue NameError # if not, tough luck
52
- raise NameError, "Unknown unit symbol: #{which}"
53
26
  end
54
27
  end
55
28
  end
56
- end # def self.instance
57
-
58
- def self.included target
59
- target.class_exec do
60
- # Let's set up the naming hook for NameMagic:
61
- name_set_closure do |name, new_instance, old_name|
62
- ɴ = name.to_s
63
- up, down = ɴ.upcase, ɴ.downcase
64
- # Check case (only all-upper or all-lower is acceptable).
65
- unless ɴ == up || ɴ = down
66
- raise NameError, "Unit must be either all-upper or all-lower case!"
67
- end
68
- # Reject the names starting with a full prefix.
69
- conflicter = SY::PREFIX_TABLE.full_prefixes
70
- .find { |prefix| down.starts_with? prefix unless prefix.empty? }
71
- raise NameError, "Name #{ɴ} starts with #{conflicter}- prefix" unless
72
- SY::Unit::PROTECTED_NAMES.include? down if conflicter
73
- # Warn about the conflicts in modules where the SY::ExpressibleInUnits
74
- # mixin is included.
75
- if new_instance.warns? then
76
- w = ::SY::ExpressibleInUnits::COLLISION_WARNING
77
- ::SY::ExpressibleInUnits.included_in.each do |ɱ|
78
- im = ɱ.instance_methods
79
- # puts ɱ, "class: #{ɱ.class}"
80
- # puts im.size
81
- # puts down
82
- # puts im.include? down
83
- warn w % [down, ɱ] if im.include? down
84
- abbrev = new_instance.abbreviation
85
- warn w % [abbrev, ɱ] if im.include? abbrev
29
+
30
+ def included target
31
+ target.class_exec do
32
+ # Let's set up the naming hook for NameMagic:
33
+ name_set_closure do |name, new_instance, old_name|
34
+ ɴ = name.to_s
35
+ up, down = ɴ.upcase, ɴ.downcase
36
+
37
+ # Check case (only all-upper or all-lower is acceptable).
38
+ msg = "Unit must be either all-upper or all-lower case!"
39
+ fail NameError, msg unless ɴ == up || ɴ = down
40
+
41
+ # Reject the names starting with a full prefix.
42
+ conflicter = SY::PREFIX_TABLE.full_prefixes
43
+ .find { |prefix| down.starts_with? prefix unless prefix.empty? }
44
+ fail NameError, "Name #{ɴ} starts with #{conflicter}- prefix!" unless
45
+ SY::Unit::PROTECTED_NAMES.include? down if conflicter
46
+
47
+ # Warn about method name conflicts in the target module(s), where
48
+ # SY::ExpressibleInUnits mixin is included.
49
+ if new_instance.warns? then
50
+ w = ::SY::ExpressibleInUnits::COLLISION_WARNING
51
+ ::SY::ExpressibleInUnits.included_in.each do |ɱ|
52
+ im = ɱ.instance_methods
53
+ # puts ɱ, "class: #{ɱ.class}"
54
+ # puts im.size
55
+ # puts down
56
+ # puts im.include? down
57
+ warn w % [down, ɱ] if im.include? down
58
+ abbrev = new_instance.abbreviation
59
+ warn w % [abbrev, ɱ] if im.include? abbrev
60
+ end
86
61
  end
62
+ up.to_sym
87
63
  end
88
- up.to_sym
89
64
  end
90
65
 
91
66
  # name_get_closure { |name| name.to_s.downcase.to_sym }
@@ -108,10 +83,10 @@ module SY::Unit
108
83
  end
109
84
  end
110
85
  end
111
- end # module_exec
112
- end # def self.included
86
+ end # def included
87
+ end # class << self
113
88
 
114
- include NameMagic
89
+ include NameMagic # it respects prefiously defined self.included
115
90
 
116
91
  class << self
117
92
  # Constructor of units of a given quantity.
@@ -144,14 +119,13 @@ module SY::Unit
144
119
  # Full list of known unit names and unit abbreviations.
145
120
  #
146
121
  def known_symbols
147
- instance_names + abbreviations.keys
122
+ instance_names.map( &:downcase ) + abbreviations.keys
148
123
  end
149
124
 
150
125
  # Parses an SPS, curring it with known unit names and abbreviations,
151
126
  # and all known full and short prefixes.
152
127
  #
153
128
  def parse_sps_using_all_prefixes sps
154
- puts "Unit about to sps parse (#{sps})" if SY::DEBUG
155
129
  SY::PREFIX_TABLE.parse_sps( sps, known_symbols )
156
130
  end
157
131
  end # class << self
@@ -178,15 +152,6 @@ module SY::Unit
178
152
  def short= unit_abbreviation
179
153
  @abbreviation = unit_abbreviation.to_sym
180
154
  end
181
-
182
- # Unit name. While named units are typically introduced as constants in
183
- # all-upper case, their names are then presented in all-lower case.
184
- #
185
- def name
186
- ɴ = super
187
- return ɴ ? ɴ.to_s.downcase.to_sym : nil
188
- end
189
- alias ɴ name
190
155
 
191
156
  # Constructor of units provides support for one additional named argument:
192
157
  # :abbreviation, alias :short. (This is in addition to :name, alias :ɴ named
@@ -1,5 +1,5 @@
1
1
  module SY
2
- VERSION = "2.0.7"
2
+ VERSION = "2.0.9"
3
3
  DEBUG = false # debug mode switch - sometimes there are lines like
4
4
  # puts "something" if SY::DEBUG
5
5
  end
@@ -241,7 +241,7 @@ describe SY::Quantity, SY::Magnitude do
241
241
  1.Mt.must_equal 1000.kiloton
242
242
  1.mm.quantity.name.must_equal :Length±
243
243
  SY::Length.standard_unit.must_equal SY::METRE
244
- SY::Length.standard_unit.name.must_equal :metre
244
+ SY::Length.standard_unit.name.must_equal :METRE
245
245
  SY::Length.standard_unit.must_equal SY::METRE
246
246
  SY.Quantity( :Length ).object_id.must_equal SY::Length.object_id
247
247
  SY::Length.relative.object_id.must_equal SY.Quantity( :Length± ).object_id
@@ -250,7 +250,7 @@ describe SY::Quantity, SY::Magnitude do
250
250
  SY.Quantity( :Length± ).colleague.object_id.must_equal SY::Length.object_id
251
251
  SY.Quantity( :Length± ).send( :Unit ).object_id
252
252
  .must_equal SY::Length.send( :Unit ).object_id
253
- 1.mm.quantity.standard_unit.name.must_equal :metre
253
+ 1.mm.quantity.standard_unit.name.must_equal :METRE
254
254
  1.mm.to_s.must_equal "0.001.m"
255
255
  1.mm.inspect.must_equal "#<±Magnitude: 0.001.m >"
256
256
  1.µs.inspect.must_equal "#<±Magnitude: 1e-06.s >"
@@ -258,12 +258,12 @@ describe SY::Quantity, SY::Magnitude do
258
258
  SY::Area.dimension.must_equal SY.Dimension( :L² )
259
259
  SY::Area.composition.must_equal SY::Composition[ SY::Length => 2 ]
260
260
 
261
- SY::AMPERE.name.must_equal :ampere
261
+ SY::AMPERE.name.must_equal :AMPERE
262
262
  SY::AMPERE.abbreviation.must_equal :A
263
263
  SY::AMPERE.dimension.must_equal 1.A.dimension
264
264
  SY.Magnitude( of: SY::ElectricCurrent, amount: 1 ).must_equal 1.A.absolute
265
265
  1.A.quantity.must_equal SY::ElectricCurrent.relative
266
- 1.A.quantity.standard_unit.name.must_equal :ampere
266
+ 1.A.quantity.standard_unit.name.must_equal :AMPERE
267
267
  1.A.to_s( SY::AMPERE ).must_equal "1.A"
268
268
  1.A.to_s.must_equal "1.A"
269
269
  1.A.amount.must_equal 1
@@ -313,7 +313,7 @@ describe SY::Quantity, SY::Magnitude do
313
313
  rescue
314
314
  end
315
315
  end.must_include :M
316
- SY::Unit.instance_names.must_include :mole
316
+ SY::Unit.instance_names.must_include :MOLE
317
317
  # Avogadro's number is defined directly in SY
318
318
  1.mol.quantity.object_id.must_equal SY::Nᴀ.unit.( SY::MoleAmount ).quantity.object_id
319
319
  SY::Nᴀ.unit.( SY::MoleAmount ).must_equal 1.mol
@@ -392,6 +392,40 @@ describe SY::Quantity, SY::Magnitude do
392
392
  assert_equal 273.15, 0.°C.in( :K )
393
393
  assert_equal SY::Unit.instance( :SECOND ), SY::Unit.instance( :second )
394
394
  assert_equal SY::TRIPLE_POINT_OF_WATER, 0.°C # coercion behavior
395
+ assert 2.°C.eql?( 1.°C + 1.K )
396
+ assert ( 1.°C - 1.°C ).eql?( 0.K )
397
+ assert_equal :raised, begin
398
+ 1.°C + 1.°C
399
+ :nothing_raised
400
+ rescue QuantityError
401
+ :raised
402
+ end
403
+ assert_equal :raised, begin
404
+ 1.K + 1.°C
405
+ :nothing_raised
406
+ rescue QuantityError
407
+ :raised
408
+ end
409
+ assert_equal :raised, begin
410
+ 1.K - 1.°C
411
+ :nothing_raised
412
+ rescue QuantityError
413
+ :raised
414
+ end
415
+ assert 1.mm.K⁻¹.eql?( 1.mm.°C⁻¹ )
416
+ assert 1.mm.K.eql?( 1.mm.°C )
417
+ assert_equal :raised, begin
418
+ 1.mm / 1.°C
419
+ :nothing_raised
420
+ rescue QuantityError
421
+ :raised
422
+ end
423
+ assert_equal :raised, begin
424
+ 1.mm * 1.°C
425
+ :nothing_raised
426
+ rescue QuantityError
427
+ :raised
428
+ end
395
429
  end
396
430
  end
397
431
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-24 00:00:00.000000000 Z
11
+ date: 2013-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport