Advertisement
Chris_M_Thomasson

Fractal Coding 32-bits: Juaquin Anderson's FractalCode class

Feb 28th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <complex>
  3. #include <cstdlib>
  4. #include <climits>
  5. #include <cassert>
  6. #include <cstdint>
  7. #include "FractalCode.h"
  8.  
  9.  
  10. static_assert(sizeof(uint32_t) == sizeof(unsigned int), "unsigned int must be 32-bits!");
  11.  
  12.  
  13. typedef double iim_float_t;
  14. typedef std::complex<iim_float_t> iim_complex_t;
  15. #define EL std::endl
  16.  
  17.  
  18. iim_float_t random()
  19. {
  20.     return std::rand() / (RAND_MAX - 0.0);
  21. }
  22.  
  23.  
  24. uint32_t random_uint32()
  25. {
  26.     return (uint32_t)(random() * UINT32_MAX);
  27. }
  28.  
  29.  
  30. bool test_all_uint32_a_to_b(iim_complex_t c, uint32_t seed, uint32_t imax)
  31. {
  32.     std::srand(seed);
  33.  
  34.     for (uint32_t i = 0; i < imax; ++i)
  35.     {
  36.         uint32_t plain = random_uint32();
  37.         uint32_t encode = 0;
  38.         uint32_t decode = 0;
  39.  
  40.         {
  41.             FractalCode fc(c.real(), c.imag());
  42.             encode = fc.Acode(plain);
  43.         }
  44.  
  45.         {
  46.             FractalCode fc(c.real(), c.imag());
  47.             decode = fc.Bcode(encode);
  48.         }
  49.  
  50.         if (decode != plain)
  51.         {
  52.             std::cout << "decode:" << decode << " != " << "plain:" << plain << EL;
  53.             std::cin.get();
  54.             assert(decode == plain);
  55.             return false;
  56.         }
  57.  
  58.         if (!(plain % ((i / 100) + 1)))
  59.         {
  60.             std::cout << "[" << i << "]:plain:" << plain << " = decode:" << decode << EL;
  61.         }
  62.     }
  63.  
  64.     return true;
  65. }
  66.  
  67.  
  68. int main()
  69. {
  70.     std::cout << "sizeof(unsigned int):" << sizeof(unsigned int) << EL;
  71.     std::cout << "sizeof(unsigned long):" << sizeof(unsigned long) << EL;
  72.  
  73.     {
  74.         iim_complex_t c = { -0.687, -0.312 };
  75.  
  76.         test_all_uint32_a_to_b(c, 123456789, 1000000);
  77.     }
  78.  
  79.     std::cout << EL << EL << "Program Complete" << EL;
  80.     std::cin.get();
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement