Skip to content

Commit

Permalink
add cases ft_strcmp
Browse files Browse the repository at this point in the history
  • Loading branch information
k11q committed Feb 23, 2023
1 parent c8e5749 commit a9a5b97
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 110 deletions.
60 changes: 60 additions & 0 deletions mini-moul/tests/C03/ex00/ft_strcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,66 @@ int main(void)
.s2 = "",
.expected = 72,
},
{
.desc = "Compare two strings of length 1",
.s1 = "a",
.s2 = "b",
.expected = -1,
},
{
.desc = "Compare two strings of length 1 (reversed)",
.s1 = "b",
.s2 = "a",
.expected = 1,
},
{
.desc = "Compare two strings of length 2",
.s1 = "ab",
.s2 = "ac",
.expected = -1,
},
{
.desc = "Compare two strings of length 2 (reversed)",
.s1 = "ac",
.s2 = "ab",
.expected = 1,
},
{
.desc = "Compare two strings with null character",
.s1 = "Hello\0world",
.s2 = "Hello",
.expected = 0,
},
{
.desc = "Compare two strings with null character (reversed)",
.s1 = "Hello",
.s2 = "Hello\0world",
.expected = 0,
},
{
.desc = "Compare two strings with multiple null characters",
.s1 = "Hello\0world\0",
.s2 = "Hello\0",
.expected = 0,
},
{
.desc = "Compare two strings with multiple null characters (reversed)",
.s1 = "Hello\0",
.s2 = "Hello\0world\0",
.expected = 0,
},
{
.desc = "Compare two identical strings with different pointers",
.s1 = "Hello",
.s2 = strdup("Hello"),
.expected = 0,
},
{
.desc = "Compare two non-identical strings with different pointers",
.s1 = "Hello",
.s2 = strdup("World"),
.expected = -15,
},
};
int count = sizeof(tests) / sizeof(tests[0]);

Expand Down
221 changes: 111 additions & 110 deletions mini-moul/tests/C04/ex03/ft_atoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,116 +40,117 @@ int main(void)
.desc = "Convert integer with non-numeric suffix",
.input = "123abc",
.expected = 123,
}, {
.desc = "Convert positive zero",
.input = "0",
.expected = 0,
},
{
.desc = "Convert negative zero",
.input = "-0",
.expected = 0,
},
{
.desc = "Convert integer with leading zeros",
.input = "000123",
.expected = 123,
},
{
.desc = "Convert integer with leading zeros and plus sign",
.input = "+000123",
.expected = 123,
},
{
.desc = "Convert integer with maximum value for int",
.input = "2147483647",
.expected = 2147483647,
},
{
.desc = "Convert integer with minimum value for int",
.input = "-2147483648",
.expected = -2147483648,
},
{
.desc = "Convert integer with overflow value",
.input = "2147483648",
.expected = -2147483648,
},
{
.desc = "Convert integer with underflow value",
.input = "-2147483649",
.expected = 2147483647,
},
{
.desc = "Convert integer with only negative sign",
.input = "-",
.expected = 0,
},
{
.desc = "Convert integer with only plus sign",
.input = "+",
.expected = 0,
},
{
.desc = "Convert empty string",
.input = "",
.expected = 0,
},
{
.desc = "Convert string with only spaces",
.input = " ",
.expected = 0,
},
{
.desc = "Convert string with spaces between digits",
.input = "12 34",
.expected = 12,
},
{
.desc = "Convert string with mixed spaces and signs",
.input = " +12 34",
.expected = 12,
},
{
.desc = "Convert string with non-numeric prefix",
.input = "abc123",
.expected = 0,
},
{
.desc = "Convert string with non-numeric prefix and sign",
.input = "+abc123",
.expected = 0,
},
{
.desc = "Convert string with non-numeric suffix and sign",
.input = "123abc+",
.expected = 123,
},
{
.desc = "Convert string with leading whitespaces, sign and zero",
.input = " - 0000",
.expected = 0,
},
{
.desc = "Convert string with multiple signs",
.input = "--123",
.expected = 123,
},
{
.desc = "Convert string with multiple signs",
.input = "++123",
.expected = 123,
},
{
.desc = "Convert string with invalid signs",
.input = "+-123",
.expected = -123,
},
{
.desc = "Convert string with out of range chars",
.input = "1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z",
.expected = 1,
},
},
{
.desc = "Convert positive zero",
.input = "0",
.expected = 0,
},
{
.desc = "Convert negative zero",
.input = "-0",
.expected = 0,
},
{
.desc = "Convert integer with leading zeros",
.input = "000123",
.expected = 123,
},
{
.desc = "Convert integer with leading zeros and plus sign",
.input = "+000123",
.expected = 123,
},
{
.desc = "Convert integer with maximum value for int",
.input = "2147483647",
.expected = 2147483647,
},
{
.desc = "Convert integer with minimum value for int",
.input = "-2147483648",
.expected = -2147483648,
},
{
.desc = "Convert integer with overflow value",
.input = "2147483648",
.expected = -2147483648,
},
{
.desc = "Convert integer with underflow value",
.input = "-2147483649",
.expected = 2147483647,
},
{
.desc = "Convert integer with only negative sign",
.input = "-",
.expected = 0,
},
{
.desc = "Convert integer with only plus sign",
.input = "+",
.expected = 0,
},
{
.desc = "Convert empty string",
.input = "",
.expected = 0,
},
{
.desc = "Convert string with only spaces",
.input = " ",
.expected = 0,
},
{
.desc = "Convert string with spaces between digits",
.input = "12 34",
.expected = 12,
},
{
.desc = "Convert string with mixed spaces and signs",
.input = " +12 34",
.expected = 12,
},
{
.desc = "Convert string with non-numeric prefix",
.input = "abc123",
.expected = 0,
},
{
.desc = "Convert string with non-numeric prefix and sign",
.input = "+abc123",
.expected = 0,
},
{
.desc = "Convert string with non-numeric suffix and sign",
.input = "123abc+",
.expected = 123,
},
{
.desc = "Convert string with leading whitespaces, sign and zero",
.input = " - 0000",
.expected = 0,
},
{
.desc = "Convert string with multiple signs",
.input = "--123",
.expected = 123,
},
{
.desc = "Convert string with multiple signs",
.input = "++123",
.expected = 123,
},
{
.desc = "Convert string with invalid signs",
.input = "+-123",
.expected = -123,
},
{
.desc = "Convert string with out of range chars",
.input = "1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z",
.expected = 1,
},
};
int count = sizeof(tests) / sizeof(tests[0]);

Expand Down

0 comments on commit a9a5b97

Please sign in to comment.