ruby-oci8 1.0.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/ChangeLog +1254 -390
  2. data/Makefile +10 -13
  3. data/README +56 -385
  4. data/VERSION +1 -1
  5. data/dist-files +26 -27
  6. data/ext/oci8/.document +1 -0
  7. data/ext/oci8/MANIFEST +0 -4
  8. data/ext/oci8/apiwrap.c.tmpl +172 -0
  9. data/ext/oci8/apiwrap.h.tmpl +61 -0
  10. data/ext/oci8/apiwrap.rb +91 -0
  11. data/ext/oci8/apiwrap.yml +1243 -0
  12. data/ext/oci8/attr.c +124 -384
  13. data/ext/oci8/bind.c +472 -164
  14. data/ext/oci8/encoding.c +196 -0
  15. data/ext/oci8/env.c +84 -253
  16. data/ext/oci8/error.c +196 -127
  17. data/ext/oci8/extconf.rb +82 -59
  18. data/ext/oci8/lob.c +710 -370
  19. data/ext/oci8/metadata.c +359 -0
  20. data/ext/oci8/object.c +622 -0
  21. data/ext/oci8/oci8.c +577 -161
  22. data/ext/oci8/oci8.h +354 -258
  23. data/ext/oci8/oci8lib.c +493 -0
  24. data/ext/oci8/ocidatetime.c +473 -0
  25. data/ext/oci8/ocinumber.c +1123 -24
  26. data/ext/oci8/oraconf.rb +72 -106
  27. data/ext/oci8/oradate.c +511 -321
  28. data/ext/oci8/stmt.c +752 -572
  29. data/ext/oci8/win32.c +131 -0
  30. data/ext/oci8/xmldb.c +383 -0
  31. data/lib/.document +2 -0
  32. data/lib/dbd/OCI8.rb +2 -17
  33. data/lib/oci8.rb.in +41 -1622
  34. data/lib/oci8/.document +5 -0
  35. data/lib/oci8/compat.rb +108 -0
  36. data/lib/oci8/datetime.rb +489 -0
  37. data/lib/oci8/encoding-init.rb +40 -0
  38. data/lib/oci8/encoding.yml +537 -0
  39. data/lib/oci8/metadata.rb +2077 -0
  40. data/lib/oci8/object.rb +548 -0
  41. data/lib/oci8/oci8.rb +773 -0
  42. data/lib/oci8/oracle_version.rb +144 -0
  43. data/metaconfig +3 -3
  44. data/ruby-oci8.gemspec +5 -5
  45. data/setup.rb +4 -4
  46. data/test/config.rb +64 -84
  47. data/test/test_all.rb +14 -21
  48. data/test/test_array_dml.rb +317 -0
  49. data/test/test_bind_raw.rb +18 -25
  50. data/test/test_bind_time.rb +78 -91
  51. data/test/test_break.rb +37 -35
  52. data/test/test_clob.rb +33 -89
  53. data/test/test_connstr.rb +5 -4
  54. data/test/test_datetime.rb +469 -0
  55. data/test/test_dbi.rb +99 -60
  56. data/test/test_dbi_clob.rb +3 -8
  57. data/test/test_metadata.rb +65 -51
  58. data/test/test_oci8.rb +151 -55
  59. data/test/test_oracle_version.rb +70 -0
  60. data/test/test_oradate.rb +76 -83
  61. data/test/test_oranumber.rb +405 -71
  62. data/test/test_rowid.rb +6 -11
  63. metadata +31 -32
  64. data/NEWS +0 -420
  65. data/ext/oci8/const.c +0 -165
  66. data/ext/oci8/define.c +0 -53
  67. data/ext/oci8/describe.c +0 -81
  68. data/ext/oci8/descriptor.c +0 -39
  69. data/ext/oci8/handle.c +0 -273
  70. data/ext/oci8/oranumber.c +0 -445
  71. data/ext/oci8/param.c +0 -37
  72. data/ext/oci8/server.c +0 -182
  73. data/ext/oci8/session.c +0 -99
  74. data/ext/oci8/svcctx.c +0 -238
  75. data/ruby-oci8.spec +0 -62
  76. data/support/README +0 -4
  77. data/support/runit/assert.rb +0 -281
  78. data/support/runit/cui/testrunner.rb +0 -101
  79. data/support/runit/error.rb +0 -4
  80. data/support/runit/method_mappable.rb +0 -20
  81. data/support/runit/robserver.rb +0 -25
  82. data/support/runit/setuppable.rb +0 -15
  83. data/support/runit/teardownable.rb +0 -16
  84. data/support/runit/testcase.rb +0 -113
  85. data/support/runit/testfailure.rb +0 -25
  86. data/support/runit/testresult.rb +0 -121
  87. data/support/runit/testsuite.rb +0 -43
  88. data/support/runit/version.rb +0 -3
  89. data/test/test_describe.rb +0 -137
@@ -1,12 +1,12 @@
1
1
  # Low-level API
2
2
  require 'oci8'
3
- require 'runit/testcase'
4
- require 'runit/cui/testrunner'
3
+ require 'test/unit'
5
4
  require File.dirname(__FILE__) + '/config'
5
+ require 'yaml'
6
6
 
7
- class TestOraNumber < RUNIT::TestCase
7
+ class TestOraNumber < Test::Unit::TestCase
8
8
 
9
- NUMBER_CHECK_TARGET = [
9
+ LARGE_RANGE_VALUES = [
10
10
  "12345678901234567890123456789012345678",
11
11
  "1234567890123456789012345678901234567",
12
12
  "1234567890123456789012345678901234567.8",
@@ -53,97 +53,431 @@ class TestOraNumber < RUNIT::TestCase
53
53
  "-1.123",
54
54
  ]
55
55
 
56
- def setup
57
- @env, @svc, @stmt = setup_lowapi()
58
- end
56
+ SMALL_RANGE_VALUES = [
57
+ "10",
58
+ "3",
59
+ "3.14159265358979323846", # PI
60
+ "2",
61
+ "1.57079632679489661923", # PI/2
62
+ "0.5",
63
+ "0.0000000001",
64
+ "0",
65
+ "-0.0000000001",
66
+ "-0.5",
67
+ "-1.57079632679489661923", # -PI/2
68
+ "-2",
69
+ "-3.14159265358979323846", # -PI
70
+ "-3",
71
+ "-10",
72
+ ]
59
73
 
60
- def test_to_s
61
- @stmt.prepare("BEGIN :number := TO_NUMBER(:str); END;")
62
- number = @stmt.bindByName(":number", OraNumber)
63
- str = @stmt.bindByName(":str", String, 40)
64
- NUMBER_CHECK_TARGET.each do |val|
65
- str.set(val)
66
- @stmt.execute(@svc)
67
- assert_equal(val, number.get.to_s)
74
+ def compare_with_float(values, rettype, proc1, proc2 = nil)
75
+ proc2 = proc1 if proc2.nil?
76
+ values.each do |x|
77
+ expected_val = proc1.call(x.to_f)
78
+ actual_val = proc2.call(OraNumber.new(x))
79
+ assert_kind_of(rettype, actual_val)
80
+ delta = [expected_val.abs * 1.0e-12, 1.0e-14].max
81
+ assert_in_delta(expected_val, actual_val, delta, x)
68
82
  end
69
83
  end
70
84
 
71
- def test_to_i
72
- @stmt.prepare("BEGIN :number := TO_NUMBER(:str); END;")
73
- number = @stmt.bindByName(":number", OraNumber)
74
- str = @stmt.bindByName(":str", String, 40)
75
- NUMBER_CHECK_TARGET.each do |val|
76
- str.set(val)
77
- @stmt.execute(@svc)
78
- assert_equal(val.to_i, number.get.to_i)
85
+ def compare_with_float2(values, proc_args, proc1, proc2 = nil)
86
+ proc2 = proc1 if proc2.nil?
87
+ values.each do |x|
88
+ proc_args.each do |y|
89
+ expected_val = proc1.call(x.to_f, y)
90
+ actual_val = proc2.call(OraNumber.new(x), y)
91
+ begin
92
+ delta = [expected_val.abs * 1.0e-12, 1.0e-14].max
93
+ rescue
94
+ puts '-----------'
95
+ p x
96
+ p y
97
+ p expected_val
98
+ puts '-----------'
99
+ raise $!
100
+ end
101
+ # explicity convert actual_val to a Float to prevent
102
+ # SEGV in OCINumberSub() if the Oracle client vesion
103
+ # is less than 10.2.0.4.
104
+ if defined? ::MiniTest and OCI8.oracle_client_version < OCI8::OracleVersion.new('10.2.0.4')
105
+ actual_val = actual_val.to_f
106
+ end
107
+ assert_in_delta(expected_val, actual_val, delta, x)
108
+ end
79
109
  end
80
110
  end
81
111
 
82
- def test_to_f
83
- @stmt.prepare("BEGIN :number := TO_NUMBER(:str); END;")
84
- number = @stmt.bindByName(":number", OraNumber)
85
- str = @stmt.bindByName(":str", String, 40)
86
- NUMBER_CHECK_TARGET.each do |val|
87
- str.set(val)
88
- @stmt.execute(@svc)
89
- assert_equal(val.to_f, number.get.to_f)
112
+ def test_in_bind
113
+ conn = get_oci8_connection
114
+ begin
115
+ conn.exec("alter session set nls_numeric_characters = '.,'")
116
+ cursor = conn.parse("BEGIN :out := TO_CHAR(:in); END;")
117
+ cursor.bind_param(:out, nil, String, 40)
118
+ cursor.bind_param(:in, OraNumber)
119
+ LARGE_RANGE_VALUES.each do |val|
120
+ cursor[:in] = OraNumber.new(val)
121
+ cursor.exec
122
+ # convert 0.0001 and -0.0001 to .0001 and -.0001 respectively
123
+ val = $1+'.'+$2 if /(-?)0\.(.*)/ =~ val
124
+ assert_equal(val, cursor[:out])
125
+ end
126
+ ensure
127
+ conn.logoff
90
128
  end
91
129
  end
92
130
 
93
- def test_uminus
94
- @stmt.prepare("BEGIN :number := - TO_NUMBER(:str); END;")
95
- number = @stmt.bindByName(":number", OraNumber)
96
- str = @stmt.bindByName(":str", String, 40)
97
- NUMBER_CHECK_TARGET.each do |val|
98
- str.set(val)
99
- @stmt.execute(@svc)
100
- assert_equal(val, (- (number.get)).to_s)
131
+ def test_out_bind
132
+ conn = get_oci8_connection
133
+ begin
134
+ conn.exec("alter session set nls_numeric_characters = '.,'")
135
+ cursor = conn.parse("BEGIN :out := TO_NUMBER(:in); END;")
136
+ cursor.bind_param(:out, OraNumber)
137
+ cursor.bind_param(:in, nil, String, 40)
138
+ LARGE_RANGE_VALUES.each do |val|
139
+ cursor[:in] = val
140
+ cursor.exec
141
+ assert_equal(OraNumber.new(val), cursor[:out])
142
+ end
143
+ ensure
144
+ conn.logoff
101
145
  end
102
146
  end
103
147
 
104
148
  def test_dup
105
- @stmt.prepare("BEGIN :number := TO_NUMBER(:str); END;")
106
- number = @stmt.bindByName(":number", OraNumber)
107
- str = @stmt.bindByName(":str", String, 40)
108
- NUMBER_CHECK_TARGET.each do |val|
109
- str.set(val)
110
- @stmt.execute(@svc)
111
- n = number.get
112
- assert_equal(n.to_s, n.dup.to_s)
113
- assert_equal(n.to_s, n.clone.to_s)
149
+ LARGE_RANGE_VALUES.each do |x|
150
+ n = OraNumber.new(x)
151
+ assert_equal(n, n.dup)
152
+ assert_equal(n, n.clone)
114
153
  end
115
154
  end
116
155
 
117
156
  def test_marshal
118
- @stmt.prepare("BEGIN :number := TO_NUMBER(:str); END;")
119
- number = @stmt.bindByName(":number", OraNumber)
120
- str = @stmt.bindByName(":str", String, 40)
121
- NUMBER_CHECK_TARGET.each do |val|
122
- str.set(val)
123
- @stmt.execute(@svc)
124
- n = number.get
125
- assert_equal(n.to_s, Marshal.load(Marshal.dump(n)).to_s)
157
+ LARGE_RANGE_VALUES.each do |x|
158
+ n = OraNumber.new(x)
159
+ assert_equal(n, Marshal.load(Marshal.dump(n)))
126
160
  end
127
161
  end
128
162
 
129
- def test_new_from_string
130
- @stmt.prepare("BEGIN :number := TO_NUMBER(:str); END;")
131
- number = @stmt.bindByName(":number", OraNumber)
132
- str = @stmt.bindByName(":str", String, 40)
133
- (NUMBER_CHECK_TARGET + ["1.230", "1.2300", "1.23000"]).each do |val|
134
- str.set(val)
135
- @stmt.execute(@svc)
136
- assert_equal(number.get.to_s, OraNumber.new(val).to_s)
163
+ def test_yaml
164
+ LARGE_RANGE_VALUES.each do |x|
165
+ n = OraNumber.new(x)
166
+ assert_equal(n, YAML.load(YAML.dump(n)))
137
167
  end
138
168
  end
139
169
 
140
- def teardown
141
- @stmt.free()
142
- @svc.logoff()
143
- @env.free()
170
+ # OCI8::Math.acos(x) -> ocinumber
171
+ def test_math_acos
172
+ test_values = []
173
+ -1.0.step(1.0, 0.01) do |n|
174
+ test_values << n
175
+ end
176
+ compare_with_float(test_values, OraNumber,
177
+ Proc.new {|n| Math::acos(n)},
178
+ Proc.new {|n| OCI8::Math::acos(n)})
179
+ end
180
+
181
+ # OCI8::Math.asin(x) -> ocinumber
182
+ def test_math_asin
183
+ test_values = []
184
+ -1.0.step(1.0, 0.01) do |n|
185
+ test_values << n
186
+ end
187
+ compare_with_float(test_values, OraNumber,
188
+ Proc.new {|n| Math::asin(n)},
189
+ Proc.new {|n| OCI8::Math::asin(n)})
190
+ end
191
+
192
+ # OCI8::Math.atan(x) -> ocinumber
193
+ def test_math_atan
194
+ compare_with_float(SMALL_RANGE_VALUES, OraNumber,
195
+ Proc.new {|n| Math::atan(n)},
196
+ Proc.new {|n| OCI8::Math::atan(n)})
197
+ end
198
+
199
+ # OCI8::Math.atan2(y, x) -> ocinumber
200
+ def test_math_atan2
201
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
202
+ Proc.new {|x, y| Math::atan2(x, y.to_f)},
203
+ Proc.new {|x, y| OCI8::Math::atan2(x, y.to_f)})
204
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
205
+ Proc.new {|x, y| Math::atan2(y.to_f, x)},
206
+ Proc.new {|x, y| OCI8::Math::atan2(y.to_f, x)})
207
+ end
208
+
209
+ # OCI8::Math.cos(x) -> ocinumber
210
+ def test_math_cos
211
+ compare_with_float(SMALL_RANGE_VALUES, OraNumber,
212
+ Proc.new {|n| Math::cos(n)},
213
+ Proc.new {|n| OCI8::Math::cos(n)})
214
+ end
215
+
216
+ # OCI8::Math.cosh(x) -> ocinumber
217
+ def test_math_cosh
218
+ compare_with_float(SMALL_RANGE_VALUES, OraNumber,
219
+ Proc.new {|n| Math::cosh(n)},
220
+ Proc.new {|n| OCI8::Math::cosh(n)})
221
+ end
222
+
223
+ # OCI8::Math.exp(x) -> ocinumber
224
+ def test_exp
225
+ compare_with_float(SMALL_RANGE_VALUES, OraNumber,
226
+ Proc.new {|n| Math::exp(n)},
227
+ Proc.new {|n| OCI8::Math::exp(n)})
228
+ end
229
+
230
+ # OCI8::Math.log(numeric) -> ocinumber
231
+ # OCI8::Math.log(numeric, base_num) -> ocinumber
232
+ def test_log
233
+ test_values = LARGE_RANGE_VALUES.reject do |x|
234
+ # reject minus and zero values
235
+ x[0,1] == '-' || x == '0'
236
+ end
237
+ compare_with_float(test_values, OraNumber,
238
+ Proc.new {|n| Math::log(n)},
239
+ Proc.new {|n| OCI8::Math::log(n)})
240
+ compare_with_float(test_values, OraNumber,
241
+ Proc.new {|n| Math::log(n)/Math::log(3)},
242
+ Proc.new {|n| OCI8::Math::log(n, 3)})
243
+ end
244
+
245
+ # OCI8::Math.log10(numeric) -> ocinumber
246
+ def test_log10
247
+ test_values = LARGE_RANGE_VALUES.reject do |x|
248
+ # reject minus and zero values
249
+ x[0,1] == '-' || x == '0'
250
+ end
251
+ compare_with_float(test_values, OraNumber,
252
+ Proc.new {|n| Math::log10(n)},
253
+ Proc.new {|n| OCI8::Math::log10(n)})
254
+ end
255
+
256
+ # OCI8::Math.sin(x) -> ocinumber
257
+ def test_math_sin
258
+ compare_with_float(SMALL_RANGE_VALUES, OraNumber,
259
+ Proc.new {|n| Math::sin(n)},
260
+ Proc.new {|n| OCI8::Math::sin(n)})
261
+ end
262
+
263
+ # OCI8::Math.sinh(x) -> ocinumber
264
+ def test_math_sinh
265
+ compare_with_float(SMALL_RANGE_VALUES, OraNumber,
266
+ Proc.new {|n| Math::sinh(n)},
267
+ Proc.new {|n| OCI8::Math::sinh(n)})
268
+ end
269
+
270
+ # OCI8::Math.sqrt(numeric) -> ocinumber
271
+ def test_sqrt
272
+ test_values = LARGE_RANGE_VALUES.reject do |x|
273
+ # reject minus values
274
+ x[0,1] == '-'
275
+ end
276
+ compare_with_float(test_values, OraNumber,
277
+ Proc.new {|n| Math::sqrt(n)},
278
+ Proc.new {|n| OCI8::Math::sqrt(n)})
279
+ end
280
+
281
+ # OCI8::Math.tan(x) -> ocinumber
282
+ def test_math_tan
283
+ test_values = SMALL_RANGE_VALUES.reject do |x|
284
+ # reject PI/2 and -PI/2.
285
+ # Those values are +inf and -info
286
+ radian = x.to_f
287
+ (radian.abs - Math::PI/2).abs < 0.000001
288
+ end
289
+ compare_with_float(test_values, OraNumber,
290
+ Proc.new {|n| Math::tan(n)},
291
+ Proc.new {|n| OCI8::Math::tan(n)})
292
+ end
293
+
294
+ # OCI8::Math.tanh() -> ocinumber
295
+ def test_math_tanh
296
+ compare_with_float(SMALL_RANGE_VALUES, OraNumber,
297
+ Proc.new {|n| Math::tanh(n)},
298
+ Proc.new {|n| OCI8::Math::tanh(n)})
299
+ end
300
+
301
+ # onum % other -> onum
302
+ # def test_mod
303
+
304
+ # onum * other -> onum
305
+ def test_mul
306
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
307
+ Proc.new {|x, y| x * y.to_f})
308
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
309
+ Proc.new {|x, y| y.to_f * x})
310
+ end
311
+
312
+ # onum ** other -> onum
313
+ def test_pow
314
+ base_values = SMALL_RANGE_VALUES.reject do |x|
315
+ # reject minus and zero values
316
+ x[0,1] == '-' || x == '0'
317
+ end
318
+ compare_with_float2(base_values, SMALL_RANGE_VALUES,
319
+ Proc.new {|x, y| x ** y.to_f})
320
+ compare_with_float2(SMALL_RANGE_VALUES, base_values,
321
+ Proc.new {|x, y| y.to_f ** x})
322
+ end
323
+
324
+ # onum + other -> onum
325
+ def test_add
326
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
327
+ Proc.new {|x, y| x + y.to_f})
328
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
329
+ Proc.new {|x, y| y.to_f + x})
330
+ end
331
+
332
+ # onum - other -> onum
333
+ def test_minus
334
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
335
+ Proc.new {|x, y| x - y.to_f})
336
+ compare_with_float2(SMALL_RANGE_VALUES, SMALL_RANGE_VALUES,
337
+ Proc.new {|x, y| y.to_f - x})
338
+ end
339
+
340
+ # -ocinumber -> ocinumber
341
+ def test_uminus
342
+ compare_with_float(LARGE_RANGE_VALUES, OraNumber, Proc.new {|n| -n})
343
+ end
344
+
345
+ # onum / other -> onum
346
+ # TODO: test_div
347
+
348
+ # onum <=> other -> -1, 0, +1
349
+ def test_cmp
350
+ test_values = SMALL_RANGE_VALUES.collect do |x|
351
+ x[0,15] # donw the precision to pass this test.
352
+ end
353
+ compare_with_float2(test_values, test_values,
354
+ Proc.new {|x, y| x <=> y.to_f})
355
+ compare_with_float2(test_values, test_values,
356
+ Proc.new {|x, y| y.to_f <=> x})
357
+ end
358
+
359
+ # onum.abs -> ocinumber
360
+ def test_abs
361
+ compare_with_float(LARGE_RANGE_VALUES, OraNumber, Proc.new {|n| n.abs})
362
+ end
363
+
364
+ # onum.ceil -> integer
365
+ def test_ceil
366
+ compare_with_float(LARGE_RANGE_VALUES, Integer, Proc.new {|n| n.ceil})
367
+ end
368
+
369
+ # onum.floor -> integer
370
+ def test_floor
371
+ compare_with_float(LARGE_RANGE_VALUES, Integer, Proc.new {|n| n.floor})
372
+ end
373
+
374
+ # onum.round -> integer
375
+ # onum.round(decplace) -> onum
376
+ def test_round
377
+ compare_with_float(LARGE_RANGE_VALUES, Integer, Proc.new {|n| n.round})
378
+ compare_with_float(LARGE_RANGE_VALUES, OraNumber,
379
+ Proc.new {|n| (n * 10).round * 0.1},
380
+ Proc.new {|n| n.round(1)})
381
+ compare_with_float(LARGE_RANGE_VALUES, OraNumber,
382
+ Proc.new {|n| (n * 100).round * 0.01},
383
+ Proc.new {|n| n.round(2)})
384
+ compare_with_float(LARGE_RANGE_VALUES, OraNumber,
385
+ Proc.new {|n| (n * 0.1).round * 10},
386
+ Proc.new {|n| n.round(-1)})
387
+ end
388
+
389
+ # onum.round_prec(digits) -> ocinumber
390
+ def test_round_prec
391
+ if OCI8::oracle_client_version >= OCI8::ORAVER_8_1
392
+ # Oracle 8.1 client or upper
393
+ compare_with_float2(LARGE_RANGE_VALUES, [1, 2, 3, 5, 10, 20],
394
+ Proc.new {|x, y|
395
+ return 0.0 if x == 0.0
396
+ factor = 10 ** (Math::log10(x.abs).to_i - y + 1)
397
+ (x / factor).round * factor
398
+ },
399
+ Proc.new {|x, y| x.round_prec(y)})
400
+ else
401
+ # Oracle 8.0 client
402
+ assert_raise NoMethodError do
403
+ OraNumber.new(1).round_prec(1)
404
+ end
405
+ end
406
+ end
407
+
408
+ # onum.shift(fixnum) -> ocinumber
409
+ def test_shift
410
+ if OCI8::oracle_client_version >= OCI8::ORAVER_8_1
411
+ # Oracle 8.1 client or upper
412
+ compare_with_float2(LARGE_RANGE_VALUES, [-5, -4, -3, -1, 0, 1, 2, 3, 4, 5],
413
+ Proc.new {|x, y| x * (10 ** y)},
414
+ Proc.new {|x, y| x.shift(y)})
415
+ else
416
+ # Oracle 8.0 client
417
+ assert_raise NoMethodError do
418
+ OraNumber.new(1).shift(1)
419
+ end
420
+ end
421
+ end
422
+
423
+ # onum.to_char(fmt = nil, nls_params = nil) -> string
424
+ def test_to_char
425
+ onum = OraNumber.new(123.45)
426
+ assert_equal(' 123.4500', onum.to_char('99999.9999'))
427
+ assert_equal(' 0123.4500', onum.to_char('90000.0009'))
428
+ assert_equal(' 00123.4500', onum.to_char('00000.0000'))
429
+ assert_equal('123.45', onum.to_char('FM99999.9999'))
430
+ assert_equal('0123.450', onum.to_char('FM90000.0009'))
431
+ assert_equal('00123.4500', onum.to_char('FM00000.0000'))
432
+ assert_equal(' -123.4500',(-onum).to_char('99999.9999'))
433
+ assert_equal(' -0123.4500',(-onum).to_char('90000.0009'))
434
+ assert_equal('-00123.4500',(-onum).to_char('00000.0000'))
435
+ assert_equal('-123.45', (-onum).to_char('FM99999.9999'))
436
+ assert_equal('-0123.450', (-onum).to_char('FM90000.0009'))
437
+ assert_equal('-00123.4500',(-onum).to_char('FM00000.0000'))
438
+ assert_equal(' 0,123.4500', onum.to_char('0G000D0000', "NLS_NUMERIC_CHARACTERS = '.,'"))
439
+ assert_equal(' 0.123,4500', onum.to_char('0G000D0000', "NLS_NUMERIC_CHARACTERS = ',.'"))
440
+ assert_equal('Ducat123.45', onum.to_char('FML9999.999', "NLS_CURRENCY = 'Ducat'"))
441
+ end
442
+
443
+ # onum.to_f -> float
444
+ def test_to_f
445
+ LARGE_RANGE_VALUES.each do |x|
446
+ expected_val = x.to_f
447
+ actual_val = OraNumber.new(x).to_f
448
+ delta = [expected_val.abs * 1.0e-12, 1.0e-14].max
449
+ assert_in_delta(expected_val, actual_val, delta, x)
450
+ end
144
451
  end
145
- end
146
452
 
147
- if $0 == __FILE__
148
- RUNIT::CUI::TestRunner.run(TestOraNumber.suite())
453
+ # onum.to_i -> integer
454
+ def test_to_i
455
+ LARGE_RANGE_VALUES.each do |x|
456
+ expected_val = x.to_i
457
+ actual_val = OraNumber.new(x).to_i
458
+ assert_equal(expected_val, actual_val, x)
459
+ end
460
+ end
461
+
462
+ # onum.to_s -> string
463
+ def test_to_s
464
+ LARGE_RANGE_VALUES.each do |x|
465
+ expected_val = x
466
+ actual_val = OraNumber.new(x).to_s
467
+ assert_equal(expected_val, actual_val, x)
468
+ end
469
+ end
470
+
471
+ # onum.truncate -> integer
472
+ # onum.truncate(decplace) -> ocinumber
473
+ # TODO: test_truncate
474
+
475
+ # onum.zero? -> true or false
476
+ def test_zero_p
477
+ LARGE_RANGE_VALUES.each do |x|
478
+ expected_val = x.to_f.zero?
479
+ actual_val = OraNumber.new(x).zero?
480
+ assert_equal(expected_val, actual_val, x)
481
+ end
482
+ end
149
483
  end