%%
%% This is file `bitset-test3.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bitset.dtx  (with options: `test2,noetex')
%% 
%% This is a generated file.
%% 
%% Project: bitset
%% Version: 2011/01/30 v1.1
%% 
%% Copyright (C) 2007, 2011 by
%%    Heiko Oberdiek <heiko.oberdiek at googlemail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% This Current Maintainer of this work is Heiko Oberdiek.
%% 
%% The Base Interpreter refers to any `TeX-Format',
%% because some files are installed in TDS:tex/generic//.
%% 
%% This work consists of the main source file bitset.dtx
%% and the derived files
%%    bitset.sty, bitset.pdf, bitset.ins, bitset.drv, bitset-test1.tex,
%%    bitset-test2.tex, bitset-test3.tex.
%% 
\NeedsTeXFormat{LaTeX2e}
\nofiles
\documentclass{article}
\makeatletter
\let\SavedNumexpr\numexpr
\let\SavedIfcsname\ifcsname
\let\SavedCurrentgrouplevel\currentgrouplevel
\def\ETeXDisable{%
  \let\ifcsname\@undefined
  \let\numexpr\@undefined
  \let\currentgrouplevel\@undefined
}
\ETeXDisable
\makeatletter
\chardef\BitSet@TestMode=1 %
\makeatother
\usepackage{bitset}[2011/01/30]
\def\ETeXEnable{%
  \let\numexpr\SavedNumexpr
  \let\ifcsname\SavedIfcsname
  \let\currentgrouplevel\SavedCurrentgrouplevel
}
\ETeXEnable
\usepackage{qstest}
\IncludeTests{*}
\LogTests{log}{*}{*}
\makeatletter
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pdfresettimer\endcsname\relax
\else
  \newcount\SummaryTime
  \newcount\TestTime
  \SummaryTime=\z@
  \newcommand*{\PrintTime}[2]{%
    \typeout{%
      [Time #1: \strip@pt\dimexpr\number#2sp\relax\space s]%
    }%
  }%
  \newcommand*{\StartTime}[1]{%
    \renewcommand*{\TimeDescription}{#1}%
    \pdfresettimer
  }%
  \newcommand*{\TimeDescription}{}%
  \newcommand*{\StopTime}{%
    \TestTime=\pdfelapsedtime
    \global\advance\SummaryTime\TestTime
    \PrintTime\TimeDescription\TestTime
  }%
  \let\saved@qstest\qstest
  \let\saved@endqstest\endqstest
  \def\qstest#1#2{%
    \saved@qstest{#1}{#2}%
    \StartTime{#1}%
  }%
  \def\endqstest{%
    \StopTime
    \saved@endqstest
  }%
  \AtEndDocument{%
    \PrintTime{summary}\SummaryTime
  }%
\fi
\let\orig@qstest\qstest
\let\orig@endqstest\endqstest
\def\qstest#1#2{%
  \orig@qstest{#1}{#2}%
  \setbox0\hbox\bgroup\begingroup\ignorespaces
}
\def\endqstest{%
  \endgroup\egroup
  \Expect*{\the\wd0}{0.0pt}%
  \orig@endqstest
}
\newcounter{Test}

\def\TestError#1#2{%
  \begingroup
    \setcounter{Test}{0}%
    \sbox0{%
      \def\@PackageError##1##2##3{%
        \stepcounter{Test}%
        \begingroup
          \let\MessageBreak\relax
          \ETeXEnable
          \Expect{##1}{bitset}%
          \Expect*{##2}*{#1}%
        \endgroup
      }%
      \ETeXDisable
      #2%
    }%
    \Expect*{\theTest}{1}%
    \Expect*{\the\wd0}{0.0pt}%
  \endgroup
}

\def\TestErrorNegativeIndex#1#2{%
  \TestError{Invalid negative index (#1)}{#2}%
}

\def\TestGetterUndefined#1{%
  \CheckUndef{dummy}%
  \expandafter\expandafter\expandafter\Expect
  \expandafter\expandafter\expandafter{#1{dummy}}{0}%
}

\def\ExpectBitSet#1#2{%
  \expandafter\expandafter\expandafter\Expect
  \expandafter\expandafter\expandafter
  {\csname BS@#1\endcsname}*{#2}%
}
\def\Check#1#2{%
  \ExpectBitSet{#1}{#2}%
}
\def\CheckUndef#1{%
  \begingroup
    \Expect*{%
      \expandafter
      \ifx\csname BS@#1\endcsname\relax true\else false\fi
    }{true}%
  \endgroup
}
\def\RevCheck#1#2{%
  \ExpectBitSet{#1}{\Reverse#2!!}%
}
\def\Set#1#2{%
  \expandafter\def\csname BS@#1\endcsname{#2}%
}
\def\RevSet#1#2{%
  \expandafter\edef\csname BS@#1\endcsname{%
    \Reverse#2!!%
  }%
}
\def\Reverse#1#2!#3!{%
  \ifx\\#2\\%
    #1#3%
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\Reverse#2!#1#3!}%
}
\begin{qstest}{Let}{Let}
  \CheckUndef{abc}%
  \CheckUndef{xyz}%
  \bitsetLet{xyz}{abc}%
  \CheckUndef{abc}%
  \Check{xyz}{0}%
  \Set{abc}{1}%
  \Check{abc}{1}%
  \Check{xyz}{0}%
  \bitsetLet{xyz}{abc}%
  \Check{abc}{1}%
  \Check{xyz}{1}%
  \Set{xyz}{11}%
  \Check{abc}{1}%
  \Check{xyz}{11}%
\end{qstest}

\begin{qstest}{Reset}{Reset}
  \bitsetReset{xyz}%
  \Check{xyz}{0}%
  \bitsetReset{abc}%
  \Check{abc}{0}%
  \Set{abc}{10101}%
  \bitsetReset{abc}%
  \Check{abc}{0}%
\end{qstest}

\begin{qstest}{Get/Query}{Get/Query}
  \expandafter\expandafter\expandafter\Expect
  \expandafter\expandafter\expandafter{%
    \bitsetGet{dummy}{0}%
  }{0}%
  \begingroup
    \expandafter\def\csname BitSetError:NegativeIndex\endcsname{}%
    \Set{abc}{1}%
    \Expect*{\bitsetQuery{abc}{-1}{true}{false}}{false}%
  \endgroup
  \def\Test#1#2#3{%
    \Set{abc}{#1}%
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{\bitsetGet{abc}{#2}}{#3}%
    \Expect*{\bitsetQuery{abc}{#2}{true}{false}}%
           *{\ifcase#3 false\or true\else error\fi}%
  }%
  \Test{1}{100}{0}%
  \Test{0}{0}{0}%
  \Test{1}{0}{1}%
  \Test{11}{1}{1}%
  \Test{111}{1}{1}%
  \Test{101}{1}{0}%
  \Test{101}{2}{1}%
  \Test{10100110011}{10}{1}%
\end{qstest}

\begin{qstest}{Size}{Size}
  \TestGetterUndefined\bitsetSize
  \def\Test#1#2{%
    \Set{abc}{#1}%
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{\bitsetSize{abc}}{#2}%
  }%
  \Test{0}{0}%
  \Test{1}{1}%
  \Test{00}{0}%
  \Test{0000000}{0}%
  \Test{10}{1}%
  \Test{01}{2}%
  \Test{11}{2}%
  \Test{010}{2}%
  \Test{011}{3}%
  \Test{100110011}{9}%
  \Test{0000011111000001111100000}{20}%
  \Test{000000000000000000000000011111111111111111111}{45}%
\end{qstest}

\begin{qstest}{Cardinality}{Cardinality}
  \TestGetterUndefined\bitsetCardinality
  \def\Test#1#2{%
    \Set{abc}{#1}%
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \bitsetCardinality{abc}%
    }{#2}%
  }%
  \Test{0}{0}%
  \Test{1}{1}%
  \Test{00}{0}%
  \Test{0000000}{0}%
  \Test{10}{1}%
  \Test{01}{1}%
  \Test{11}{2}%
  \Test{010}{1}%
  \Test{011}{2}%
  \Test{100110011}{5}%
  \Test{0000011111000001111100000}{10}%
  \Test{000000000000000000000000011111111111111111111}{20}%
\end{qstest}

\begin{qstest}{NextClearBit/NextSetBit}{NextClearBit/NextSetBit}
  \def\Test#1#2{%
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \TestOp{abc}{#1}%
    }{#2}%
  }%
  \def\Clear{\let\TestOp\bitsetNextClearBit}%
  \def\Set{\let\TestOp\bitsetNextSetBit}%
  \begingroup
    \catcode`\:=11 %
    \bitsetSetBin{abc}{1}%
    \Clear
    \Test{-1}{1\BitSetError:NegativeIndex}%
    \Set
    \Test{-1}{0\BitSetError:NegativeIndex}%
  \endgroup
  \let\BS@abc\@undefined
  \Clear
  \Test{0}{0}%
  \Test{1}{1}%
  \Test{2}{2}%
  \Test{100}{100}%
  \Set
  \Test{0}{-1}%
  \Test{1}{-1}%
  \Test{100}{-1}%
  \bitsetReset{abc}%
  \Clear
  \Test{0}{0}%
  \Test{1}{1}%
  \Test{2}{2}%
  \Test{100}{100}%
  \Set
  \Test{0}{-1}%
  \Test{1}{-1}%
  \Test{100}{-1}%
  \bitsetSetBin{abc}{1}%
  \Clear
  \Test{0}{1}%
  \Test{1}{1}%
  \Test{2}{2}%
  \Test{100}{100}%
  \Set
  \Test{0}{0}%
  \Test{1}{-1}%
  \Test{100}{-1}%
  \bitsetSetBin{abc}{111000111000111000111}%
  \Clear
  \Test{0}{3}%
  \Test{1}{3}%
  \Test{2}{3}%
  \Test{3}{3}%
  \Test{4}{4}%
  \Test{5}{5}%
  \Test{6}{9}%
  \Test{7}{9}%
  \Test{8}{9}%
  \Test{9}{9}%
  \Test{10}{10}%
  \Test{11}{11}%
  \Test{12}{15}%
  \Test{13}{15}%
  \Test{14}{15}%
  \Test{15}{15}%
  \Test{16}{16}%
  \Test{17}{17}%
  \Test{18}{21}%
  \Test{19}{21}%
  \Test{20}{21}%
  \Test{21}{21}%
  \Test{22}{22}%
  \Test{100}{100}%
  \Set
  \Test{0}{0}%
  \Test{1}{1}%
  \Test{2}{2}%
  \Test{3}{6}%
  \Test{4}{6}%
  \Test{5}{6}%
  \Test{6}{6}%
  \Test{7}{7}%
  \Test{8}{8}%
  \Test{9}{12}%
  \Test{10}{12}%
  \Test{11}{12}%
  \Test{12}{12}%
  \Test{13}{13}%
  \Test{14}{14}%
  \Test{15}{18}%
  \Test{16}{18}%
  \Test{17}{18}%
  \Test{18}{18}%
  \Test{19}{19}%
  \Test{20}{20}%
  \Test{21}{-1}%
  \Test{22}{-1}%
  \Test{100}{-1}%
  \bitsetSetBin{abc}{1111111}%
  \Clear
  \Test{6}{7}%
  \Test{7}{7}%
  \Test{8}{8}%
  \Test{100}{100}%
  \Set
  \Test{6}{6}%
  \Test{7}{-1}%
  \Test{8}{-1}%
  \Test{100}{-1}%
  \bitsetSetBin{abc}{11111111}%
  \Clear
  \Test{7}{8}%
  \Test{8}{8}%
  \Test{9}{9}%
  \Test{100}{100}%
  \Set
  \Test{7}{7}%
  \Test{8}{-1}%
  \Test{9}{-1}%
  \Test{100}{-1}%
  \bitsetSetBin{abc}{111111111}%
  \Clear
  \Test{8}{9}%
  \Test{9}{9}%
  \Test{10}{10}%
  \Test{100}{100}%
  \Set
  \Test{8}{8}%
  \Test{9}{-1}%
  \Test{10}{-1}%
  \Test{100}{-1}%
  \bitsetSetBin{abc}{1111111111}%
  \Clear
  \Test{9}{10}%
  \Test{10}{10}%
  \Test{11}{11}%
  \Test{100}{100}%
  \Set
  \Test{9}{9}%
  \Test{10}{-1}%
  \Test{11}{-1}%
  \Test{100}{-1}%
\end{qstest}

\begin{qstest}{GetSetBitList}{GetSetBitList}
  \let\BS@abc\@undefined
  \expandafter\expandafter\expandafter\Expect
  \expandafter\expandafter\expandafter{%
    \bitsetGetSetBitList{abc}%
  }{}%
  \def\Test#1#2{%
    \bitsetSetBin{abc}{#1}%
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \bitsetGetSetBitList{abc}%
    }{#2}%
  }%
  \Test{0}{}%
  \Test{1}{0}%
  \Test{10}{1}%
  \Test{11}{0,1}%
  \Test{10110100}{2,4,5,7}%
  \Test{101101001010011}{0,1,4,6,9,11,12,14}%
\end{qstest}

\begin{qstest}{GetDec}{GetDec}
  \TestGetterUndefined\bitsetGetDec
  \def\Test#1#2{%
    \RevSet{abc}{#1}%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \bitsetGetDec{abc}%
    }{#2}%
  }%
  \Test{0}{0}%
  \Test{1}{1}%
  \Test{10}{2}%
  \Test{11}{3}%
  \Test{100}{4}%
  \Test{101}{5}%
  \Test{110}{6}%
  \Test{111}{7}%
  \Test{1000}{8}%
  \Test{000111}{7}%
  \Test{1111111111111111%
        111111111111111}{2147483647}%
  \Test{0001111111111111111%
        111111111111111}{2147483647}%
  \Test{1000000000000000%
        0000000000000000}{2147483648}%
  \Test{1000000000000000%
        00000000000000000}{4294967296}%
  \Test{0001000000000000000%
        00000000000000000}{4294967296}%
  \Test{1100000000000000%
        00000000000000011}{6442450947}%
\end{qstest}

\begin{qstest}{Clear}{Clear}
  \def\Test#1#2#3{%
    \RevSet{abc}{#1}%
    \bitsetClear{abc}{#2}%
    \Expect*{\BS@abc}*{\Reverse#3!!}%
  }%
  \bitsetClear{abc}{2}%
  \RevCheck{abc}{0}%
  \TestErrorNegativeIndex{-1}{\bitsetClear{abc}{-1}}%
  \RevCheck{abc}{0}%
  \Test{0}{0}{0}%
  \Test{1}{0}{0}%
  \Test{111}{1}{101}%
  \Test{111}{30}{111}%
  \Test{0000111}{5}{0000111}% 111 would also be ok
  \Test{10000111}{5}{10000111}%
  \Test{1001001}{3}{1000001}%
\end{qstest}

\begin{qstest}{Set}{Set}
  \def\Test#1#2#3{%
    \RevSet{abc}{#1}%
    \bitsetSet{abc}{#2}%
    \Expect*{\BS@abc}*{\Reverse#3!!}%
  }%
  \bitsetSet{abc}{2}%
  \RevCheck{abc}{100}%
  \TestErrorNegativeIndex{-1}{\bitsetSet{abc}{-1}}%
  \RevCheck{abc}{100}%
  \Test{0}{0}{1}%
  \Test{1}{0}{1}%
  \Test{100}{1}{110}%
  \Test{111}{1}{111}%
  \Test{11}{1}{11}%
  \Test{11}{2}{111}%
  \Test{11}{3}{1011}%
  \Test{111}{10}{10000000111}%
  \Test{0000111}{5}{0100111}% 100111 would also be ok
  \Test{10000111}{5}{10100111}%
  \Test{1000001}{3}{1001001}%
  \Test{1001001}{3}{1001001}%
\end{qstest}

\begin{qstest}{Flip}{Flip}
  \def\Test#1#2#3{%
    \RevSet{abc}{#1}%
    \bitsetFlip{abc}{#2}%
    \Expect*{\BS@abc}*{\Reverse#3!!}%
  }%
  \bitsetFlip{abc}{2}%
  \RevCheck{abc}{100}%
  \TestErrorNegativeIndex{-1}{\bitsetFlip{abc}{-1}}%
  \RevCheck{abc}{100}%
  \Test{0}{0}{1}%
  \Test{1}{0}{0}%
  \Test{0}{2}{100}%
  \Test{100}{1}{110}%
  \Test{111}{1}{101}%
  \Test{11}{1}{1}%
  \Test{11}{2}{111}%
  \Test{11}{3}{1011}%
  \Test{111}{10}{10000000111}%
  \Test{0000111}{5}{0100111}% 100111 would also be ok
  \Test{10000111}{5}{10100111}%
  \Test{1000001}{3}{1001001}%
  \Test{1001001}{3}{1000001}%
  \Test{11111}{2}{11011}%
\end{qstest}

\begin{qstest}{SetValue}{SetValue}
  \def\Test#1#2{%
    \TestError{Invalid bit value (#2) not in range 0..1}{%
      \bitsetSetValue{abc}{#1}{#2}%
    }%
  }%
  \Test{0}{-1}%
  \Test{0}{2}%
  \Test{0}{10}%
  \def\Test#1#2#3{%
    \let\BS@abc\@undefined
    \bitsetSetValue{abc}{#1}{#2}%
    \bitsetSetBin{result}{#3}%
    \Expect*{\BS@abc}*{\BS@result}%
  }%
  \Test{0}{0}{0}%
  \Test{0}{1}{1}%
  \Test{1}{0}{0}%
  \Test{1}{1}{10}%
  \def\Test#1#2#3#4{%
    \bitsetSetBin{abc}{#1}%
    \bitsetSetBin{result}{#4}%
    \bitsetSetValue{abc}{#2}{#3}%
    \Expect*{\BS@abc}*{\BS@result}%
  }%
  \Test{0}{0}{0}{0}%
  \Test{0}{0}{0}{0}%
  \Test{0}{0}{1}{1}%
  \Test{0}{1}{0}{0}%
  \Test{0}{1}{1}{10}%
  \Test{1010}{2}{1}{1110}%
  \Test{1010}{4}{1}{11010}%
  \Test{1010}{6}{1}{1001010}%
  \Test{1010}{1}{0}{1000}%
  \Test{1010}{2}{0}{1010}%
  \Test{1010}{3}{0}{10}%
  \Test{1010}{4}{0}{1010}%
  \Test{1010}{6}{0}{1010}%
  \Test{1010}{2}{\csname iffalse\endcsname 0\else 1\fi}{1110}%
  \Test{1010}{1}{\csname iffalse\endcsname 1\else 0\fi}{1000}%
\end{qstest}

\begin{qstest}{IsDefined}{IsDefined}
  \let\BS@abc\@undefined
  \Expect*{\bitsetIsDefined{abc}{true}{false}}{false}%
  \bitsetReset{abc}%
  \Expect*{\bitsetIsDefined{abc}{true}{false}}{true}%
\end{qstest}

\begin{qstest}{IsEmpty}{IsEmpty}
  \let\BS@abc\@undefined
  \Expect*{\bitsetIsEmpty{abc}{true}{false}}{true}%
  \bitsetReset{abc}%
  \Expect*{\bitsetIsEmpty{abc}{true}{false}}{true}%
  \bitsetSet{abc}{1}%
  \Expect*{\bitsetIsEmpty{abc}{true}{false}}{false}%
\end{qstest}

\begin{qstest}{Equals}{Equals}
  \def\Test#1#2#3{%
    \Expect*{\bitsetEquals{#1}{#2}{true}{false}}{#3}%
  }%
  \let\BS@abc\@undefined
  \Test{abc}{abc}{true}%
  \Test{abc}{foo}{true}%
  \Test{foo}{abc}{true}%
  \bitsetReset{abc}%
  \Test{abc}{abc}{true}%
  \Test{abc}{foo}{false}%
  \Test{foo}{abc}{false}%
  \bitsetReset{foo}%
  \Test{abc}{foo}{true}%
  \Test{foo}{abc}{true}%
  \bitsetSet{abc}{4}%
  \Test{abc}{foo}{false}%
  \Test{foo}{abc}{false}%
  \bitsetFlip{foo}{4}%
  \Test{abc}{foo}{true}%
  \Test{foo}{abc}{true}%
\end{qstest}

\begin{qstest}{Intersects}{Intersects}
  \def\Test#1{%
    \Expect*{\bitsetIntersects{abc}{foo}{true}{false}}{#1}%
  }%
  \let\BS@abc\@undefined
  \let\BS@foo\@undefined
  \Test{false}%
  \Set{abc}{0}%
  \Test{false}%
  \Set{foo}{0}%
  \Test{false}%
  \let\BS@abc\@undefined
  \Test{false}%
  \Set{foo}{1}%
  \Test{false}%
  \Set{abc}{0}%
  \Test{false}%
  \Set{abc}{1}%
  \Test{true}%
  \let\BS@foo\@undefined
  \Test{false}%
  \Set{foo}{0}%
  \Test{false}%
  \def\Test#1#2#3{%
    \bitsetSetBin{abc}{#1}%
    \bitsetSetBin{foo}{#2}%
    \Expect*{\bitsetIntersects{abc}{foo}{true}{false}}{#3}%
  }%
  \Test{1010}{0101}{false}%
  \Test{0}{10}{false}%
  \Test{1}{11}{true}%
  \Test{11}{1}{true}%
  \Test{10}{1}{false}%
\end{qstest}

\begin{qstest}{And/AndNot/Or/Xor}{And/AndNot/Or/Xor}
  \def\@Test#1#2#3#4#5{%
    \begingroup
      #5%
      \begingroup
        \let\BS@foo\@undefined
        \csname bitset#1\endcsname{abc}{foo}%
        \CheckUndef{foo}%
        \Check{abc}{#2}%
      \endgroup
      \begingroup
        \bitsetReset{foo}%
        \csname bitset#1\endcsname{abc}{foo}%
        \Check{foo}{0}%
        \Check{abc}{#3}%
      \endgroup
      \begingroup
        \def\BS@foo{0101}%
        \csname bitset#1\endcsname{abc}{foo}%
        \Check{foo}{0101}%
        \Check{abc}{#4}%
      \endgroup
    \endgroup
  }%
  \def\Test#1{%
    \def\Op{#1}%
    \Test@
  }%
  \def\Test@#1#2#3#4#5#6#7#8#9{%
    \@Test\Op{#1}{#2}{#3}{%
      \let\BS@abc\@undefined
    }%
    \@Test\Op{#4}{#5}{#6}{%
      \bitsetReset{abc}%
    }%
    \@Test\Op{#7}{#8}{#9}{%
      \def\BS@abc{1001}%
    }%
  }%
  \Test{And}%
       {0}{0}{0}%
       {0}{0}{0}%
       {0}{0}{0001}%
  \Test{AndNot}%
       {0}{0}{0}%
       {0}{0}{0}%
       {1001}{1001}{1}%
  \Test{Or}%
       {0}{0}{0101}%
       {0}{0}{0101}%
       {1001}{1001}{1101}%
  \Test{Xor}%
       {0}{0}{0101}%
       {0}{0}{0101}%
       {1001}{1001}{11}%
  \def\Test#1#2#3{%
    \bitsetSetBin{abc}{#1}%
    \bitsetSetBin{foo}{#2}%
    \csname bitset\Op\endcsname{abc}{foo}%
    \RevCheck{foo}{#2}%
    \RevCheck{abc}{#3}%
  }%
  \def\Op{And}%
  \Test{1}{111}{1}%
  \Test{111}{1}{1}%
  \Test{10}{111}{10}%
  \Test{111}{10}{10}%
  \Test{111}{1000}{0}%
  \Test{1000}{111}{0}%
  \def\Op{AndNot}%
  \Test{1010}{11}{1000}%
  \Test{100}{100}{0}%
  \Test{111}{1111}{0}%
  \Test{100}{111}{0}%
  \def\Op{Or}%
  \Test{0}{0}{0}%
  \Test{1}{0}{1}%
  \Test{0}{1}{1}%
  \Test{1}{1}{1}%
  \Test{1000}{10}{1010}%
  \Test{10}{1000}{1010}%
  \def\Op{Xor}%
  \Test{0}{0}{0}%
  \Test{1}{0}{1}%
  \Test{0}{1}{1}%
  \Test{1}{1}{0}%
  \Test{1000}{10}{1010}%
  \Test{10}{1000}{1010}%
  \Test   {110011001100}%
       {111000111000111}%
       {111110100001011}%
  \Test{111000111000111}%
          {110011001100}%
       {111110100001011}%
\end{qstest}

\begin{qstest}{GetUndef}{GetUndef, GetBin, GetOct, GetHex}
  \def\TestUndef#1#2{%
    \let\BS@abc\@undefined
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \x{abc}{#1}%
    }{#2}%
  }%
  \let\x\bitsetGetBin
  \TestUndef{-1}{0}%
  \TestUndef{0}{0}%
  \TestUndef{1}{0}%
  \TestUndef{2}{00}%
  \TestUndef{8}{00000000}%
  \let\x\bitsetGetOct
  \TestUndef{-1}{0}%
  \TestUndef{0}{0}%
  \TestUndef{1}{0}%
  \TestUndef{2}{0}%
  \TestUndef{3}{0}%
  \TestUndef{4}{00}%
  \TestUndef{5}{00}%
  \TestUndef{6}{00}%
  \TestUndef{7}{000}%
  \TestUndef{8}{000}%
  \TestUndef{9}{000}%
  \TestUndef{10}{0000}%
  \let\x\bitsetGetHex
  \TestUndef{-1}{0}%
  \TestUndef{0}{0}%
  \TestUndef{1}{0}%
  \TestUndef{2}{0}%
  \TestUndef{3}{0}%
  \TestUndef{4}{0}%
  \TestUndef{5}{00}%
  \TestUndef{6}{00}%
  \TestUndef{7}{00}%
  \TestUndef{8}{00}%
  \TestUndef{9}{000}%
  \TestUndef{10}{000}%
  \TestUndef{12}{000}%
  \TestUndef{13}{0000}%
  \TestUndef{16}{0000}%
  \TestUndef{17}{00000}%
\end{qstest}

\begin{qstest}{SetBin}{SetBin}
  \def\Test#1#2{%
    \let\BS@abc\@undefined
    \bitsetSetBin{abc}{#1}%
    \expandafter\Expect\expandafter{\BS@abc}{#2}%
  }%
  \Test{}{0}%
  \Test{0}{0}%
  \Test{1}{1}%
  \Test{10}{01}%
  \Test{11}{11}%
  \Test{010}{01}%
  \Test{011}{11}%
  \Test{0010}{01}%
  \Test{1010}{0101}%
\end{qstest}

\begin{qstest}{SetOct}{SetOct}
  \def\Test#1#2{%
    \bitsetSetOct{abc}{#1}%
    \expandafter\Expect\expandafter{\BS@abc}{#2}%
  }%
  \Test{}{0}%
  \Test{0}{0}%
  \Test{000}{0}%
  \Test{1}{1}%
  \Test{001}{1}%
  \Test{010}{0001}%
  \Test{020}{00001}%
  \Test{42}{010001}%
  \Test{377}{11111111}%
  \Test{0377}{11111111}%
  \Test{76543210}{000100010110001101011111}%
  \Test{ 0 7 0 7 1 }{100111000111}%
\end{qstest}

\begin{qstest}{SetHex}{SetHex}
  \def\Test#1#2{%
    \bitsetSetHex{abc}{#1}%
    \expandafter\Expect\expandafter{\BS@abc}{#2}%
  }%
  \Test{}{0}%
  \Test{0}{0}%
  \Test{000}{0}%
  \Test{1}{1}%
  \Test{001}{1}%
  \Test{010}{00001}%
  \Test{020}{000001}%
  \Test{42}{0100001}%
  \Test{3F}{111111}%
  \Test{03F}{111111}%
  \Test{43210}{0000100001001100001}%
  \Test{98765}{10100110111000011001}%
  \Test{FEDCBA}{010111010011101101111111}%
  \Test{ 0 F 0 F 1 }{1000111100001111}%
\end{qstest}

\begin{qstest}{SetDec}{SetDec}
  \def\Test#1#2{%
    \bitsetSetDec{abc}{#1}%
    \expandafter\Expect\expandafter{\BS@abc}{#2}%
  }%
  \Test{}{0}%
  \Test{0}{0}%
  \Test{000}{0}%
  \Test{1}{1}%
  \Test{7}{111}%
  \Test{8}{0001}%
  \Test{001}{1}%
  \Test{010}{0101}%
  \Test{020}{00101}%
  \Test{53}{101011}%
  \Test{255}{11111111}%
  \Test{256}{000000001}%
  \Test{999999999}{111111111001001101011001110111}%
  \Test{1000000000}{000000000101001101011001110111}%
  \Test{4210987654}{01100001010010010111111101011111}%
  \Test{2147483647}{1111111111111111111111111111111}%
  \Test{2147483648}{00000000000000000000000000000001}%
\end{qstest}

\begin{qstest}{GetBin}{GetBin}
  \def\TestUndef#1#2{%
    \let\BS@abc\@undefined
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \bitsetGetBin{abc}{#1}%
    }{#2}%
  }%
  \TestUndef{-1}{0}%
  \TestUndef{0}{0}%
  \TestUndef{1}{0}%
  \TestUndef{2}{00}%
  \TestUndef{8}{00000000}%
  \def\Test#1#2{%
    \bitsetSetBin{abc}{#2}%
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \bitsetGetBin{abc}{#1}%
    }{#2}%
  }%
  \Test{-1}{0}%
  \Test{0}{0}%
  \Test{1}{0}%
  \Test{1}{1}%
  \Test{2}{01}%
  \Test{2}{10}%
  \Test{3}{010}%
  \Test{2}{00}%
  \Test{2}{01}%
  \Test{8}{00101100}%
  \Test{2}{10101}%
  \Test{-100}{11011}%
\end{qstest}

\begin{qstest}{GetOct}{GetOct}
  \def\Test#1#2#3{%
    \edef\x{\zap@space#1 \@empty}%
    \edef\x{\noexpand\bitsetSetBin{abc}{\x}}%
    \x
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \bitsetGetOct{abc}{#2}%
    }{#3}%
  }%
  \Test{111 110 101 100 011 010 001 000}{0}{76543210}%
  \Test{000 111}{0}{7}%
  \Test{101 000}{-1}{50}%
  \Test{111}{-1}{7}%
  \Test{111}{0}{7}%
  \Test{111}{1}{7}%
  \Test{111}{3}{7}%
  \Test{111}{4}{07}%
  \Test{111}{6}{07}%
  \Test{111}{7}{007}%
  \Test{111 010}{6}{72}%
  \Test{111 010}{7}{072}%
  \Test{011 111}{0}{37}%
  \Test{011 111}{6}{37}%
  \Test{011 111}{7}{037}%
  \Test{001 111}{0}{17}%
  \Test{001 111}{6}{17}%
  \Test{001 111}{7}{017}%
\end{qstest}

\begin{qstest}{GetHex}{GetHex}
  \def\Test#1#2#3{%
    \bitsetSetBin{abc}{#1}%
    \expandafter\expandafter\expandafter\Expect
    \expandafter\expandafter\expandafter{%
      \bitsetGetHex{abc}{#2}%
    }{#3}%
  }%
  \Test{1111 1110 1101 1100 1011 1010 1001 1000}{0}{FEDCBA98}%
  \Test{0111 0110 0101 0100 0011 0010 0001 0000}{0}{76543210}%
  \Test{0000 1111}{0}{F}%
  \Test{0101 0000}{-1}{50}%
  \Test{1111}{-1}{F}%
  \Test{1111}{0}{F}%
  \Test{1111}{1}{F}%
  \Test{1111}{4}{F}%
  \Test{1111}{5}{0F}%
  \Test{1111}{8}{0F}%
  \Test{1111}{9}{00F}%
  \Test{1111 0010}{8}{F2}%
  \Test{1111 0010}{9}{0F2}%
  \Test{0111 1111}{0}{7F}%
  \Test{0111 1111}{8}{7F}%
  \Test{0111 1111}{9}{07F}%
  \Test{0011 1111}{0}{3F}%
  \Test{0011 1111}{8}{3F}%
  \Test{0011 1111}{9}{03F}%
  \Test{0001 1111}{0}{1F}%
  \Test{0001 1111}{8}{1F}%
  \Test{0001 1111}{9}{01F}%
\end{qstest}

\begin{qstest}{Range}{Range}
  \TestError{%
    Wrong index numbers in range [9..8]\MessageBreak% hash-ok
    for clear/set/flip on bit set `abc'.\MessageBreak
    The lower index exceeds the upper index.\MessageBreak
    Canceling the operation as error recovery%
  }{%
    \bitsetSetRange{abc}{9}{8}%
  }%
  \def\TestErrorNegInd#1#2#3#4#5#6{%
    \TestError{%
      Negative index in range [#2..#3]\MessageBreak % hash-ok
      for \string\bitset #1Range on bit set `abc'.\MessageBreak
      Using [#4..#5] as error recovery% hash-ok
    }{%
      \csname bitset#1Range\endcsname{abc}{#2}{#3}%
      \global\let\BS@global\BS@abc
    }%
    \Check{global}{#6}%
  }%
  \Set{abc}{111}%
  \TestErrorNegInd{Clear}{-1}{0}{0}{0}{111}%
  \TestErrorNegInd{Clear}{0}{-1}{0}{0}{111}%
  \TestErrorNegInd{Clear}{-2}{2}{0}{2}{001}%
  \bitsetReset{abc}%
  \TestErrorNegInd{Set}{-1}{0}{0}{0}{0}%
  \TestErrorNegInd{Set}{0}{-1}{0}{0}{0}%
  \TestErrorNegInd{Set}{-2}{2}{0}{2}{11}%
  \Set{abc}{101}%
  \TestErrorNegInd{Flip}{-1}{0}{0}{0}{101}%
  \TestErrorNegInd{Flip}{0}{-1}{0}{0}{101}%
  \TestErrorNegInd{Flip}{-2}{2}{0}{2}{011}%
  \def\Test#1#2#3#4{%
    \bitsetSetBin{abc}{#1}%
    \csname bitset\TestOp Range\endcsname{abc}{#2}{#3}%
    \Expect*{\bitsetGetBin{abc}{0}}{#4}%
  }%
  \def\TestOp{Clear}%
  \Test{0}{0}{1}{0}%
  \Test{1111}{1}{2}{1101}%
  \Test{1111}{1}{3}{1001}%
  \Test{1111111100000000}{12}{14}{1100111100000000}%
  \def\TestOp{Set}%
  \Test{0}{0}{1}{1}%
  \Test{1000}{1}{2}{1010}%
  \Test{0}{1}{2}{10}%
  \Test{1}{12}{15}{111000000000001}%
  \Test{1111}{1}{3}{1111}%
  \Test{1000000000000000}{12}{14}{1011000000000000}%
  \def\TestOp{Flip}%
  \Test{0}{0}{1}{1}%
  \Test{1}{0}{1}{0}%
  \Test{10101010}{1}{5}{10110100}%
  \def\Test#1#2#3#4#5{%
    \bitsetSetBin{abc}{#1}%
    \bitsetSetValueRange{abc}{#2}{#3}{#4}%
    \Expect*{\bitsetGetBin{abc}{0}}{#5}%
  }%
  \Test{0}{0}{1}{0}{0}%
  \Test{0}{0}{1}{1}{1}%
  \Test{1010}{1}{3}{0}{1000}%
  \Test{1010}{1}{3}{1}{1110}%
\end{qstest}

\begin{qstest}{ShiftLeft/ShiftRight}{ShiftLeft/ShiftRight}
  \def\@Test#1#2{%
    \let\BS@abc\@undefined
    \csname bitsetShift#1\endcsname{abc}{#2}%
    \Expect*{\BS@abc}{0}%
  }%
  \def\Test#1{%
    \@Test{Left}{#1}%
    \@Test{Right}{#1}%
  }%
  \Test{-16}%
  \Test{-1}%
  \Test{0}%
  \Test{1}%
  \Test{16}%
  \def\Test#1#2#3{%
    \bitsetSetBin{abc}{#1}%
    \bitsetSetBin{result}{#3}%
    \csname bitsetShift\Op\endcsname{abc}{#2}%
    \Expect*{\bitsetGetBin{abc}{0}}*{\bitsetGetBin{result}{0}}%
  }%
  \def\Op{Left}%
  \Test{0}{0}{0}%
  \Test{0}{1}{0}%
  \Test{0}{-1}{0}%
  \Test{1}{0}{1}%
  \Test{1}{1}{10}%
  \Test{1}{-1}{0}%
  \Test{10}{1}{100}%
  \Test{10}{-1}{1}%
  \Test{1}{32}{100000000000000000000000000000000}%
  \Test{1}{-100}{0}%
  \def\Op{Right}%
  \Test{0}{0}{0}%
  \Test{0}{1}{0}%
  \Test{0}{-1}{0}%
  \Test{1}{0}{1}%
  \Test{1}{1}{0}%
  \Test{1}{-1}{10}%
  \Test{10}{1}{1}%
  \Test{10}{-1}{100}%
  \Test{1}{-32}{100000000000000000000000000000000}%
  \Test{1}{100}{0}%
  \Test{110110110110110}{10}{11011}%
  \Test{110110110110110}{100}{0}%
  \Test{1}{100000}{0}%
\end{qstest}

\begin{qstest}{Profile: Set}{Profile: Set}
  \bitsetSet{abc}{4095}%
  \global\let\BS@global\BS@abc
\end{qstest}

\begin{qstest}{Profile: Get}{Profile: Get}
  \edef\x{\bitsetGet{global}{4095}}%
\end{qstest}

\begin{document}
\end{document}
\endinput
%%
%% End of file `bitset-test3.tex'.
