jdk/test/java/util/BitSet/BSMethods.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 5506 202f599c92aa
child 24257 f524e23d7f7b
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 4098239 4107540 4080736 4261102 4274710 4305272
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *      4979017 4979028 4979031 5030267 6222207
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test the operation of the methods of BitSet class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Mike McCloskey, Martin Buchholz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This is a simple test class created to run tests on the BitSet class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class BSMethods {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static Random generator = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static boolean failure = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static void fail(String diagnostic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        new Error(diagnostic).printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        failure = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static void check(boolean condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        check(condition, "something's fishy");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static void check(boolean condition, String diagnostic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (! condition)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            fail(diagnostic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static void checkEmpty(BitSet s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        check(s.isEmpty(), "isEmpty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        check(s.length() == 0, "length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        check(s.cardinality() == 0, "cardinality");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        check(s.equals(new BitSet())   , "equals");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        check(s.equals(new BitSet(0))  , "equals");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        check(s.equals(new BitSet(127)), "equals");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        check(s.equals(new BitSet(128)), "equals");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        check(s.nextSetBit(0)   == -1, "nextSetBit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        check(s.nextSetBit(127) == -1, "nextSetBit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        check(s.nextSetBit(128) == -1, "nextSetBit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        check(s.nextClearBit(0)   == 0,   "nextClearBit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        check(s.nextClearBit(127) == 127, "nextClearBit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        check(s.nextClearBit(128) == 128, "nextClearBit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        check(s.toString().equals("{}"), "toString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        check(! s.get(0), "get");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static BitSet makeSet(int... elts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        BitSet s = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        for (int elt : elts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            s.set(elt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static void checkEquality(BitSet s, BitSet t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        checkSanity(s, t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        check(s.equals(t), "equals");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        check(s.toString().equals(t.toString()), "equal strings");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        check(s.length() == t.length(), "equal lengths");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        check(s.cardinality() == t.cardinality(), "equal cardinalities");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static void checkSanity(BitSet... sets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        for (BitSet s : sets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            int len = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            int cardinality1 = s.cardinality();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            int cardinality2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            for (int i = s.nextSetBit(0); i >= 0; i = s.nextSetBit(i+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                check(s.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                cardinality2++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            check(s.nextSetBit(len) == -1, "last set bit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            check(s.nextClearBit(len) == len, "last set bit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            check(s.isEmpty() == (len == 0), "emptiness");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            check(cardinality1 == cardinality2, "cardinalities");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            check(len <= s.size(), "length <= size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            check(len >= 0, "length >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            check(cardinality1 >= 0, "cardinality >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        //testFlipTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // These are the single bit versions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        testSetGetClearFlip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // Test the ranged versions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        testClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        testFlip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        testSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        testGet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // BitSet interaction calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        testAndNot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        testAnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        testOr();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        testXor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // Miscellaneous calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        testLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        testEquals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        testNextSetBit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        testNextClearBit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        testIntersects();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        testCardinality();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        testEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        testEmpty2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        testToString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        testLogicalIdentities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (failure)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            throw new RuntimeException("One or more BitSet failures.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static void report(String testName, int failCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        System.err.println(testName+": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                           (failCount==0 ? "Passed":"Failed("+failCount+")"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (failCount > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            failure = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static void testFlipTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // Make a fairly random bitset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        b1.set(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        long startTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        for(int x=0; x<100000; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            b1.flip(100, 900);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        long endTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        long total = endTime - startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        System.out.println("Multiple word flip Time "+total);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        startTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for(int x=0; x<100000; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            b1.flip(2, 44);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        endTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        total = endTime - startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        System.out.println("Single word flip Time "+total);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private static void testNextSetBit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            BitSet testSet = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            int[] history = new int[numberOfSetBits];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            // Set some random bits and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            for (int x=0; x<numberOfSetBits; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                nextBitToSet += generator.nextInt(30)+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                history[x] = nextBitToSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                testSet.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // Verify their retrieval using nextSetBit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            int historyIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            for(int x=testSet.nextSetBit(0); x>=0; x=testSet.nextSetBit(x+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                if (x != history[historyIndex++])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            checkSanity(testSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        report("NextSetBit                  ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static void testNextClearBit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        for (int i=0; i<1000; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            BitSet b = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            int[] history = new int[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // Set all the bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            for (int x=0; x<256; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                b.set(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            // Clear some random bits and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            int nextBitToClear = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            for (int x=0; x<10; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                nextBitToClear += generator.nextInt(24)+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                history[x] = nextBitToClear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                b.clear(nextBitToClear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            // Verify their retrieval using nextClearBit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            int historyIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            for(int x=b.nextClearBit(0); x<256; x=b.nextClearBit(x+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                if (x != history[historyIndex++])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            checkSanity(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // regression test for 4350178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        BitSet bs  = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (bs.nextClearBit(0) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        for (int i = 0; i < 64; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            bs.set(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (bs.nextClearBit(0) != i+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        checkSanity(bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        report("NextClearBit                ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private static void testSetGetClearFlip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            BitSet testSet = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            HashSet<Integer> history = new HashSet<Integer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            // Set a random number of bits in random places
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            // up to a random maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            for (int x=0; x<numberOfSetBits; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                nextBitToSet = generator.nextInt(highestPossibleSetBit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                history.add(new Integer(nextBitToSet));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                testSet.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            // Make sure each bit is set appropriately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            for (int x=0; x<highestPossibleSetBit; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                if (testSet.get(x) != history.contains(new Integer(x)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            // Clear the bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            Iterator<Integer> setBitIterator = history.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            while (setBitIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                Integer setBit = setBitIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                testSet.clear(setBit.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            // Verify they were cleared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            for (int x=0; x<highestPossibleSetBit; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                if (testSet.get(x))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            if(testSet.length() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // Set them with set(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            setBitIterator = history.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            while (setBitIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                Integer setBit = setBitIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                testSet.set(setBit.intValue(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            // Make sure each bit is set appropriately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            for (int x=0; x<highestPossibleSetBit; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                if (testSet.get(x) != history.contains(new Integer(x)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            // Clear them with set(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            setBitIterator = history.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            while (setBitIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                Integer setBit = (Integer)setBitIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                testSet.set(setBit.intValue(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            // Verify they were cleared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            for (int x=0; x<highestPossibleSetBit; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                if (testSet.get(x))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if(testSet.length() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            // Flip them on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            setBitIterator = history.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            while (setBitIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                Integer setBit = (Integer)setBitIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                testSet.flip(setBit.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            // Verify they were flipped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            for (int x=0; x<highestPossibleSetBit; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                if (testSet.get(x) != history.contains(new Integer(x)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            // Flip them off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            setBitIterator = history.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            while (setBitIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                Integer setBit = (Integer)setBitIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                testSet.flip(setBit.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // Verify they were flipped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            for (int x=0; x<highestPossibleSetBit; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (testSet.get(x))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if(testSet.length() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            checkSanity(testSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        report("SetGetClearFlip             ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private static void testAndNot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            BitSet b2 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            // Set some random bits in first set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            for (int x=0; x<10; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                b1.set(generator.nextInt(255));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            // Set some random bits in second set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            for (int x=10; x<20; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                b2.set(generator.nextInt(255));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            // andNot the sets together
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            BitSet b3 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            b3.andNot(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            // Examine each bit of b3 for errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            for(int x=0; x<256; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                boolean bit1 = b1.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                boolean bit2 = b2.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                boolean bit3 = b3.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                if (!(bit3 == (bit1 & (!bit2))))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            checkSanity(b1, b2, b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        report("AndNot                      ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private static void testAnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            BitSet b2 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            // Set some random bits in first set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            for (int x=0; x<10; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                b1.set(generator.nextInt(255));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            // Set more random bits in second set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            for (int x=10; x<20; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                b2.set(generator.nextInt(255));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            // And the sets together
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            BitSet b3 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            b3.and(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            // Examine each bit of b3 for errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            for(int x=0; x<256; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                boolean bit1 = b1.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                boolean bit2 = b2.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                boolean bit3 = b3.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                if (!(bit3 == (bit1 & bit2)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            checkSanity(b1, b2, b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        // `and' that happens to clear the last word
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        BitSet b4 = makeSet(2, 127);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        b4.and(makeSet(2, 64));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        checkSanity(b4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (!(b4.equals(makeSet(2))))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        report("And                         ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    private static void testOr() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            BitSet b2 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            int[] history = new int[20];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            // Set some random bits in first set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            for (int x=0; x<10; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                nextBitToSet = generator.nextInt(255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                history[x] = nextBitToSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                b1.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            // Set more random bits in second set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            for (int x=10; x<20; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                nextBitToSet = generator.nextInt(255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                history[x] = nextBitToSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                b2.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            // Or the sets together
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            BitSet b3 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            b3.or(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            // Verify the set bits of b3 from the history
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            int historyIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            for(int x=0; x<20; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                if (!b3.get(history[x]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            // Examine each bit of b3 for errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            for(int x=0; x<256; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                boolean bit1 = b1.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                boolean bit2 = b2.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                boolean bit3 = b3.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                if (!(bit3 == (bit1 | bit2)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            checkSanity(b1, b2, b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        report("Or                          ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    private static void testXor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            BitSet b2 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            // Set some random bits in first set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            for (int x=0; x<10; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                b1.set(generator.nextInt(255));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            // Set more random bits in second set and remember them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            for (int x=10; x<20; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                b2.set(generator.nextInt(255));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            // Xor the sets together
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            BitSet b3 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            b3.xor(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            // Examine each bit of b3 for errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            for(int x=0; x<256; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                boolean bit1 = b1.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                boolean bit2 = b2.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                boolean bit3 = b3.get(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                if (!(bit3 == (bit1 ^ bit2)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            checkSanity(b1, b2, b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            b3.xor(b3); checkEmpty(b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        // xor that happens to clear the last word
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        BitSet b4 = makeSet(2, 64, 127);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        b4.xor(makeSet(64, 127));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        checkSanity(b4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (!(b4.equals(makeSet(2))))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        report("Xor                         ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    private static void testEquals() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            // Create BitSets of different sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            BitSet b1 = new BitSet(generator.nextInt(1000)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            BitSet b2 = new BitSet(generator.nextInt(1000)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            // Set some random bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            for (int x=0; x<10; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                nextBitToSet += generator.nextInt(50)+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                b1.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                b2.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            // Verify their equality despite different storage sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (!b1.equals(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            checkEquality(b1,b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        report("Equals                      ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    private static void testLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        // Test length after set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            int highestSetBit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            for(int x=0; x<100; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                int nextBitToSet = generator.nextInt(255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                if (nextBitToSet > highestSetBit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    highestSetBit = nextBitToSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                b1.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                if (b1.length() != highestSetBit + 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            checkSanity(b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        // Test length after flip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            for(int x=0; x<100; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                // Flip a random range twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                int rangeStart = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                int rangeEnd = rangeStart + generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                b1.flip(rangeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                b1.flip(rangeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                if (b1.length() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                b1.flip(rangeStart, rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                b1.flip(rangeStart, rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                if (b1.length() != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            checkSanity(b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // Test length after or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            BitSet b2 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            int bit1 = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            int bit2 = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            int highestSetBit = (bit1 > bit2) ? bit1 : bit2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            b1.set(bit1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            b2.set(bit2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            b1.or(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (b1.length() != highestSetBit + 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            checkSanity(b1, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        report("Length                      ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    private static void testClear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        for (int i=0; i<1000; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            // Make a fairly random bitset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            for (int x=0; x<numberOfSetBits; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                b1.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            BitSet b2 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            // Clear out a random range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            int rangeStart = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            int rangeEnd = rangeStart + generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            // Use the clear(int, int) call on b1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            b1.clear(rangeStart, rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            // Use a loop on b2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            for (int x=rangeStart; x<rangeEnd; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                b2.clear(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            // Verify their equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if (!b1.equals(b2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                System.out.println("rangeStart = " + rangeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                System.out.println("rangeEnd = " + rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                System.out.println("b1 = " + b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                System.out.println("b2 = " + b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            checkEquality(b1,b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        report("Clear                       ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private static void testSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        // Test set(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        for (int i=0; i<1000; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            // Make a fairly random bitset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            for (int x=0; x<numberOfSetBits; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                b1.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            BitSet b2 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            // Set a random range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            int rangeStart = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            int rangeEnd = rangeStart + generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            // Use the set(int, int) call on b1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            b1.set(rangeStart, rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            // Use a loop on b2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            for (int x=rangeStart; x<rangeEnd; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                b2.set(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            // Verify their equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            if (!b1.equals(b2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                System.out.println("Set 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                System.out.println("rangeStart = " + rangeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                System.out.println("rangeEnd = " + rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                System.out.println("b1 = " + b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                System.out.println("b2 = " + b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            checkEquality(b1,b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // Test set(int, int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            // Make a fairly random bitset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            for (int x=0; x<numberOfSetBits; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                b1.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            BitSet b2 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            boolean setOrClear = generator.nextBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            // Set a random range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            int rangeStart = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            int rangeEnd = rangeStart + generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            // Use the set(int, int, boolean) call on b1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            b1.set(rangeStart, rangeEnd, setOrClear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            // Use a loop on b2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            for (int x=rangeStart; x<rangeEnd; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                b2.set(x, setOrClear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            // Verify their equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            if (!b1.equals(b2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                System.out.println("Set 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                System.out.println("b1 = " + b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                System.out.println("b2 = " + b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            checkEquality(b1,b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        report("Set                         ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    private static void testFlip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        for (int i=0; i<1000; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            // Make a fairly random bitset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            for (int x=0; x<numberOfSetBits; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                b1.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            BitSet b2 = (BitSet)b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            // Flip a random range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            int rangeStart = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            int rangeEnd = rangeStart + generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            // Use the flip(int, int) call on b1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            b1.flip(rangeStart, rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            // Use a loop on b2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            for (int x=rangeStart; x<rangeEnd; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                b2.flip(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            // Verify their equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            if (!b1.equals(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            checkEquality(b1,b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        report("Flip                        ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    private static void testGet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        for (int i=0; i<1000; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            // Make a fairly random bitset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            for (int x=0; x<numberOfSetBits; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                b1.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            // Get a new set from a random range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            int rangeStart = generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            int rangeEnd = rangeStart + generator.nextInt(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            BitSet b2 = b1.get(rangeStart, rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            BitSet b3 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            for(int x=rangeStart; x<rangeEnd; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                b3.set(x-rangeStart, b1.get(x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            // Verify their equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            if (!b2.equals(b3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                System.out.println("start="+rangeStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                System.out.println("end="+rangeEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                System.out.println(b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                System.out.println(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                System.out.println(b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            checkEquality(b2,b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        report("Get                         ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private static void testIntersects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            BitSet b2 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            // Set some random bits in first set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            for (int x=0; x<30; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                nextBitToSet = generator.nextInt(255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                b1.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            // Set more random bits in second set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            for (int x=0; x<30; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                nextBitToSet = generator.nextInt(255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                b2.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            // Make sure they intersect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            nextBitToSet = generator.nextInt(255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            b1.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            b2.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (!b1.intersects(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            // Remove the common set bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            b1.andNot(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            // Make sure they don't intersect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            if (b1.intersects(b2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            checkSanity(b1, b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        report("Intersects                  ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    private static void testCardinality() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        for (int i=0; i<100; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            BitSet b1 = new BitSet(256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            // Set a random number of increasing bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            int iterations = generator.nextInt(20)+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            for (int x=0; x<iterations; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                nextBitToSet += generator.nextInt(20)+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                b1.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            if (b1.cardinality() != iterations) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                System.out.println("Iterations is "+iterations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                System.out.println("Cardinality is "+b1.cardinality());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            checkSanity(b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        report("Cardinality                 ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    private static void testEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        if (!b1.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        int nextBitToSet = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        for (int x=0; x<numberOfSetBits; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            nextBitToSet = generator.nextInt(highestPossibleSetBit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            b1.set(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (b1.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            b1.clear(nextBitToSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            if (!b1.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        report("Empty                       ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    private static void testEmpty2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        {BitSet t = new BitSet(); t.set(100); t.clear(3,600); checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        checkEmpty(new BitSet(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        checkEmpty(new BitSet(342));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        BitSet s = new BitSet(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        checkEmpty(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        s.clear(92);      checkEmpty(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        s.clear(127,127); checkEmpty(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        s.set(127,127);   checkEmpty(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        s.set(128,128);   checkEmpty(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        BitSet empty = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        {BitSet t = new BitSet(); t.and   (empty);     checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        {BitSet t = new BitSet(); t.or    (empty);     checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        {BitSet t = new BitSet(); t.xor   (empty);     checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        {BitSet t = new BitSet(); t.andNot(empty);     checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        {BitSet t = new BitSet(); t.and   (t);         checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        {BitSet t = new BitSet(); t.or    (t);         checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        {BitSet t = new BitSet(); t.xor   (t);         checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        {BitSet t = new BitSet(); t.andNot(t);         checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        {BitSet t = new BitSet(); t.and(makeSet(1));   checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        {BitSet t = new BitSet(); t.and(makeSet(127)); checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        {BitSet t = new BitSet(); t.and(makeSet(128)); checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        {BitSet t = new BitSet(); t.flip(7);t.flip(7); checkEmpty(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        {BitSet t = new BitSet(); checkEmpty(t.get(200,300));}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        {BitSet t = makeSet(2,5); check(t.get(2,6).equals(makeSet(0,3)),"");}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    private static void testToString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        check(new BitSet().toString().equals("{}"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        check(makeSet(2,3,42,43,234).toString().equals("{2, 3, 42, 43, 234}"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    private static void testLogicalIdentities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        int failCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        // Verify that (!b1)|(!b2) == !(b1&b2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        for (int i=0; i<50; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            // Construct two fairly random bitsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            BitSet b2 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            for (int x=0; x<numberOfSetBits; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                b1.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                b2.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            BitSet b3 = (BitSet) b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            BitSet b4 = (BitSet) b2.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            for (int x=0; x<highestPossibleSetBit; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                b1.flip(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                b2.flip(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            b1.or(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            b3.and(b4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            for (int x=0; x<highestPossibleSetBit; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                b3.flip(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            if (!b1.equals(b3))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            checkSanity(b1, b2, b3, b4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        // Verify that (b1&(!b2)|(b2&(!b1) == b1^b2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        for (int i=0; i<50; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            // Construct two fairly random bitsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            BitSet b1 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            BitSet b2 = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            int numberOfSetBits = generator.nextInt(100) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            int highestPossibleSetBit = generator.nextInt(1000) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            for (int x=0; x<numberOfSetBits; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                b1.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                b2.set(generator.nextInt(highestPossibleSetBit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            BitSet b3 = (BitSet) b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            BitSet b4 = (BitSet) b2.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            BitSet b5 = (BitSet) b1.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            BitSet b6 = (BitSet) b2.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            for (int x=0; x<highestPossibleSetBit; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                b2.flip(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            b1.and(b2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            for (int x=0; x<highestPossibleSetBit; x++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                b3.flip(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            b3.and(b4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            b1.or(b3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            b5.xor(b6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            if (!b1.equals(b5))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                failCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            checkSanity(b1, b2, b3, b4, b5, b6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        report("Logical Identities          ", failCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
}