stick 1.3.2 → 1.3.3
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.
- data/CHANGES +3 -4
- data/README +1 -1
- data/lib/stick/constants/cgs.rb +112 -110
- data/lib/stick/constants/mks.rb +6 -4
- data/lib/stick/constants/number.rb +3 -2
- data/lib/stick/constants/typeless_cgs.rb +105 -106
- data/lib/stick/constants/typeless_mks.rb +106 -107
- data/lib/stick/currency.rb +2 -0
- data/lib/stick/mapcar.rb +36 -23
- data/lib/stick/matrix.rb +10 -395
- data/lib/stick/matrix/core.rb +1408 -0
- data/lib/stick/matrix/exception.rb +23 -0
- data/lib/stick/matrix/givens.rb +59 -0
- data/lib/stick/matrix/hessenberg.rb +63 -0
- data/lib/stick/matrix/householder.rb +106 -0
- data/lib/stick/matrix/jacobi.rb +106 -0
- data/lib/stick/matrix/lu.rb +60 -0
- data/lib/stick/quaternion.rb +10 -6
- data/lib/stick/units.rb +2 -0
- data/lib/stick/units/base.rb +75 -72
- data/lib/stick/units/currency.rb +8 -8
- data/lib/stick/units/loaders.rb +3 -2
- data/lib/stick/units/units.rb +2 -0
- data/lib/stick/vector.rb +20 -0
- data/meta/MANIFEST +23 -3
- data/meta/stick.roll +1 -1
- data/task/tests/solo +293 -0
- data/test/spec_matrix.rb +3 -0
- data/test/test_constants.rb +4 -0
- data/test/test_currency.rb +2 -2
- data/test/test_matrix.rb +7 -1
- data/test/test_units.rb +2 -2
- metadata +15 -2
data/lib/stick/units/currency.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'stick/units/base'
|
2
2
|
require 'soap/wsdlDriver'
|
3
3
|
|
4
|
+
module Stick
|
4
5
|
module Units
|
5
6
|
|
6
7
|
class CurrencyLoader < Loader
|
@@ -10,17 +11,16 @@ module Units
|
|
10
11
|
|
11
12
|
def ce_service(converter, name, &blk)
|
12
13
|
old_service = Thread.current[THREAD_REFERENCE]
|
13
|
-
Thread.current[THREAD_REFERENCE] =
|
14
|
+
Thread.current[THREAD_REFERENCE] = Units::Converter::ExchangeRate.const_get(name)
|
14
15
|
yield
|
15
16
|
ensure
|
16
17
|
Thread.current[THREAD_REFERENCE] = old_service
|
17
18
|
end
|
18
19
|
|
19
20
|
def currency_unit(converter, name)
|
20
|
-
service = Thread.current[THREAD_REFERENCE] ||
|
21
|
+
service = Thread.current[THREAD_REFERENCE] || Units::Config::DEFAULT_CURRENCY_SERVICE
|
21
22
|
converter.send(:register_unit, name, :equals => service.create_conversion(name, converter))
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
25
25
|
|
26
26
|
class Converter
|
@@ -40,7 +40,7 @@ module Units
|
|
40
40
|
class ExchangeRate
|
41
41
|
|
42
42
|
def self.create_conversion(curr, converter) # :nodoc:
|
43
|
-
{:unit =>
|
43
|
+
{:unit => Units::Unit.new({'--base-currency--'.to_sym => 1}, converter), :multiplier => self.new(curr)}
|
44
44
|
end
|
45
45
|
|
46
46
|
def initialize(curr) # :nodoc:
|
@@ -104,7 +104,7 @@ module Units
|
|
104
104
|
private
|
105
105
|
|
106
106
|
def data
|
107
|
-
@@data ||= eval(File.read(File.join(
|
107
|
+
@@data ||= eval(File.read(File.join(Units::Config::CONFIGDIR, 'xmethods', 'mapping.rb')))
|
108
108
|
end
|
109
109
|
|
110
110
|
def country_mapping
|
@@ -133,7 +133,7 @@ module Units
|
|
133
133
|
private
|
134
134
|
|
135
135
|
def data
|
136
|
-
@@data ||= eval(File.read(File.join(
|
136
|
+
@@data ||= eval(File.read(File.join(Units::Config::CONFIGDIR, 'xmethods', 'cached.rb')))
|
137
137
|
end
|
138
138
|
|
139
139
|
end #class CachedXMethods
|
@@ -153,8 +153,8 @@ module Units
|
|
153
153
|
# Contains some configuration related constants
|
154
154
|
module Config
|
155
155
|
# The standard service used for looking up currency exchange rates
|
156
|
-
DEFAULT_CURRENCY_SERVICE =
|
156
|
+
DEFAULT_CURRENCY_SERVICE = Units::Converter::ExchangeRate::XMethods
|
157
157
|
end
|
158
158
|
|
159
159
|
end
|
160
|
-
|
160
|
+
end
|
data/lib/stick/units/loaders.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
module Stick
|
1
2
|
module Units
|
2
3
|
|
3
4
|
class Loader
|
@@ -73,7 +74,7 @@ module Units
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def load_config(file, context)
|
76
|
-
data = File.read(File.join(
|
77
|
+
data = File.read(File.join(Units::Config::CONFIGDIR, file)) rescue File.read(file)
|
77
78
|
context.instance_eval { eval data, nil, file }
|
78
79
|
end
|
79
80
|
|
@@ -96,4 +97,4 @@ module Units
|
|
96
97
|
end
|
97
98
|
|
98
99
|
end
|
99
|
-
|
100
|
+
end
|
data/lib/stick/units/units.rb
CHANGED
data/lib/stick/vector.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# = TITLE:
|
2
|
+
# Vector
|
3
|
+
#
|
4
|
+
# = SYNOPSIS:
|
5
|
+
# An implementation of the Vector class.
|
6
|
+
#
|
7
|
+
# = AUTHORS:
|
8
|
+
# - Keiju ISHITSUKA
|
9
|
+
# - Cosmin Bonchis
|
10
|
+
#
|
11
|
+
# = DOCUMENTORS:
|
12
|
+
# - Gavin Sinclair
|
13
|
+
#
|
14
|
+
# = NOTES:
|
15
|
+
# - Original Version from Smalltalk-80 version.
|
16
|
+
# - Extensions from Google Summer of Code 2007 project for Ruby Central Inc.
|
17
|
+
|
18
|
+
require 'stick/matrix'
|
19
|
+
|
20
|
+
# TODO: Separate Vector from Matrix.
|
data/meta/MANIFEST
CHANGED
@@ -15,6 +15,14 @@ lib/stick/constants/typeless_mks.rb
|
|
15
15
|
lib/stick/constants.rb
|
16
16
|
lib/stick/currency.rb
|
17
17
|
lib/stick/mapcar.rb
|
18
|
+
lib/stick/matrix
|
19
|
+
lib/stick/matrix/core.rb
|
20
|
+
lib/stick/matrix/exception.rb
|
21
|
+
lib/stick/matrix/givens.rb
|
22
|
+
lib/stick/matrix/hessenberg.rb
|
23
|
+
lib/stick/matrix/householder.rb
|
24
|
+
lib/stick/matrix/jacobi.rb
|
25
|
+
lib/stick/matrix/lu.rb
|
18
26
|
lib/stick/matrix.rb
|
19
27
|
lib/stick/quaternion.rb
|
20
28
|
lib/stick/units
|
@@ -51,6 +59,7 @@ lib/stick/units/data/xmethods.rb
|
|
51
59
|
lib/stick/units/loaders.rb
|
52
60
|
lib/stick/units/units.rb
|
53
61
|
lib/stick/units.rb
|
62
|
+
lib/stick/vector.rb
|
54
63
|
meta
|
55
64
|
meta/MANIFEST
|
56
65
|
meta/config.yaml
|
@@ -65,14 +74,25 @@ task/rdoc
|
|
65
74
|
task/release
|
66
75
|
task/setup
|
67
76
|
task/test
|
77
|
+
task/tests
|
78
|
+
task/tests/solo
|
68
79
|
test
|
69
80
|
test/spec_matrix.rb
|
81
|
+
test/test_constants.rb
|
70
82
|
test/test_currency.rb
|
71
83
|
test/test_matrix.rb
|
72
84
|
test/test_units.rb
|
73
85
|
test/unit
|
74
86
|
work
|
75
87
|
work/TODO
|
76
|
-
work/
|
77
|
-
work/
|
78
|
-
work/
|
88
|
+
work/bonchis
|
89
|
+
work/bonchis/extendmatrix.rb
|
90
|
+
work/bonchis/mapcar.rb
|
91
|
+
work/kilmer
|
92
|
+
work/kilmer/bytes.rb
|
93
|
+
work/kilmer/multipliers.rb
|
94
|
+
work/kilmer/times.rb
|
95
|
+
work/matrix.rb
|
96
|
+
work/p
|
97
|
+
work/tmatrix.rb
|
98
|
+
work/trash-matrix.rb
|
data/meta/stick.roll
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
stick 1.3.
|
1
|
+
stick 1.3.3 stable 2007-12-21
|
2
2
|
lib/stick
|
data/task/tests/solo
ADDED
@@ -0,0 +1,293 @@
|
|
1
|
+
#!/usr/bin/env ratch
|
2
|
+
|
3
|
+
#
|
4
|
+
require 'facets/hash/rekey'
|
5
|
+
require 'facets/string/tabs'
|
6
|
+
require 'facets/progressbar'
|
7
|
+
|
8
|
+
require 'test/unit/ui/testrunnermediator' #require 'test/unit'
|
9
|
+
::Test::Unit.run = true # Don't autorun tests!
|
10
|
+
|
11
|
+
main :test_solo do
|
12
|
+
run_isotests
|
13
|
+
end
|
14
|
+
|
15
|
+
# Run unit-tests. Each test is run in a separate interpretor
|
16
|
+
# to prevent script clash. This makes for a more robust test
|
17
|
+
# facility and prevents potential conflicts between test scripts.
|
18
|
+
#
|
19
|
+
# tests Test files (eg. test/tc_**/*.rb) [test/**/*]
|
20
|
+
# libs Directories to include in load path.
|
21
|
+
# ('./lib' is always included)
|
22
|
+
# live Deactive use of local libs and test against install.
|
23
|
+
# reqs List of files to require prior to running tests.
|
24
|
+
# extract Extract embedded tests first? [false]
|
25
|
+
#
|
26
|
+
# To isolate tests this tool marshals test results across a
|
27
|
+
# stdout->stdin shell pipe. This prevents interfence of one
|
28
|
+
# script's tests on another. But consequently it is not always
|
29
|
+
# possible to send debug info to stdout in the tests themselves
|
30
|
+
# (eg. #p and #puts).
|
31
|
+
|
32
|
+
def run_isotests
|
33
|
+
info = configuration['test'] || {}
|
34
|
+
|
35
|
+
tests = info['files'] || 'test/**/test_*.rb'
|
36
|
+
libs = info['libpath'] || 'lib'
|
37
|
+
reqs = info['require']
|
38
|
+
live = info['live']
|
39
|
+
#extract = info['extract']
|
40
|
+
|
41
|
+
tests = [ tests ].flatten
|
42
|
+
libs = [ libs ].flatten
|
43
|
+
|
44
|
+
#files = [ @files ].flatten
|
45
|
+
#extract_tests if extract
|
46
|
+
|
47
|
+
results = TestResults.new #(style)
|
48
|
+
|
49
|
+
# get test files
|
50
|
+
test_libs = libs.join(':')
|
51
|
+
test_files = Dir.multiglob( *tests )
|
52
|
+
if test_files.empty?
|
53
|
+
puts "Tests [NONE]"
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
# run tests
|
58
|
+
|
59
|
+
if trace?
|
60
|
+
pbar = nil
|
61
|
+
size = test_files.collect{|f| f.size}.max + 5
|
62
|
+
dots = '.' * size
|
63
|
+
else
|
64
|
+
pbar = Console::ProgressBar.new( 'Testing', test_files.size )
|
65
|
+
pbar.inc
|
66
|
+
end
|
67
|
+
|
68
|
+
test_files.each do |test_file|
|
69
|
+
pbar.inc if pbar
|
70
|
+
if ! File.file?(test_file)
|
71
|
+
next #r = nil
|
72
|
+
else
|
73
|
+
unless pbar
|
74
|
+
print test_file + dots[test_file.size..-1]
|
75
|
+
$stdout.flush
|
76
|
+
end
|
77
|
+
r = fork_test( test_file, :libs=>libs, :reqs=>reqs, :live=>live )
|
78
|
+
unless pbar
|
79
|
+
puts r.passed? ? "[PASS]" : "[FAIL]"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
results << r
|
83
|
+
end
|
84
|
+
|
85
|
+
pbar.finish if pbar
|
86
|
+
|
87
|
+
# display results
|
88
|
+
puts results
|
89
|
+
|
90
|
+
fails, errrs = results.failure_count, results.error_count
|
91
|
+
#CHECKLIST << :test if fails > 0
|
92
|
+
#CHECKLIST << :test if errrs > 0
|
93
|
+
return (fails + errrs > 0)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Run a test in a separate process.
|
97
|
+
#
|
98
|
+
# Currently send program output to null device.
|
99
|
+
# Could send to a logger in future version.
|
100
|
+
#
|
101
|
+
# Key parameters are libs, reqs, live.
|
102
|
+
|
103
|
+
def fork_test( file, keys )
|
104
|
+
keys = keys.rekey(:to_s)
|
105
|
+
|
106
|
+
libs = keys['lib'] || []
|
107
|
+
reqs = keys['req'] || []
|
108
|
+
live = keys['live']
|
109
|
+
|
110
|
+
src = ''
|
111
|
+
|
112
|
+
unless live
|
113
|
+
l = File.join( Dir.pwd, 'lib' )
|
114
|
+
if File.directory?( l )
|
115
|
+
src << %{$:.unshift('#{l}')\n}
|
116
|
+
end
|
117
|
+
libs.each { |r| src << %{$:.unshift('#{r}')\n} }
|
118
|
+
end
|
119
|
+
|
120
|
+
src << %{
|
121
|
+
#require 'test/unit'
|
122
|
+
require 'test/unit/collector'
|
123
|
+
require 'test/unit/collector/objectspace'
|
124
|
+
require 'test/unit/ui/testrunnermediator'
|
125
|
+
}
|
126
|
+
|
127
|
+
reqs.each do |fix|
|
128
|
+
src << %Q{
|
129
|
+
require '#{fix}'
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
src << %{
|
134
|
+
def warn(*null); end # silence warnings
|
135
|
+
|
136
|
+
output = STDOUT.dup
|
137
|
+
STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" )
|
138
|
+
|
139
|
+
load('#{file}')
|
140
|
+
tests = Test::Unit::Collector::ObjectSpace.new.collect
|
141
|
+
runner = Test::Unit::UI::TestRunnerMediator.new( tests )
|
142
|
+
result = runner.run_suite
|
143
|
+
|
144
|
+
begin
|
145
|
+
marshalled = Marshal.dump(result)
|
146
|
+
rescue TypeError => e
|
147
|
+
$stderr << "MARSHAL ERROR\n"
|
148
|
+
$stderr << "TEST: #{file}\n"
|
149
|
+
$stderr << "DATA:" << result.inspect
|
150
|
+
exit -1
|
151
|
+
end
|
152
|
+
output << marshalled
|
153
|
+
|
154
|
+
STDOUT.reopen(output)
|
155
|
+
output.close
|
156
|
+
}
|
157
|
+
|
158
|
+
result = IO.popen("ruby","w+") do |ruby|
|
159
|
+
ruby.puts src
|
160
|
+
ruby.close_write
|
161
|
+
ruby.read
|
162
|
+
end
|
163
|
+
|
164
|
+
begin
|
165
|
+
marsh = Marshal.load(result)
|
166
|
+
rescue ArgumentError
|
167
|
+
$stderr << "\nCannot load marshalled test data.\n"
|
168
|
+
$stderr << result << "\n"
|
169
|
+
exit -1
|
170
|
+
end
|
171
|
+
|
172
|
+
return marsh
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Support class for collecting test results.
|
177
|
+
#
|
178
|
+
|
179
|
+
class TestResults
|
180
|
+
attr_reader :assertion_count,
|
181
|
+
:run_count,
|
182
|
+
:failure_count,
|
183
|
+
:error_count
|
184
|
+
|
185
|
+
attr_accessor :style
|
186
|
+
|
187
|
+
def initialize( style=nil )
|
188
|
+
@style = style
|
189
|
+
|
190
|
+
@results = []
|
191
|
+
|
192
|
+
@assertion_count = 0
|
193
|
+
@run_count = 0
|
194
|
+
@failure_count = 0
|
195
|
+
@error_count = 0
|
196
|
+
end
|
197
|
+
|
198
|
+
# Add a result to the results collection.
|
199
|
+
|
200
|
+
def <<( result )
|
201
|
+
@results << result
|
202
|
+
|
203
|
+
@assertion_count += result.assertion_count
|
204
|
+
@run_count += result.run_count
|
205
|
+
@failure_count += result.failure_count
|
206
|
+
@error_count += result.error_count
|
207
|
+
end
|
208
|
+
|
209
|
+
#
|
210
|
+
|
211
|
+
def errors
|
212
|
+
errors = []
|
213
|
+
@results.each do |r|
|
214
|
+
unless r.passed?
|
215
|
+
errors << r.instance_variable_get('@errors')
|
216
|
+
end
|
217
|
+
end
|
218
|
+
errors.reject! { |e| e == [] }
|
219
|
+
errors
|
220
|
+
end
|
221
|
+
|
222
|
+
#
|
223
|
+
|
224
|
+
def failures
|
225
|
+
failures = []
|
226
|
+
@results.each do |r|
|
227
|
+
unless r.passed?
|
228
|
+
failures << r.instance_variable_get('@failures')
|
229
|
+
end
|
230
|
+
end
|
231
|
+
failures.reject! { |e| e == [] }
|
232
|
+
failures
|
233
|
+
end
|
234
|
+
|
235
|
+
# Output format for test results.
|
236
|
+
|
237
|
+
def to_s
|
238
|
+
return @results.to_s if style == 'pease'
|
239
|
+
|
240
|
+
s = []
|
241
|
+
# Display failures
|
242
|
+
unless failures.empty?
|
243
|
+
s << ''
|
244
|
+
s << "FAILURES:"
|
245
|
+
failures.reverse.each do |fails|
|
246
|
+
fails.reverse.each do |failure|
|
247
|
+
#puts
|
248
|
+
s << %{ - test : #{failure.test_name}}
|
249
|
+
s << %{ location : #{failure.location}}
|
250
|
+
if failure.message.index("\n")
|
251
|
+
s << %{ message : >}
|
252
|
+
s << failure.message.tabto(6)
|
253
|
+
else
|
254
|
+
s << %{ message : #{failure.message}}
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
# Display errors
|
261
|
+
unless errors.empty?
|
262
|
+
s << ''
|
263
|
+
s << "ERRORS:"
|
264
|
+
errors.reverse.each do |errs|
|
265
|
+
errs.reverse.each do |err|
|
266
|
+
s << ''
|
267
|
+
s << %{ - test : #{err.test_name}}
|
268
|
+
s << %{ message : #{err.exception.message}}
|
269
|
+
s << %{ backtrace :}
|
270
|
+
err.exception.backtrace[0...-1].each { |bt| s << %Q{ - #{bt}} }
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# Display final results
|
276
|
+
s << ''
|
277
|
+
s << "Summary:"
|
278
|
+
s << " Tests : #{@run_count}"
|
279
|
+
s << " Assertions : #{@assertion_count}"
|
280
|
+
s << " Failures : #{@failure_count}"
|
281
|
+
s << " Errors : #{@error_count}"
|
282
|
+
s << ''
|
283
|
+
s << ''
|
284
|
+
|
285
|
+
return s.join("\n")
|
286
|
+
end
|
287
|
+
|
288
|
+
# Delegate missing call to the results array.
|
289
|
+
|
290
|
+
def method_missing(*a,&b)
|
291
|
+
@results.send(*a,&b)
|
292
|
+
end
|
293
|
+
end
|