summaryrefslogtreecommitdiffstats
path: root/tests/brodnik.test
blob: efcb415984b8384b3dcf40572cb3df9374626437 (plain)
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
# This file contains a collection of tests for the procedures in the
# file tclBrodnik.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 Tcltest}
    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
	    }
	}
    }

    # Tests for values with MSB in the low block
    variable v 0
    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)} {

	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
    }

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