Commit 9d83fce77ee3b1d0f2a0968197b93202cc5ddc95

Steffen Jaeckel 2014-12-10T18:59:42

add tests

diff --git a/demo/demo.c b/demo/demo.c
index f9921ec..91b8104 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -97,6 +97,7 @@ int main(void)
    char* ret;
 #else
    unsigned long s, t;
+   unsigned long long q, r;
    mp_digit mp;
    int i, n, err;
 #endif
@@ -201,6 +202,26 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
       } while(t);
    }
 
+   printf("\n\nTesting: mp_get_long_long\n");
+   for (i = 0; i < (int)sizeof(unsigned long long)*CHAR_BIT; ++i) {
+      r = (1ULL << (i+1)) - 1;
+      if (!r)
+         r = -1;
+      printf(" r = 0x%llx i = %d\r", r, i);
+      do {
+         if (mp_set_long_long(&a, r) != MP_OKAY) {
+            printf("\nmp_set_long_long() error!");
+            return EXIT_FAILURE;
+         }
+         q = mp_get_long_long(&a);
+         if (q != r) {
+            printf("\nmp_get_long_long() bad result! 0x%llx != 0x%llx", q, r);
+            return EXIT_FAILURE;
+         }
+         r <<= 1;
+      } while(r);
+   }
+
    // test mp_sqrt
    printf("\n\nTesting: mp_sqrt\n");
    for (i = 0; i < 1000; ++i) {