// test_class_SSArray_ctor_dctor_count
// Test suite for class template SSArray, number of class to item type
//  ctor, dctor.
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_SSArray_ctor_dctor_count(Tester & t)
{
    std::cout << "Test Suite: class template SSArray - ctor, dctor count"
              << std::endl;

    // Check number of value type ctor/dctor calls
    //  on array creation & destruction
    Counter::reset();
    { // Block, so we get dctor calls before function ends
        const SSArray<Counter> tacc(10);

        t.test(Counter::getCtorCount() == 10,
          "Counting default ctor calls due to array creation");

        Counter::reset();
    }
    t.test(Counter::getDctorCount() == 10,
      "Counting dctor calls due to destruction");

/*
    // Check correct number of value type ctor & dctor calls
    //  on self-assignment
    SSArray<Counter> tacc2(10);
    Counter::reset();
    tacc2 = tacc2;
    int i1 = Counter::getCtorCount() + Counter::getDctorCount();
    t.test(i1 == 0 || i1 == 20, "Self-assignment ctor/dctor calls");
*/
}
// test_class_KSArray_types
// Test suite for class KSArray, types
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_types(Tester & t)
{
    std::cout << "Test Suite: class KSArray - types" << std::endl;

    bool correctType;  // result of type checking

    // value_type test #1: int
    KSArray<int>::value_type i1 = 0;
    correctType = TypeCheck<int>::check(i1);
    t.test(correctType, "value_type test #1");

    // value_type test #2: double
    KSArray<double>::value_type d1 = 0.;
    correctType = TypeCheck<double>::check(d1);
    t.test(correctType, "value_type test #2");

    // value_type check modifiability (only needs to compile)
    KSArray<double>::value_type d2;
    d2 = 0.;
    t.test(true, "value_type check modifiability");

    // size_type test
    KSArray<Counter>::size_type s1 = 0;
    correctType = TypeCheck<std::size_t>::check(s1)
                  || TypeCheck<std::ptrdiff_t>::check(s1);
    t.test(correctType, "size_type test");

    // size_type check modifiability (only needs to compile)
    KSArray<Counter>::size_type s2;
    s2 = 0;
    t.test(true, "size_type check modifiability");
}
// test_class_SSArray_bracket_op
// Test suite for class Product, bracket operator
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
void test_class_SSArray_bracket_op(Tester & t)
{
    std::cout << "Test Suite: class Product, bracket operator" << std::endl;

    const int theSize = 10;
    bool noErrors;  // True if no errors encountered
    int i;          // Counter

    SSArray<int> ssai(theSize);
    for (i = 0; i < theSize; ++i)
        ssai[i] = 15 - i * i;

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (ssai[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Bracket operator (non-const)");

    // Make const version, no copy
    const SSArray<int> & ssaiRef = ssai;

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (ssaiRef[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Bracket operator (const)");
}
// test_class_SSArray_ctor_from_size_and_val
// Test suite for class template SSArray, ctor from size & value
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_SSArray_ctor_from_size_and_val(Tester & t)
{
    std::cout << "Test Suite: class template SSArray - "
              << "ctor from size & value"
              << std::endl;

    const int theSize = 1000;
    bool noErrors;  // True if no errors encountered
    const double val = -3.2;

    SSArray<double> tad(theSize, val);

    // check size
    t.test(tad.size() == theSize, "Ctor from size & value - check size");

    // check values
    typedef SSArray<double>::size_type ST;
    noErrors = true;
    for (auto i = static_cast<ST>(0);
         i < tad.size();
         ++i)
    {
        if (tad[i] != val)
            noErrors = false;
    }
    t.test(noErrors, "Ctor from size & value - check values");
}
// test_class_SSArray_copy_assn
// Test suite for class SSArray, copy assignment
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
void test_class_SSArray_copy_assn(Tester & t)
{
    std::cout << "Test Suite: class SSArray - copy assignment" << std::endl;

    const int theSize = 10;
    bool noErrors;  // True if no errors encountered
    int i;          // Counter

    SSArray<int> ssai(theSize);
    for (i = 0; i < theSize; ++i)
        ssai[i] = 15 - i * i;

    // Make const version, no copy
    const SSArray<int> & ssaiRef = ssai;
    // Make copy (copy assignment)
    SSArray<int> ssaiCopy(1);
    ssaiCopy = ssaiRef;

    t.test(ssaiCopy.size() == theSize, "Copy assignment - check size");

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (ssaiCopy[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Copy assignment - check values");
}
// test_class_SSArray_equality_comparisons
// Test suite for class template SSArray, comparisons ==, !=
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_SSArray_equality_comparisons(Tester & t)
{
    std::cout << "Test Suite: class template SSArray - "
              << "equality comparisons"
              << std::endl;

    bool correctType;  // result of type checking

    const int theSize = 10;
    int i;          // Counter

    SSArray<int> tai1(theSize);
    for (i = 0; i < theSize; ++i)
        tai1[i] = 15 - i * i;
    const SSArray<int> & tai1Ref = tai1;
    SSArray<int> tai1Copy(tai1Ref);
    SSArray<int> tai2(theSize-1);
    for (i = 0; i < theSize-1; ++i)
        tai2[i] = 15 - i * i;
    const SSArray<int> & tai2Ref = tai2;
    
    // operator== return type
    correctType = TypeCheck<bool>::check(tai1 == tai1Copy);
    t.test(correctType, "operator==, return type");

    // operator!= return type
    correctType = TypeCheck<bool>::check(tai1 != tai1Copy);
    t.test(correctType, "operator!=, return type");

    // Check equality of copies
    t.test(tai1 == tai1Copy, "Equality of copies");

    // Check inequality of copies
    t.test(!(tai1 != tai1Copy), "Inequality of copies");

    // Check equality of different sizes #1
    //  (compilation checks constness of op==)
    t.test(!(tai1Ref == tai2Ref), "Equality of different sizes #1");

    // Check inequality of different sizes #1
    //  (compilation checks constness of op!=)
    t.test(tai1Ref != tai2Ref, "Inequality of different sizes #1");

    // Check equality of different sizes #2
    t.test(!(tai2Ref == tai1Ref), "Equality of different sizes #2");

    // Check inequality of different sizes #2
    t.test(tai2Ref != tai1Ref, "Inequality of different sizes #2");

    // Modify copy
    ++tai1Copy[theSize-1];

    // Check equality of modification of copy
    t.test(!(tai1 == tai1Copy), "Equality of modification of copy");

    // Check inequality of modification of copy
    t.test(tai1 != tai1Copy, "Inequality of modification of copy");
}
// test_class_SSArray_bracket_op
// Test suite for class template SSArray, bracket operator
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_SSArray_bracket_op(Tester & t)
{
    std::cout << "Test Suite: class template SSArray, bracket operator"
              << std::endl;

    bool correctType;  // result of type checking

    const int theSize = 10;
    bool noErrors;  // True if no errors encountered
    int i;          // Counter

    SSArray<double> tad1;
    correctType = TypeCheck<SSArray<double>::value_type>::check(tad1[1]);
    t.test(correctType, "Bracket operator (non-const), return type");

    SSArray<int> tai(theSize);
    for (i = 0; i < theSize; ++i)
        tai[i] = 15 - i * i;

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (tai[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Bracket operator (non-const) #1");

    tai[2] = 1000;
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (tai[i] != ((i == 2) ? 1000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Bracket operator (non-const) #2");

    // Make const version, no copy
    const SSArray<int> & taiRef = tai;

    const SSArray<double> tad2;
    correctType = TypeCheck<SSArray<double>::value_type>::check(tad2[1]);
    t.test(correctType, "Bracket operator (const), return type");

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiRef[i] != ((i == 2) ? 1000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Bracket operator (const)");

}
// test_class_SSArray_size_and_ctor_from_size
// Test suite for class SSArray, function size and ctor from size
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
void test_class_SSArray_size_and_ctor_from_size(Tester & t)
{
    std::cout << "Test Suite: class SSArray - function size, ctor from size" << std::endl;

    const SSArray<int> ssai(10);
    t.test(ssai.size() == 10, "size, ctor from size (const) #1");

    const SSArray<double> ssad(100);
    t.test(ssad.size() == 100, "size, ctor from size (const) #2)");

    SSArray<int> ssai2(20);
    t.test(ssai2.size() == 20, "size, ctor from size (non-const)");
}
// test_class_KSArray_begin_end
// Test suite for class KSArray, functions begin & end
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_begin_end(Tester & t)
{
    std::cout << "Test Suite: class KSArray - functions begin & end" << std::endl;

    bool correctType;  // result of type checking

    const int theSize = 10;
    bool noErrors;      // True if no errors encountered
    int i;              // Counter
    int * iter;         // iterator
    const int * citer;  // const_iterator

    KSArray<int> tai(theSize);
    for (iter = tai.begin(), i = 0; iter != tai.end(); ++iter, ++i)
        *iter = 15 - i * i;

    // Non-const test
    KSArray<double> tad1;

    correctType = TypeCheck<KSArray<double>::value_type *>::check(tad1.begin());
    t.test(correctType, "begin (non-const), return type");

    correctType = TypeCheck<KSArray<double>::value_type *>::check(tad1.end());
    t.test(correctType, "end (non-const), return type");

    t.test(tai.begin() != tai.end(), "begin/end - inequality (non-const)");
    t.test (tai.end() - tai.begin() == theSize, "begin/end - check difference (non-const)");
    noErrors = true;
    for (iter = tai.begin(), i = 0; iter != tai.end(); ++iter, ++i)
    {
        if (*iter != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "begin/end - check values (non-const)");

    // Make const version, no copy
    const KSArray<int> & taiRef = tai;

    // Const test
    const KSArray<double> tad2;

    correctType = TypeCheck<const KSArray<double>::value_type *>::check(tad2.begin());
    t.test(correctType, "begin (const), return type");

    correctType = TypeCheck<const KSArray<double>::value_type *>::check(tad2.end());
    t.test(correctType, "end (const), return type");

    t.test(taiRef.end() - taiRef.begin() == theSize, "begin/end - check difference (const)");
    noErrors = true;
    for (citer = taiRef.begin(), i = 0; citer != taiRef.end(); ++citer, ++i)
    {
        if (*citer != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "begin/end - check values (const)");
}
// test_class_KSArray_default_ctor
// Test suite for class KSArray, default ctor
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_default_ctor(Tester & t)
{
    std::cout << "Test Suite: class KSArray - default ctor" << std::endl;

    const KSArray<int> tai1;
    t.test(tai1.size() == 10, "default ctor, size");
}
示例#11
0
int main( int argc, char **argv )
{
  QApplication app( argc, argv );
  
  Tester t;
  t.test();
  
  return 0;
}
示例#12
0
// gcd_single_test
// Helper function for testing function gcd
// Pre:
//     a, b are nonnegative, not both zero.
//     c is the GCD of a, b.
// Post:
//     gcd(a, b) == c has been tested.
//     Pass/fail status has been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee
void gcd_single_test(Tester & t,
                     int a,
                     int b,
                     int c)
{
    std::ostringstream oss;
    int result = gcd(a, b);
    oss << "gcd(" << a << ", " << b << ") = " << c;
    if (c != result)
        oss << " [actual return value: " << result << "]";
    t.test(result == c, oss.str());
}
// test_class_SSArray_ctor_dctor_count
// Test suite for class SSArray, number of class to item type
//  ctor, dctor.
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
void test_class_SSArray_ctor_dctor_count(Tester & t)
{
    std::cout << "Test Suite: class SSArray - ctor, dctor count" << std::endl;

    // Check number of value type ctor/dctor calls on array creation & destruction
    TestItem::resetCount();
    { // Block, so we get dctor calls before function ends
        const SSArray<TestItem> ssat(10);

        t.test(TestItem::getCount() == 10, "Counting default ctor calls due to array creation");

        TestItem::resetCount();
    }
    t.test(TestItem::getCount() == 10, "Counting dctor calls after due to destruction");

    // Check number of value type ctor/dctor calls on self-assignment
    SSArray<TestItem> ssat2(10);
    TestItem::resetCount();
    ssat2 = ssat2;
    t.test(TestItem::getCount() == 0, "Self-assignment should generate no ctor/dctor calls");
}
// test_class_KSArray_size_and_ctor_from_size
// Test suite for class KSArray, function size and ctor from size
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_size_and_ctor_from_size(Tester & t)
{
    std::cout << "Test Suite: class KSArray - function size, ctor from size"
              << std::endl;

    bool correctType;  // result of type checking

    const KSArray<int> tai1(1);

    correctType = TypeCheck<KSArray<int>::size_type>::check(tai1.size());
    t.test(correctType, "size, return type");

    t.test(tai1.size() == 1, "ctor from size (const) #1, check size");

    const KSArray<int> tai2(10);
    t.test(tai2.size() == 10, "ctor from size (const) #2, check size");

    const KSArray<double> tad(100);
    t.test(tad.size() == 100, "ctor from size (const) #3, check size");

    KSArray<int> tai3(20);
    t.test(tai3.size() == 20, "ctor from size (non-const), check size");

    const KSArray<int> tai4(0);
    t.test(tai4.size() == 0, "ctor from size (size 0), check size");
}
// test_class_SSArray_comparisons
// Test suite for class SSArray, comparisons
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
void test_class_SSArray_comparisons(Tester & t)
{
    std::cout << "Test Suite: class SSArray - comparisons" << std::endl;

    const int theSize = 10;
    int i;          // Counter

    SSArray<int> ssai1(theSize);
    for (i = 0; i < theSize; ++i)
        ssai1[i] = 15 - i * i;
    const SSArray<int> & ssai1Ref = ssai1;
    const SSArray<int> ssai2(theSize + 1);
    SSArray<int> ssai1Copy(ssai1Ref);

    // Check equality of copies
    t.test(ssai1 == ssai1Copy, "Equality of copies");

    // Check inequality of copies
    t.test(!(ssai1 != ssai1Copy), "Inequality of copies");

    // Check equality of different sizes (compilation checks constness of op==)
    t.test(!(ssai1Ref == ssai2), "Equality of different sizes");

    // Check inequality of different sizes (compilation checks constness of op!=)
    t.test(ssai1Ref != ssai2, "Inequality of different sizes");

    // Modify copy
    ++ssai1Copy[4];

    // Check equality of modification of copy
    t.test(!(ssai1 == ssai1Copy), "Equality of modification of copy");

    // Check inequality of modification of copy
    t.test(ssai1 != ssai1Copy, "Inequality of modification of copy");
}
// test_class_KSArray_ctor_from_size_and_val
// Test suite for class KSArray, ctor from size & value
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_ctor_from_size_and_val(Tester & t)
{
    std::cout << "Test Suite: class KSArray - ctor from size & value"
              << std::endl;

    const int theSize = 1000;
    bool noErrors;  // True if no errors encountered
    const double val = -3.2;

    KSArray<double> tad(theSize, val);

    // check size
    t.test(tad.size() == theSize, "Ctor from size & value - check size");

    // check values
    noErrors = true;
    for (unsigned int i = 0; i < tad.size(); ++i)
    {
        if (tad[i] != val)
            noErrors = false;
    }
    t.test(noErrors, "Ctor from size & value - check values");
}
// test_class_SSArray_begin_end
// Test suite for class SSArray, functions begin & end
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate have been messages printed to cout.
void test_class_SSArray_begin_end(Tester & t)
{
    std::cout << "Test Suite: class SSArray - functions begin & end" << std::endl;

    const int theSize = 10;
    bool noErrors;      // True if no errors encountered
    int i;              // Counter
    int * iter;         // iterator
    const int * citer;  // const_iterator

    SSArray<int> ssai(theSize);
    for (iter = ssai.begin(), i = 0; iter != ssai.end(); ++iter, ++i)
        *iter = 15 - i * i;

    // Non-const test
    t.test (ssai.end() - ssai.begin() == theSize, "begin/end - check difference (non-const)");
    noErrors = true;
    for (iter = ssai.begin(), i = 0; iter != ssai.end(); ++iter, ++i)
    {
        if (*iter != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "begin/end - check values (non-const)");

    // Make const version, no copy
    const SSArray<int> & ssaiRef = ssai;

    // Const test
    t.test(ssaiRef.end() - ssaiRef.begin() == theSize, "begin/end - check difference (const)");
    noErrors = true;
    for (citer = ssaiRef.begin(), i = 0; citer != ssaiRef.end(); ++citer, ++i)
    {
        if (*citer != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "begin/end - check values (const)");
}
示例#18
0
int main(){
  
  vector   <int> test_vec;
  Tester t;
  Tester2 tt;
  insert_iterator <vector <int> > ll (test_vec,test_vec.begin());
  t.test(ll);
  vector <int>::iterator it;
  
  for(it = test_vec.begin(); it != test_vec.end(); ++it){
    cout << *it << " ";
  }
  cout << endl;
  return 0;
  

}
示例#19
0
int run_main(int, ACE_TCHAR* [])
{
  ACE_START_TEST (ACE_TEXT ("UUID_Test"));

  Tester tester;

  int const result = tester.test();

  if (result == 0)
    ACE_DEBUG((LM_DEBUG,
               ACE_TEXT ("UUID_Test succeeded\n")));
  else
    ACE_ERROR((LM_ERROR,
               ACE_TEXT ("UUID_Test failed\n")));

  ACE_END_TEST;

  return result;
}
示例#20
0
// test_function_gcd
// Test suite for function gcd
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_function_gcd(Tester & t)
{
    std::cout << "Test Suite: function template gcd (Exercise D)"
              << std::endl;

    // Check return type of gcd
    t.test(TypeCheck<int>::check(gcd(2, 3)), "gcd: return type");

    // GCD function data
    // Three integers: a, b, GCD of a & b
    std::vector<std::vector<int> > gcd_data {
        {       0,      1,    1 },
        {       1,      0,    1 },
        {       1,      1,    1 },
        {       3,     10,    1 },
        {      10,      3,    1 },
        {       6,     15,    3 },
        {      15,      6,    3 },
        {       5, 100000,    5 },
        {  100000,      5,    5 },
        {       5, 100001,    1 },
        {  100001,      5,    1 },
        {     910,     42,   14 },
        {      42,    910,   14 },
        {  311850, 429975, 4725 },
        {  429975, 311850, 4725 },
        {  196418, 317811,    1 },
        {  317811, 196418,    1 },
        {  196418, 317812,    2 },
        {  317812, 196418,    2 },
    };

    // Test function gcd using the above vector
    for (const auto & v : gcd_data)
    {
        gcd_single_test(t, v[0], v[1], v[2]);
    }
}
示例#21
0
int main()
{
	// PICTURE
	Tester 	*tester = new Tester("Picture");
	Picture p;

	tester->test(p.data, std::string(""),
		"constructor without filename make an empty string");

	p.getPictureFromFile(std::string("file.test"));
	tester->test(p.data, std::string("this is a test\ncool"),
		"when a correct filename is provided, it correctly reads the file");

	p.getPictureFromFile(std::string("notExistingFile.test"));
	tester->test(p.data, std::string("ERROR"),
		"when there is an error, the string is set to ERROR");

	delete tester;
	// PICTURE

	// TOY
	tester = new Tester("Toy");
	Toy		t;

	tester->test(t.getType(), Toy::BASIC_TOY,
		"default constructor set the type to BASIC_TOY");
	tester->test(t.getName(), std::string("toy"),
		"default constructor set the name to toy");
	tester->test(t.getAscii(), std::string(""),
		"default constructor set the ascii to ''");

	Toy 	t2(Toy::ALIEN, std::string("E.T"), std::string("file.test"));

	tester->test(t2.getType(), Toy::ALIEN,
		"constructor set the type correctly");
	tester->test(t2.getName(), std::string("E.T"),
		"constructor set the name correctly");
	tester->test(t2.getAscii(), std::string("this is a test\ncool"),
		"constructor set the ascii correctly");

	t = t2;

	tester->test(t.getType(), t2.getType() ,
		"operator= set the type correctly");
	tester->test(t.getName(), t2.getName(),
		"operator= set the name correctly");
	tester->test(t.getAscii(), t2.getAscii(),
		"operator= set the ascii correctly");

	delete tester;
	// TOY

	// BUZZ + WOODY
	tester = new Tester("Buzz and Woody");

	Buzz 	buzz(std::string("foo"));
	Woody 	woody(std::string("bar"), std::string("file.test"));

	tester->test(buzz.getType(), Toy::BUZZ,
		"Buzz constructor (no file) set the type correctly");
	tester->test(buzz.getName(), std::string("foo"),
		"Buzz constructor (no file) set the name correctly");
	tester->test(buzz.getAscii(), std::string("Buzz !!!"),
		"Buzz constructor (no file) set the ascii correctly");	

	tester->test(woody.getType(), Toy::WOODY,
		"Woody constructor set the type correctly");
	tester->test(woody.getName(), std::string("bar"),
		"Woody constructor set the name correctly");
	tester->test(woody.getAscii(), std::string("this is a test\ncool"),
		"Woody constructor set the ascii correctly");


	tester->warn("The following tests cannot be unit tested, please check by hand");
	t.speak("I cannot unit test this... Does it work ? (toy)");
	buzz.speak("I cannot unit test this... Does it work ? (buzz)");
	woody.speak("I cannot unit test this... Does it work ? (woody)");

	delete tester;
	// BUZZ + WOODY

	// OPERATOR<<
	tester = new Tester("operator<<");

	t << "woohoo";

	tester->test(t.getAscii(), std::string("woohoo"),
		"operator<< with TOY and STRING");

	tester->warn("The following test cannot be unit tested, please check by hand");
	std::cout << t;

	delete tester;
	// OPERATOR<<

	return 0;
}
示例#22
0
  void sortThreeOfThreeEqual() {
    T data[] = { 1, 1, 1 };
    T expected[] = { 1, 1, 1 };

    tester.test(data, expected);
  }
示例#23
0
  void sortLimitValues() {
    T data[] = { max, 0, max, min  };
    T expected[] = { min, 0, max, max };

    tester.test(data, expected);
  }
示例#24
0
  /*
   * Other tests
   */ 
  void sortLargeA() {
    T data[] = { 37, min, big, -2, 231, small, big, max, 0, min };
    T expected[] = { min, min, small, -2, 0, 37, 231, big, big, max };   

    tester.test(data, expected);
  }
示例#25
0
  void sortOne() {
    T data[] = { 1 };
    T expected[] = { 1 };

    tester.test(data, expected);
  }
示例#26
0
  void sortTwoIn() {
    T data[] = { 0, 1 };
    T expected[] = { 0, 1 };

    tester.test(data, expected);
  }
// test_class_KSArray_order_comparisons
// Test suite for class KSArray, comparisons <, <=, >, >=
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_order_comparisons(Tester & t)
{
    std::cout << "Test Suite: class KSArray - comparisons" << std::endl;

    bool correctType;  // result of type checking

    const int theSize = 10;
    int i;          // Counter

    KSArray<int> tai1(theSize);
    for (i = 0; i < theSize; ++i)
        tai1[i] = 15 - i * i;
    const KSArray<int> tai1Eq(tai1);  // Equal to tai1
    KSArray<int> tai1Sm1(tai1);       // Smaller than tai1, due to values
    --tai1Sm1[5];
    KSArray<int> tai1Sm2(theSize-2);  // Smaller than tai1, due to size
    for (i = 0; i < tai1Sm2.size(); ++i)
        tai1Sm2[i] = tai1[i];
    KSArray<int> cmh(theSize+1);
    for (i = 0; i < theSize; ++i)
        cmh[i] = 15 - i * i;
    cmh[theSize-1]--;

    // operator< return type
    correctType = TypeCheck<bool>::check(tai1 < tai1Eq);
    t.test(correctType, "operator<, return type");

    // operator<= return type
    correctType = TypeCheck<bool>::check(tai1 <= tai1Eq);
    t.test(correctType, "operator<=, return type");

    // operator> return type
    correctType = TypeCheck<bool>::check(tai1 > tai1Eq);
    t.test(correctType, "operator>, return type");

    // operator>= return type
    correctType = TypeCheck<bool>::check(tai1 >= tai1Eq);
    t.test(correctType, "operator>=, return type");

    // Equal arrays, operator<
    t.test(!(tai1 < tai1Eq), "Equal arrays, operator<");

    // Equal arrays, operator<=
    t.test(tai1 <= tai1Eq, "Equal arrays, operator<=");

    // Equal arrays, operator>
    t.test(!(tai1 > tai1Eq), "Equal arrays, operator>");

    // Equal arrays, operator>=
    t.test(tai1 >= tai1Eq, "Equal arrays, operator>=");

    // Differing values #1, operator<
    t.test(!(tai1 < tai1Sm1), "Differing values #1, operator<");

    t.test(!(tai1<cmh),"! 223<222");

    // Differing values #1, operator<=
    t.test(!(tai1 <= tai1Sm1), "Differing values #1, operator<=");

    // Differing values #1, operator>
    t.test(tai1 > tai1Sm1, "Differing values #1, operator>");

    // Differing values #1, operator>=
    t.test(tai1 >= tai1Sm1, "Differing values #1, operator>=");

    // Differing values #2, operator<
    t.test(tai1Sm1 < tai1, "Differing values #2, operator<");

    // Differing values #2, operator<=
    t.test(tai1Sm1 <= tai1, "Differing values #2, operator<=");

    // Differing values #2, operator>
    t.test(!(tai1Sm1 > tai1), "Differing values #2, operator>");

    // Differing values #2, operator>=
    t.test(!(tai1Sm1 >= tai1), "Differing values #2, operator>=");

    // Differing sizes #1, operator<
    t.test(!(tai1 < tai1Sm2), "Differing sizes #1, operator<");

    // Differing sizes #1, operator<=
    t.test(!(tai1 <= tai1Sm2), "Differing sizes #1, operator<=");

    // Differing sizes #1, operator>
    t.test(tai1 > tai1Sm2, "Differing sizes #1, operator>");

    // Differing sizes #1, operator>=
    t.test(tai1 >= tai1Sm2, "Differing sizes #1, operator>=");

    // Differing sizes #2, operator<
    t.test(tai1Sm2 < tai1, "Differing sizes #2, operator<");

    // Differing sizes #2, operator<=
    t.test(tai1Sm2 <= tai1, "Differing sizes #2, operator<=");

    // Differing sizes #2, operator>
    t.test(!(tai1Sm2 > tai1), "Differing sizes #2, operator>");

    // Differing sizes #2, operator>=
    t.test(!(tai1Sm2 >= tai1), "Differing sizes #2, operator>=");
}
// test_class_SSArray_order_comparisons
// Test suite for class template SSArray, comparisons <, <=, >, >=
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_SSArray_order_comparisons(Tester & t)
{
    std::cout << "Test Suite: class template SSArray - order comparisons"
              << std::endl;

    bool correctType;  // result of type checking

    // Make vector of 10 SSArray<int> objects, in ascending order
    auto NUM_ARRAYS = static_cast<std::size_t>(10);
    std::vector<SSArray<int> > vv(NUM_ARRAYS);

    vv[0] = SSArray<int>(0);

    vv[1] = SSArray<int>(1);
    vv[1][0] = -1;

    vv[2] = SSArray<int>(2);
    vv[2][0] = -1;
    vv[2][1] = -1;

    vv[3] = SSArray<int>(99);
    for (auto & x : vv[3])
        x = -1;
        
    vv[4] = SSArray<int>(100);
    for (auto & x : vv[4])
        x = -1;

    vv[5] = SSArray<int>(100);
    for (auto & x : vv[5])
        x = -1;
    vv[5][90] = 1;

    vv[6] = SSArray<int>(2);
    vv[6][0] = -1;
    vv[6][1] = 1;

    vv[7] = SSArray<int>(1);
    vv[7][0] = 1;

    vv[8] = SSArray<int>(2);
    vv[8][0] = 1;
    vv[8][1] = -1;

    vv[9] = SSArray<int>(2);
    vv[9][0] = 1;
    vv[9][1] = 1;

    // operator< return type
    correctType = TypeCheck<bool>::check(vv[0] < vv[1]);
    t.test(correctType, "operator<, return type");

    // operator<= return type
    correctType = TypeCheck<bool>::check(vv[0] <= vv[1]);
    t.test(correctType, "operator<=, return type");

    // operator> return type
    correctType = TypeCheck<bool>::check(vv[0] > vv[1]);
    t.test(correctType, "operator>, return type");

    // operator>= return type
    correctType = TypeCheck<bool>::check(vv[0] >= vv[1]);
    t.test(correctType, "operator>=, return type");

    for (std::size_t i = 0; i < NUM_ARRAYS; ++i)
    {
        for (std::size_t j = 0; j < NUM_ARRAYS; ++j)
        {
            std::ostringstream os;
            os << ", test " << i << "," << j;
            t.test((vv[i] < vv[j]) == (i < j),
              "operator<" + os.str());
            t.test((vv[i] <= vv[j]) == (i <= j),
              "operator<=" + os.str());
            t.test((vv[i] > vv[j]) == (i > j),
              "operator>" + os.str());
            t.test((vv[i] >= vv[j]) == (i >= j),
              "operator>=" + os.str());
            t.test((vv[i] == vv[j]) == (i == j),
              "operator==" + os.str());
            t.test((vv[i] != vv[j]) == (i != j),
              "operator!=" + os.str());
        }
    }
}
// test_class_KSArray_copy_assn
// Test suite for class KSArray, copy assignment
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_copy_assn(Tester & t)
{
    std::cout << "Test Suite: class KSArray - copy assignment" << std::endl;

    bool correctType;  // result of type checking

    const int theSize = 10;
    bool noErrors;  // True if no errors encountered
    int i;          // Counter

    KSArray<int> tai(theSize);
    for (i = 0; i < theSize; ++i)
        tai[i] = 15 - i * i;

    // Make const version, no copy
    const KSArray<int> & taiRef = tai;
    // Make copy (copy ctor)
    KSArray<int> taiCopy(1);
    taiCopy = taiRef;

    // Do copy assignment & check return type
    correctType = TypeCheck<KSArray<int> >::check(taiCopy = taiRef);
    t.test(correctType, "Copy assn - return type");

    t.test(taiCopy.size() == theSize, "Copy assn - check size, copy");

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiCopy[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Copy assn - check values, copy");

    // Change original
    tai[2] = 1000;

    // Check original
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (tai[i] != ((i == 2) ? 1000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Copy assn - change original, check values, original");

    // Check copy
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiCopy[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Copy assn - change original, check values, copy");

    // Change copy
    taiCopy[3] = 2000;

    // Check original
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (tai[i] != ((i == 2) ? 1000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Copy assn - change copy, check values, original");

    // Check copy
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiCopy[i] != ((i == 3) ? 2000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Copy assn - change copy, check values, copy");

    // Check self-assignment
    taiCopy = taiCopy;

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiCopy[i] != ((i == 3) ? 2000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Copy assn - values after self-assignment");
}
// test_class_KSArray_copy_ctor
// Test suite for class KSArray, copy ctor
// Pre: None.
// Post:
//     Pass/fail status of tests have been registered with t.
//     Appropriate messages have been printed to cout.
// Does not throw (No-Throw Guarantee)
void test_class_KSArray_copy_ctor(Tester & t)
{
    std::cout << "Test Suite: class KSArray - copy ctor" << std::endl;

    const int theSize = 10;
    bool noErrors;  // True if no errors encountered
    int i;          // Counter

    KSArray<int> tai(theSize);
    for (i = 0; i < theSize; ++i)
        tai[i] = 15 - i * i;

    // Make const version, no copy
    const KSArray<int> & taiRef = tai;
    // Make copy (copy ctor)
    KSArray<int> taiCopy(taiRef);

    t.test(taiCopy.size() == theSize, "Copy ctor - check size, copy");

    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiCopy[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Copy ctor - check values, copy");

    // Change original
    tai[2] = 1000;

    // Check original
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (tai[i] != ((i == 2) ? 1000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Copy ctor - change original, check values, original");

    // Check copy
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiCopy[i] != 15 - i * i)
            noErrors = false;
    }
    t.test(noErrors, "Copy ctor - change original, check values, copy");

    // Change copy
    taiCopy[3] = 2000;

    // Check original
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (tai[i] != ((i == 2) ? 1000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Copy ctor - change copy, check values, original");

    // Check copy
    noErrors = true;
    for (i = 0; i < theSize; ++i)
    {
        if (taiCopy[i] != ((i == 3) ? 2000 : 15 - i * i))
            noErrors = false;
    }
    t.test(noErrors, "Copy ctor - change copy, check values, copy");
}