Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <complex>
- #include <cstdlib>
- #include <climits>
- #include <cassert>
- #include <cstdint>
- #include "FractalCode.h"
- static_assert(sizeof(uint32_t) == sizeof(unsigned int), "unsigned int must be 32-bits!");
- typedef double iim_float_t;
- typedef std::complex<iim_float_t> iim_complex_t;
- #define EL std::endl
- iim_float_t random()
- {
- return std::rand() / (RAND_MAX - 0.0);
- }
- uint32_t random_uint32()
- {
- return (uint32_t)(random() * UINT32_MAX);
- }
- bool test_all_uint32_a_to_b(iim_complex_t c, uint32_t seed, uint32_t imax)
- {
- std::srand(seed);
- for (uint32_t i = 0; i < imax; ++i)
- {
- uint32_t plain = random_uint32();
- uint32_t encode = 0;
- uint32_t decode = 0;
- {
- FractalCode fc(c.real(), c.imag());
- encode = fc.Acode(plain);
- }
- {
- FractalCode fc(c.real(), c.imag());
- decode = fc.Bcode(encode);
- }
- if (decode != plain)
- {
- std::cout << "decode:" << decode << " != " << "plain:" << plain << EL;
- std::cin.get();
- assert(decode == plain);
- return false;
- }
- if (!(plain % ((i / 100) + 1)))
- {
- std::cout << "[" << i << "]:plain:" << plain << " = decode:" << decode << EL;
- }
- }
- return true;
- }
- int main()
- {
- std::cout << "sizeof(unsigned int):" << sizeof(unsigned int) << EL;
- std::cout << "sizeof(unsigned long):" << sizeof(unsigned long) << EL;
- {
- iim_complex_t c = { -0.687, -0.312 };
- test_all_uint32_a_to_b(c, 123456789, 1000000);
- }
- std::cout << EL << EL << "Program Complete" << EL;
- std::cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement