File indexing completed on 2025-10-12 04:59:55

0001 // bjgb_shoeutil.t.cpp                                                -*-C++-*-
0002 #include <bjgb_shoeutil.h>
0003 
0004 #include <bjgb_rank.h>
0005 
0006 #include <cstdlib>
0007 #include <iostream>
0008 #include <sstream>
0009 
0010 // ============================================================================
0011 //                        STANDARD ASSERT TEST FUNCTION
0012 // ----------------------------------------------------------------------------
0013 
0014 namespace {
0015 
0016 int testStatus = 0;
0017 
0018 void aSsErT(bool condition, const char *message, int line)
0019 {
0020     if (condition) {
0021         std::cout << "Error " __FILE__ "(" << line << "): " << message << "    (failed)" << std::endl;
0022 
0023         if (0 <= testStatus && testStatus <= 100) {
0024             ++testStatus;
0025         }
0026     }
0027 }
0028 
0029 } // namespace
0030 
0031 // ============================================================================
0032 //                         STANDARD TEST DRIVER MACROS
0033 // ----------------------------------------------------------------------------
0034 
0035 #define ASSERT(X) aSsErT(!(X), #X, __LINE__);
0036 
0037 // ============================================================================
0038 //                              MAIN PROGRAM
0039 // ----------------------------------------------------------------------------
0040 
0041 int main(int argc, char *argv[])
0042 {
0043     const int test = argc > 1 ? std::atoi(argv[1]) : 0;
0044     const bool verbose = argc > 2;
0045     const bool veryVerbose = argc > 3;
0046     const bool veryVeryVerbose = argc > 4;
0047     const bool veryVeryVeryVerbose = argc > 5;
0048 
0049     std::cout << "TEST " << __FILE__ << " CASE " << test << std::endl;
0050 
0051     switch (test) {
0052     case 0:
0053     case 1: {
0054         // --------------------------------------------------------------------
0055         // BREATHING TEST
0056         //
0057         // Concerns:
0058         //: 1 TBD
0059         //
0060         // Plan:
0061         //: 1 TBD
0062         //
0063         // Testing:
0064         //   BREATHING TEST
0065         // --------------------------------------------------------------------
0066 
0067         if (verbose)
0068             std::cout << std::endl << "BREATHING TEST" << std::endl << "==============" << std::endl;
0069 
0070         // 'isUnused'
0071         {
0072             const bjgb::Shoe X;
0073 
0074             ASSERT(true == bjgb::ShoeUtil::isUnused(X));
0075             ASSERT(0 == bjgb::ShoeUtil::tenRichness(X));
0076 
0077             bjgb::Shoe mY(2);
0078             const bjgb::Shoe& Y = mY;
0079 
0080             ASSERT(true == bjgb::ShoeUtil::isUnused(Y));
0081             ASSERT(0 == bjgb::ShoeUtil::tenRichness(Y));
0082 
0083             using namespace bjgb::RankLiterals;
0084 
0085             mY.setNumCardsOfRank(1_R, 9);
0086 
0087             ASSERT(false == bjgb::ShoeUtil::isUnused(Y));
0088             ASSERT(0 > bjgb::ShoeUtil::tenRichness(Y));
0089 
0090             mY.setNumCardsOfRank(2_R, 7);
0091 
0092             ASSERT(false == bjgb::ShoeUtil::isUnused(Y));
0093             ASSERT(0 == bjgb::ShoeUtil::tenRichness(Y));
0094 
0095             mY.setNumCardsOfRank(3_R, 7);
0096 
0097             ASSERT(false == bjgb::ShoeUtil::isUnused(Y));
0098             ASSERT(0 < bjgb::ShoeUtil::tenRichness(Y));
0099         }
0100 
0101         // 'setTenRichness', 'tenRichness'
0102         {
0103             const bjgb::Shoe X;
0104             ASSERT(0 == bjgb::ShoeUtil::tenRichness(X));
0105 
0106             bjgb::Shoe m2;
0107             bjgb::ShoeUtil::setTenRichness(&m2, -2);
0108             bjgb::Shoe m1;
0109             bjgb::ShoeUtil::setTenRichness(&m1, -1);
0110             bjgb::Shoe p0;
0111             bjgb::ShoeUtil::setTenRichness(&p0, +0);
0112             bjgb::Shoe p1;
0113             bjgb::ShoeUtil::setTenRichness(&p1, +1);
0114             bjgb::Shoe p2;
0115             bjgb::ShoeUtil::setTenRichness(&p2, +2);
0116 
0117             ASSERT(-2 == bjgb::ShoeUtil::tenRichness(m2));
0118             ASSERT(-1 == bjgb::ShoeUtil::tenRichness(m1));
0119             ASSERT(0 == bjgb::ShoeUtil::tenRichness(p0));
0120             ASSERT(1 == bjgb::ShoeUtil::tenRichness(p1));
0121             ASSERT(2 == bjgb::ShoeUtil::tenRichness(p2));
0122         }
0123 
0124     } break;
0125     default: {
0126         std::cerr << "WARNING: CASE `" << test << "' NOT FOUND." << std::endl;
0127         testStatus = -1;
0128     }
0129     }
0130 
0131     if (testStatus > 0) {
0132         std::cerr << "Error, non-zero test status = " << testStatus << "." << std::endl;
0133     }
0134 
0135     return testStatus;
0136 }