source: tol/toltcl/tests/tableset.tcl

devel
Last change on this file was 4865c64, checked in by Jorge Pérez <josp.jorge@…>, 14 years ago

refs #1369, updating test code for tableset command

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@5657 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100755
File size: 8.1 KB
RevLine 
[6d7779d]1#//////////////////////////////////////////////////////////////////////////////
2#
3# FILE: tableset.tcl
4#
5# PURPOSE: test the command tol::tableset
6#
7#//////////////////////////////////////////////////////////////////////////////
8
9
10
11#//////////////////////////////////////////////////////////////////////////////
12#
13# PROCEDURE: TestWrong
14#
15# PURPOSE: Test that doesn't produce the expected result
16#
17#//////////////////////////////////////////////////////////////////////////////
18proc TestWrong { } {
19  #no puede crear el comando
[4865c64]20  tol::tableset create tblset {Set AllLinear}
[6d7779d]21  tol::tableset destroy tblset
22}
23
24proc Write {args} {
25  puts $args
26}
27
28proc TestWrong1 { } {
29  #
[4865c64]30  tol::tableset create tblset {Set AxisDatingList}
[6d7779d]31  puts "Da como resultado [tblset info datarows] filas, en realidad son 10"
32  puts "Vamos a imprimir todo el contenido del conjunto"
33  tblset data apply all Write
34  puts "No aparece entero"
35  puts [tblset info rowsnames]
36  tol::tableset destroy tblset
37 
38}
39
40#//////////////////////////////////////////////////////////////////////////////
41#
42# PROCEDURE: TestGenericHeader
43#
44# PURPOSE: test over a set with generic header
45#
46#//////////////////////////////////////////////////////////////////////////////
47
48proc TestGenericHeader { } {
49  puts "Testing: Generic Header ..."
50  tol::console eval {Set setGenHead = [[ [[1,2,3]], [[2,4]], [[6,7,8]] ]]; }
[4865c64]51  tol::tableset create tblset {Set setGenHead}
[6d7779d]52  # test the results
53  set header_type [tblset info header]
54  if { [string equal $header_type "generic"] } {
55    puts "Header type '$header_type' ok"
56    set idx 1
57    foreach lstColInfo [tblset info columns] {
58      array set arrColInfo $lstColInfo
59      if { [string equal $arrColInfo(name) "Column$idx"] } {
60        puts "Column $idx name '$arrColInfo(name)' ok"
61      } else {
62        puts "Column $idx name check failed: $arrColInfo(name) and should be Column$idx"
63      }
64      incr idx
65    }
66  } else {
67    puts "Header type check failed: [tblset info header] and should be generic"
68  }
69  tol::tableset destroy tblset
70  tol::console stack release setGenHead
71}
72
73#//////////////////////////////////////////////////////////////////////////////
74#
75# PROCEDURE: TestStructHeader
76#
77# PURPOSE: test over a set with Struct header
78#
79#//////////////////////////////////////////////////////////////////////////////
80
81
82proc TestStructHeader { } {
83  puts "Testing: Struc Header ..."
84  tol::console eval {Struct STR { Real RealField; Text TextField };}
85  tol::console eval {Set SET = [[ STR(1,"value1"), STR(2,"value2") ]];}
[4865c64]86  tol::tableset create tblset {Set SET}
[6d7779d]87  # test the results
88  set header_type [tblset info header]
89  if { [string equal $header_type "struct"] } {
90    puts "Header type '$header_type' ok"
91    set idx 1
92    foreach name {"RealField" "TextField"} lstColInfo [tblset info columns] {
93      array set arrColInfo $lstColInfo
94      if { [string equal $arrColInfo(name) $name] } {
95        puts "Column $idx name '$name' ok"
96      } else {
97        puts "Column $idx name check failed: '$arrColInfo(name)' and should be '$name'"
98      }
99      incr idx
100    }
101  } else {
102    puts "Header type check failed: $header_type and should be struct"
103  }
104  tol::tableset destroy tblset
105  tol::console stack release STR SET
106}
107
108#//////////////////////////////////////////////////////////////////////////////
109#
110# PROCEDURE: TestRowHeader
111#
112# PURPOSE: test over a set with row header
113#
114#//////////////////////////////////////////////////////////////////////////////
115
116proc TestRowHeader { } {
117  puts "Testing: Row Header ..."
118  tol::console eval {Set setGenHead = \
119                         [[ [["A","B","C"]], [[1,2,3]], [[2,4]], [[6,7,8]] ]]; }
[4865c64]120  tol::tableset create tblset {Set setGenHead}
[6d7779d]121  # test the results
122  set header_type [tblset info header]
123  if { [string equal [lindex $header_type 0] "row"] } {
124    puts "Header type '$header_type' ok"
125    set idx 1
126    foreach name {"A" "B" "C"} lstColInfo [tblset info columns] {
127      array set arrColInfo $lstColInfo
128      if { [string equal $arrColInfo(name) $name] } {
129        puts "Column $idx name '$name' ok"
130      } else {
131        puts "Column $idx name check failed: '$arrColInfo(name)' and should be '$name'"
132      }
133      incr idx
134    }
135  } else {
136    puts "Header type check failed: [tblset info header] and should be row"
137  }
138  tol::tableset destroy tblset
139  tol::console stack release setGenHead
140}
141
142#//////////////////////////////////////////////////////////////////////////////
143#
144# PROCEDURE: TestRealData
145#
146# PURPOSE: test over a set with real content
147#
148#//////////////////////////////////////////////////////////////////////////////
149
150proc TestRealData { } {
151  puts "Testing set with real content ..."
152  tol::console eval {Set realSet = [[ [[1,?,3,5,6]], [[4,Real(1/0),?]], [[7,Real(-1/0),9,7]] ]];}
[4865c64]153  tol::tableset create tblset {Set realSet}
[6d7779d]154  puts [tblset info columns]
155  puts [tblset data column 0]
156  puts [tblset data column 1]
157  puts [tblset data column 2]
158  puts [tblset data column 3]
159  puts [tblset data column 4]
160  tol::tableset destroy tblset
161  tol::console stack release realSet
162}
163
164#//////////////////////////////////////////////////////////////////////////////
165#
166# PROCEDURE: TestDateData
167#
168# PURPOSE: test over a set with date content
169#
170#//////////////////////////////////////////////////////////////////////////////
171
172proc TestDateData { } {
173  puts "Testing set with date content ..."
174  tol::console eval {Set dteSet = [[ [["Date1", "Date2"]], [[y1999,y2000]], [[y2001,y2002]] ]];}
[4865c64]175  tol::tableset create tblset {Set dteSet}
[6d7779d]176  puts [tblset info columns]
177  puts [tblset data column 0]
178  puts [tblset data column 1] 
179  tol::tableset destroy tblset
180  tol::console stack release dteSet
181}
182
183#//////////////////////////////////////////////////////////////////////////////
184#
185# PROCEDURE: TestMixedColumn
186#
187# PURPOSE: test over a set with column having all checked data type:
188#          Real, Date, & Text
189#
190#//////////////////////////////////////////////////////////////////////////////
191
192proc TestMixedColumn { } {
193  puts "Testing set with mixed content ..."
194  tol::console eval {Set mixSet = [[ [["Real", "Date", "Text"]],
195                                     [[1,      y2000,   "aaa"]],
196                                     [[2,      y2001,   "bbb"]] ]];}
[4865c64]197  tol::tableset create tblset {Set mixSet}
[6d7779d]198  puts [tblset info columns]
199  puts [tblset data column 0]
200  puts [tblset data column 1] 
201  puts [tblset data column 2] 
202  tol::tableset destroy tblset
203  tol::console stack release mixSet
204}
205
206#//////////////////////////////////////////////////////////////////////////////
207#
208# PROCEDURE: TestTextData
209#
210# PURPOSE: test over a set with generic (Text) content. In fact we'll have a
211#          row that start in Real and Date and will be converted because of
212#          the appearance of a black lamb,  neither Real nor Date SyntaxObject.
213#
214#//////////////////////////////////////////////////////////////////////////////
215
216proc TestTextData { } {
217  puts "Testing set with mixed content ..."
218  tol::console eval {Set mixSet = [[ [["RealMix", "DateMix"]],
219                                     [[1,          y2000,   "aaa", "kkk"]],
220                                     [[y2002,      "aaa",   "bbb"]] ]];}
[4865c64]221  tol::tableset create tblset {Set mixSet}
[6d7779d]222  puts "Header info : [tblset info header]"
223  puts [tblset info columns]
224  puts [tblset data column 0]
225  puts [tblset data column 1] 
226  puts [tblset data column 2] 
227  puts [tblset data column 3] 
228  tol::tableset destroy tblset
229  tol::console stack release mixSet
230}
231
232proc TestError { } {
233  tol::console eval {Set __error = [[ [[ 1, 1.5, 2, 3]],
234                                      [[ 2, 2.5, 5, 2]],
235                                      [[ 3, 3.5, 4   ]],
236                                      [[ 4, 4.5, 0   ]],
237                                      [[ 5, 5.5, 6, 2]],
238                                      [[ 6, 6.5, 1, 6]],
239                                      [[ 7, 7.5, 3   ]],
240                                      [[ 8, 8.5, 4   ]],
241                                      [[ 9, 9.5, 9, 1]],
242                                      [[10,10.5, 2, 4]],
243                                      [[11,11.5, 4   ]],
244                                      [[12,12.5, 7, 8]] ]]; }
[4865c64]245  tol::tableset create tblset {Set __error}
[6d7779d]246  tol::tableset destroy tblset
247}
248
249proc TestNames {  } {
250  tol::console eval {Set row1 = [[Real col1 = 11, Real col2 = 12]];}
251  tol::console eval {Set s1 = [[row1]];}
252 
[4865c64]253  tol::tableset create tbl {Set s1}
[6d7779d]254  puts [tbl info columns]
255  tol::tableset destroy tbl
256  tol::console stack release s1 row1
257}
[4865c64]258
259proc Test_Ticket1450 { } {
260  tol::console eval {
261    Set s2 = BinGroup("|", For(1, 4, Set (Real i) {
262      Set For(1, 10, Set (Real j) {
263        [[j, If(i==j, ?, i+j)]]
264      })
265    }));
266  }
267  tol::tableset create tbls2 {Set s2}
268}
Note: See TracBrowser for help on using the repository browser.