mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:57:46 +00:00
LibTest: Add the Chunk abstraction
A prerequisite for shrinking the failing RandomRuns in randomized tests.
This commit is contained in:
parent
a60e3b17b1
commit
5dbcc396da
1 changed files with 46 additions and 0 deletions
46
Userland/Libraries/LibTest/Randomized/Chunk.h
Normal file
46
Userland/Libraries/LibTest/Randomized/Chunk.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Martin Janiczek <martin@janiczek.cz>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
namespace Test {
|
||||
namespace Randomized {
|
||||
|
||||
// Chunk is a description of a RandomRun slice.
|
||||
// Used to say which part of a given RandomRun will be shrunk by some
|
||||
// ShrinkCommand.
|
||||
//
|
||||
// For a RandomRun [0,1,2,3,4,5,6,7,8], the Chunk{size=4, index=2} means this:
|
||||
// [_,_,X,X,X,X,_,_,_]
|
||||
//
|
||||
// Different ShrinkCommands will use the Chunk in different ways.
|
||||
// A few examples:
|
||||
//
|
||||
// Original RandomRun: [5,1,3,9,4,2,3,0]
|
||||
// Chunk we'll show off: [_,_,X,X,X,X,_,_]
|
||||
//
|
||||
// ZeroChunk: [5,1,0,0,0,0,3,0]
|
||||
// SortChunk: [5,1,2,3,4,9,3,0]
|
||||
// DeleteChunkAndMaybeDecPrevious: [5,1, 3,0]
|
||||
struct Chunk {
|
||||
// Possible sizes: 1,2,3,4,8
|
||||
u8 size = 0;
|
||||
size_t index = 0;
|
||||
};
|
||||
|
||||
} // namespace Randomized
|
||||
} // namespace Test
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Test::Randomized::Chunk> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Test::Randomized::Chunk chunk)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, TRY(String::formatted("Chunk<size={}, i={}>", chunk.size, chunk.index)));
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue