Advertisement
Guest User

clb79a

a guest
Jan 3rd, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 30.09 KB | None | 0 0
  1. #ifndef TEST_BIGINT_H
  2. #define TEST_BIGINT_H
  3.  
  4. #include "BigInt.h"
  5. #include <iostream>
  6. #include <iomanip>
  7.  
  8.  
  9. #endif
  10.  
  11.  
  12. // *******************  Test_BigInt.cpp  ***********************
  13. #include "Test_BigInt.h"
  14.  
  15. #define BOOST_TEST_MODULE BigInt test
  16. #include <boost/test/unit_test.hpp>
  17.  
  18. class KeepRunning
  19. {
  20. public:
  21.     ~KeepRunning()
  22.     {
  23.     std::cout << "Press ENTER to continue...";
  24.     std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
  25.     }
  26. };
  27.  
  28. BOOST_AUTO_TEST_CASE( BigInt_test )
  29. {
  30.     using std::cout;
  31.     using std::cin;
  32.     using std::endl;
  33.     using std::string;
  34.  
  35.     KeepRunning kr;
  36.  
  37.     std::ostringstream oss;
  38.     std::string s;
  39.  
  40.     BigInt biDefault;
  41.     oss << biDefault;
  42.     s = "0";
  43.     BOOST_CHECK( oss.str() == s );
  44.  
  45.     // constructor with unsigned long
  46.     unsigned long n = 4294967295;
  47.     BigInt bi1A( n );
  48.     oss.str( "" );
  49.     oss << bigintbin << bi1A;
  50.     s = "b11111111111111111111111111111111";
  51.     BOOST_CHECK( oss.str() == s );
  52.  
  53.     n = 65537;
  54.     BigInt bi1B( n );
  55.     oss.str( "" );
  56.     oss << bigintbin << bi1B;
  57.     s = "b10000000000000001";
  58.     BOOST_CHECK( oss.str() == s );
  59.  
  60.     n = 1;
  61.     BigInt bi1C( n );
  62.     oss.str( "" );
  63.     oss << bigintbin << bi1C;
  64.     s = "b1";
  65.     BOOST_CHECK( oss.str() == s );
  66.  
  67.     n = 0;
  68.     BigInt bi1D( n );
  69.     oss.str( "" );
  70.     oss << bigintbin << bi1D;
  71.     s = "b0";
  72.     BOOST_CHECK( oss.str() == s );
  73.  
  74.     // *********************************************************************
  75.  
  76.     // constructor with signed long
  77.     signed long m = -2147483647;
  78.     BigInt bi2A( m );
  79.     oss.str( "" );
  80.     oss << bigintbin << bi2A;
  81.     s = "b-1111111111111111111111111111111";
  82.     BOOST_CHECK( oss.str() == s );
  83.  
  84.     // negative number with the largest possible magnitude
  85.     m = -2147483647;
  86.     --m;
  87.     BigInt bi2B( m );
  88.     oss.str( "" );
  89.     oss << bigintbin << bi2B;
  90.     s = "b-10000000000000000000000000000000";
  91.     BOOST_CHECK( oss.str() == s );
  92.  
  93.     m = -65537;
  94.     BigInt bi2C( m );
  95.     oss.str( "" );
  96.     oss << bigintbin << bi2C;
  97.     s = "b-10000000000000001";
  98.     BOOST_CHECK( oss.str() == s );
  99.  
  100.     m = -1;
  101.     BigInt bi2D( m );
  102.     oss.str( "" );
  103.     oss << bigintbin << bi2D;
  104.     s = "b-1";
  105.     BOOST_CHECK( oss.str() == s );
  106.  
  107.     // *********************************************************************
  108.  
  109.     // constructor with int
  110.     int a = 16;
  111.     BigInt bi3A( a );
  112.     oss.str( "" );
  113.     oss << bigintbin << bi3A;
  114.     s = "b10000";
  115.     BOOST_CHECK( oss.str() == s );
  116.  
  117.     a = -16;
  118.     BigInt bi3B( a );
  119.     oss.str( "" );
  120.     oss << bigintbin << bi3B;
  121.     s = "b-10000";
  122.     BOOST_CHECK( oss.str() == s );
  123.  
  124.  
  125.     // *********************************************************************
  126.  
  127.     // constructor with string as binary
  128.  
  129.     string strParameter( "b1110" );
  130.     BigInt biBinA( strParameter );
  131.     oss.str( "" );
  132.     oss << bigintbin << biBinA;
  133.     s = "b1110";
  134.     BOOST_CHECK( oss.str() == s );
  135.  
  136.     strParameter = "b+1110";
  137.     BigInt biBinB( strParameter );
  138.     oss.str( "" );
  139.     oss << bigintbin << biBinB;
  140.     s = "b1110";
  141.     BOOST_CHECK( oss.str() == s );
  142.  
  143.     strParameter = "b-1110";
  144.     BigInt biBinC( strParameter );
  145.     oss.str( "" );
  146.     oss << bigintbin << biBinC;
  147.     s = "b-1110";
  148.     BOOST_CHECK( oss.str() == s );
  149.  
  150.     strParameter = "b0001";
  151.     BigInt biBinD( strParameter );
  152.     oss.str( "" );
  153.     oss << bigintbin << biBinD;
  154.     s = "b1";
  155.     BOOST_CHECK( oss.str() == s );
  156.  
  157.     strParameter = "B-0001";
  158.     BigInt biBinE( strParameter );
  159.     oss.str( "" );
  160.     oss << bigintbin << biBinE;
  161.     s = "b-1";
  162.     BOOST_CHECK( oss.str() == s );
  163.  
  164.     strParameter = "B0";
  165.     BigInt biBinF( strParameter );
  166.     oss.str( "" );
  167.     oss << bigintbin << biBinF;
  168.     s = "b0";
  169.     BOOST_CHECK( oss.str() == s );
  170.  
  171.     strParameter = "B-0";
  172.     BigInt biBinG( strParameter );
  173.     oss.str( "" );
  174.     oss << bigintbin << biBinG;
  175.     s = "b0";
  176.     BOOST_CHECK( oss.str() == s );
  177.  
  178.     // *********************************************************************
  179.  
  180.     // constructor with string as decimal
  181.  
  182.     strParameter = "d14";
  183.     BigInt biDecA( strParameter );
  184.     oss.str( "" );
  185.     oss << bigintbin << biDecA;
  186.     s = "b1110";
  187.     BOOST_CHECK( oss.str() == s );
  188.  
  189.     strParameter = "d+14";
  190.     BigInt biDecB( strParameter );
  191.     oss.str( "" );
  192.     oss << bigintbin << biDecB;
  193.     s = "b1110";
  194.     BOOST_CHECK( oss.str() == s );
  195.  
  196.     strParameter = "d-14";
  197.     BigInt biDecC( strParameter );
  198.     oss.str( "" );
  199.     oss << bigintbin << biDecC;
  200.     s = "b-1110";
  201.     BOOST_CHECK( oss.str() == s );
  202.  
  203.     strParameter = "d0001";
  204.     BigInt biDecD( strParameter );
  205.     oss.str( "" );
  206.     oss << bigintbin << biDecD;
  207.     s = "b1";
  208.     BOOST_CHECK( oss.str() == s );
  209.  
  210.     strParameter = "D-0001";
  211.     BigInt biDecE( strParameter );
  212.     oss.str( "" );
  213.     oss << bigintbin << biDecE;
  214.     s = "b-1";
  215.     BOOST_CHECK( oss.str() == s );
  216.  
  217.     strParameter = "D0";
  218.     BigInt biDecF( strParameter );
  219.     oss.str( "" );
  220.     oss << bigintbin << biDecF;
  221.     s = "b0";
  222.     BOOST_CHECK( oss.str() == s );
  223.  
  224.     strParameter = "D-0";
  225.     BigInt biDecG( strParameter );
  226.     oss.str( "" );
  227.     oss << bigintbin << biDecG;
  228.     s = "b0";
  229.     BOOST_CHECK( oss.str() == s );
  230.  
  231.     strParameter = "14";
  232.     BigInt biDecH( strParameter );
  233.     oss.str( "" );
  234.     oss << bigintbin << biDecH;
  235.     s = "b1110";
  236.     BOOST_CHECK( oss.str() == s );
  237.  
  238.     strParameter = "+14";
  239.     BigInt biDecI( strParameter );
  240.     oss.str( "" );
  241.     oss << bigintbin << biDecI;
  242.     s = "b1110";
  243.     BOOST_CHECK( oss.str() == s );
  244.  
  245.     strParameter = "-14";
  246.     BigInt biDecJ( strParameter );
  247.     oss.str( "" );
  248.     oss << bigintbin << biDecJ;
  249.     s = "b-1110";
  250.     BOOST_CHECK( oss.str() == s );
  251.  
  252.     strParameter = "-0007";
  253.     BigInt biDecK( strParameter );
  254.     oss.str( "" );
  255.     oss << bigintbin << biDecK;
  256.     s = "b-111";
  257.     BOOST_CHECK( oss.str() == s );
  258.  
  259.     strParameter = "-0";
  260.     BigInt biDecL( strParameter );
  261.     oss.str( "" );
  262.     oss << bigintbin << biDecL;
  263.     s = "b0";
  264.     BOOST_CHECK( oss.str() == s );
  265.  
  266.     strParameter = "+0";
  267.     BigInt biDecM( strParameter );
  268.     oss.str( "" );
  269.     oss << bigintbin << biDecM;
  270.     s = "b0";
  271.     BOOST_CHECK( oss.str() == s );
  272.  
  273.     strParameter = "-4294967295";
  274.     BigInt biDecN( strParameter );
  275.     oss.str( "" );
  276.     oss << bigintbin << biDecN;
  277.     s = "b-11111111111111111111111111111111";
  278.     BOOST_CHECK( oss.str() == s );
  279.  
  280.     // *********************************************************************
  281.  
  282.     // constructor with string as hexadecimal
  283.  
  284.     strParameter = "x14";
  285.     BigInt biHexA( strParameter );
  286.     oss.str( "" );
  287.     oss << bigintbin << biHexA;
  288.     s = "b10100";
  289.     BOOST_CHECK( oss.str() == s );
  290.  
  291.     strParameter = "x+14";
  292.     BigInt biHexB( strParameter );
  293.     oss.str( "" );
  294.     oss << bigintbin << biHexB;
  295.     s = "b10100";
  296.     BOOST_CHECK( oss.str() == s );
  297.  
  298.     strParameter = "X-14";
  299.     BigInt biHexC( strParameter );
  300.     oss.str( "" );
  301.     oss << bigintbin << biHexC;
  302.     s = "b-10100";
  303.     BOOST_CHECK( oss.str() == s );
  304.  
  305.     strParameter = "X0001";
  306.     BigInt biHexD( strParameter );
  307.     oss.str( "" );
  308.     oss << bigintbin << biHexD;
  309.     s = "b1";
  310.     BOOST_CHECK( oss.str() == s );
  311.  
  312.     strParameter = "X-000A";
  313.     BigInt biHexE( strParameter );
  314.     oss.str( "" );
  315.     oss << bigintbin << biHexE;
  316.     s = "b-1010";
  317.     BOOST_CHECK( oss.str() == s );
  318.  
  319.     strParameter = "X0";
  320.     BigInt biHexF( strParameter );
  321.     oss.str( "" );
  322.     oss << bigintbin << biHexF;
  323.     s = "b0";
  324.     BOOST_CHECK( oss.str() == s );
  325.  
  326.     strParameter = "x-0";
  327.     BigInt biHexG( strParameter );
  328.     oss.str( "" );
  329.     oss << bigintbin << biHexG;
  330.     s = "b0";
  331.     BOOST_CHECK( oss.str() == s );
  332.  
  333.     strParameter = "xaF";
  334.     BigInt biHexH( strParameter );
  335.     oss.str( "" );
  336.     oss << bigintbin << biHexH;
  337.     s = "b10101111";
  338.     BOOST_CHECK( oss.str() == s );
  339.  
  340.     strParameter = "X-aF";
  341.     BigInt biHexI( strParameter );
  342.     oss.str( "" );
  343.     oss << bigintbin << biHexI;
  344.     s = "b-10101111";
  345.     BOOST_CHECK( oss.str() == s );
  346.  
  347.     strParameter = "x-ffffffff";
  348.     BigInt biHexL( strParameter );
  349.     oss.str( "" );
  350.     oss << bigintbin << biHexL;
  351.     s = "b-11111111111111111111111111111111";
  352.     BOOST_CHECK( oss.str() == s );
  353.  
  354.     // constructor with bad string
  355.     bool isBad = false;
  356.     try
  357.     {
  358.         BigInt badBigInt( "b+h" );
  359.     }
  360.     catch ( const std::invalid_argument& e )
  361.     {
  362.         isBad = true;
  363.         BOOST_CHECK( e.what() == string( "Invalid BigInt string=b+h" ) );
  364.     }
  365.     BOOST_CHECK( isBad == true );
  366.  
  367.  
  368.     // constructor with string using implicit conversion from char* to string
  369.  
  370.     BigInt bi5A( "b1110" );
  371.     oss.str( "" );
  372.     oss << bigintbin << bi5A;
  373.     s = "b1110";
  374.     BOOST_CHECK( oss.str() == s );
  375.  
  376.     BigInt bi5B( "b-1110" );
  377.     oss.str( "" );
  378.     oss << bigintbin << bi5B;
  379.     s = "b-1110";
  380.     BOOST_CHECK( oss.str() == s );
  381.  
  382.     BigInt bi5C( "b-0000101" );
  383.     oss.str( "" );
  384.     oss << bigintbin << bi5C;
  385.     s = "b-101";
  386.     BOOST_CHECK( oss.str() == s );
  387.  
  388.  
  389.  
  390.     // assignment operators
  391.     BigInt biAssignment;
  392.  
  393.     unsigned long k1 = 16;
  394.     biAssignment = k1;
  395.     oss.str( "" );
  396.     oss << bigintbin << biAssignment;
  397.     s = "b10000";
  398.     BOOST_CHECK( oss.str() == s );
  399.  
  400.     signed long k2 = -16;
  401.     biAssignment = k2;
  402.     oss.str( "" );
  403.     oss << bigintbin << biAssignment;
  404.     s = "b-10000";
  405.     BOOST_CHECK( oss.str() == s );
  406.  
  407.     int k3 = -15;
  408.     biAssignment = k3;
  409.     oss.str( "" );
  410.     oss << bigintbin << biAssignment;
  411.     s = "b-1111";
  412.     BOOST_CHECK( oss.str() == s );
  413.  
  414.     std::string k4( "255" );
  415.     biAssignment = k4;
  416.     oss.str( "" );
  417.     oss << bigintbin << biAssignment;
  418.     s = "b11111111";
  419.     BOOST_CHECK( oss.str() == s );
  420.  
  421.     biAssignment = "0011";
  422.     oss.str( "" );
  423.     oss << bigintbin << biAssignment;
  424.     s = "b1011";
  425.     BOOST_CHECK( oss.str() == s );
  426.  
  427.     // assignment with a bad BigInt string
  428.     isBad = false;
  429.     try
  430.     {
  431.         // This should cause implicit construction of rhs to fail
  432.         biAssignment = "qw78";
  433.     }
  434.     catch ( const std::invalid_argument& e )
  435.     {
  436.         isBad = true;
  437.         BOOST_CHECK( e.what() == string( "Invalid BigInt string=qw78" ) );
  438.     }
  439.     BOOST_CHECK( isBad == true );
  440.  
  441.  
  442.     // comparison operators
  443.  
  444.     BOOST_CHECK( BigInt( "999" ) < BigInt( "1000" ) );
  445.     BOOST_CHECK( BigInt( "-1" )  < BigInt( "0" ) );
  446.     BOOST_CHECK( BigInt( "-11" ) < BigInt( "-10" ) );
  447.     BOOST_CHECK(  -11 < BigInt( "-10" ) );
  448.     BOOST_CHECK( BigInt( "-11" ) < -10 );
  449.  
  450.     BOOST_CHECK( BigInt( "999" ) <= BigInt( "1000" ) );
  451.     BOOST_CHECK( BigInt( "1000" ) <= BigInt( "1000" ) );
  452.     BOOST_CHECK( BigInt( "-1" ) <= BigInt( "0" ) );
  453.     BOOST_CHECK( BigInt( "-0" ) <= BigInt( "0" ) );
  454.     BOOST_CHECK( BigInt( "-11" ) <= BigInt( "10" ) );
  455.     BOOST_CHECK( BigInt( "111" ) <= BigInt( "111" ) );
  456.     BOOST_CHECK( 999 <= BigInt( "1000" ) );
  457.     BOOST_CHECK( BigInt( "1000" ) <= 1000 );
  458.  
  459.  
  460.     BOOST_CHECK( BigInt( "b111" ) == BigInt( "b111" ) );
  461.     BOOST_CHECK( 7 == BigInt( "b111" ) );
  462.     BOOST_CHECK( BigInt( "b111" ) == 7 );
  463.     BOOST_CHECK( BigInt( "b111" ) != BigInt( "b110" ) );
  464.     BOOST_CHECK( 7 != BigInt( "b110" ) );
  465.     BOOST_CHECK( BigInt( "b111" ) != BigInt( "b-111" ) );
  466.     BOOST_CHECK( BigInt( "b111" ) != -7 );
  467.  
  468.  
  469.     BOOST_CHECK( BigInt( "1001" ) > BigInt( "1000" ) );
  470.     BOOST_CHECK( 1001 > BigInt( "1000" ) );
  471.     BOOST_CHECK( BigInt( "-1000" ) > BigInt( "-1001" ) );
  472.     BOOST_CHECK( BigInt( "-1000" ) > -1001 );
  473.     BOOST_CHECK( BigInt( "0" ) > BigInt( "-1" ) );
  474.  
  475.     BOOST_CHECK( BigInt( "1001" ) >= BigInt( "1000" ) );
  476.     BOOST_CHECK( 1001 >= BigInt( "1000" ) );
  477.     BOOST_CHECK( BigInt( "-1000" ) >= BigInt( "-1001" ) );
  478.     BOOST_CHECK( BigInt( "-1000" ) >= -1001 );
  479.     BOOST_CHECK( 0 >= BigInt( "-1" ) );
  480.     BOOST_CHECK( BigInt( "0" ) >= BigInt( "-1" ) );
  481.     BOOST_CHECK( BigInt( "0" ) >= -1 );
  482.  
  483.    
  484.     // unary operators + and -
  485.  
  486.     BOOST_CHECK( BigInt( "b1001" ) == +BigInt( "b1001" ) );
  487.     BOOST_CHECK( -BigInt( "-1001" ) == BigInt( "1001" ) );
  488.     BOOST_CHECK( BigInt( "0" ) == -BigInt( "0" ) );
  489.  
  490.  
  491.     // conversion functions
  492.  
  493.     string sampleDecString( "368" );  // 0x170
  494.     string hexString( BigInt::decToHex( sampleDecString ) );
  495.     BOOST_CHECK( hexString == "170" );
  496.  
  497.     sampleDecString = "369"; // 0x171
  498.     hexString = BigInt::decToHex( sampleDecString );
  499.     BOOST_CHECK( hexString == "171" );
  500.  
  501.     sampleDecString = "1000"; // 0x3E8
  502.     hexString = BigInt::decToHex( sampleDecString );
  503.     BOOST_CHECK( hexString == "3e8" );
  504.  
  505.     sampleDecString = "0000"; // 0x0
  506.     hexString = BigInt::decToHex( sampleDecString );
  507.     BOOST_CHECK( hexString == "0" );
  508.  
  509.     sampleDecString = "4294967295"; // 0xFFFFFFFF
  510.     hexString = BigInt::decToHex( sampleDecString );
  511.     BOOST_CHECK( hexString == "ffffffff" );
  512.  
  513.     sampleDecString = "5"; // 0x5
  514.     hexString = BigInt::decToHex( sampleDecString );
  515.     BOOST_CHECK( hexString == "5" );
  516.  
  517.     sampleDecString = "55"; // 0x37
  518.     hexString = BigInt::decToHex( sampleDecString );
  519.     BOOST_CHECK( hexString == "37" );
  520.  
  521.  
  522.     // compound assignment +=
  523.     BigInt result;
  524.     BigInt bi6A( "111" );
  525.     result += bi6A;
  526.     BOOST_CHECK( result == bi6A );
  527.  
  528.     result += -bi6A;
  529.     BOOST_CHECK( result == BigInt( 0 ) );
  530.  
  531.     result += BigInt( "xFFFF" );
  532.     result += BigInt( "x1" );
  533.     BOOST_CHECK( result == BigInt( "x10000" ) );
  534.  
  535.     result += BigInt( "x-10001" );
  536.     BOOST_CHECK( result == BigInt( "x-1" ) );
  537.  
  538.     result += 256;
  539.     BOOST_CHECK( result == BigInt( "xff" ) );
  540.  
  541.     result += -2147483647;
  542.     BOOST_CHECK( result == BigInt( "x-7fffff00" ) );
  543.  
  544.     result = 3;
  545.     result += BigInt( -2 );
  546.     BOOST_CHECK( result == BigInt( 1 ) );
  547.  
  548.     result  = 3;
  549.     result += BigInt( -5 );
  550.     BOOST_CHECK( result == BigInt( -2 ) );
  551.  
  552.     result  = -2;
  553.     result += -5;
  554.     BOOST_CHECK( result == BigInt( -7 ) );
  555.  
  556.     result  = -5;
  557.     result += -2;
  558.     BOOST_CHECK( result == BigInt( -7 ) );
  559.  
  560.  
  561.     // compound assignment -=
  562.     result  = 3;
  563.     result -= 2;
  564.     BOOST_CHECK( result == BigInt( "1" ) );
  565.  
  566.     result -= 2;
  567.     BOOST_CHECK( result == BigInt( "-1" ) );
  568.  
  569.     result -= -1;
  570.     BOOST_CHECK( result == BigInt( "0" ) );
  571.  
  572.  
  573.     // compound assignment *=
  574.     BigInt resultMult( "b101001" );
  575.     BigInt bi8A( "b111" );
  576.     resultMult *= bi8A;
  577.     BOOST_CHECK( resultMult == BigInt( "b100011111" ) );
  578.  
  579.     resultMult  = "b101001";
  580.     resultMult *= -bi8A;
  581.     BOOST_CHECK( resultMult == BigInt( "b-100011111" ) );
  582.  
  583.     resultMult  = "b-101001";
  584.     resultMult *= -bi8A;
  585.     BOOST_CHECK( resultMult == BigInt( "b100011111" ) );
  586.  
  587.     resultMult *= 0;
  588.     BOOST_CHECK( resultMult == BigInt( 0 ) );
  589.  
  590.  
  591.     // compound assignment /=
  592.     BigInt resultQuotient( 10 );
  593.     resultQuotient /= 2;
  594.     BOOST_CHECK( resultQuotient == BigInt( 5 ) );
  595.  
  596.     resultQuotient  = 11;
  597.     resultQuotient /= 2;
  598.     BOOST_CHECK( resultQuotient == BigInt( 5 ) );
  599.  
  600.     resultQuotient  = 9;
  601.     resultQuotient /= 2;
  602.     BOOST_CHECK( resultQuotient == BigInt( 4 ) );
  603.  
  604.     resultQuotient  = 9;
  605.     resultQuotient /= 10;
  606.     BOOST_CHECK( resultQuotient == BigInt( 0 ) );
  607.  
  608.  
  609.     // compound assignment %=
  610.     BigInt resultRemainder = 10;
  611.     resultRemainder %= 5;
  612.     BOOST_CHECK( resultRemainder == BigInt( 0 ) );
  613.  
  614.     resultRemainder = 11;
  615.     resultRemainder %= 5;
  616.     BOOST_CHECK( resultRemainder == BigInt( 1 ) );
  617.  
  618.     resultRemainder = 9;
  619.     resultRemainder %= 5;
  620.     BOOST_CHECK( resultRemainder == BigInt( 4 ) );
  621.  
  622.  
  623.     // divisionAndRemainder()
  624.     BigInt quotient;
  625.     BigInt remainder;
  626.     BigInt dividend( "b10001101" );
  627.     BigInt divisor( "b111" );
  628.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  629.     BOOST_CHECK( quotient == BigInt( "b10100" ) && remainder == BigInt( "b1" ) );
  630.  
  631.     dividend = "b111000";
  632.     divisor  = "b111";
  633.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  634.     BOOST_CHECK( quotient == BigInt( "b1000" ) && remainder == 0 );
  635.  
  636.     dividend = 307;
  637.     divisor  = 5;
  638.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  639.     BOOST_CHECK( quotient == BigInt( 61 ) && remainder == BigInt( 2 ) );
  640.  
  641.     dividend = "xffff";
  642.     divisor  = "xff";
  643.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  644.     BOOST_CHECK( quotient == BigInt( "x101" ) && remainder == BigInt( "x0" ) );
  645.  
  646.     dividend = "xff";
  647.     divisor  = "xffff";
  648.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  649.     BOOST_CHECK( quotient == BigInt( "x0" ) && remainder == BigInt( "xff" ) );
  650.  
  651.     dividend = "0";
  652.     divisor  = "16";
  653.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  654.     BOOST_CHECK( quotient == BigInt( "x0" ) && remainder == BigInt( "x0" ) );
  655.  
  656.     dividend = "15";
  657.     divisor  = "16";
  658.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  659.     BOOST_CHECK( quotient == BigInt( "x0" ) && remainder == BigInt( "xf" ) );
  660.  
  661.     dividend = "16";
  662.     divisor  = "16";
  663.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  664.     BOOST_CHECK( quotient == BigInt( "x1" ) && remainder == BigInt( "x0" ) );
  665.  
  666.     dividend = "17";
  667.     divisor  = "16";
  668.     dividend.divisionAndRemainder( divisor, quotient, remainder );
  669.     BOOST_CHECK( quotient == BigInt( "x1" ) && remainder == BigInt( "x1" ) );
  670.  
  671.     // division by zero
  672.     isBad = false;
  673.     try
  674.     {
  675.         dividend = 8;
  676.         divisor = 0;
  677.         dividend.divisionAndRemainder( divisor, quotient, remainder );
  678.     }
  679.     catch ( const std::domain_error& e )
  680.     {
  681.         isBad = true;
  682.         BOOST_CHECK( e.what() == string( "Division by zero" ) );
  683.     }
  684.     BOOST_CHECK( isBad == true );
  685.  
  686.  
  687.  
  688.     // binary arithmetic operators
  689.     BigInt resultBinaryArith;
  690.     resultBinaryArith = BigInt( -2 ) + BigInt( 5 );
  691.     BOOST_CHECK( resultBinaryArith == BigInt( 3 ) );
  692.  
  693.     resultBinaryArith = BigInt( -2 ) + 5;
  694.     BOOST_CHECK( resultBinaryArith == BigInt( 3 ) );
  695.  
  696.     resultBinaryArith = 5 + BigInt( -2 );
  697.     BOOST_CHECK( resultBinaryArith == BigInt( 3 ) );
  698.  
  699.  
  700.     resultBinaryArith = BigInt( -2 ) - BigInt( 5 );
  701.     BOOST_CHECK( resultBinaryArith == BigInt( -7 ) );
  702.  
  703.     resultBinaryArith = BigInt( -2 ) - 5;
  704.     BOOST_CHECK( resultBinaryArith == BigInt( -7 ) );
  705.  
  706.     resultBinaryArith = -5 - BigInt( -2 );
  707.     BOOST_CHECK( resultBinaryArith == BigInt( -3 ) );
  708.  
  709.  
  710.     resultBinaryArith = BigInt( -2 ) * BigInt( 5 );
  711.     BOOST_CHECK( resultBinaryArith == BigInt( -10 ) );
  712.  
  713.     resultBinaryArith = BigInt( -2 ) * BigInt( -5 );
  714.     BOOST_CHECK( resultBinaryArith == BigInt( 10 ) );
  715.  
  716.     resultBinaryArith = BigInt( -2 ) * -5;
  717.     BOOST_CHECK( resultBinaryArith == BigInt( 10 ) );
  718.  
  719.     resultBinaryArith = -5 * BigInt( -2 );
  720.     BOOST_CHECK( resultBinaryArith == BigInt( 10 ) );
  721.  
  722.  
  723.     resultBinaryArith = BigInt( 4 ) / BigInt( 5 );
  724.     BOOST_CHECK( resultBinaryArith == BigInt( 0 ) );
  725.  
  726.     resultBinaryArith = BigInt( 5 ) / BigInt( 5 );
  727.     BOOST_CHECK( resultBinaryArith == BigInt( 1 ) );
  728.  
  729.     resultBinaryArith = BigInt( 6 ) / BigInt( 5 );
  730.     BOOST_CHECK( resultBinaryArith == BigInt( 1 ) );
  731.  
  732.     resultBinaryArith = BigInt( 6 ) / 5;
  733.     BOOST_CHECK( resultBinaryArith == BigInt( 1 ) );
  734.  
  735.     resultBinaryArith = 6 / BigInt( 5 );
  736.     BOOST_CHECK( resultBinaryArith == BigInt( 1 ) );
  737.  
  738.  
  739.     resultBinaryArith = BigInt( 4 ) % BigInt( 5 );
  740.     BOOST_CHECK( resultBinaryArith == BigInt( 4 ) );
  741.  
  742.     resultBinaryArith = BigInt( 5 ) % BigInt( 5 );
  743.     BOOST_CHECK( resultBinaryArith == BigInt( 0 ) );
  744.  
  745.     resultBinaryArith = BigInt( 6 ) % BigInt( 5 );
  746.     BOOST_CHECK( resultBinaryArith == BigInt( 1 ) );
  747.  
  748.     resultBinaryArith = BigInt( 6 ) % 5;
  749.     BOOST_CHECK( resultBinaryArith == BigInt( 1 ) );
  750.  
  751.     resultBinaryArith = 4 % BigInt( 5 );
  752.     BOOST_CHECK( resultBinaryArith == BigInt( 4 ) );
  753.  
  754.  
  755.     // increment and decrement operators
  756.     BigInt increment( -1 );
  757.     BigInt resultInc;
  758.     resultInc = ++increment;
  759.     BOOST_CHECK( resultInc == BigInt( 0 ) && increment == BigInt( 0 ) );
  760.  
  761.     resultInc = ++increment;
  762.     BOOST_CHECK( resultInc == BigInt( 1 ) && increment == BigInt( 1 ) );
  763.  
  764.     resultInc = 0;
  765.     increment = -1;
  766.     resultInc = increment++;
  767.     BOOST_CHECK( resultInc == BigInt( -1 ) && increment == BigInt( 0 ) );  
  768.  
  769.     resultInc = increment++;
  770.     BOOST_CHECK( resultInc == BigInt( 0 ) && increment == BigInt( 1 ) );
  771.  
  772.  
  773.     BigInt decrement( 1 );
  774.     BigInt resultDec;
  775.     resultDec = --decrement;
  776.     BOOST_CHECK( resultDec == BigInt( 0 ) && decrement == BigInt( 0 ) );
  777.  
  778.     resultDec = --decrement;
  779.     BOOST_CHECK( resultDec == BigInt( -1 ) && decrement == BigInt( -1 ) );
  780.  
  781.     decrement = 0;
  782.     resultDec = decrement--;
  783.     BOOST_CHECK( resultDec == BigInt( 0 ) && decrement == BigInt( -1 ) );
  784.  
  785.     resultDec = decrement--;
  786.     BOOST_CHECK( resultDec == BigInt( -1 ) && decrement == BigInt( -2 ) );
  787.  
  788.  
  789.     // swap()
  790.     BigInt biSwap1( "20" );
  791.     BigInt biSwap2( "-5" );
  792.     biSwap1.swap( biSwap2 );
  793.     BOOST_CHECK( biSwap1 == -5 && biSwap2 == 20 );
  794.  
  795.  
  796.     // conversion from binary string to decimal string
  797.     string decFromBinStr( BigInt::binToDec( "11111111" ) );
  798.     BOOST_CHECK( decFromBinStr == string( "255" ) );
  799.  
  800.     decFromBinStr = BigInt::binToDec( "11111111111111111111111111111111" );
  801.     BOOST_CHECK( decFromBinStr == string( "4294967295" ) );
  802.  
  803.     decFromBinStr = BigInt::binToDec( "000000001111" );
  804.     BOOST_CHECK( decFromBinStr == string( "15" ) );
  805.  
  806.  
  807.     // conversion from hex string to decimal string
  808.     string decFromHexStr( BigInt::hexToDec( "ffff" ) );
  809.     BOOST_CHECK( decFromHexStr == string( "65535" ) );
  810.  
  811.     decFromHexStr = BigInt::hexToDec( "000000ffff" );
  812.     BOOST_CHECK( decFromHexStr == string( "65535" ) );
  813.  
  814.    
  815.     // conversion from binary string to hex string
  816.     string hexFromBinStr( BigInt::binToHex( "1111000001011010" ) );  // 0xf05a
  817.     BOOST_CHECK( hexFromBinStr == string( "f05a" ) );
  818.  
  819.     hexFromBinStr = BigInt::binToHex( "1111010" );  //  0x7A;
  820.     BOOST_CHECK( hexFromBinStr == string( "7a" ) );
  821.  
  822.     hexFromBinStr = BigInt::binToHex( "11111" );
  823.     BOOST_CHECK( hexFromBinStr == string( "1f" ) );
  824.  
  825.     hexFromBinStr = BigInt::binToHex( "000001111" );
  826.     BOOST_CHECK( hexFromBinStr == string( "f" ) );
  827.  
  828.     hexFromBinStr = BigInt::binToHex( "000000000" );
  829.     BOOST_CHECK( hexFromBinStr == string( "0" ) );
  830.  
  831.  
  832.     // conversion from hex string to binary string
  833.     string binFromHexStr( BigInt::hexToBin( "000A" ) );
  834.     BOOST_CHECK( binFromHexStr == string( "1010" ) );
  835.  
  836.     // conversion from decimal string to binary string
  837.     string binFromDecStr( BigInt::decToBin( "0000015" ) );
  838.     BOOST_CHECK( binFromDecStr == string( "1111" ) );
  839.  
  840.     // conversion from decimal string to hex string
  841.     string hexFromDecStr( BigInt::decToHex( "0000255" ) );
  842.     BOOST_CHECK( hexFromDecStr == string( "ff" ) );
  843.  
  844.  
  845.     // output manipulators
  846.     BigInt outMan = "b1010";
  847.     oss.str( "" );
  848.     oss << bigintdefault << outMan;
  849.     BOOST_CHECK( oss.str() == string( "10" ) );
  850.  
  851.     oss.str( "" );
  852.     oss << bigintshowbase << outMan;
  853.     BOOST_CHECK( oss.str() == string( "10" ) );
  854.  
  855.     oss.str( "" );
  856.     oss << biginthex << outMan;
  857.     BOOST_CHECK( oss.str() == string( "xa" ) );
  858.  
  859.     oss.str( "" );
  860.     oss << bigintupper << outMan;
  861.     BOOST_CHECK( oss.str() == string( "XA" ) );
  862.    
  863.     oss.str( "" );
  864.     oss << bigintbin << outMan;
  865.     BOOST_CHECK( oss.str() == string( "B1010" ) );
  866.  
  867.     oss.str( "" );
  868.     oss << bigintlower << outMan;
  869.     BOOST_CHECK( oss.str() == string( "b1010" ) );
  870.  
  871.     oss.str( "" );
  872.     oss << bigintnoshowbase << outMan;
  873.     BOOST_CHECK( oss.str() == string( "1010" ) );
  874.  
  875.     oss.str( "" );
  876.     oss << biginthex << outMan;
  877.     BOOST_CHECK( oss.str() == string( "a" ) );
  878.  
  879.     oss.str( "" );
  880.     oss << bigintdec << outMan;
  881.     BOOST_CHECK( oss.str() == string( "10" ) );
  882.  
  883.  
  884.  
  885.  
  886.     // isValidBigIntString()
  887.     s = "";
  888.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  889.  
  890.     s = "b";
  891.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  892.  
  893.     s = "B";
  894.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  895.  
  896.     s = "x";
  897.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  898.  
  899.     s = "X";
  900.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  901.  
  902.     s = "d";
  903.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  904.  
  905.     s = "D";
  906.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  907.  
  908.     s = "+";
  909.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  910.  
  911.     s = "-";
  912.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  913.  
  914.     s = "b+";
  915.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  916.  
  917.     s = "b-";
  918.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  919.  
  920.     s = "x+";
  921.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  922.  
  923.     s = "x-";
  924.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  925.  
  926.     s = "d+";
  927.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  928.  
  929.     s = "d-";
  930.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  931.  
  932.     s = "b2";
  933.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  934.  
  935.     s = "xg";
  936.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  937.  
  938.     s = "da";
  939.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  940.  
  941.     s = "+a";
  942.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  943.  
  944.     s = "-a";
  945.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  946.  
  947.     s = "b-2";
  948.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  949.  
  950.     s = "x-g";
  951.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  952.  
  953.     s = "d-a";
  954.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  955.  
  956.     s = "+2a";
  957.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  958.  
  959.     s = "-2a";
  960.     BOOST_CHECK( ! BigInt::isValidBigIntString( s ) );
  961.  
  962.  
  963.     s = "b101";
  964.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  965.  
  966.     s = "b+101";
  967.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  968.  
  969.     s = "b-110";
  970.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  971.  
  972.     s = "b1101";
  973.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  974.  
  975.     s = "x+107af";
  976.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  977.  
  978.     s = "x-107af";
  979.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  980.  
  981.     s = "x107af";
  982.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  983.  
  984.     s = "d-12390";
  985.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  986.  
  987.     s = "d12390";
  988.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  989.  
  990.     s = "-456";
  991.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  992.  
  993.     s = "+456";
  994.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  995.  
  996.     s = "12389";
  997.     BOOST_CHECK( BigInt::isValidBigIntString( s ) );
  998.  
  999.  
  1000.     // input operator >>
  1001.     BigInt biInput1( 5 );
  1002.     std::istringstream iss;
  1003.     iss.str( "" );
  1004.     iss >> biInput1;
  1005.     BOOST_CHECK( biInput1 == 5 && iss.fail() && iss.eof() );
  1006.  
  1007.     iss.clear();
  1008.     iss.str( "b+tt" );
  1009.     iss >> biInput1;
  1010.     BOOST_CHECK( biInput1 == 5 && iss.fail() && iss.eof() );
  1011.  
  1012.     iss.clear();
  1013.     iss.str( "b+ss 234" );
  1014.     iss >> biInput1;
  1015.     BOOST_CHECK( biInput1 == 5 && iss.fail() && ! iss.eof() );
  1016.  
  1017.     iss.clear();
  1018.     iss.str( "1234" );
  1019.     iss >> biInput1;
  1020.     BOOST_CHECK( biInput1 == 1234 && ! iss.fail() && iss.eof() );
  1021.  
  1022.     BigInt biInput2 = "50";
  1023.     BigInt biInput3 = "75";
  1024.     iss.clear();
  1025.     iss.str( "b-1010 xff " );
  1026.     iss >> biInput1 >> biInput2 >> biInput3;
  1027.     BOOST_CHECK( biInput1 == -10 && biInput2 ==255 && biInput3 == 75 && iss.fail() && iss.eof() );
  1028.  
  1029.     // input stream manipulators
  1030.     // bigintdefault
  1031.     biInput1 = 0;
  1032.     iss.clear();
  1033.     iss >> bigintdefault;
  1034.     iss.str( "b1010" );
  1035.     iss >> biInput1;
  1036.     BOOST_CHECK(  biInput1 == 10 && ! iss.fail() && iss.eof() );
  1037.  
  1038.     biInput1 = 0;
  1039.     iss.clear();
  1040.     iss.str( "b-1010" );
  1041.     iss >> biInput1;
  1042.     BOOST_CHECK(  biInput1 == -10 && ! iss.fail() && iss.eof() );
  1043.  
  1044.     biInput1 = 0;
  1045.     iss.clear();
  1046.     iss.str( "x1010" );
  1047.     iss >> biInput1;
  1048.     BOOST_CHECK(  biInput1 == 4112 && ! iss.fail() && iss.eof() );
  1049.  
  1050.     biInput1 = 0;
  1051.     iss.clear();
  1052.     iss.str( "x-1010" );
  1053.     iss >> biInput1;
  1054.     BOOST_CHECK(  biInput1 == -4112 && ! iss.fail() && iss.eof() );
  1055.  
  1056.     biInput1 = 0;
  1057.     iss.clear();
  1058.     iss.str( "d1010" );
  1059.     iss >> biInput1;
  1060.     BOOST_CHECK(  biInput1 == 1010 && ! iss.fail() && iss.eof() );
  1061.  
  1062.     biInput1 = 0;
  1063.     iss.clear();
  1064.     iss.str( "d-1010" );
  1065.     iss >> biInput1;
  1066.     BOOST_CHECK(  biInput1 == -1010 && ! iss.fail() && iss.eof() );
  1067.  
  1068.     biInput1 = 0;
  1069.     iss.clear();
  1070.     iss.str( "1010" );
  1071.     iss >> biInput1;
  1072.     BOOST_CHECK(  biInput1 == 1010 && ! iss.fail() && iss.eof() );
  1073.  
  1074.     biInput1 = 0;
  1075.     iss.clear();
  1076.     iss.str( "-1010" );
  1077.     iss >> biInput1;
  1078.     BOOST_CHECK(  biInput1 == -1010 && ! iss.fail() && iss.eof() );
  1079.  
  1080.     // bigintdecimal ( should be the same as bigintdefault )
  1081.     biInput1 = 0;
  1082.     iss.clear();
  1083.     iss >> bigintdec;
  1084.     iss.str( "b1010" );
  1085.     iss >> biInput1;
  1086.     BOOST_CHECK(  biInput1 == 10 && ! iss.fail() && iss.eof() );
  1087.  
  1088.     biInput1 = 0;
  1089.     iss.clear();
  1090.     iss.str( "b-1010" );
  1091.     iss >> biInput1;
  1092.     BOOST_CHECK(  biInput1 == -10 && ! iss.fail() && iss.eof() );
  1093.  
  1094.     biInput1 = 0;
  1095.     iss.clear();
  1096.     iss.str( "x1010" );
  1097.     iss >> biInput1;
  1098.     BOOST_CHECK(  biInput1 == 4112 && ! iss.fail() && iss.eof() );
  1099.  
  1100.     biInput1 = 0;
  1101.     iss.clear();
  1102.     iss.str( "x-1010" );
  1103.     iss >> biInput1;
  1104.     BOOST_CHECK(  biInput1 == -4112 && ! iss.fail() && iss.eof() );
  1105.  
  1106.     biInput1 = 0;
  1107.     iss.clear();
  1108.     iss.str( "d1010" );
  1109.     iss >> biInput1;
  1110.     BOOST_CHECK(  biInput1 == 1010 && ! iss.fail() && iss.eof() );
  1111.  
  1112.     biInput1 = 0;
  1113.     iss.clear();
  1114.     iss.str( "d-1010" );
  1115.     iss >> biInput1;
  1116.     BOOST_CHECK(  biInput1 == -1010 && ! iss.fail() && iss.eof() );
  1117.  
  1118.     biInput1 = 0;
  1119.     iss.clear();
  1120.     iss.str( "1010" );
  1121.     iss >> biInput1;
  1122.     BOOST_CHECK(  biInput1 == 1010 && ! iss.fail() && iss.eof() );
  1123.  
  1124.     biInput1 = 0;
  1125.     iss.clear();
  1126.     iss.str( "-1010" );
  1127.     iss >> biInput1;
  1128.     BOOST_CHECK(  biInput1 == -1010 && ! iss.fail() && iss.eof() );
  1129.  
  1130.     // bigintbin
  1131.     biInput1 = 0;
  1132.     iss.clear();
  1133.     iss >> bigintbin;
  1134.     iss.str( "b1010" );
  1135.     iss >> biInput1;
  1136.     BOOST_CHECK(  biInput1 == 10 && ! iss.fail() && iss.eof() );
  1137.  
  1138.     biInput1 = 0;
  1139.     iss.clear();
  1140.     iss.str( "b-1010" );
  1141.     iss >> biInput1;
  1142.     BOOST_CHECK(  biInput1 == -10 && ! iss.fail() && iss.eof() );
  1143.  
  1144.     biInput1 = 0;
  1145.     iss.clear();
  1146.     iss.str( "x1010" );
  1147.     iss >> biInput1;
  1148.     BOOST_CHECK(  biInput1 == 4112 && ! iss.fail() && iss.eof() );
  1149.  
  1150.     biInput1 = 0;
  1151.     iss.clear();
  1152.     iss.str( "x-1010" );
  1153.     iss >> biInput1;
  1154.     BOOST_CHECK(  biInput1 == -4112 && ! iss.fail() && iss.eof() );
  1155.  
  1156.     biInput1 = 0;
  1157.     iss.clear();
  1158.     iss.str( "d1010" );
  1159.     iss >> biInput1;
  1160.     BOOST_CHECK(  biInput1 == 1010 && ! iss.fail() && iss.eof() );
  1161.  
  1162.     biInput1 = 0;
  1163.     iss.clear();
  1164.     iss.str( "d-1010" );
  1165.     iss >> biInput1;
  1166.     BOOST_CHECK(  biInput1 == -1010 && ! iss.fail() && iss.eof() );
  1167.  
  1168.     biInput1 = 0;
  1169.     iss.clear();
  1170.     iss.str( "1010" );
  1171.     iss >> biInput1;
  1172.     BOOST_CHECK(  biInput1 == 10 && ! iss.fail() && iss.eof() );
  1173.  
  1174.     biInput1 = 0;
  1175.     iss.clear();
  1176.     iss.str( "-1010" );
  1177.     iss >> biInput1;
  1178.     BOOST_CHECK(  biInput1 == -10 && ! iss.fail() && iss.eof() );
  1179.  
  1180.     // biginthex
  1181.     biInput1 = 0;
  1182.     iss.clear();
  1183.     iss >> biginthex;
  1184.     iss.str( "b1010" );
  1185.     iss >> biInput1;
  1186.     BOOST_CHECK(  biInput1 == 10 && ! iss.fail() && iss.eof() );
  1187.  
  1188.     biInput1 = 0;
  1189.     iss.clear();
  1190.     iss.str( "b-1010" );
  1191.     iss >> biInput1;
  1192.     BOOST_CHECK(  biInput1 == -10 && ! iss.fail() && iss.eof() );
  1193.  
  1194.     biInput1 = 0;
  1195.     iss.clear();
  1196.     iss.str( "x1010" );
  1197.     iss >> biInput1;
  1198.     BOOST_CHECK(  biInput1 == 4112 && ! iss.fail() && iss.eof() );
  1199.  
  1200.     biInput1 = 0;
  1201.     iss.clear();
  1202.     iss.str( "x-1010" );
  1203.     iss >> biInput1;
  1204.     BOOST_CHECK(  biInput1 == -4112 && ! iss.fail() && iss.eof() );
  1205.  
  1206.     biInput1 = 0;
  1207.     iss.clear();
  1208.     iss.str( "d1010" );
  1209.     iss >> biInput1;
  1210.     BOOST_CHECK(  biInput1 == 1010 && ! iss.fail() && iss.eof() );
  1211.  
  1212.     biInput1 = 0;
  1213.     iss.clear();
  1214.     iss.str( "d-1010" );
  1215.     iss >> biInput1;
  1216.     BOOST_CHECK(  biInput1 == -1010 && ! iss.fail() && iss.eof() );
  1217.  
  1218.     biInput1 = 0;
  1219.     iss.clear();
  1220.     iss.str( "1010" );
  1221.     iss >> biInput1;
  1222.     BOOST_CHECK(  biInput1 == 4112 && ! iss.fail() && iss.eof() );
  1223.  
  1224.     biInput1 = 0;
  1225.     iss.clear();
  1226.     iss.str( "-1010" );
  1227.     iss >> biInput1;
  1228.     BOOST_CHECK(  biInput1 == -4112 && ! iss.fail() && iss.eof() );
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.     // factorial function
  1235.     string factorial_100String( "9332621544394415268169923885626670049071596826438162146859296389521759999322991"
  1236.         "5608941463976156518286253697920827223758251185210916864000000000000000000000000" );
  1237.  
  1238.     BigInt resultFactorial_100;
  1239.     resultFactorial_100 = factorial( 100 );
  1240.     oss.str( "" );
  1241.     oss << bigintnoshowbase << bigintdec << resultFactorial_100;
  1242.     BOOST_CHECK( factorial_100String == oss.str() );
  1243.  
  1244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement