Files
secondo/Tests/Testspecs/array.test
2026-01-23 17:03:45 +08:00

156 lines
4.7 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
#
# A fresh restored opt database needs to be present for
# this test
#setup arraytest
open database opt;
# 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)
# 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
# 1 - Construction of Arrays
#testcase distribute1
#yields success
let plz_a20 = plz feed extend[Pkg: seqnext() mod 20] distribute[Pkg];
#testcase distribute2
#yields success
let staedte_a20 = Staedte feed extend[Pkg: seqnext() mod 20] distribute[Pkg];
#testcase distribute3
#yields success
let orte_a5 = Orte feed extend[Pkg: seqnext() mod 5] distribute[Pkg];
#testcase array(int)
#yields success
let intset_a10 = [const array(int) value (1 2 3 4 5 6 7 8 9 10)];
#testcase array(real)
#yields success
let realset_a10 = [const array(real) value (1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0)];
#testcase array2
#yields success
let stringset_a4 = [const array(string) value ("This" "is" "an" "array!")];
# 2 - Simple Operations
#testcase size
#yields (int 5)
query size(orte_a5);
#The first element of an array has position 0!
#testcase get1
#yields (int 4)
query get(intset_a10, 3);
# Name: put
# Signature: ((array t) t int) -> (array t)
# Syntax: put ( _, _, _ )
# Meaning: Replaces an element at a given index.
# Example: query put(ai,9,3)
# Name: sortarray
# Signature: ((array t) (map t int)) -> (array t)
# Syntax: _ sortarray [ fun ]
# Meaning: Sorts an array in order of the function values of the
# elements.
# Example: query ai sortarray[fun(i:int)i]
# Name: tie
# Signature: ((array t) (map t t t)) -> t
# Syntax: _ tie [ fun ]
# Meaning: Calculates the "value" of an array evaluating the elements
# of the array with a given function from left to right.
# Example: query ai tie[fun(i:int,l:int)(i+l)]
# Name: cumulate
# Signature: ((array t) (map t t t)) -> (array t)
# Syntax: _ cumulate [ fun ]
# Meaning: Cumulates the values of an array under a given function.
# Example: query ai cumulate[fun(i:int,l:int)(i+l)]
#testcase cumulate
#yields ((array int) (1 3 6 10 15 21 28 36 45 55))
query intset_a10 cumulate[. + ..]
#testcase summarize
#yields (bool TRUE)
query plz_a20 summarize count = plz count;
#testcase loop1
#yields (bool TRUE)
query plz_a20 loop[. count] tie [. + ..] = plz count;
#testcase loopa1
#yields (bool TRUE)
query plz_a20 staedte_a20 loopa[. count + .. count] tie[. + ..] = (plz count) + (Staedte count);
#testcase loopb1
#yields (int 400)
query size(plz_a20 staedte_a20 loopb[. count * .. count]);
#-testcase loopswitch
#-yields success
#-query Plz_a20 loopswitch[ f1: . feed plz feed {ren1} hashjoin[PLZ, PLZ_ren1, 997] count,
# f2: . feed plz feed {ren1} sortmergejoin[PLZ, PLZ_ren1] count ]
# tie[. + ..];
#testcase loopselect
#yields (int 248793)
query plz_a20 loopselect[ f1: . feed plz feed {ren1} hashjoin[PLZ, PLZ_ren1, 997] count,
f2: . feed plz feed {ren1} sortmergejoin[PLZ, PLZ_ren1] count; 5, 0.2 ] tie[. + ..];
#testcase loopselectb
#yields (int 248793)
query plz_a20 plz_a20 loopselectb[ f1: . feed .. feed {ren1} hashjoin[PLZ, PLZ_ren1, 997] count, f2: . feed .. feed {ren1} sortmergejoin[PLZ, PLZ_ren1] count; 5, 0.2 ] tie[. + ..];
#teardown
delete plz_a20;
delete orte_a5;
delete staedte_a20;
delete intset_a10;
delete realset_a10;
delete stringset_a4;
close database;
#delete database opt;