vimix

factorial.cpp

May 23rd, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. //Venix Cador
  2. // bigint Test Program
  3. //
  4. // Tests: int constructor, uses ==
  5. //
  6. #include "bigint.h"
  7.  
  8. #include <cassert>
  9.  
  10. //===========================================================================
  11. int main()
  12. {
  13. std::cout << "Testing factorial function!" << std::endl;
  14.  
  15. {
  16. bigint bi = 1,
  17. result = 0;
  18.  
  19. result = bi.factorial();
  20.  
  21. assert(result == 1);
  22.  
  23. std::cout << "Test: " << bi << "! == " << result << std::endl;
  24. }
  25.  
  26. {
  27. bigint bi = 2,
  28. result = 0;
  29.  
  30. result = bi.factorial();
  31.  
  32. assert(result == 2);
  33.  
  34. std::cout << "Test: " << bi << "! == " << result << std::endl;
  35. }
  36.  
  37. {
  38. bigint bi = 3,
  39. result = 0;
  40.  
  41. result = bi.factorial();
  42.  
  43. assert(result == 6);
  44.  
  45. std::cout << "Test: " << bi << "! == " << result << std::endl;
  46. }
  47.  
  48. {
  49. bigint bi = 4,
  50. result = 0;
  51.  
  52. result = bi.factorial();
  53.  
  54. assert(result == 24);
  55.  
  56. std::cout << "Test: " << bi << "! == " << result << std::endl;
  57. }
  58.  
  59. {
  60. bigint bi = 5,
  61. result = 0;
  62.  
  63. result = bi.factorial();
  64.  
  65. assert(result == 120);
  66.  
  67. std::cout << "Test: " << bi << "! == " << result << std::endl;
  68. }
  69.  
  70. {
  71. bigint bi = 20,
  72. result = 0;
  73.  
  74. result = bi.factorial();
  75.  
  76. assert(result == bigint("2432902008176640000"));
  77.  
  78. std::cout << "Test: " << bi << "! == " << result << std::endl;
  79. }
  80.  
  81. {
  82. bigint bi = 50,
  83. result = 0;
  84.  
  85. result = bi.factorial();
  86.  
  87. assert(result == bigint("30414093201713378043612608166064768844377641568960512000000000000"));
  88.  
  89. std::cout << "Test: " << bi << "! == " << result << std::endl;
  90. }
  91.  
  92. {
  93. bigint bi = 100,
  94. result = 0;
  95.  
  96. result = bi.factorial();
  97.  
  98. assert(result == bigint("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"));
  99.  
  100. std::cout << "Test: " << bi << "! == " << result << std::endl;
  101. }
  102.  
  103. std::cout << "Done with testing factorial." << std::endl;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment