Files
secondo/bin/example.test
2026-01-23 17:03:45 +08:00

221 lines
6.5 KiB
Plaintext

# This file is part of SECONDO.
#
# Copyright (C) 2004, University in Hagen, Department of Computer Science,
# Database Systems for New Applications.
#
# SECONDO is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# SECONDO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SECONDO; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# An example test spec for the Secondo TestRunner
# run it with :
#
# TestRunner -i example.test
#
# By default a temporary database directory will be created. If you
# want to use existing databases run
#
# TestRunner --no-tmp -i <file>
#
# If one of your tests (say number N ) reports an error you can run
# it directly by
#
# TestRunner -i <file> -num N
#
# this is useful for debugging
# A test specification consists of initial commands, a section of commands
# setting up the test, a sequence of test cases, and a section of commands
# cleaning up. The TestRunner uses directives to specify these sections.
# directives are specified in comment lines, all comment lines beginning with a
# directive are interpreted as commands to the TestRunner, non-comment lines are
# passed to Secondo. The possible directives are SETUP, TESTCASE, YIELDS and
# TEARDOWN (here i have written the directives in upper case to avoid confusion,
# the real directives must be written in lower case). The meanings of those
# directives are explained the following commented examples.
# before the SETUP directive one can place Secondo commands
# which may or may not succeed
delete database mytestdb;
# the SETUP directive may specify the name of the test and a
# some algebra modules which are needed for it.
# the SETUP directive must appear exactly once in a test spec
#setup exampletest StandardAlgebra RelationAlgebra
# if a command between the SETUP directive and the first
# TESTCASE directive fails, then the whole test has failed
# and we immediately skip to the teardown
# (the whole test does not make sense anymore if the
# SETUP has failed)
create database mytestdb;
open database mytestdb;
# the conventions for commands are the same as in SecondoTTYBDB
# make sure that commands are always terminated
# (either by a semicolon or by a newline)
(create staedte : (rel(tuple((SName string)(Bev int)(PLZ int)
(Vorwahl string)(Kennzeichen string)))))
(update staedte := ((rel(tuple((SName string)(Bev int)(PLZ int)
(Vorwahl string)(Kennzeichen string))))
(("Aachen" 239000 5100 "0241" "AC")
("Dortmund" 572000 4600 "0231" "DO")
("Hagen" 206000 5800 "02331" "HA")
("Krefeld" 217000 4150 "02151" "KR")
("Muenster" 270000 4400 "0251" "MS")
("Nuernberg" 465000 8500 "0911" "N")
("Saarbruecken" 187000 6600 "0681" "SB")
("Stuttgart" 562000 7000 "0711" "S")
("Wiesbaden" 267000 6200 "06121" "WI")
("Wuerzburg" 128000 8700 "0931" "WUE")
("Wuppertal" 377000 5600 "0202" "W"))))
let resObj1 = 5;
# a TESTCASE consists of a TESTCASE declarative followed
# by a YIELDS declarative followed by a command.
# multiple or no commands after a YIELD directive
# will confuse the TestRunner
# the expected output specified by the YIELD declarative
# is converted to a ListExpr and the TestRunner compares
# it to Secondo's actual output by calling
# NestedList->Equal. You can specifiy results in 4 ways:
#
# 1. a list expression
# 2. in a separate file
# 3. as a database object
# 4. a simple check for "error" or "success"
#
# See below for examples.
#testcase countTestcase
#yields (int 11)
query staedte feed count;
# in the YIELDS directive one can also specify that a command
# is expected to result in an errror
#testcase caseDoesMatter
#yields error
query Staedte count;
# testcase sumOfStaedte
# yields (int 3490000)
query staedte feed sum[Bev]
#testcase
#yields error
query Staedte feed avg[Bev]
# directives can be continued by placing a backslash at the end
# of the line
# testcase StaedteQuery
# yields ((rel(tuple((SName string)(Bev int)(PLZ int)\
(Vorwahl string)(Kennzeichen string))))\
(("Aachen" 239000 5100 "0241" "AC")\
("Dortmund" 572000 4600 "0231" "DO")\
("Hagen" 206000 5800 "02331" "HA")\
("Krefeld" 217000 4150 "02151" "KR")\
("Muenster" 270000 4400 "0251" "MS")\
("Nuernberg" 465000 8500 "0911" "N")\
("Saarbruecken" 187000 6600 "0681" "SB")\
("Stuttgart" 562000 7000 "0711" "S")\
("Wiesbaden" 267000 6200 "06121" "WI")\
("Wuerzburg" 128000 8700 "0931" "WUE")\
("Wuppertal" 377000 5600 "0202" "W")))
query staedte;
# In order to specify big result lists you may specify a
# result file by @<file>, for example
# testcase StaedteQuery2
# yields @example.result1
query staedte;
# you do not have to specify a complete result in a YIELD
# directive, you may also just specify that a command suceeds
#testcase StaedteQuery2
#yields success
query staedte feed avg[Bev];
# In order to specify a database object as result
# use *<ident>, for example
#testcase query a constant value
#yields *resObj1
query 5;
# testcase StaedteQuery3
# yields *staedte
query staedte;
# a demonstration of the various kinds of errors which can happen
#testcase UnexpectedSuccess
#yields error
query staedte feed;
#testcase UnexpectedResult
#yields (int 11)
query staedte feed consume count;
# For floating point values it may be sufficient if the result
# is aprroximately correct. Therefore a tolerance can be specified
# either as relative or as absolute abberration. The tolerance will
# be defined until it is reset by ~tolerance_real 0.0~
# First we compute 10 / 3.14 ~ 3.1847133758
# we allow a deviation in the 4th value behind the period
# by setting
#
# tolerance_real 0.0009
#
# hence the following test will be correct
#testcase FloatingPoint1
# yields (real 3.184)
query 10 / 3.14
# Alternatively you can specify an relative tolerance, e.g.
#
# tolerance_real %10.0
#testcase FloatingPoint2
# yields (real 3.3)
query 10 / 3.14
# An unspecified yields definition will result in an error
# for example a result specified as "yields 3.184" will do so.
# the TEARDOWN directive is followed by commands which
# should be executed after the execution of all TESTCASES
#teardown
close database;
delete database mytestdb;