예제 #1
0
int main() {
	Board Z;
	Z.AddAParticle(0, "Red");
	Z.AddBParticle(9, 2.7128);
	Z.AddAParticle(7, "Yellow");
	Z.AddBParticle(12, 24601);
	std::cout << Z << std::endl;
	
	std::cout << "Are there any Particles in position 9? ";
	bool a = Z[9];
	if (a) { std::cout << "Yes" << std::endl; }
	else { std::cout << "No" << std::endl; }
	std::cout << std::endl;
	
	std::cout << "Are there any Particles in position 2? ";
	bool b = Z[2];
	if (b) { std::cout << "Yes" << std::endl; }
	else { std::cout << "No" << std::endl; }
	std::cout << std::endl;

	std::cout << "Are there any Particles that share the same position? ";
	bool c = Z();
	if (c) { std::cout << "Yes" << std::endl; }
	else { std::cout << "No" << std::endl; }
	std::cout << std::endl;

	Z.AddAParticle(12, "John Cena");
	std::cout << Z << std::endl;
	std::cout<<"After adding a Particle, now are there any Particles that share the same position? ";
	bool d = Z();
	if (d) { std::cout << "Yes" << std::endl; }
	else { std::cout << "No" << std::endl; }
	std::cout << std::endl;

	ThingB copy = ThingB(20, 12.5, Z);
	copy.print(std::cout);
	std::cout << std::endl << std::endl;
	
	std::cout << "We propose the change the Particle's position to 12. Will it work? ";
	bool e = copy.propose_new_position(12);
	if (e) { std::cout << "Yes" << std::endl; }
	else { std::cout << "No" << std::endl; }
	copy.print(std::cout);
	std::cout << std::endl << std::endl;

	std::cout << "We propose the change the Particle's position to 24. Will it work? ";
	bool f = copy.propose_new_position(24);
	if (f) { std::cout << "Yes" << std::endl; }
	else { std::cout << "No" << std::endl; }
	copy.print(std::cout);
	std::cout << std::endl << std::endl;

	return 0;
}
예제 #2
0
int main() {
    
    Board test;
    //Testing operator << on empty board, should return nothing
    std::cout << test << std::endl;
    
    //Testing operator [] on empty board, should return 0
    std::cout << test[0] << std::endl;
    
    //Add particles to the board
    test.AddAParticle(0, "red");
    test.AddBParticle(9, 2.71828);
    test.AddAParticle(7, "yellow");
    
    //Test operator << on board with particles, should print out particles added above
    std::cout << test;
    
    //Test oeprator [] on board with particles, both particles in existence and not in existence, should return 1 for existing particles and return 0 for non-existing particles
    std::cout << test[0] << std::endl;
    std::cout << test[3] << std::endl;
    
    //Test operator () on board with no particles, should return 0
    Board test1;
    std::cout << test1() << std::endl;
    
    //Add two of the same particles to the board
    test1.AddAParticle(2, "blue");
    test1.AddAParticle(2, "blue");
    
    //Test operator () on board with same particles, should return 1
    std::cout << test1() << std::endl;
    
    //Add two different particles to a different board
    Board test2;
    test2.AddAParticle(3, "black");
    test2.AddBParticle(3, 6.8795);
    
    //Test operator () on board with different particles, should return 0
    std::cout << test2() << std::endl;
    
    //Test operator () on board with random particles
    Board test3;
    test3.AddAParticle(3, "black");
    test3.AddAParticle(0, "red");
    test3.AddBParticle(2, 5.4623);
    test3.AddAParticle(3, "black");
    
    //Test operator () should return 1
    std::cout << test3() << std::endl;
    
    
    return 0;
}
예제 #3
0
int main()
{
	//need this to get a memory leak dump at end of code execution
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );


	Board Z;
	Z.AddAParticle(0, "red");
	Z.AddBParticle(9, 2.71828);
	Z.AddAParticle(7, "yellow");
	//ThingA a = ThingA(0, "red");
	//a.print(cout);
	ThingB* B = new ThingB(-1, 9, &Z);
	
	
	cout<<"Does the particle at position 5 change?(true)   "<< B->propose_new_position(5)<<"\n\n";
	//cout << "Did the propose_new_position function replace the current position with the input value?(5)   ";
	//cout << Z.get_things()[5];
	cout << "Does the particle at position 7 change?(false)   " << B->propose_new_position(7) << "\n\n";



	cout << Z << endl << endl;
	cout << "Is there a particle at 9?(true)   " << Z[9]<<"\n\n";  //should return a 1
	cout << "Is there a particle at 3?(false)   " << Z[3]<<"\n\n";  //should return 0

	cout <<"Do any particles share the same position?(false)   "<< Z()<<"\n\n";
	Z.AddAParticle(0, "lavender");
	cout << "Two particles should now share the same position.(true)   " << Z() << "\n\n";

	ThingB* B1 = new ThingB(-1, 5, &Z);
	ThingB* B2 = new ThingB(-2, 4, &Z);

	B1->propose_new_position(9);  //checks to see if B1 object changed and if placed on board
	Z.AddThingBParticlePtr(B1);  //add B1 to the board, Z

	cout<<"B1 object:  ";
	B1->print(cout);
	cout << "\nGood, B1 did not change its position to 9 because there's already a Thing there." << Z;


	cout << endl << endl;
	B2->propose_new_position(2);
	Z.AddThingBParticlePtr(B2);  //add B2 to the board, Z
	cout<<"B2 object:  ";
	B2->print(cout);
	cout << "\nAs expected, B2 changed its position to 2.";
	cout <<"\n\n"<< Z <<"\n\n";
	
	/*  These pointers get deleted after they get added to the board, whose deconstructor automatically deallocates all
		thing pointers on it, in the vector, thing, of thing pointers.
	*/
	//delete B;
	//delete B1;
	//delete B2;

	cout << "\n\n";

	return 0;

	//_CrtDumpMemoryLeaks();
}