1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
# -*- tcl -*-
# Tests for the counter module.
#
# This file contains a collection of tests for a module in the
# Standard Tcl Library. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: counter.test,v 1.13 2006/10/09 21:41:40 andreas_kupries Exp $
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.2
testsNeedTcltest 1.0
testing {
useLocal counter.tcl counter
}
# -------------------------------------------------------------------------
proc Stamp {tag} {
puts stderr "[clock format [clock seconds]] [clock clicks -milliseconds] $tag"
}
# -------------------------------------------------------------------------
test counter-1.1 {counter::init} {
catch {counter::init} err
} {1}
if 0 {
set x 0
puts "incr scaler [time {incr x} 100]"
set a(x) 0
puts "incr array [time {incr a(x)} 100]"
set a(x) 0
set a(n) 0
puts "rawcount [time {
set a(x) [expr {$a(x) + 2.4}]
incr a(n)
} 100]"
}
test counter-simple {counter::count} {
counter::init simple
counter::count simple
counter::count simple
counter::count simple
counter::get simple
} {3}
#puts "simple [time {counter::count simple} 100]"
test counter-avg-1.0 {counter::count} {
counter::init avg
counter::count avg 2.2
counter::count avg 3.3
counter::count avg 9.8
format %3.1f [counter::get avg -avg]
} {5.1}
test counter-avg-1.1 {counter::count} {
counter::init avg
counter::get avg -avg
} {0}
test counter-lastn-1.0 {averge over lastn} {
counter::init lastn -lastn 4
counter::count lastn 2.2
counter::count lastn 4.6
counter::get lastn -avgn
} {3.4}
test counter-lastn-1.1 {averge over lastn} {
counter::init lastn -lastn 4
counter::count lastn 2.2
counter::count lastn 3.3
counter::count lastn 8.6
counter::count lastn 4.1
counter::count lastn 6.9
counter::count lastn 0.4
counter::get lastn -avgn
} {5.0}
#puts "lastn [time {counter::count lastn 2.4} 100]"
test counter-lastn-1.2 {lifetime average} {
counter::init lastn -lastn 4
counter::count lastn 2.2
counter::count lastn 3.3
counter::count lastn 8.6
counter::count lastn 4.1
counter::count lastn 6.9
counter::count lastn 0.4
counter::get lastn -avg
} {4.25}
#puts "lastn [time {counter::count lastn 2.4} 100]"
test counter-hist-1.0 {basic histogram} {
counter::init hist -hist 10
counter::count hist 2.2
counter::count hist 18.6
counter::count hist 14.1
counter::count hist 26.9
counter::count hist 20.4
counter::count hist 23.3
counter::count hist 53.3
counter::get hist -hist
} {0 1 1 2 2 3 5 1}
test counter-hist-1.1 {histogram average} {
counter::init hist -hist 10
counter::count hist 2.2
counter::count hist 18.6
counter::count hist 14.1
counter::count hist 26.9
counter::count hist 20.4
counter::count hist 23.3
counter::count hist 53.3
format %13.10f [counter::get hist -avg]
} {22.6857142857}
#puts "hist [time {counter::count hist 2.4} 100]"
test counter-hist2x {counter::count} {
counter::init hist -hist2x 10
counter::count hist 8
counter::count hist 18
counter::count hist 28
counter::count hist 38
counter::count hist 48
counter::count hist 58
counter::count hist 68
counter::count hist 78
counter::count hist 178
counter::count hist 478
counter::get hist -hist
} {0 1 1 1 2 2 3 4 5 1 6 1}
#puts "hist2x [time {counter::count hist 50} 100]"
test counter-hist10x {counter::count} {
counter::init hist -hist10x 10
counter::count hist 8
counter::count hist 18
counter::count hist 28
counter::count hist 38
counter::count hist 48
counter::count hist 58
counter::count hist 68
counter::count hist 78
counter::count hist 178
counter::count hist 478
counter::count hist 1478
counter::count hist 1478000
counter::get hist -hist
} {0 1 1 7 2 2 3 1 6 1}
test counter-histlog {counter::count} {
counter::init histlog -histlog 1
counter::count histlog 0.1
counter::count histlog 0.5
counter::count histlog 0.9
counter::count histlog 1.0
counter::count histlog 2
counter::count histlog 3
counter::count histlog 5
counter::count histlog 10
counter::count histlog 30
counter::count histlog 50
counter::count histlog 100
counter::count histlog 300
counter::count histlog 500
counter::count histlog 1000
counter::get histlog -hist
} {-2 1 0 4 1 2 2 1 3 2 4 1 5 1 6 2}
test counter-timehist {counter::count} {load-dependent} {
counter::init hits -timehist 4
catch {#puts stderr "Pausing during timehist tests"}
counter::count hits 2
# We need to reach in and find out what bucket was used
array set info [counter::get hits -all]
set min0 $info(lastMinute)
after [expr 4000]
counter::count hits 4
after [expr 4000]
counter::count hits 8
set result [list]
foreach {n v} [counter::get hits -hist] {
if {$v > 0} {
lappend result [expr {$n - $min0}] $v
}
}
#puts "timehist [time {counter::count hits} 100]"
set result
} {0 2 1 4 2 8}
test counter-countNames {counter::names} {
counter::init simple
counter::init avg
counter::init lastn -lastn 4
counter::init hist -hist 10
counter::init histlog -histlog 1
counter::init hits -timehist 4
lsort [counter::names]
} {avg hist histlog hits lastn simple}
test counter-countExists {counter::exists} {
counter::init simple
counter::init lastn -lastn 4
unset counter::T-lastn
list [counter::exists simple] [counter::exists lastn]
} {1 0}
test counter-countReset {counter::reset} {
counter::init simple
counter::count simple 1
counter::count simple 1
counter::count simple 1
counter::reset simple
counter::get simple
} {0}
testsuiteCleanup
|