Advertisement
2607

s21_test.c

Nov 24th, 2021
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.03 KB | None | 0 0
  1. #include <string.h>
  2. #include <check.h>
  3. #include "s21_string.h"
  4. #include <stdio.h>
  5.  
  6. START_TEST(s21_strcmp_test)
  7. {
  8.     char *str1 = "12345";
  9.     char *str2 = "12344";
  10.     ck_assert_int_eq(s21_strcmp(str1, str2), strcmp(str1, str2));
  11.     ck_assert_int_eq(s21_strcmp(str1, str1), strcmp(str1, str1));
  12.     char *str3 = "123456789";
  13.     ck_assert_int_eq(s21_strcmp(str1, str3), strcmp(str1, str3));
  14.     char *str4 = "";
  15.     char *str5 = " ";
  16.     ck_assert_int_eq(s21_strcmp(str4, str4), strcmp(str4, str4));
  17.     ck_assert_int_eq(s21_strcmp(str4, str5), strcmp(str4, str5));
  18.  
  19. }
  20. END_TEST
  21.  
  22. START_TEST(s21_strncmp_test)
  23. {
  24.     char *str1 = "12345";
  25.     char *str2 = "12344";
  26.     ck_assert_int_eq(s21_strncmp(str1, str2, 5), strncmp(str1, str2, 5));
  27.     ck_assert_int_eq(s21_strncmp(str1, str1, 4), strncmp(str1, str1, 4));
  28.     char *str3 = "123456789";
  29.     ck_assert_int_eq(s21_strncmp(str1, str3, 15), strncmp(str1, str3, 15));
  30.     char *str4 = "";
  31.     char *str5 = " ";
  32.     ck_assert_int_eq(s21_strncmp(str4, str4, 1), strncmp(str4, str4, 1));
  33.     ck_assert_int_eq(s21_strncmp(str4, str5, 2), strncmp(str4, str5, 2));
  34. }
  35. END_TEST
  36.  
  37. START_TEST(s21_strcpy_test)
  38. {
  39.     char str1[] = "123456";
  40.     char buf[60]="";
  41.     ck_assert_str_eq(s21_strcpy(buf, str1), strcpy(buf, str1));
  42. }
  43. END_TEST
  44.  
  45. START_TEST(s21_strncpy_test)
  46. {
  47.     char str1[] = "123456";
  48.     char buf[60]="";
  49.     char buf1[60]="";
  50.     ck_assert_str_eq(s21_strncpy(buf, str1, 3), strncpy(buf, str1, 3));
  51.     ck_assert_str_eq(s21_strncpy(buf1, str1, 10), strncpy(buf1, str1, 10));
  52. }
  53. END_TEST
  54.  
  55. START_TEST(s21_sprintf_test)
  56. {
  57.     char str1[150] = "";
  58.     char str2[150] = "";
  59.     char buf1[60]="";
  60.     char buf2[60]="";
  61.     //ck_assert_int_eq(s21_sprintf(str1, "%*.*d %d % f %+-*d %% %*.*s %.*i %*c %-*lu\n",9,6, 2888, -286, 4.0,6, 100,8, 3, "Hello", 7, 45674,8,'Q',7, 5555555555), sprintf(str2,"%*.*d %d % f %+-*d %% %*.*s %.*i %*c %-*lu\n",9,6, 2888, -286, 4.0,6, 100,8, 3, "Hello", 7, 45674,8,'Q',7, 5555555555));
  62.     int l1 = s21_sprintf(str1, "%+*d", 6, 534);
  63.     int l2 = sprintf(str2, "%+*d", 6, 534);
  64.     ck_assert_int_eq(l1, l2);
  65.     ck_assert_str_eq(str1, str2);
  66.     printf("%s\n", buf1);
  67.     printf("%s\n", buf2);
  68.     int l3 = s21_sprintf(buf1, "%.*d %d % f %+-*d %% ", 6, 2888, -286, 4.0,6, 100);
  69.     int l4 = sprintf(buf2, "%.*d %d % f %+-*d %% ", 6, 2888, -286, 4.0,6, 100);
  70.     ck_assert_int_eq(l3, l4);
  71.     ck_assert_str_eq(buf1, buf2);
  72.     //ck_assert_str_eq(s21_sprintf(buf1, str1, 10), sprintf(buf1, str1, 10));
  73. }
  74. END_TEST
  75.  
  76. int main(void)
  77. {
  78.     Suite *s1 = suite_create("Core");
  79.     TCase *tc1_1 = tcase_create("Core");
  80.     SRunner *sr = srunner_create(s1);
  81.     int nf;
  82.  
  83.     suite_add_tcase(s1, tc1_1);
  84.     tcase_add_test(tc1_1, s21_strcmp_test);
  85.     tcase_add_test(tc1_1, s21_strncmp_test);
  86.     tcase_add_test(tc1_1, s21_strcpy_test);
  87.     tcase_add_test(tc1_1, s21_strncpy_test);
  88.     tcase_add_test(tc1_1, s21_sprintf_test);
  89.  
  90.     srunner_run_all(sr, CK_ENV);
  91.     nf = srunner_ntests_failed(sr);
  92.     srunner_free(sr);
  93.  
  94.     return nf == 0 ? 0 : 1;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement