| Index: test/cctest/test-utils.cc
|
| diff --git a/test/cctest/test-utils.cc b/test/cctest/test-utils.cc
|
| index 0c1e0412d3484db5d4d94a9c90732ae45e9ece29..8c5ad0e641d772cc11126c90a0ca4f76ea5e4fe3 100644
|
| --- a/test/cctest/test-utils.cc
|
| +++ b/test/cctest/test-utils.cc
|
| @@ -76,6 +76,46 @@ TEST(Utils1) {
|
| }
|
|
|
|
|
| +TEST(BitSetComputer) {
|
| + typedef BitSetComputer<bool, 1, kSmiValueSize, uint32_t> BoolComputer;
|
| + CHECK_EQ(0, BoolComputer::word_count(0));
|
| + CHECK_EQ(1, BoolComputer::word_count(8));
|
| + CHECK_EQ(2, BoolComputer::word_count(50));
|
| + CHECK_EQ(0, BoolComputer::index(0, 8));
|
| + CHECK_EQ(100, BoolComputer::index(100, 8));
|
| + CHECK_EQ(1, BoolComputer::index(0, 40));
|
| + uint32_t data = 0;
|
| + data = BoolComputer::encode(data, 1, true);
|
| + data = BoolComputer::encode(data, 4, true);
|
| + CHECK_EQ(true, BoolComputer::decode(data, 1));
|
| + CHECK_EQ(true, BoolComputer::decode(data, 4));
|
| + CHECK_EQ(false, BoolComputer::decode(data, 0));
|
| + CHECK_EQ(false, BoolComputer::decode(data, 2));
|
| + CHECK_EQ(false, BoolComputer::decode(data, 3));
|
| +
|
| + // Lets store 2 bits per item with 3000 items and verify the values are
|
| + // correct.
|
| + typedef BitSetComputer<unsigned char, 2, 8, unsigned char> TwoBits;
|
| + const int words = 750;
|
| + CHECK_EQ(words, TwoBits::word_count(3000));
|
| + const int offset = 10;
|
| + Vector<unsigned char> buffer = Vector<unsigned char>::New(offset + words);
|
| + memset(buffer.start(), 0, sizeof(unsigned char) * buffer.length());
|
| + for (int i = 0; i < words; i++) {
|
| + const int index = TwoBits::index(offset, i);
|
| + unsigned char data = buffer[index];
|
| + data = TwoBits::encode(data, i, i % 4);
|
| + buffer[index] = data;
|
| + }
|
| +
|
| + for (int i = 0; i < words; i++) {
|
| + const int index = TwoBits::index(offset, i);
|
| + unsigned char data = buffer[index];
|
| + CHECK_EQ(i % 4, TwoBits::decode(data, i));
|
| + }
|
| +}
|
| +
|
| +
|
| TEST(SNPrintF) {
|
| // Make sure that strings that are truncated because of too small
|
| // buffers are zero-terminated anyway.
|
|
|