Skip to content

Commit

Permalink
Add qsort test
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterymath committed Jan 30, 2024
1 parent fadf614 commit 5dad93b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions SingleSource/UnitTests/qsort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2024 LLVM-MOS
//
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions,
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.

#undef NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <string.h>

// Originally from the Public Domain C Library (PDCLib)


static int compare(const void *left, const void *right) {
return *((unsigned char *)left) - *((unsigned char *)right);
}

int main(void) {
char presort[] = {"shreicnyjqpvozxmbt"};
char sorted1[] = {"bcehijmnopqrstvxyz"};
char sorted2[] = {"bticjqnyozpvreshxm"};
char s[19];
strcpy(s, presort);
qsort(s, 18, 1, compare);
assert(strcmp(s, sorted1) == 0);
strcpy(s, presort);
qsort(s, 9, 2, compare);
assert(strcmp(s, sorted2) == 0);
strcpy(s, presort);
qsort(s, 1, 1, compare);
assert(strcmp(s, presort) == 0);
qsort(s, 100, 0, compare);
assert(strcmp(s, presort) == 0);
return 0;
}
1 change: 1 addition & 0 deletions SingleSource/UnitTests/qsort.reference_output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 0

0 comments on commit 5dad93b

Please sign in to comment.