Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator for creating command sequences of scaled length #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/rapidcheck/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
#include "rapidcheck/state/Commands.h"
#include "rapidcheck/state/State.h"
#include "rapidcheck/state/gen/Commands.h"
#include "rapidcheck/state/gen/CommandsScaledLength.h"
#include "rapidcheck/state/gen/ExecCommands.h"
21 changes: 21 additions & 0 deletions include/rapidcheck/state/gen/CommandsScaledLength.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "rapidcheck/state/Commands.h"

namespace rc {
namespace state {
namespace gen {

/// Generates a valid commands sequence for the given state initial state
/// consisting of commands of the given type.
/// Uses the scaling factor to scale the length of the command sequence
/// by the provided value
template <typename Cmd, typename GenerationFunc>
Gen<Commands<Cmd>> commandsScaledLength(const typename Cmd::Model &initialState,
double scale, GenerationFunc &&genFunc);

} // namespace gen
} // namespace state
} // namespace rc

#include "CommandsScaledLength.hpp"
29 changes: 29 additions & 0 deletions include/rapidcheck/state/gen/CommandsScaledLength.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "rapidcheck/state/Commands.h"

namespace rc {
namespace state {
namespace gen {

template <typename Cmd, typename GenerationFunc>
Gen<Commands<Cmd>> commandsScaledLength(const typename Cmd::Model &initialState,
double scale,
GenerationFunc &&genFunc) {

/// Generate a sequence of commands where the commands themself
/// get passed the size ``size``.
auto commands_with_size = [=](int size) {
return commands<Cmd>(initialState, [=](const typename Cmd::Model &state) {
return rc::gen::resize(size, genFunc(state));
});
};

return rc::gen::withSize([=](int size) {
return rc::gen::scale(scale, commands_with_size(size));
});
}

} // namespace gen
} // namespace state
} // namespace rc