/* * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * @test * @bug 8028267 * @summary Unit tests for the com.sun.tools.javac.util.Bits class. * @modules jdk.compiler/com.sun.tools.javac.util * @run main BitsTest
*/
// Test Bits.incl staticvoid testIncl() { for (int a : samples) { for (int b : samples) {
Bits bits = new Bits();
bits.incl(a); if (a != b)
bits.incl(b); for (int i = 0; i < LENGTH; i++) assert bits.isMember(i) == (i == a || i == b);
}
}
}
// Test Bits.excl staticvoid testExcl() { for (int a : samples) { for (int b : samples) {
Bits bits = new Bits();
bits.inclRange(0, LENGTH);
bits.excl(a); if (a != b)
bits.excl(b); for (int i = 0; i < LENGTH; i++) assert !bits.isMember(i) == (i == a || i == b);
}
}
}
// Test Bits.inclRange with various ranges. staticvoid testInclRange() { for (int i = 0; i < samples.length; i++) { for (int j = i; j < samples.length; j++)
testInclRangeHelper(samples[i], samples[j]);
}
}
// Tests Bits.inclRange for the given range. staticvoid testInclRangeHelper(int from, int to) {
Bits bits = new Bits();
bits.inclRange(from, to); for (int i = 0; i < LENGTH; i++) assert bits.isMember(i) == (from <= i && i < to);
}
// Create a Bits-instance based on bits in 'ints' argument. static Bits fromInts(int[] ints) {
Bits bits = new Bits(); for (int bit = 0; bit < ints.length * 32; bit++) if ((ints[bit / 32] & (1 << (bit % 32))) != 0)
bits.incl(bit); return bits;
}
// Asserts that two Bits-instances are equal up to first 'len' bits. staticvoid assertEquals(int len, Bits a, Bits b) { for (int i = 0; i < len; i++) assert a.isMember(i) == b.isMember(i);
}
// Test Bits.nextBit staticvoid testNextBit() {
Bits bits = sampleBits();
int index = 0; for (int bit = 0; bit < LENGTH; bit++) {
int expected;
// Passed last sample index? if (index < samples.length) {
expected = samples[index]; if (bit == samples[index])
index++;
} else {
expected = -1;
}
assert bits.nextBit(bit) == expected;
}
}
// Convenience method: Generate a Bits-instance based on samples. static Bits sampleBits() {
Bits bits = new Bits(); for (int i : samples)
bits.incl(i); return bits;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.