Refactoring Demo v11

From J. Arrizza Wiki

Jump to: navigation, search

No changes to the code. Just added a couple more unit tests. I now have 22 asserts:

<nowiki>

Num Asserts : 22 Num Failures: 0 Done! Press any key to continue <nowiki>

But the main() has become a repository of the test cases. I always worry that I'm going to forget to add a test case. This isn't just paranoia, I have in the past. So I'm going to look into whipping up something to make this problem go away...

main.cpp

<nowiki>
  1. pragma warning(disable: 4786)
  2. define WIN32_LEAN_AND_MEAN
  3. include <windows.h>
  1. include <iostream>

using namespace std;

  1. include "Compare.h"
  2. include "UtAsserter.h"

void Test1()

 {
 Comparer::StringList leftlist;
 Comparer::StringList rightlist;
 leftlist.clear();
 rightlist.clear();
 leftlist.push_back("item1");
 leftlist.push_back("item2");
 rightlist.push_back("item1");
 rightlist.push_back("item3");
 rightlist.push_back("item4");
 
 int result;
 Comparer cmp;
 cmp.Init(leftlist, rightlist);
 result = cmp.compare();
 utassert(Comparer::CHG, result);
 utassert(1, cmp.leftDiff.size());
 utassert(1, cmp.rightDiff.size());
 utassert("item2", cmp.leftDiff[0]);
 utassert("item3", cmp.rightDiff[0]);
 result = cmp.compare();
 utassert(Comparer::INS, result);
 utassert(0, cmp.leftDiff.size());
 utassert(1, cmp.rightDiff.size());
 utassert("item4", cmp.rightDiff[0]);
 result = cmp.compare();
 utassert(cmp.DONE, result);
 }

void Test2()

 {
 Comparer::StringList leftlist;
 Comparer::StringList rightlist;
 leftlist.clear();
 rightlist.clear();
 leftlist.push_back("item1");
 leftlist.push_back("item2");
 
 int result;
 Comparer cmp;
 cmp.Init(leftlist, rightlist);
 result = cmp.compare();
 utassert(Comparer::DEL, result);
 utassert(2, cmp.leftDiff.size());
 utassert(0, cmp.rightDiff.size());
 utassert("item1", cmp.leftDiff[0]);
 utassert("item2", cmp.leftDiff[1]);
 result = cmp.compare();
 utassert(cmp.DONE, result);
 }

void Test3()

 {
 Comparer::StringList leftlist;
 Comparer::StringList rightlist;
 leftlist.clear();
 rightlist.clear();
 rightlist.push_back("item1");
 rightlist.push_back("item2");
 
 int result;
 Comparer cmp;
 cmp.Init(leftlist, rightlist);
 result = cmp.compare();
 utassert(Comparer::INS, result);
 utassert(0, cmp.leftDiff.size());
 utassert(2, cmp.rightDiff.size());
 utassert("item1", cmp.rightDiff[0]);
 utassert("item2", cmp.rightDiff[1]);
 result = cmp.compare();
 utassert(cmp.DONE, result);
 }

//------------------------------------------ void main()

 {
 //test utassert

// utassert(0, 0); // utassert(1, 0); // utassert("ok", "ok"); // utassert("ok", "bad");

 Test1();
 Test2();
 Test3();
 ut.Report();
 cout << "Done!" << endl;
 OutputDebugString("Done!\n");
 }

<nowiki>

Personal tools