Skip to content

Commit 65717fa

Browse files
committed
test_vtable: use assert_operator/assert_equal instead of simple assert for better error messages
1 parent 2bea180 commit 65717fa

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

test/test_vtable.rb

+20-20
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_working
6767

6868
#execute an sql statement
6969
nb_row = @db.execute("select x, sum(y), avg(y), avg(y*y), min(y), max(y), count(y) from TestVTable group by x").each.count
70-
assert( nb_row > 0 )
70+
assert_operator nb_row, :>, 0
7171
end
7272

7373
def test_vtable
@@ -77,58 +77,58 @@ def test_vtable
7777
[3, 6, 9]
7878
])
7979
nb_row = @db.execute('select count(*) from TestVTable2').each.first[0]
80-
assert( nb_row == 3 )
80+
assert_equal( 3, nb_row )
8181
sum_a, sum_b, sum_c = *@db.execute('select sum(a), sum(b), sum(c) from TestVTable2').each.first
82-
assert( sum_a = 6 )
83-
assert( sum_b == 12 )
84-
assert( sum_c == 18 )
82+
assert_equal( 6, sum_a )
83+
assert_equal( 12, sum_b )
84+
assert_equal( 18, sum_c )
8585
end
8686

8787
def test_multiple_vtable
8888
SQLite3.vtable(@db, 'TestVTable3', 'col1', [['a'], ['b']])
8989
SQLite3.vtable(@db, 'TestVTable4', 'col2', [['c'], ['d']])
9090
rows = @db.execute('select col1, col2 from TestVTable3, TestVTable4').each.to_a
91-
assert( rows.include?(['a', 'c']) )
92-
assert( rows.include?(['a', 'd']) )
93-
assert( rows.include?(['b', 'c']) )
94-
assert( rows.include?(['b', 'd']) )
91+
assert_includes rows, ['a', 'c']
92+
assert_includes rows, ['a', 'd']
93+
assert_includes rows, ['b', 'c']
94+
assert_includes rows, ['b', 'd']
9595
end
9696

9797
def test_best_filter
9898
test = self
9999
SQLite3.vtable(@db, 'TestVTable5', 'col1, col2', [['a', 1], ['b', 2]]).tap do |vtable|
100100
vtable.send(:define_method, :best_index) do |constraint, order_by|
101101
# check constraint
102-
test.assert( constraint.include?([0, :<=]) ) # col1 <= 'c'
103-
test.assert( constraint.include?([0, :>]) ) # col1 > 'a'
104-
test.assert( constraint.include?([1, :<]) ) # col2 < 3
102+
test.assert_includes constraint, [0, :<=] # col1 <= 'c'
103+
test.assert_includes constraint, [0, :>] # col1 > 'a'
104+
test.assert_includes constraint, [1, :<] # col2 < 3
105105
@constraint = constraint
106106

107107
# check order by
108-
test.assert( order_by == [
108+
test.assert_equal( [
109109
[1, 1], # col2
110110
[0, -1], # col1 desc
111-
] )
111+
], order_by )
112112

113113
{ idxNum: 45 }
114114
end
115115
vtable.send(:alias_method, :orig_filter, :filter)
116116
vtable.send(:define_method, :filter) do |idxNum, args|
117117
# idxNum should be the one returned by best_index
118-
test.assert( idxNum == 45 )
118+
test.assert_equal( 45, idxNum )
119119

120120
# args should be consistent with the constraint given to best_index
121-
test.assert( args.size == @constraint.size )
121+
test.assert_equal( @constraint.size, args.size )
122122
filters = @constraint.zip(args)
123-
test.assert( filters.include?([[0, :<=], 'c']) ) # col1 <= 'c'
124-
test.assert( filters.include?([[0, :>], 'a']) ) # col1 > 'a'
125-
test.assert( filters.include?([[1, :<], 3]) ) # col2 < 3
123+
test.assert_includes filters, [[0, :<=], 'c'] # col1 <= 'c'
124+
test.assert_includes filters, [[0, :>], 'a'] # col1 > 'a'
125+
test.assert_includes filters, [[1, :<], 3] # col2 < 3
126126

127127
orig_filter(idxNum, args)
128128
end
129129
end
130130
rows = @db.execute('select col1 from TestVTable5 where col1 <= \'c\' and col1 > \'a\' and col2 < 3 order by col2, col1 desc').each.to_a
131-
assert( rows == [['b']] )
131+
assert_equal( [['b']], rows )
132132
end
133133

134134
end if defined?(SQLite3::Module)

0 commit comments

Comments
 (0)