-
Notifications
You must be signed in to change notification settings - Fork 0
Home
YASUOKA Masahiko edited this page Aug 31, 2014
·
3 revisions
Some test cases:
#include <stdio.h>
#include "stralnumcmp.h"
#define TEST(_cond) do { \
if (_cond) \
printf(" %-50s ... ok\n", #_cond); \
else \
printf(" %-50s ... ng\n", #_cond); \
} while (0)
int
main(int argc, char *argv[])
{
// http://stackoverflow.com/questions/10202794/compare-two-alphanumeric-string
printf("test cases from stackoverflow.com:\n");
TEST(stralnumcmp("a5", "a11") < 0); // because 5 is less than 11
TEST(stralnumcmp("6xxx", "007asdf") < 0); // because 6 < 7
TEST(stralnumcmp("00042Q", "42s") < 0); // because Q < s alphabetically
TEST(stralnumcmp("6 8", "006 9") < 0); // because 8 < 9
// https://code.google.com/p/android-source-browsing/source/browse/strverscmp.c?repo=platform--external--blktrace
printf("Test cases from strverscmp:\n");
TEST(stralnumcmp("no digit", "no digit") == 0);
TEST(stralnumcmp("item#99", "item#100") < 0);
TEST(stralnumcmp("alpha1", "alpha001") > 0);
TEST(stralnumcmp("part1_f012", "part1_f01") > 0);
TEST(stralnumcmp("foo.009", "foo.0") < 0);
}
Results:
test cases from stackoverflow.com:
stralnumcmp("a5", "a11") < 0 ... ok
stralnumcmp("6xxx", "007asdf") < 0 ... ok
stralnumcmp("00042Q", "42s") < 0 ... ok
stralnumcmp("6 8", "006 9") < 0 ... ng
Test cases from strverscmp:
stralnumcmp("no digit", "no digit") == 0 ... ok
stralnumcmp("item#99", "item#100") < 0 ... ok
stralnumcmp("alpha1", "alpha001") > 0 ... ng
stralnumcmp("part1_f012", "part1_f01") > 0 ... ok
stralnumcmp("foo.009", "foo.0") < 0 ... ng