Integration part of tests of grid chl
[occt.git] / tests / bugs / begin
1 # File : begin
2 if { [array get Draw_Groups "TOPOLOGY Check commands"] == "" } {
3     pload TOPTEST
4     pload VISUALIZATION
5 #    set env(CSF_DrawPluginQADefaults) $env(CASROOT)/src/DrawResources/.
6 #    pload QAcommands
7 #    pload -DrawPluginQA QAcommands
8 }
9
10 # to prevent loops limit to 16 minutes
11 cpulimit 1000
12
13 #set script_dir [file dirname [info script]]/script
14 # if { [info exist WorkDirectory] == 0 } {
15 #    set WorkDirectory "/tmp"
16 #    if { [array get env TEMP] != "" } {
17 #       set WorkDirectory "$env(TEMP)"
18 #       }
19 #    }
20
21 if { [info exists imagedir] == 0 } {
22    set imagedir .
23 }
24 if { [info exists test_image] == 0 } {
25    set test_image photo
26 }
27
28 # Procedure to check if sequence of values in listval follows linear trend
29 # adding the same delta on each step.
30 #
31 # The function does statistical estimation of the mean variation of the
32 # values of the sequence, and dispersion, and returns true only if both 
33 # dispersion and deviation of the mean from expected delta are within 
34 # specified tolerance.
35 #
36 # If mean variation differs from expected delta on more than two dispersions,
37 # the check fails and procedure raises error with specified message.
38 #
39 # Otherwise the procedure returns false meaning that more iterations are needed.
40 # Note that false is returned in any case if length of listval is less than 3.
41 #
42 # See example of use to check memory leaks in bugs/caf/bug23489
43 #
44 proc checktrend {listval delta tolerance message} {
45     set nbval [llength $listval]
46     if { $nbval < 3} {
47         return 0
48     }
49
50     # calculate mean value
51     set mean 0.
52     set prev [lindex $listval 0]
53     foreach val [lrange $listval 1 end] {
54         set mean [expr $mean + ($val - $prev)]
55         set prev $val
56     }
57     set mean [expr $mean / $nbval]
58
59     # calculate dispersion
60     set sigma 0.
61     set prev [lindex $listval 0]
62     foreach val [lrange $listval 1 end] {
63         set d [expr ($val - $prev) - $mean]
64         set sigma [expr $sigma + $d * $d]
65         set prev $val
66     }
67     set sigma [expr sqrt ($sigma / ($nbval - 1))]
68
69     puts "Checking trend: nb = $nbval, mean delta = $mean, sigma = $sigma"
70
71     # check if deviation is definitely too big
72     if { abs ($mean - $delta) > 2. * $sigma } {
73         puts "Checking trend failed: mean delta per step = $mean, sigma = $sigma, expected delta = $delta"
74         error $message
75     }
76
77     # check if deviation is clearly within a range
78     return [expr abs ($mean - $delta) <= $sigma && $sigma <= $tolerance]
79 }