firebird 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.gitlab-ci.yml +27 -0
- data/.travis.yml +20 -0
- data/Gemfile +2 -0
- data/README.md +15 -0
- data/Rakefile +13 -0
- data/USAGE.txt +180 -0
- data/ext/fb/extconf.rb +93 -0
- data/ext/fb/fb_ext.c +3022 -0
- data/fb.gemspec +34 -0
- data/lib/fb.rb +23 -0
- data/lib/fb/version.rb +3 -0
- data/mkmf.cmd +1 -0
- data/test/ConnectionTestCases.rb +550 -0
- data/test/CursorTestCases.rb +294 -0
- data/test/DataTypesTestCases.rb +556 -0
- data/test/DatabaseTestCases.rb +183 -0
- data/test/EncodingTestCases.rb +39 -0
- data/test/NumericDataTypesTestCases.rb +588 -0
- data/test/TransactionTestCases.rb +270 -0
- data/test/test_helper.rb +91 -0
- metadata +108 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class DatabaseTestCases < FbTestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@parms = get_db_conn_params
|
7
|
+
@reader = @parms.merge(:username => 'rubytest', :password => 'rubytest', :role => 'READER')
|
8
|
+
@writer = @parms.merge(:username => 'rubytest', :password => 'rubytest', :role => 'WRITER')
|
9
|
+
@database = @reader[:database]
|
10
|
+
@db_file = @database.split(":", 2).last
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_new
|
14
|
+
db = Database.new
|
15
|
+
assert_instance_of Database, db
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_properties_read
|
19
|
+
db = Database.new
|
20
|
+
assert_nil db.database
|
21
|
+
assert_nil db.username
|
22
|
+
assert_nil db.password
|
23
|
+
assert_nil db.charset
|
24
|
+
assert_nil db.role
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_properties_write
|
28
|
+
db = Database.new
|
29
|
+
db.database = @database
|
30
|
+
assert_equal @database, db.database
|
31
|
+
db.username = 'sysdba'
|
32
|
+
assert_equal 'sysdba', db.username
|
33
|
+
db.password = 'masterkey'
|
34
|
+
assert_equal 'masterkey', db.password
|
35
|
+
db.charset = 'NONE'
|
36
|
+
assert_equal 'NONE', db.charset
|
37
|
+
db.role = 'READER'
|
38
|
+
assert_equal 'READER', db.role
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_initialize_hash
|
42
|
+
db = Database.new(@parms)
|
43
|
+
assert_equal @database, db.database
|
44
|
+
assert_equal @parms[:username], db.username
|
45
|
+
assert_equal @parms[:password], db.password
|
46
|
+
assert_equal 'NONE', db.charset
|
47
|
+
assert_equal 'READER', db.role
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_initialize_string
|
51
|
+
params = @parms
|
52
|
+
params_s = get_db_conn_string(params)
|
53
|
+
db = Database.new params_s
|
54
|
+
assert_equal @database, db.database
|
55
|
+
assert_equal params[:username], db.username
|
56
|
+
assert_equal params[:password], db.password
|
57
|
+
assert_equal 'NONE', db.charset
|
58
|
+
assert_equal 'READER', db.role
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_create_instance
|
62
|
+
db = Database.new(@parms)
|
63
|
+
db.create
|
64
|
+
assert File.exist?(@db_file)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_create_instance_block
|
68
|
+
db = Database.new(@parms)
|
69
|
+
db.create do |connection|
|
70
|
+
connection.execute("select * from RDB$DATABASE") do |cursor|
|
71
|
+
row = cursor.fetch
|
72
|
+
assert_instance_of Array, row
|
73
|
+
end
|
74
|
+
assert_equal 3, connection.dialect
|
75
|
+
assert_equal 3, connection.db_dialect
|
76
|
+
end
|
77
|
+
assert File.exist?(@db_file)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_create_singleton
|
81
|
+
Database.create(@parms);
|
82
|
+
assert File.exist?(@db_file)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_create_singleton_with_defaults
|
86
|
+
Database.create(:database => @parms[:database]);
|
87
|
+
assert File.exist?(@db_file)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_create_singleton_block
|
91
|
+
db = Database.create(@parms) do |connection|
|
92
|
+
connection.execute("select * from RDB$DATABASE") do |cursor|
|
93
|
+
row = cursor.fetch
|
94
|
+
assert_instance_of Array, row
|
95
|
+
end
|
96
|
+
end
|
97
|
+
assert_instance_of Database, db
|
98
|
+
assert File.exist?(@db_file)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_create_bad_param
|
102
|
+
assert_raises TypeError do
|
103
|
+
Database.create(1)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_create_bad_page_size
|
108
|
+
assert_raises Error do
|
109
|
+
Database.create(@parms.merge(:page_size => 1000))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_connect_instance
|
114
|
+
db = Database.create(@parms)
|
115
|
+
connection = db.connect
|
116
|
+
assert_instance_of Connection, connection
|
117
|
+
connection.close
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_connect_singleton
|
121
|
+
Database.create(@parms)
|
122
|
+
connection = Database.connect(@parms)
|
123
|
+
assert_instance_of Connection, connection
|
124
|
+
connection.close
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_drop_instance
|
128
|
+
assert !File.exist?(@db_file)
|
129
|
+
db = Database.create(@parms)
|
130
|
+
assert File.exist?(@db_file)
|
131
|
+
db.drop
|
132
|
+
assert !File.exist?(@db_file)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_drop_singleton
|
136
|
+
assert !File.exist?(@db_file)
|
137
|
+
Database.create(@parms)
|
138
|
+
assert File.exist?(@db_file)
|
139
|
+
Database.drop(@parms)
|
140
|
+
assert !File.exist?(@db_file)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_role_support
|
144
|
+
Database.create(@parms) do |connection|
|
145
|
+
connection.execute("create table test (id int, test varchar(10))")
|
146
|
+
connection.execute("create role writer")
|
147
|
+
connection.execute("grant all on test to writer")
|
148
|
+
connection.execute("insert into test values (1, 'test role')")
|
149
|
+
end
|
150
|
+
|
151
|
+
connection = Database.connect(@parms)
|
152
|
+
begin
|
153
|
+
connection.execute("drop user rubytest")
|
154
|
+
connection.commit
|
155
|
+
rescue Error
|
156
|
+
ensure
|
157
|
+
connection.close rescue nil
|
158
|
+
end
|
159
|
+
|
160
|
+
Database.connect(@parms) do |connection|
|
161
|
+
connection.execute("CREATE USER rubytest password 'rubytest'")
|
162
|
+
connection.execute("GRANT WRITER TO rubytest")
|
163
|
+
connection.commit
|
164
|
+
end
|
165
|
+
|
166
|
+
Database.connect(@reader) do |connection|
|
167
|
+
assert_raises Error do
|
168
|
+
connection.execute("select * from test") do |cursor|
|
169
|
+
flunk "Should not reach here."
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
Database.connect(@writer) do |connection|
|
175
|
+
connection.execute("select * from test") do |cursor|
|
176
|
+
row = cursor.fetch :hash
|
177
|
+
assert_equal 1, row["ID"]
|
178
|
+
assert_equal 'test role', row["TEST"]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
require File.expand_path("../test_helper", __FILE__)
|
3
|
+
|
4
|
+
if RUBY_VERSION =~ /^1.9/
|
5
|
+
class EncodingTestCases < FbTestCase
|
6
|
+
def test_encoding
|
7
|
+
sql_schema = <<-END
|
8
|
+
create table TEST (
|
9
|
+
ID INTEGER,
|
10
|
+
C10 CHAR(10),
|
11
|
+
VC10 VARCHAR(10),
|
12
|
+
MEMO BLOB SUB_TYPE TEXT)
|
13
|
+
END
|
14
|
+
sql_insert = <<-END
|
15
|
+
insert into test
|
16
|
+
(ID, C10, VC10, MEMO)
|
17
|
+
values
|
18
|
+
(?, ?, ?, ?);
|
19
|
+
END
|
20
|
+
sql_select = "select * from TEST order by ID"
|
21
|
+
lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
22
|
+
|
23
|
+
params = @parms.merge(:encoding => "UTF-8")
|
24
|
+
Database.create(params) do |connection|
|
25
|
+
connection.execute(sql_schema)
|
26
|
+
connection.execute(sql_insert, 1, "abcdef", "한글", lorem)
|
27
|
+
row = connection.query(sql_select).first
|
28
|
+
|
29
|
+
assert_equal 1, row[0]
|
30
|
+
assert_equal Encoding::UTF_8, row[1].encoding
|
31
|
+
assert_equal "abcdef ", row[1]
|
32
|
+
assert_equal Encoding::UTF_8, row[2].encoding
|
33
|
+
assert_equal "한글", row[2]
|
34
|
+
assert_equal Encoding::UTF_8, row[3].encoding
|
35
|
+
assert_equal lorem, row[3]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,588 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class NumericDataTypesTestCases < FbTestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@connection = Database.create(@parms).connect
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@connection.drop
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare_test_table(datatype)
|
14
|
+
@table = "test#{@id ||= 0 + 1}"
|
15
|
+
@connection.execute("create table #{@table} (val #{datatype})")
|
16
|
+
end
|
17
|
+
|
18
|
+
def write_and_read_value(insert_value)
|
19
|
+
@connection.execute("insert into #{@table} (val) values (?)", insert_value)
|
20
|
+
read_value = @connection.query("select * from #{@table}")[0][0]
|
21
|
+
@connection.execute("delete from #{@table}")
|
22
|
+
read_value
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_smallint_max
|
26
|
+
prepare_test_table("smallint")
|
27
|
+
assert_equal 32767, write_and_read_value(32767)
|
28
|
+
assert_equal 32767, write_and_read_value("32767")
|
29
|
+
assert_equal 32767, write_and_read_value(32767.0)
|
30
|
+
assert_equal 32767, write_and_read_value(BigDecimal("32767"))
|
31
|
+
assert write_and_read_value(32767).is_a?(Integer)
|
32
|
+
assert write_and_read_value("32767").is_a?(Integer)
|
33
|
+
assert write_and_read_value(32767.0).is_a?(Integer)
|
34
|
+
assert write_and_read_value(BigDecimal("32767")).is_a?(Integer)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_smallint_min
|
38
|
+
prepare_test_table("smallint")
|
39
|
+
assert_equal -32768, write_and_read_value(-32768)
|
40
|
+
assert_equal -32768, write_and_read_value("-32768")
|
41
|
+
assert_equal -32768, write_and_read_value(-32768.0)
|
42
|
+
assert_equal -32768, write_and_read_value(BigDecimal("-32768"))
|
43
|
+
assert write_and_read_value(-32768).is_a?(Integer)
|
44
|
+
assert write_and_read_value("-32768").is_a?(Integer)
|
45
|
+
assert write_and_read_value(-32768.0).is_a?(Integer)
|
46
|
+
assert write_and_read_value(BigDecimal("-32768")).is_a?(Integer)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_smallint_rounding
|
50
|
+
prepare_test_table("smallint")
|
51
|
+
assert_equal 0, write_and_read_value(0.4)
|
52
|
+
assert_equal 0, write_and_read_value("0.4")
|
53
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.4"))
|
54
|
+
assert_equal 0, write_and_read_value(-0.4)
|
55
|
+
assert_equal 0, write_and_read_value("-0.4")
|
56
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.4"))
|
57
|
+
assert_equal 1, write_and_read_value(0.5)
|
58
|
+
assert_equal 1, write_and_read_value("0.5")
|
59
|
+
assert_equal 1, write_and_read_value(BigDecimal("0.5"))
|
60
|
+
assert_equal -1, write_and_read_value(-0.5)
|
61
|
+
assert_equal -1, write_and_read_value("-0.5")
|
62
|
+
assert_equal -1, write_and_read_value(BigDecimal("-0.5"))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_smallint_input_type
|
66
|
+
prepare_test_table("smallint")
|
67
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
68
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
69
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
70
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_smallint_input_range
|
74
|
+
prepare_test_table("smallint")
|
75
|
+
assert_raises(RangeError) { write_and_read_value(32768) }
|
76
|
+
assert_raises(RangeError) { write_and_read_value("32768") }
|
77
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("32768")) }
|
78
|
+
assert_raises(RangeError) { write_and_read_value(-32769) }
|
79
|
+
assert_raises(RangeError) { write_and_read_value("-32769") }
|
80
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-32769")) }
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_integer_max
|
84
|
+
prepare_test_table("integer")
|
85
|
+
assert_equal 2147483647, write_and_read_value(2147483647)
|
86
|
+
assert_equal 2147483647, write_and_read_value("2147483647")
|
87
|
+
assert_equal 2147483647, write_and_read_value(2147483647.0)
|
88
|
+
assert_equal 2147483647, write_and_read_value(BigDecimal("2147483647"))
|
89
|
+
assert write_and_read_value(2147483647).is_a?(Integer)
|
90
|
+
assert write_and_read_value("2147483647").is_a?(Integer)
|
91
|
+
assert write_and_read_value(2147483647.0).is_a?(Integer)
|
92
|
+
assert write_and_read_value(BigDecimal("2147483647")).is_a?(Integer)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_integer_min
|
96
|
+
prepare_test_table("integer")
|
97
|
+
assert_equal -2147483648, write_and_read_value(-2147483648)
|
98
|
+
assert_equal -2147483648, write_and_read_value("-2147483648")
|
99
|
+
assert_equal -2147483648, write_and_read_value(-2147483648.0)
|
100
|
+
assert_equal -2147483648, write_and_read_value(BigDecimal("-2147483648"))
|
101
|
+
assert write_and_read_value(-2147483648).is_a?(Integer)
|
102
|
+
assert write_and_read_value("-2147483648").is_a?(Integer)
|
103
|
+
assert write_and_read_value(-2147483648.0).is_a?(Integer)
|
104
|
+
assert write_and_read_value(BigDecimal("-2147483648")).is_a?(Integer)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_integer_rounding
|
108
|
+
prepare_test_table("integer")
|
109
|
+
assert_equal 0, write_and_read_value(0.4)
|
110
|
+
assert_equal 0, write_and_read_value("0.4")
|
111
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.4"))
|
112
|
+
assert_equal 0, write_and_read_value(-0.4)
|
113
|
+
assert_equal 0, write_and_read_value("-0.4")
|
114
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.4"))
|
115
|
+
assert_equal 1, write_and_read_value(0.5)
|
116
|
+
assert_equal 1, write_and_read_value("0.5")
|
117
|
+
assert_equal 1, write_and_read_value(BigDecimal("0.5"))
|
118
|
+
assert_equal -1, write_and_read_value(-0.5)
|
119
|
+
assert_equal -1, write_and_read_value("-0.5")
|
120
|
+
assert_equal -1, write_and_read_value(BigDecimal("-0.5"))
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_integer_input_type
|
124
|
+
prepare_test_table("integer")
|
125
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
126
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
127
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
128
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_integer_input_range
|
132
|
+
prepare_test_table("integer")
|
133
|
+
assert_raises(RangeError) { write_and_read_value(2147483648) }
|
134
|
+
assert_raises(RangeError) { write_and_read_value("2147483648") }
|
135
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("2147483648")) }
|
136
|
+
assert_raises(RangeError) { write_and_read_value(-2147483649) }
|
137
|
+
assert_raises(RangeError) { write_and_read_value("-2147483649") }
|
138
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-2147483649")) }
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_bigint_max
|
142
|
+
prepare_test_table("bigint")
|
143
|
+
assert_equal 9223372036854775807, write_and_read_value(9223372036854775807)
|
144
|
+
assert_equal 9223372036854775807, write_and_read_value("9223372036854775807")
|
145
|
+
#assert_equal 9223372036854775807, write_and_read_value(9223372036854775807.0)
|
146
|
+
assert_equal 9223372036854775807, write_and_read_value(BigDecimal("9223372036854775807"))
|
147
|
+
assert write_and_read_value(9223372036854775807).is_a?(Integer)
|
148
|
+
assert write_and_read_value("9223372036854775807").is_a?(Integer)
|
149
|
+
#assert write_and_read_value(9223372036854775807.0).is_a?(Integer)
|
150
|
+
assert write_and_read_value(BigDecimal("9223372036854775807")).is_a?(Integer)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_bigint_min
|
154
|
+
prepare_test_table("bigint")
|
155
|
+
assert_equal(-9223372036854775808, write_and_read_value(-9223372036854775808))
|
156
|
+
assert_equal(-9223372036854775808, write_and_read_value("-9223372036854775808"))
|
157
|
+
#assert_equal -9223372036854775808, write_and_read_value(-9223372036854775808.0)
|
158
|
+
assert_equal -9223372036854775808, write_and_read_value(BigDecimal("-9223372036854775808"))
|
159
|
+
assert write_and_read_value(-9223372036854775808).is_a?(Integer)
|
160
|
+
assert write_and_read_value("-9223372036854775808").is_a?(Integer)
|
161
|
+
#assert write_and_read_value(-9223372036854775808.0).is_a?(Integer)
|
162
|
+
assert write_and_read_value(BigDecimal("-9223372036854775808")).is_a?(Integer)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_bigint_rounding
|
166
|
+
prepare_test_table("bigint")
|
167
|
+
assert_equal 0, write_and_read_value(0.4)
|
168
|
+
assert_equal 0, write_and_read_value("0.4")
|
169
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.4"))
|
170
|
+
assert_equal 0, write_and_read_value(-0.4)
|
171
|
+
assert_equal 0, write_and_read_value("-0.4")
|
172
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.4"))
|
173
|
+
assert_equal 1, write_and_read_value(0.5)
|
174
|
+
assert_equal 1, write_and_read_value("0.5")
|
175
|
+
assert_equal 1, write_and_read_value(BigDecimal("0.5"))
|
176
|
+
assert_equal -1, write_and_read_value(-0.5)
|
177
|
+
assert_equal -1, write_and_read_value("-0.5")
|
178
|
+
assert_equal -1, write_and_read_value(BigDecimal("-0.5"))
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_bigint_input_type
|
182
|
+
prepare_test_table("bigint")
|
183
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
184
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
185
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
186
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_bigint_input_range
|
190
|
+
prepare_test_table("bigint")
|
191
|
+
assert_raises(RangeError) { write_and_read_value(9223372036854775808) }
|
192
|
+
assert_raises(RangeError) { write_and_read_value("9223372036854775808") }
|
193
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("9223372036854775808")) }
|
194
|
+
assert_raises(RangeError) { write_and_read_value(-9223372036854775809) }
|
195
|
+
assert_raises(RangeError) { write_and_read_value("-9223372036854775809") }
|
196
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-9223372036854775809")) }
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_decimal_4_0_max
|
200
|
+
prepare_test_table("decimal(4, 0)")
|
201
|
+
assert_equal 32767, write_and_read_value(32767)
|
202
|
+
assert_equal 32767, write_and_read_value("32767")
|
203
|
+
assert_equal 32767, write_and_read_value(32767.0)
|
204
|
+
assert_equal 32767, write_and_read_value(BigDecimal("32767"))
|
205
|
+
assert write_and_read_value(32767).is_a?(Integer)
|
206
|
+
assert write_and_read_value("32767").is_a?(Integer)
|
207
|
+
assert write_and_read_value(32767.0).is_a?(Integer)
|
208
|
+
assert write_and_read_value(BigDecimal("32767")).is_a?(Integer)
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_decimal_4_0_min
|
212
|
+
prepare_test_table("decimal(4, 0)")
|
213
|
+
assert_equal -32768, write_and_read_value(-32768)
|
214
|
+
assert_equal -32768, write_and_read_value("-32768")
|
215
|
+
assert_equal -32768, write_and_read_value(-32768.0)
|
216
|
+
assert_equal -32768, write_and_read_value(BigDecimal("-32768"))
|
217
|
+
assert write_and_read_value(-32768).is_a?(Integer)
|
218
|
+
assert write_and_read_value("-32768").is_a?(Integer)
|
219
|
+
assert write_and_read_value(-32768.0).is_a?(Integer)
|
220
|
+
assert write_and_read_value(BigDecimal("-32768")).is_a?(Integer)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_decimal_4_0_rounding
|
224
|
+
prepare_test_table("decimal(4, 0)")
|
225
|
+
assert_equal 0, write_and_read_value(0.4)
|
226
|
+
assert_equal 0, write_and_read_value("0.4")
|
227
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.4"))
|
228
|
+
assert_equal 0, write_and_read_value(-0.4)
|
229
|
+
assert_equal 0, write_and_read_value("-0.4")
|
230
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.4"))
|
231
|
+
assert_equal 1, write_and_read_value(0.5)
|
232
|
+
assert_equal 1, write_and_read_value("0.5")
|
233
|
+
assert_equal 1, write_and_read_value(BigDecimal("0.5"))
|
234
|
+
assert_equal -1, write_and_read_value(-0.5)
|
235
|
+
assert_equal -1, write_and_read_value("-0.5")
|
236
|
+
assert_equal -1, write_and_read_value(BigDecimal("-0.5"))
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_decimal_4_0_input_type
|
240
|
+
prepare_test_table("decimal(4, 0)")
|
241
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
242
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
243
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
244
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_decimal_4_0_input_range
|
248
|
+
prepare_test_table("decimal(4, 0)")
|
249
|
+
assert_raises(RangeError) { write_and_read_value(2147483648) }
|
250
|
+
assert_raises(RangeError) { write_and_read_value("2147483648") }
|
251
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("2147483648")) }
|
252
|
+
assert_raises(RangeError) { write_and_read_value(-2147483649) }
|
253
|
+
assert_raises(RangeError) { write_and_read_value("-2147483649") }
|
254
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-2147483649")) }
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_decimal_9_0_max
|
258
|
+
prepare_test_table("decimal(9, 0)")
|
259
|
+
assert_equal 2147483647, write_and_read_value(2147483647)
|
260
|
+
assert_equal 2147483647, write_and_read_value("2147483647")
|
261
|
+
assert_equal 2147483647, write_and_read_value(2147483647.0)
|
262
|
+
assert_equal 2147483647, write_and_read_value(BigDecimal("2147483647"))
|
263
|
+
assert write_and_read_value(2147483647).is_a?(Integer)
|
264
|
+
assert write_and_read_value("2147483647").is_a?(Integer)
|
265
|
+
assert write_and_read_value(2147483647.0).is_a?(Integer)
|
266
|
+
assert write_and_read_value(BigDecimal("2147483647")).is_a?(Integer)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_decimal_9_0_min
|
270
|
+
prepare_test_table("decimal(9, 0)")
|
271
|
+
assert_equal 2147483647, write_and_read_value(2147483647)
|
272
|
+
assert_equal 2147483647, write_and_read_value("2147483647")
|
273
|
+
assert_equal 2147483647, write_and_read_value(2147483647.0)
|
274
|
+
assert_equal 2147483647, write_and_read_value(BigDecimal("2147483647"))
|
275
|
+
assert write_and_read_value(2147483647).is_a?(Integer)
|
276
|
+
assert write_and_read_value("2147483647").is_a?(Integer)
|
277
|
+
assert write_and_read_value(2147483647.0).is_a?(Integer)
|
278
|
+
assert write_and_read_value(BigDecimal("2147483647")).is_a?(Integer)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_decimal_9_0_rounding
|
282
|
+
prepare_test_table("decimal(9, 0)")
|
283
|
+
assert_equal 0, write_and_read_value(0.4)
|
284
|
+
assert_equal 0, write_and_read_value("0.4")
|
285
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.4"))
|
286
|
+
assert_equal 0, write_and_read_value(-0.4)
|
287
|
+
assert_equal 0, write_and_read_value("-0.4")
|
288
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.4"))
|
289
|
+
assert_equal 1, write_and_read_value(0.5)
|
290
|
+
assert_equal 1, write_and_read_value("0.5")
|
291
|
+
assert_equal 1, write_and_read_value(BigDecimal("0.5"))
|
292
|
+
assert_equal -1, write_and_read_value(-0.5)
|
293
|
+
assert_equal -1, write_and_read_value("-0.5")
|
294
|
+
assert_equal -1, write_and_read_value(BigDecimal("-0.5"))
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_decimal_9_0_input_type
|
298
|
+
prepare_test_table("decimal(9, 0)")
|
299
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
300
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
301
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
302
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_decimal_9_0_input_range
|
306
|
+
prepare_test_table("decimal(9, 0)")
|
307
|
+
assert_raises(RangeError) { write_and_read_value(2147483648) }
|
308
|
+
assert_raises(RangeError) { write_and_read_value("2147483648") }
|
309
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("2147483648")) }
|
310
|
+
assert_raises(RangeError) { write_and_read_value(-2147483649) }
|
311
|
+
assert_raises(RangeError) { write_and_read_value("-2147483649") }
|
312
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-2147483649")) }
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_decimal_9_4_max
|
316
|
+
prepare_test_table("decimal(9, 4)")
|
317
|
+
assert_equal BigDecimal("214748.3647"), write_and_read_value("214748.3647")
|
318
|
+
assert_equal BigDecimal("214748.3647"), write_and_read_value(214748.3647)
|
319
|
+
assert_equal BigDecimal("214748.3647"), write_and_read_value(BigDecimal("214748.3647"))
|
320
|
+
assert write_and_read_value("214748.3647").is_a?(BigDecimal)
|
321
|
+
assert write_and_read_value(214748.3647).is_a?(BigDecimal)
|
322
|
+
assert write_and_read_value(BigDecimal("214748.3647")).is_a?(BigDecimal)
|
323
|
+
end
|
324
|
+
|
325
|
+
def test_decimal_9_4_min
|
326
|
+
prepare_test_table("decimal(9, 4)")
|
327
|
+
assert_equal BigDecimal("-214748.3648"), write_and_read_value("-214748.3648")
|
328
|
+
assert_equal BigDecimal("-214748.3648"), write_and_read_value(-214748.3648)
|
329
|
+
assert_equal BigDecimal("-214748.3648"), write_and_read_value(BigDecimal("-214748.3648"))
|
330
|
+
assert write_and_read_value("-214748.3648").is_a?(BigDecimal)
|
331
|
+
assert write_and_read_value(-214748.3648).is_a?(BigDecimal)
|
332
|
+
assert write_and_read_value(BigDecimal("-214748.3648")).is_a?(BigDecimal)
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_decimal_9_4_rounding
|
336
|
+
prepare_test_table("decimal(9, 4)")
|
337
|
+
assert_equal 0, write_and_read_value(0.00004)
|
338
|
+
assert_equal 0, write_and_read_value("0.00004")
|
339
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.00004"))
|
340
|
+
assert_equal 0, write_and_read_value(-0.00004)
|
341
|
+
assert_equal 0, write_and_read_value("-0.00004")
|
342
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.00004"))
|
343
|
+
assert_equal BigDecimal('0.0001'), write_and_read_value(0.00005)
|
344
|
+
assert_equal BigDecimal('0.0001'), write_and_read_value("0.00005")
|
345
|
+
assert_equal BigDecimal('0.0001'), write_and_read_value(BigDecimal("0.00005"))
|
346
|
+
assert_equal BigDecimal('-0.0001'), write_and_read_value(-0.00005)
|
347
|
+
assert_equal BigDecimal('-0.0001'), write_and_read_value("-0.00005")
|
348
|
+
assert_equal BigDecimal('-0.0001'), write_and_read_value(BigDecimal("-0.00005"))
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_decimal_9_4_input_type
|
352
|
+
prepare_test_table("decimal(9, 4)")
|
353
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
354
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
355
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
356
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_decimal_9_4_input_range
|
360
|
+
prepare_test_table("decimal(9, 4)")
|
361
|
+
assert_raises(RangeError) { write_and_read_value(214748.3648) }
|
362
|
+
assert_raises(RangeError) { write_and_read_value("214748.3648") }
|
363
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("214748.3648")) }
|
364
|
+
assert_raises(RangeError) { write_and_read_value(-214748.3649) }
|
365
|
+
assert_raises(RangeError) { write_and_read_value("-214748.3649") }
|
366
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-214748.3649")) }
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_decimal_9_9_max
|
370
|
+
prepare_test_table("decimal(9, 9)")
|
371
|
+
assert_equal BigDecimal("2.147483647"), write_and_read_value("2.147483647")
|
372
|
+
assert_equal BigDecimal("2.147483647"), write_and_read_value(2.147483647)
|
373
|
+
assert_equal BigDecimal("2.147483647"), write_and_read_value(BigDecimal("2.147483647"))
|
374
|
+
assert write_and_read_value("2.147483647").is_a?(BigDecimal)
|
375
|
+
assert write_and_read_value(2.147483647).is_a?(BigDecimal)
|
376
|
+
assert write_and_read_value(BigDecimal("2.147483647")).is_a?(BigDecimal)
|
377
|
+
end
|
378
|
+
|
379
|
+
def test_decimal_9_9_min
|
380
|
+
prepare_test_table("decimal(9, 9)")
|
381
|
+
assert_equal BigDecimal("-2.147483648"), write_and_read_value("-2.147483648")
|
382
|
+
assert_equal BigDecimal("-2.147483648"), write_and_read_value(-2.147483648)
|
383
|
+
assert_equal BigDecimal("-2.147483648"), write_and_read_value(BigDecimal("-2.147483648"))
|
384
|
+
assert write_and_read_value("-2.147483648").is_a?(BigDecimal)
|
385
|
+
assert write_and_read_value(-2.147483648).is_a?(BigDecimal)
|
386
|
+
assert write_and_read_value(BigDecimal("-2.147483648")).is_a?(BigDecimal)
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_decimal_9_9_rounding
|
390
|
+
prepare_test_table("decimal(9, 9)")
|
391
|
+
assert_equal 0, write_and_read_value(0.0000000004)
|
392
|
+
assert_equal 0, write_and_read_value("0.0000000004")
|
393
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.0000000004"))
|
394
|
+
assert_equal 0, write_and_read_value(-0.0000000004)
|
395
|
+
assert_equal 0, write_and_read_value("-0.0000000004")
|
396
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.0000000004"))
|
397
|
+
assert_equal BigDecimal("0.000000001"), write_and_read_value(0.0000000005)
|
398
|
+
assert_equal BigDecimal("0.000000001"), write_and_read_value("0.0000000005")
|
399
|
+
assert_equal BigDecimal("0.000000001"), write_and_read_value(BigDecimal("0.0000000005"))
|
400
|
+
assert_equal BigDecimal("-0.000000001"), write_and_read_value(-0.0000000005)
|
401
|
+
assert_equal BigDecimal("-0.000000001"), write_and_read_value("-0.0000000005")
|
402
|
+
assert_equal BigDecimal("-0.000000001"), write_and_read_value(BigDecimal("-0.0000000005"))
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_decimal_9_9_input_type
|
406
|
+
prepare_test_table("decimal(9, 9)")
|
407
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
408
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
409
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
410
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_decimal_9_9_input_range
|
414
|
+
prepare_test_table("decimal(9, 9)")
|
415
|
+
assert_raises(RangeError) { write_and_read_value(2.147483648) }
|
416
|
+
assert_raises(RangeError) { write_and_read_value("2.147483648") }
|
417
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("2.147483648")) }
|
418
|
+
assert_raises(RangeError) { write_and_read_value(-2.147483649) }
|
419
|
+
assert_raises(RangeError) { write_and_read_value("-2.147483649") }
|
420
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-2.147483649")) }
|
421
|
+
end
|
422
|
+
|
423
|
+
def test_decimal_18_0_max
|
424
|
+
prepare_test_table("decimal(18, 0)")
|
425
|
+
assert_equal 9223372036854775807, write_and_read_value(9223372036854775807)
|
426
|
+
assert_equal 9223372036854775807, write_and_read_value("9223372036854775807")
|
427
|
+
#assert_equal 9223372036854775807, write_and_read_value(9223372036854775807.0)
|
428
|
+
assert_equal 9223372036854775807, write_and_read_value(BigDecimal("9223372036854775807"))
|
429
|
+
assert write_and_read_value(9223372036854775807).is_a?(Integer)
|
430
|
+
assert write_and_read_value("9223372036854775807").is_a?(Integer)
|
431
|
+
#assert write_and_read_value(9223372036854775807.0).is_a?(Integer)
|
432
|
+
assert write_and_read_value(BigDecimal("9223372036854775807")).is_a?(Integer)
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_decimal_18_0_min
|
436
|
+
prepare_test_table("decimal(18, 0)")
|
437
|
+
assert_equal(-9223372036854775808, write_and_read_value(-9223372036854775808))
|
438
|
+
assert_equal(-9223372036854775808, write_and_read_value("-9223372036854775808"))
|
439
|
+
#assert_equal -9223372036854775808, write_and_read_value(-9223372036854775808.0)
|
440
|
+
assert_equal -9223372036854775808, write_and_read_value(BigDecimal("-9223372036854775808"))
|
441
|
+
assert write_and_read_value(-9223372036854775808).is_a?(Integer)
|
442
|
+
assert write_and_read_value("-9223372036854775808").is_a?(Integer)
|
443
|
+
#assert write_and_read_value(-9223372036854775808.0).is_a?(Integer)
|
444
|
+
assert write_and_read_value(BigDecimal("-9223372036854775808")).is_a?(Integer)
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_decimal_18_0_rounding
|
448
|
+
prepare_test_table("decimal(18, 0)")
|
449
|
+
assert_equal 0, write_and_read_value(0.4)
|
450
|
+
assert_equal 0, write_and_read_value("0.4")
|
451
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.4"))
|
452
|
+
assert_equal 0, write_and_read_value(-0.4)
|
453
|
+
assert_equal 0, write_and_read_value("-0.4")
|
454
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.4"))
|
455
|
+
assert_equal 1, write_and_read_value(0.5)
|
456
|
+
assert_equal 1, write_and_read_value("0.5")
|
457
|
+
assert_equal 1, write_and_read_value(BigDecimal("0.5"))
|
458
|
+
assert_equal -1, write_and_read_value(-0.5)
|
459
|
+
assert_equal -1, write_and_read_value("-0.5")
|
460
|
+
assert_equal -1, write_and_read_value(BigDecimal("-0.5"))
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_decimal_18_0_input_types
|
464
|
+
prepare_test_table("decimal(18, 0)")
|
465
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
466
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
467
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
468
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
469
|
+
end
|
470
|
+
|
471
|
+
def test_decimal_18_0_input_range
|
472
|
+
prepare_test_table("decimal(18, 0)")
|
473
|
+
assert_raises(RangeError) { write_and_read_value(9223372036854775808) }
|
474
|
+
assert_raises(RangeError) { write_and_read_value("9223372036854775808") }
|
475
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("9223372036854775808")) }
|
476
|
+
assert_raises(RangeError) { write_and_read_value(-9223372036854775809) }
|
477
|
+
assert_raises(RangeError) { write_and_read_value("-9223372036854775809") }
|
478
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-9223372036854775809")) }
|
479
|
+
end
|
480
|
+
|
481
|
+
def test_decimal_18_9_max
|
482
|
+
prepare_test_table("decimal(18, 9)")
|
483
|
+
assert_equal BigDecimal("9223372036.854775807"), write_and_read_value("9223372036.854775807")
|
484
|
+
#assert_equal BigDecimal("9223372036.854775807"), write_and_read_value(9223372036.854775807)
|
485
|
+
assert_equal BigDecimal("9223372036.854775807"), write_and_read_value(BigDecimal("9223372036.854775807"))
|
486
|
+
assert write_and_read_value("9223372036.854775807").is_a?(BigDecimal)
|
487
|
+
#assert write_and_read_value(9223372036.854775807).is_a?(BigDecimal)
|
488
|
+
assert write_and_read_value(BigDecimal("9223372036.854775807")).is_a?(BigDecimal)
|
489
|
+
end
|
490
|
+
|
491
|
+
def test_decimal_18_9_min
|
492
|
+
prepare_test_table("decimal(18, 9)")
|
493
|
+
assert_equal BigDecimal("-9223372036.854775808"), write_and_read_value("-9223372036.854775808")
|
494
|
+
#assert_equal BigDecimal("-9223372036.854775808"), write_and_read_value(-9223372036.854775808)
|
495
|
+
assert_equal BigDecimal("-9223372036.854775808"), write_and_read_value(BigDecimal("-9223372036.854775808"))
|
496
|
+
assert write_and_read_value("-9223372036.854775808").is_a?(BigDecimal)
|
497
|
+
#assert write_and_read_value(-9223372036.854775808).is_a?(BigDecimal)
|
498
|
+
assert write_and_read_value(BigDecimal("-9223372036.854775808")).is_a?(BigDecimal)
|
499
|
+
end
|
500
|
+
|
501
|
+
def test_decimal_18_9_rounding
|
502
|
+
prepare_test_table("decimal(18, 9)")
|
503
|
+
assert_equal 0, write_and_read_value(0.0000000004)
|
504
|
+
assert_equal 0, write_and_read_value("0.0000000004")
|
505
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.0000000004"))
|
506
|
+
assert_equal 0, write_and_read_value(-0.0000000004)
|
507
|
+
assert_equal 0, write_and_read_value("-0.0000000004")
|
508
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.0000000004"))
|
509
|
+
assert_equal BigDecimal('0.000000001'), write_and_read_value(0.0000000005)
|
510
|
+
assert_equal BigDecimal('0.000000001'), write_and_read_value("0.0000000005")
|
511
|
+
assert_equal BigDecimal('0.000000001'), write_and_read_value(BigDecimal("0.0000000005"))
|
512
|
+
assert_equal BigDecimal('-0.000000001'), write_and_read_value(-0.0000000005)
|
513
|
+
assert_equal BigDecimal('-0.000000001'), write_and_read_value("-0.0000000005")
|
514
|
+
assert_equal BigDecimal('-0.000000001'), write_and_read_value(BigDecimal("-0.0000000005"))
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_decimal_18_9_input_type
|
518
|
+
prepare_test_table("decimal(18, 9)")
|
519
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
520
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
521
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
522
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
523
|
+
end
|
524
|
+
|
525
|
+
def test_decimal_18_9_input_range
|
526
|
+
prepare_test_table("decimal(18, 9)")
|
527
|
+
assert_raises(RangeError) { write_and_read_value(9223372036.854775808) }
|
528
|
+
assert_raises(RangeError) { write_and_read_value("9223372036.854775808") }
|
529
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("9223372036.854775808")) }
|
530
|
+
assert_raises(RangeError) { write_and_read_value(-9223372036.854775809) }
|
531
|
+
assert_raises(RangeError) { write_and_read_value("-9223372036.854775809") }
|
532
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-9223372036.854775809")) }
|
533
|
+
end
|
534
|
+
|
535
|
+
def test_decimal_18_18_max
|
536
|
+
prepare_test_table("decimal(18, 18)")
|
537
|
+
assert_equal BigDecimal("9.223372036854775807"), write_and_read_value(BigDecimal("9.223372036854775807"))
|
538
|
+
#assert_equal BigDecimal("9.223372036854775807"), write_and_read_value(9.223372036854775807)
|
539
|
+
assert_equal BigDecimal("9.223372036854775807"), write_and_read_value("9.223372036854775807")
|
540
|
+
assert write_and_read_value("9.223372036854775807").is_a?(BigDecimal)
|
541
|
+
#assert write_and_read_value(9.223372036854775807).is_a?(BigDecimal)
|
542
|
+
assert write_and_read_value(BigDecimal("9.223372036854775807")).is_a?(BigDecimal)
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_decimal_18_18_min
|
546
|
+
prepare_test_table("decimal(18, 18)")
|
547
|
+
assert_equal BigDecimal("-9.223372036854775808"), write_and_read_value("-9.223372036854775808")
|
548
|
+
#assert_equal BigDecimal("-9.223372036854775808"), write_and_read_value(-9.223372036854775808)
|
549
|
+
assert_equal BigDecimal("-9.223372036854775808"), write_and_read_value(BigDecimal("-9.223372036854775808"))
|
550
|
+
assert write_and_read_value("-9.223372036854775808").is_a?(BigDecimal)
|
551
|
+
#assert write_and_read_value(-9.223372036854775808).is_a?(BigDecimal)
|
552
|
+
assert write_and_read_value(BigDecimal("-9.223372036854775808")).is_a?(BigDecimal)
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_decimal_18_18_rounding
|
556
|
+
prepare_test_table("decimal(18, 18)")
|
557
|
+
assert_equal 0, write_and_read_value(0.0000000000000000004)
|
558
|
+
assert_equal 0, write_and_read_value("0.0000000000000000004")
|
559
|
+
assert_equal 0, write_and_read_value(BigDecimal("0.0000000000000000004"))
|
560
|
+
assert_equal 0, write_and_read_value(-0.0000000000000000004)
|
561
|
+
assert_equal 0, write_and_read_value("-0.0000000000000000004")
|
562
|
+
assert_equal 0, write_and_read_value(BigDecimal("-0.0000000000000000004"))
|
563
|
+
assert_equal BigDecimal("0.000000000000000001"), write_and_read_value(0.0000000000000000005)
|
564
|
+
assert_equal BigDecimal("0.000000000000000001"), write_and_read_value("0.0000000000000000005")
|
565
|
+
assert_equal BigDecimal("0.000000000000000001"), write_and_read_value(BigDecimal("0.0000000000000000005"))
|
566
|
+
assert_equal BigDecimal("-0.000000000000000001"), write_and_read_value(-0.0000000000000000005)
|
567
|
+
assert_equal BigDecimal("-0.000000000000000001"), write_and_read_value("-0.0000000000000000005")
|
568
|
+
assert_equal BigDecimal("-0.000000000000000001"), write_and_read_value(BigDecimal("-0.0000000000000000005"))
|
569
|
+
end
|
570
|
+
|
571
|
+
def test_decimal_18_18_input_type
|
572
|
+
prepare_test_table("decimal(18, 18)")
|
573
|
+
#assert_raises(TypeError) { write_and_read_value('abcde') }
|
574
|
+
assert_raises(TypeError) { write_and_read_value(Date.new) }
|
575
|
+
assert_raises(TypeError) { write_and_read_value(Time.new) }
|
576
|
+
assert_raises(TypeError) { write_and_read_value(Object.new) }
|
577
|
+
end
|
578
|
+
|
579
|
+
def test_decimal_18_18_input_range
|
580
|
+
prepare_test_table("decimal(18, 18)")
|
581
|
+
assert_raises(RangeError) { write_and_read_value(9.223372036854775808) }
|
582
|
+
assert_raises(RangeError) { write_and_read_value("9.223372036854775808") }
|
583
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("9.223372036854775808")) }
|
584
|
+
assert_raises(RangeError) { write_and_read_value(-9.223372036854775809) }
|
585
|
+
assert_raises(RangeError) { write_and_read_value("-9.223372036854775809") }
|
586
|
+
assert_raises(RangeError) { write_and_read_value(BigDecimal("-9.223372036854775809")) }
|
587
|
+
end
|
588
|
+
end
|