mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 17:17:35 +00:00
Tests: License headers, clang-format, clearer output
This commit is contained in:
parent
29eceebdbf
commit
58240aedd9
16 changed files with 359 additions and 30 deletions
|
@ -37,7 +37,8 @@ struct SortableObject {
|
|||
int m_payload;
|
||||
};
|
||||
|
||||
int compare_sortable_object(const void* a, const void* b) {
|
||||
int compare_sortable_object(const void* a, const void* b)
|
||||
{
|
||||
const int key1 = static_cast<const SortableObject*>(a)->m_key;
|
||||
const int key2 = static_cast<const SortableObject*>(b)->m_key;
|
||||
if (key1 < key2) {
|
||||
|
@ -49,12 +50,13 @@ int compare_sortable_object(const void* a, const void* b) {
|
|||
}
|
||||
}
|
||||
|
||||
int calc_payload_for_pos(size_t pos) {
|
||||
int calc_payload_for_pos(size_t pos)
|
||||
{
|
||||
pos *= 231;
|
||||
return pos ^ (pos << 8) ^ (pos << 16) ^ (pos << 24);
|
||||
}
|
||||
|
||||
void shuffle_vec(Vector<SortableObject> &test_objects)
|
||||
void shuffle_vec(Vector<SortableObject>& test_objects)
|
||||
{
|
||||
for (size_t i = 0; i < test_objects.size() * 3; ++i) {
|
||||
auto i1 = rand() % test_objects.size();
|
||||
|
@ -68,7 +70,7 @@ int main()
|
|||
// Generate vector of SortableObjects in sorted order, with payloads determined by their sorted positions
|
||||
Vector<SortableObject> test_objects;
|
||||
for (auto i = 0; i < 1024; ++i) {
|
||||
test_objects.append({i * 137, calc_payload_for_pos(i)});
|
||||
test_objects.append({ i * 137, calc_payload_for_pos(i) });
|
||||
}
|
||||
for (size_t i = 0; i < NUM_RUNS; i++) {
|
||||
// Shuffle the vector, then sort it again
|
||||
|
@ -76,8 +78,8 @@ int main()
|
|||
qsort(test_objects.data(), test_objects.size(), sizeof(SortableObject), compare_sortable_object);
|
||||
// Check that the objects are sorted by key
|
||||
for (auto i = 0u; i + 1 < test_objects.size(); ++i) {
|
||||
const auto &key1 = test_objects[i].m_key;
|
||||
const auto &key2 = test_objects[i + 1].m_key;
|
||||
const auto& key1 = test_objects[i].m_key;
|
||||
const auto& key2 = test_objects[i + 1].m_key;
|
||||
if (key1 > key2) {
|
||||
printf("\x1b[01;35mTests failed: saw key %d before key %d\n", key1, key2);
|
||||
return 1;
|
||||
|
@ -93,6 +95,6 @@ int main()
|
|||
}
|
||||
}
|
||||
}
|
||||
printf("Tests succeeded\n");
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue