Skip to content
Snippets Groups Projects
Select Git revision
  • c51f863bc19c0fc745e786af2f46d0a0e3d2bc73
  • main default
  • detached3
  • detached2
  • modernisation-gestion-donnees
  • detached
  • 1.5.1
  • 1.5.0
  • 1.4.3
  • 1.4.2
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.2
  • 1.1.1
  • 1.1.0
  • 1.0.6
  • 1.0.5
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • 1.0.0
  • 0.9.10
  • 0.9.9
26 results

FunctionManager.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    bignum_tests.c 1.10 KiB
    #include <stdio.h>
    #include <string.h>
    #include <assert.h>
    #include "bignum.h"
    
    #define BG(n) bignum_from_int(n)
    
    void test_arithmetic(){
      assert(bignum_eq(bignum_add(BG(3), BG(4)), BG(7)));
      assert(bignum_eq(bignum_sub(BG(4), BG(3)), BG(1)));
      assert(bignum_eq(bignum_mul(BG(4), BG(3)), BG(12)));
      assert(bignum_eq(bignum_div(BG(36), BG(6)), BG(6)));
      assert(bignum_eq(bignum_mod(BG(21), BG(4)), BG(1)));
      assert(bignum_eq(bignum_pow(BG(2), BG(10)), BG(1024)));
      assert(bignum_eq(bignum_powm(BG(2), BG(10), BG(7)), BG(2)));
      printf("test_arithmetic OK\n");
    }
    
    void test_cmp(){
      assert(bignum_lt(BG(3), BG(42)));
      assert(bignum_lte(BG(3), BG(42)));
      assert(bignum_lte(BG(3), BG(3)));
      assert(!bignum_lte(BG(3), BG(1)));
    
      assert(!bignum_gt(BG(3), BG(42)));
      assert(!bignum_gte(BG(3), BG(42)));
      assert(bignum_gte(BG(3), BG(3)));
      assert(bignum_gte(BG(3), BG(1)));
      
      printf("test_cmp OK\n");
    }
    
    void test_str(){
      assert(strcmp(bignum_to_str(BG(17)), "17") == 0);
      printf("test_str OK\n");
    }
    
    int main(){
      printf("=== BIGNUM tests ===\n");
      test_arithmetic();
      test_cmp();
      test_str();
    
      return 0;
    }