コード例 #1
0
ファイル: test-bit-subvector.C プロジェクト: Singular/LELA
int testIterator (size_t n, size_t k)
{
	commentator.start ("Testing BitSubvector::word_iterator", __FUNCTION__);

	bool pass = true;

	std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR);

	BitVector<Endianness> v (n);

	BitVector<Endianness>::word_iterator w;
	unsigned int flip = 0;
	
	for (w = v.word_begin (); w != v.word_end (); ++w, flip = 1 - flip)
		*w = pattern[flip];

	v.back_word () = pattern[flip];

	size_t offset;
	
	for (offset = 0; offset <= n - k; ++offset) {
		BitSubvector<BitVector<Endianness>::iterator> vp (v.begin () + offset, v.begin () + (offset + k));

		BitSubvector<BitVector<Endianness>::iterator>::word_iterator i;
		BitSubvector<BitVector<Endianness>::iterator>::const_word_iterator j1, j2;

		flip = ((offset / WordTraits<BitVector<Endianness>::word_type>::bits) % 2 == 0) ? 0 : 1;
				
		for (i = vp.word_begin (), j1 = vp.word_begin (), j2 = vp.word_begin (); i != vp.word_end (); ++i, ++j1, ++j2, flip = 1 - flip) {
			if (*j1 != *i) {
				error << "ERROR: error at offset " << offset << " (n = " << n << ", k = " << k << ")" << std::endl;
				error << "ERROR: word_iterator and const_word_iterator don't agree" << std::endl;
				error << "ERROR: word_iterator: " << std::hex << *i << std::endl;
				error << "ERROR: const_word_iterator: " << std::hex << *j1 << std::endl;
				pass = false;
				goto end_test;
			}

			BitVector<Endianness>::word_type val = *j1;
			
			*i ^= val;
			
			if (*j2 != 0) {
				error << "ERROR: error at offset " << offset << " (n = " << n << ", k = " << k << ")" << std::endl;
				error << "ERROR: Pattern should be 0 after clearing" << std::endl;
				error << "ERROR: Detected " << std::hex << *j2 << std::endl;
				pass = false;
				goto end_test;
			}

			*i ^= val;
		}
	}

end_test:
	commentator.stop (MSG_STATUS (pass));

	return pass;
}
コード例 #2
0
ファイル: test-bit-subvector.C プロジェクト: Singular/LELA
bool testConstIterator (size_t n, size_t k)
{
	commentator.start ("Testing BitSubvector::const_word_iterator", __FUNCTION__);

	bool pass = true;

	std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR);

	BitVector<Endianness> v (n);

	BitVector<Endianness>::word_iterator w;
	unsigned int flip = 0;
	
	for (w = v.word_begin (); w != v.word_end (); ++w, flip = 1 - flip)
		*w = pattern[flip];

	v.back_word () = pattern[flip];

	size_t offset;
	
	for (offset = 0; offset <= n - k; ++offset) {
		BitSubvector<BitVector<Endianness>::const_iterator> vp (v.begin () + offset, v.begin () + (offset + k));

		BitSubvector<BitVector<Endianness>::const_iterator>::const_word_iterator i;

		flip = ((offset / WordTraits<BitVector<Endianness>::word_type>::bits) % 2 == 0) ? 0 : 1;

		size_t idx = 0;
				
		for (i = vp.word_begin (); i != vp.word_end (); ++i, flip = 1 - flip, idx += WordTraits<BitVector<Endianness>::word_type>::bits) {
			BitVector<Endianness>::word_type check = connect (pattern[flip], pattern[1-flip], offset % WordTraits<BitVector<Endianness>::word_type>::bits);

			if (idx + WordTraits<BitVector<Endianness>::word_type>::bits > k)
				check &= Endianness::mask_left (k % WordTraits<BitVector<Endianness>::word_type>::bits);
			
			if (*i != check) {
				error << "ERROR: error at offset " << offset << std::endl;
				error << "ERROR: Pattern should be " << std::hex << check << std::endl;
				error << "ERROR: Detected " << std::hex << *i << std::endl;
				pass = false;
				goto end_test;
			}
		}
	}

end_test:
	commentator.stop (MSG_STATUS (pass));

	return pass;
}