Пример #1
0
void testPunctureUnpuncture(const char *label, const unsigned int *punk, size_t plth)
{
	bool ok = true;
	// Things could go wrong and be missed due to we're just wrangling bit vectors,
	// so run each speed a few times to reduce the probability of missing an error.
	for (int i = 0; i < 5; i++) {
		// generate orig
		BitVector orig = randomBitVector(448+plth);
		// puncture
		BitVector punctured(orig.size() - plth);
		orig.copyPunctured(punctured, punk, plth);
		SoftVector softPunctured(punctured);
		// unpuncture
		SoftVector unpunctured(orig.size());
		softPunctured.copyUnPunctured(unpunctured, punk, plth);
		// verify
		const unsigned *p = punk;
		for (unsigned i = 0; i < orig.size(); i++) {
			if (unpunctured[i] == 0.5) {
				if (*p++ != i) ok = false;
			} else {
				if (orig.bit(i) != unpunctured[i]) ok = false;
			}
		}
		ok = ok && (p == punk + plth);
	}
	cout << "puncture->unpuncture " << label << " " << (ok ? "ok" : "NOT ok") << endl;
}