Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <check.h>
- #include "s21_string.h"
- #include <stdio.h>
- START_TEST(s21_strcmp_test)
- {
- char *str1 = "12345";
- char *str2 = "12344";
- ck_assert_int_eq(s21_strcmp(str1, str2), strcmp(str1, str2));
- ck_assert_int_eq(s21_strcmp(str1, str1), strcmp(str1, str1));
- char *str3 = "123456789";
- ck_assert_int_eq(s21_strcmp(str1, str3), strcmp(str1, str3));
- char *str4 = "";
- char *str5 = " ";
- ck_assert_int_eq(s21_strcmp(str4, str4), strcmp(str4, str4));
- ck_assert_int_eq(s21_strcmp(str4, str5), strcmp(str4, str5));
- }
- END_TEST
- START_TEST(s21_strncmp_test)
- {
- char *str1 = "12345";
- char *str2 = "12344";
- ck_assert_int_eq(s21_strncmp(str1, str2, 5), strncmp(str1, str2, 5));
- ck_assert_int_eq(s21_strncmp(str1, str1, 4), strncmp(str1, str1, 4));
- char *str3 = "123456789";
- ck_assert_int_eq(s21_strncmp(str1, str3, 15), strncmp(str1, str3, 15));
- char *str4 = "";
- char *str5 = " ";
- ck_assert_int_eq(s21_strncmp(str4, str4, 1), strncmp(str4, str4, 1));
- ck_assert_int_eq(s21_strncmp(str4, str5, 2), strncmp(str4, str5, 2));
- }
- END_TEST
- START_TEST(s21_strcpy_test)
- {
- char str1[] = "123456";
- char buf[60]="";
- ck_assert_str_eq(s21_strcpy(buf, str1), strcpy(buf, str1));
- }
- END_TEST
- START_TEST(s21_strncpy_test)
- {
- char str1[] = "123456";
- char buf[60]="";
- char buf1[60]="";
- ck_assert_str_eq(s21_strncpy(buf, str1, 3), strncpy(buf, str1, 3));
- ck_assert_str_eq(s21_strncpy(buf1, str1, 10), strncpy(buf1, str1, 10));
- }
- END_TEST
- START_TEST(s21_sprintf_test)
- {
- char str1[150] = "";
- char str2[150] = "";
- char buf1[60]="";
- char buf2[60]="";
- //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));
- int l1 = s21_sprintf(str1, "%+*d", 6, 534);
- int l2 = sprintf(str2, "%+*d", 6, 534);
- ck_assert_int_eq(l1, l2);
- ck_assert_str_eq(str1, str2);
- printf("%s\n", buf1);
- printf("%s\n", buf2);
- int l3 = s21_sprintf(buf1, "%.*d %d % f %+-*d %% ", 6, 2888, -286, 4.0,6, 100);
- int l4 = sprintf(buf2, "%.*d %d % f %+-*d %% ", 6, 2888, -286, 4.0,6, 100);
- ck_assert_int_eq(l3, l4);
- ck_assert_str_eq(buf1, buf2);
- //ck_assert_str_eq(s21_sprintf(buf1, str1, 10), sprintf(buf1, str1, 10));
- }
- END_TEST
- int main(void)
- {
- Suite *s1 = suite_create("Core");
- TCase *tc1_1 = tcase_create("Core");
- SRunner *sr = srunner_create(s1);
- int nf;
- suite_add_tcase(s1, tc1_1);
- tcase_add_test(tc1_1, s21_strcmp_test);
- tcase_add_test(tc1_1, s21_strncmp_test);
- tcase_add_test(tc1_1, s21_strcpy_test);
- tcase_add_test(tc1_1, s21_strncpy_test);
- tcase_add_test(tc1_1, s21_sprintf_test);
- srunner_run_all(sr, CK_ENV);
- nf = srunner_ntests_failed(sr);
- srunner_free(sr);
- return nf == 0 ? 0 : 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement