From 07c1eb59726073a38472b7fd8e04d13dd25ae85d Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Wed, 5 Oct 2005 05:33:43 +0000 Subject: [PATCH] Agregar algunos casos de prueba en number.cpp. --- tests/number.cpp | 82 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 18 deletions(-) diff --git a/tests/number.cpp b/tests/number.cpp index 3b9d1b5..dd9b450 100644 --- a/tests/number.cpp +++ b/tests/number.cpp @@ -3,31 +3,77 @@ int main() { -#if 0 - unsigned long buf[5] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0 }; +#if 1 + unsigned bufA[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; + unsigned bufB[] = { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 }; //unsigned buf[3] = { 0xffffffff, 0x1, 0 }; - number<> nu(buf, 4); //number< unsigned > nu2(nu); - number<> nu2 = 2u; - std::cout << "nu = " << nu << "\n\n"; - std::cout << "nu2 = " << nu2 << "\n\n"; - std::cout << "nu + nu2 = " << nu + nu2 << "\n\n"; - std::cout << "nu * nu2 = " << nu * nu2 << "\n\n"; - std::cout << "nu^nu2 = " << potencia(nu, nu2) << "\n\n"; + //number<> B = 0xffffffffU; + number<> A(bufA, 4, positive); + number<> B(bufB, 4, positive); + + + std::cout << "nu = " << A << "\n\n"; + std::cout << "nu2 = " << B << "\n\n"; + std::cout << "nu + nu2 = " << A + B << "\n\n"; + + number<> N = naif(A, B); + std::cout << "nu `naif` nu2 = " << N << "\n\n"; + + number<> K = karatsuba(A, B); + std::cout << "nu `ko` nu2 = " << K << "\n\n"; + + assert(N == K); + + number<> N2 = naif(A, A); + std::cout << "nu `naif` nu = " << N2 << "\n\n"; + + number<> K2 = karatsuba(A, A); + std::cout << "nu `ko` nu = " << K2 << "\n\n"; + + assert(N2 == K2); + + //std::cout << "nu^nu2 = " << pot_dyc(A, B) << "\n\n"; + + number<> X = 0xff; + number<> Y = 0xff; + std::cout << "r = " << naif(X, Y) << "\n\n"; + +#if 1 + number <>rd = pot_dyc(X, Y); + std::cout << "x `pot_dyc` y = " << rd << "\n\n"; + number <>rc = pot_ko(X, Y); + std::cout << "x `pot_ko` y = " << rc << "\n\n"; + if (!(rc == rd)) { + printf("Las pot NO DAN\n"); + } else { + printf("Las pot dan iguales\n"); + } #endif -#if 0 + unsigned buf1[] = { 0xffffffff, 0xffffffff }; + number<> T(buf1, 2, positive); + normalize_length(T, T); + std::cout << "test: " << naif(T, T) << "\n\n"; +#endif + +#if 1 number< unsigned > nu = 0xffffffff; std::cout << "nu = " << nu ; nu << 5; std::cout << "nu = " << nu ; - number<> n1 = 0xFFFFFFFF; - number<> n2 = 0xFFFFFFFF; + number<> n1 = 0xffff00f1; + number<> n2 = 0xffff00f0; - n1 += 1; + normalize_length(n1, n2); + /* + n2 += 1; + n1 <<= 4; + n2 <<= 4; + */ /* for (int k = 0; k < 100; k++) { n1 += (unsigned) rand() * k; @@ -42,11 +88,11 @@ int main() std::cout << "n1 es menor que n2\n"; else if (n2 < n1) std::cout << "n1 es mayor que n2\n"; - else + else std::cout << "n1 es igual que n2\n"; std::cout << "\n"; - + // for (int j=0; j<10; j++) // n1.borrow(0); @@ -58,10 +104,10 @@ int main() n1 -= n2; - std::cout << "n1-n2: " << n1 ; + std::cout << "n1-n2: " << n1 << "\n"; #endif -#if 1 +#if 0 uint32_t buf[] = { 0x00000040, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; number<> nu(buf, 8, negative); number<> nu2 = 0x2; @@ -100,7 +146,7 @@ int main() number<> a = h - d - m; - std::cout << "h-d-m: " << a ; + std::cout << "h-d-m: " << a << "\n"; return 0; -- 2.43.0