File: brodnik.test

package info (click to toggle)
tcl9.0 9.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,000 kB
  • sloc: ansic: 219,245; tcl: 23,817; makefile: 3,556; sh: 2,572; ada: 1,681; pascal: 1,139; cpp: 1,001; cs: 879; yacc: 842; asm: 468; perl: 420; xml: 95
file content (72 lines) | stat: -rw-r--r-- 1,754 bytes parent folder | download
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
# This file contains a collection of tests for the routine TclMSB() in the
# file tclUtil.c.
#
# Contributions from Don Porter, NIST, 2013. (not subject to US copyright)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require Tcl 8.6-
package require tcltest 2

namespace eval ::tcl::test::brodnik {
    namespace import ::tcltest::loadTestedCommands
    namespace import ::tcltest::testConstraint
    namespace import ::tcltest::test
    namespace import ::tcltest::cleanupTests

    loadTestedCommands
    try {package require tcl::test}
    testConstraint testmsb [expr {[namespace which -command testmsb] ne {}}]

    namespace eval tcl {
	namespace eval mathfunc {
	    proc log2 {i} {
		set k 0
		while {[set i [expr {$i>>1}]]} {
		    incr k
		}
		return $k
	    }
	}
    }

    # Test out-of-range rejection
    test brodnik-1.0 {TclMSB correctness} -constraints testmsb -body {
	    testmsb 0
    } -returnCodes error -match glob -result *

    # Tests for values with MSB in the low block
    variable v 1
    while {$v < 1<<8} {
	test brodnik-1.$v {TclMSB correctness} testmsb {
	    testmsb $v
	} [expr {int(log2($v))}]
	incr v
    }

    variable i 8
    while {$i < 8*$::tcl_platform(pointerSize) - 1} {

	variable j -1
	while {$j < 2} {
	    set v [expr {(1<<$i) + $j}]

	    test brodnik-2.$i.$j {TclMSB correctness} testmsb {
		testmsb $v
	    } [expr {int(log2($v))}]

	    incr j
	}
	incr i
    }

    # Test out-of-range rejection
    test brodnik-3.0 {TclMSB correctness} -constraints testmsb -body {
	    testmsb [expr 1<<64]
    } -returnCodes error -match glob -result *

    cleanupTests
}
namespace delete ::tcl::test::brodnik
return