Subversion Repositories Kolibri OS

Rev

Rev 9262 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. int comp(void *a, void *b) {
  7.         return *(int*)a - *(int*)b;
  8. }
  9.  
  10. int main(){
  11.         puts("Start testing.");
  12.         assert(NULL == ((void*)0));
  13.         assert(RAND_MAX == 65535);
  14.         assert(min(3, 10) == 3);
  15.         assert(max(3, 10) == 10);
  16.         assert(atof("12.4") == 12.4);
  17.         assert(atoi("-123") == -123);
  18.         assert(atol("-2146483647") == -2146483647L);
  19.         assert(atoll("-9223372036854775806") == -9223372036854775806LL);
  20.         assert(!strcmp("123", "123"));
  21.  
  22.         char st1[32];
  23.         itoa(-2341, st1);
  24.         assert(!strcmp(st1, "-2341"));
  25.  
  26.         assert(strlen("12345") == 5);
  27.         assert(abs(4) == 4);
  28.         assert(abs(-4) == 4);
  29.         assert(labs(1000000000) == 1000000000);
  30.         assert(labs(-1000000000) == 1000000000);
  31.         assert(llabs(100000000000) == 100000000000);
  32.         assert(llabs(-100000000000) == 100000000000);
  33.  
  34.         div_t output1 = div(27, 4);
  35.         assert(output1.quot == 6);
  36.         assert(output1.rem == 3);
  37.  
  38.         ldiv_t output2 = ldiv(27, 4);
  39.         assert(output2.quot == 6);
  40.         assert(output2.rem == 3);
  41.  
  42.         lldiv_t output3 = lldiv(27, 4);
  43.         assert(output3.quot == 6);
  44.         assert(output3.rem == 3);
  45.  
  46.         char *st2 = malloc(sizeof(char)*2);
  47.         assert(st2 != NULL);
  48.         st2[0] = 'H';
  49.         st2[1] = 'i';
  50.         st2 = realloc(st2, sizeof(char)*3);
  51.         st2[2] = '!';
  52.         assert(!strcmp(st2, "Hi!"));
  53.         free(st2);
  54.  
  55.         st2 = calloc(2, sizeof(char));
  56.         assert(st2 != NULL);
  57.         st2[0] = 'H';
  58.         st2[1] = 'i';
  59.         assert(!strcmp(st2, "Hi"));
  60.         free(st2);
  61.  
  62.         char *start = "100.00 Rub";
  63.         char *end;
  64.         assert(strtol(start, &end, 10) == 100L);
  65.         assert(!strcmp(end, ".00 Rub"));
  66.  
  67.         end = NULL;
  68.         assert(strtod(start, &end) == 100.0);
  69.         assert(!strcmp(end, " Rub"));
  70.  
  71.         // rand ¨ srand ¯à®¢¥à¥­ë ¢àãç­ãî :3
  72.  
  73.         char *st3 = "21.3e3Hello World!";
  74.         assert(atof(st3) == 21300.0);
  75.  
  76.         int nums[10] = {5, 3, 9, 1, 8, 4, 2, 0, 7, 6};
  77.         qsort(nums, 10, sizeof(int), (int(*) (const void *, const void *))comp);
  78.         for (int i = 0;  i < 10; i++) {
  79.                 assert(nums[i] == i);
  80.         }
  81.  
  82.         puts("End testing.");
  83.         exit(0);
  84. }