Question
Unit Tests Test-driving development is the process of creating the unit tests before writing the code the unit tests are meant to exercise. We are
Unit Tests
Test-driving development is the process of creating the unit tests before writing the code the unit tests are meant to exercise. We are going to follow that methodology this week.
Select the Classes
Select the most important two classes of our project. These can be the classes selected last week, or you might want to make adjustments based on feedback you received from your submission.
Write the Tests
With classes selected, it is time to write the unit tests. Each unit test should have four parts: Setup, Exercise, Verify, and Teardown. Additionally, each unit test should be encapsulated in a test class.
Strive to make every unit test fulfill the requirements in Chapter 25 of the textbook, and all the test cases meet the requirements of Chapter 14 of the textbook.
Run the Tests
The final step for this assignment is to run the tests. Initially, we expect the tests to fail. It probably will not even compile! Our job here is to write stub code for the classes under tests so they do compile but fail the test.
I just need two unit test classes for the code below. I think chess.cpp and point.h are the ones to focus on for testing:
chess.cpp:
point.h:
uiDraw.cpp:
uiDraw.h:
uiInteract.cpp:
uiInteract.h:
These are some tests I've made so far, could do with some more:
#include
class TestPoint
{
void defaultConstructor()
{
Point Point;
Point.setX();
Point.setY();
assert(Point.setX()) = 200;
assert(Point.setY()) = 200;
}
}
class TestChess
{
set
{
assert(board() = 65);
assert(board[location] = 'P' && row = 8);
assert(board[location] = 'k' && board[r * 8 + c] == isBlack() ||
Castle().inCheck = TRUE);
}
};
void ogstream:: drawSelected(int pos) \{ // do nothing if there is nothing to do if ( pos 0 \& \& pos =64 ) return; // find the row and column int row = pos /8; int col= pos %8; // set the color and drawing style glBegin(GL_QUADS); glColor(RGB_SELECTED); // draw the square glVertex2i((GLint) ((col+0)32+3), (GLint) (( row +0)32+3)); glVertex2i((GLint) ((col+1)323), (GLint) (( row +0)32+3)); glvertex2i((GLint) ((col+1)323), (GLint) (( row +1)323)); glVertex2i((GLint) ((col+0)32+3), (GLint) (( row +1)323)); // indicate we are finished glend (); \} void ogstream:: drawHover(int pos) \{ // do nothing if there is nothing to do if ( pos 0 pos =64 ) return; // find the row and column int row = pos /8; int col= pos %8; // set the color and drawing style glBegin (GL_QUADS); glColor(RGB_SELECTED); // draw the square glvertex2i((GLint) ((col+0)32), (GLint) (( row +0)32)); glVertex2i((GLint) ((col+1)32), /,1 \#pragma once using std: :string; \#endif'// LINUX, XCODE return; void clickCallback(int button, int state, int x, int y ) \{ // determine what to do if the button is selected if (button == GLUT_LEFT_BUTTON \& \& state == GLUT_DOWN) \{ // Even though this is a local variable, all the members are static // so we are actually getting the same version as in the constructor. Interface ui; // get coordinates from screen dimensions int pos = ui.positionFromXY (x,y); // if the current cell is selected, then deselect it if (ui.getselectPosition() == pos) ui.clearselectPosition(); else ui.setSelectPosition (pos); \} 3 void moveCallback(int x, int y ) \{ // Even though this is a local variable, all the members are static // so we are actually getting the same version as in the constructor. Interface ui; // get coordinates from screen dimensions int pos = ui.positionFromXY (x,y); ui. sethoverPosition (pos); \} / void closeCallback() \{ exit(0); \} extition \#pragma onceStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started