Question: Help with writing Boost tests in C++ Testing. Implement unit tests using the Boost test framework. Two additional unit tests in Boost, in a file

Help with writing Boost tests in C++

Testing. Implement unit tests using the Boost test framework.

Two additional unit tests in Boost, in a file test.cpp (start with the existing file ~/COMP2040/PS2a/test.cpp in our Ubuntu VM). You must have two more sets of tests in additional BOOST_AUTO_TEST_CASE blocks. Each block should be commented with a short description of the test. Try to test some edge cases of your implementation (e.g. very long or short seed strings).

lfsr.cpp:

/******************************************************/

#include "LFSR.hpp"

#include

#include

LFSR::LFSR(std::string seed, int tap) {

_seed = seed; _tap = tap;

}

LFSR:: LFSR() { }

int LFSR::step() {

// ascii code of first char

int bit = _seed[0] - 0;

int tap = _seed[_seed.length() - _tap - 1] - 0;

(bit == tap) ? bit = 0 : bit = 1;

// shift bits for(size_t i = 0;

i < _seed.length() - 1; i++) {

_seed[i] = _seed[i + 1];

}

// convert back to char

_seed[_seed.length() - 1] = bit + 48;

return bit;

}

int LFSR::generate(int k) {

int num = 0;

int b;

for(int i = k; i > 0; i--) {

b = step();

if(b == 1) {

num += pow(2, i - 1);

}

}

return num;

}

/*********************************************/

lfsr.hpp

/**********************************************/

#include

#include

using namespace std;

class lfsr {

public: lfsr(string seed, int tap);

~lfsr();

int step();

int generate(int m);

friend ostream& operator<< (ostream &out, const lfsr &lfsr) {

out << lfsr._seed; return out;

}

private: string _seed;

int _tap;

};

Please help me write two tests using BOOST_AUTO_TEST_CASE blocks These are the two I already have:

/*****************************************************/

test.cpp

/******************************************/

#include

#include

#include "LFSR.hpp"

#define BOOST_TEST_DYN_LINK

#define BOOST_TEST_MODULE Main

#include

/* Note: originally, the line above was: "#include " */ BOOST_AUTO_TEST_CASE(fiveBitsTapAtTwo) { LFSR l("00111", 2);

BOOST_REQUIRE(l.step() == 1);

BOOST_REQUIRE(l.step() == 1);

BOOST_REQUIRE(l.step() == 0);

BOOST_REQUIRE(l.step() == 0);

BOOST_REQUIRE(l.step() == 0);

BOOST_REQUIRE(l.step() == 1);

BOOST_REQUIRE(l.step() == 1);

BOOST_REQUIRE(l.step() == 0);

LFSR l2("00111", 2);

BOOST_REQUIRE(l2.generate(8) == 198);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!