(temporary hosted)
package : sqltest-2.zip
Presently it can handle combination of and/or with 2-3 variables. The generator is in the file "table.c". The rest is SQL parser (not modify). You can try to run example in "test" directory. The input test file is "test3.txt". It can run only one line (the rest is commented out). Currently, it successfully parsed all cases in "test3.txt".
Try it! enjoy.
clause := clause and clause
clause := clause or clause
clause := ( clause )
clause := name operator value
clause := name like 'string'
clause := name not like 'string'
clause := name between value and value
clause := name not between value and value
clause := name in list
clause := name not in list
clause := name is null
clause := name is not null
name := iden | fun ( iden )
operator := = | <> | < | <= | =>
list := ( values )
values := value | value , values
value := number | 'string' | fun list
iden identifier
fun function name
only two functions: upper( ) and
to_date('date-string','dd-mm-yyyy')
input
a1 = 4 and a2 = '764'
parse
(and (= a1 4)(= a2 '764'))
output
case 1 expect v
a1 = 4 v
a2 = '764' v
case 2 expect i
a1 = 4 v
a2 = '456' i
case 3 expect i
a1 = 5 i
a2 = '764' v
case 4 expect i
a1 = 5 i
a2 = '456' i
Each variable has its own two test cases. v test case is the valid case.
The invalid is generated.
i test case
for integer value, use nearest-value, by +1 to the original
for string value, use the string-value that is not the original but
exists in the database
a1
value test-case
v a1 = 4
i a1 = 5
a2
value test-case
v a2 = '764'
i a2 = '456'
Generate a truth table of two variables using and-or rule by
1. generate combination of variable (4 rows)
2. calculate output by
for and
out = v when both is v. otherwise i
for or
out = i when both is i, otherwise v
and the truth table is
a1 a2 out
i i i
i v i
v i i
v v v
To merge one variable and a table:
a1 merge t2
where a1 is a variable and t2 is and-table
1. generate combination of variable and table (8 rows) by
stacking vertically two tables
front append half v, half i
2. calculate output by
for and
out = v when both is v. otherwise i
for or
out = i when both is i, otherwise v
a1 and (a2 and a3)
the truth table of (a2 and a3) is
a2 a3 out
i i i
i v i
v i i
v v v
the truth table of the input expression is:
a1 a2 a3 a2a3-out merge-out
i ...
i i
i
i i
i
i i
i
v i
v
i i
v
i i
v
i i
v
v v
1. generate a first table (of two variables) using and-or rules
2. merge the third variable with the first table
Test case generation is the enumeration of the result table. the
expect result is the output of this table.
Invalid case is made to inversion of operator. The following operators are recognised:
a1 =
500
to a1 =
501 nearest integer value
a1 =
'abc'
to a1 = 'xyz' to string not in the database
a1 <>
500
to a1 = 500
a1 >=
500
to a1 < 500
a1 >
500
to a1 <= 500
a1 <=
500
to a1 > 500
a1 <
500
to a1 >= 500
a1 in ('10','20')
to a1 not in ('10','20')
a1 not in ('10','20') to a1
in ('10','20')
a1 is null
to a1 is not null
a1 is not null
to a1 is null
a1 like 'abc'
to a1 not like 'abc'
a1 not like 'abc'
to a1 like 'abc'
a1 between date1 and date2
to a1 not between date1 and date2
a1 not between date1 and date2 to a1 between
date1 and date2
Need to compute:
table of two variables (and/or)
table of three variables (one variable and/or with a
table of two variables)
A table has three columns and four rows, value is 0/1
fill first two columns 00, 01, 10, 11
calculate third column (output)
operator and
fill all with 0
fill 4th row out with 1
operator or
fill all with 1
fill 1st row out with 0
The table has five columns and eight rows, value is 0/1
fill first three columns 000,001....,111
fill the 4th columns by copy output of table-of-two twice.
calculate the 5th columns (output)
operator and
fill all with 0
scan all rows to find 1st col = 1 and 4th col = 1, fill output 1
operator or
fill all with 1
scan all rows to find 1st col = 0 and 4th col = 0, fill output 0
last update 4 July 2017