MCPcopy Create free account
hub / github.com/GJDuck/e9patch / test_qsort

Function test_qsort

test/regtest/patch.cpp:1061–1103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1059 return (a < b? -1: 1);
1060}
1061void test_qsort(void)
1062{
1063 int M = 50;
1064 int a[M];
1065 for (int i = 0; i < M; i++)
1066 a[i] = i;
1067 srand(1234);
1068 for (int X = 0; X < 50; X++, M--)
1069 {
1070 printf("\n---- test #%d\n", X+1);
1071 for (int i = 0; i < M; i++)
1072 {
1073 int j = rand() % M, k = rand() % M;
1074 int t = a[j]; a[j] = a[k]; a[k] = t;
1075 }
1076 for (int i = 0; i < M; i++)
1077 printf("%s%d", (i == 0? "": ","), a[i]);
1078 putchar('\n');
1079 qsort(a, M, sizeof(a[0]), int_compare);
1080 for (int i = 0; i < M; i++)
1081 {
1082 if (i > 0 && a[i] <= a[i-1]) abort();
1083 printf("%s%d", (i == 0? "": ","), a[i]);
1084 }
1085 putchar('\n');
1086 for (int Y = 0; Y < 10; Y++)
1087 {
1088 int k = rand() % M + 10;
1089 void *r = bsearch(&k, a, M, sizeof(a[0]), int_compare);
1090 if (r == NULL)
1091 {
1092 if (k < M) abort();
1093 printf("%s%d=_", (Y == 0? "": " "), k);
1094 }
1095 else
1096 {
1097 if (*(int *)r != k) abort();
1098 printf("%s%d=X", (Y == 0? "": " "), k);
1099 }
1100 }
1101 putchar('\n');
1102 }
1103}
1104
1105void check_flags(const char *_asm, uint64_t flags, uint64_t rflags)
1106{

Callers

nothing calls this directly

Calls 7

srandFunction · 0.85
randFunction · 0.85
putcharFunction · 0.85
qsortFunction · 0.85
abortFunction · 0.85
bsearchFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected