stable tested
This commit is contained in:
parent
dc9f4a6a4e
commit
eab192ebd3
8 changed files with 35 additions and 95 deletions
|
|
@ -17,7 +17,7 @@ public:
|
|||
void printHelp();
|
||||
|
||||
private:
|
||||
static void reportError(const std::string& string);
|
||||
void reportError(const std::string& string) const;
|
||||
|
||||
private:
|
||||
std::map<std::string, Command> mCommands;
|
||||
|
|
@ -25,5 +25,5 @@ private:
|
|||
|
||||
public:
|
||||
FileSystem mFileSystem;
|
||||
bool verbose = true;
|
||||
enum LoggingPolicy { DEFAULT, DEBUG, NONE } logType = DEFAULT;
|
||||
};
|
||||
|
|
@ -53,19 +53,16 @@ void Directory::getMaxDepthUtil(ui32 depth, ui32& maxDepth) const {
|
|||
}
|
||||
|
||||
void Directory::dumpUtil(std::stringstream& ss, const Key& key, ui32 currentDepth, std::vector<bool>& indents) {
|
||||
|
||||
indents[currentDepth] = true;
|
||||
indent(ss, currentDepth, indents);
|
||||
|
||||
ss << key;
|
||||
ss << " [h" << mIncomingHardLinks.size() << ": d" << mIncomingDynamicLinks.size() << "] ";
|
||||
// ss << " [h" << mIncomingHardLinks.size() << ": d" << mIncomingDynamicLinks.size() << "] ";
|
||||
// ss << " [" << mWorkingNodeFlag.lock().get() << "] ";
|
||||
ss << "\n";
|
||||
|
||||
currentDepth++;
|
||||
|
||||
if (mMembers.empty()) return;
|
||||
|
||||
const auto& lastNode = mMembers.rbegin()->first;
|
||||
for (auto & member : mMembers) {
|
||||
if (lastNode == member.first) indents[currentDepth - 1] = false;
|
||||
|
|
|
|||
|
|
@ -91,11 +91,14 @@ Interpreter::Interpreter() {
|
|||
};
|
||||
}
|
||||
|
||||
void Interpreter::reportError(const std::string& description) {
|
||||
std::cout << "ERROR: " << description << "\n\n";
|
||||
void Interpreter::reportError(const std::string& description) const {
|
||||
if (logType == DEFAULT)
|
||||
std::cout << "ERROR: " << description << "\n\n";
|
||||
}
|
||||
|
||||
void Interpreter::printHelp() {
|
||||
if (logType != DEFAULT) return;
|
||||
|
||||
std::cout << "Commands: \n";
|
||||
for (auto& command : mCommands) {
|
||||
std::cout << command.first << " - ";
|
||||
|
|
@ -110,7 +113,7 @@ bool Interpreter::interpret(const std::string& command) {
|
|||
getWords(command, words);
|
||||
|
||||
if (words.empty()) {
|
||||
if (verbose && 0) reportError("Empty command");
|
||||
reportError("Empty command");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -120,23 +123,25 @@ bool Interpreter::interpret(const std::string& command) {
|
|||
auto iter = mCommands.find(commandName);
|
||||
|
||||
if (iter == mCommands.end()) {
|
||||
if (verbose && 0) reportError("Command not found");
|
||||
if (verbose && 0) printHelp();
|
||||
reportError("Command not found");
|
||||
printHelp();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->second.numArguments != words.size() - 1) {
|
||||
if (verbose && 0) reportError("Invalid number of arguments given for: " + commandName);
|
||||
reportError("Invalid number of arguments given for: " + commandName);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success = iter->second.callback(mFileSystem, words);
|
||||
|
||||
if (verbose && success) std::cout << command << "\n";
|
||||
if (verbose && success) mFileSystem.log();
|
||||
if (logType == DEFAULT || (logType == DEBUG && success)) {
|
||||
std::cout << command << "\n";
|
||||
mFileSystem.log();
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (verbose && 0) reportError(FileSystem::getLastError());
|
||||
reportError(FileSystem::getLastError());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
21
src/Link.cpp
21
src/Link.cpp
|
|
@ -6,11 +6,9 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
Link::Link() {}
|
||||
Link::Link() = default;
|
||||
|
||||
Link::Link(const Link &node) : Node(node) {
|
||||
|
||||
}
|
||||
Link::Link(const Link &node) : Node(node) {}
|
||||
|
||||
std::shared_ptr<Node> Link::clone() const {
|
||||
auto out = std::make_shared<Link>(*this);
|
||||
|
|
@ -37,6 +35,7 @@ bool Link::linkNodes(const std::shared_ptr<Link>& link, const std::shared_ptr<No
|
|||
return true;
|
||||
}
|
||||
|
||||
// TODO : move from link to node class or vise versa
|
||||
void Link::removeOutgoingLinks() {
|
||||
auto target = mLink.lock();
|
||||
assert(target);
|
||||
|
|
@ -45,8 +44,7 @@ void Link::removeOutgoingLinks() {
|
|||
links.erase(std::remove_if(links.begin(), links.end(), [&](std::weak_ptr<Link>& node){
|
||||
auto targetLink = node.lock();
|
||||
assert(targetLink);
|
||||
auto res = targetLink.get() == this;
|
||||
return res;
|
||||
return targetLink.get() == this;
|
||||
}), links.end());
|
||||
}
|
||||
|
||||
|
|
@ -70,16 +68,15 @@ std::shared_ptr<Node> Link::findNode(const std::vector<Key>& path, ui32 currentD
|
|||
}
|
||||
|
||||
void Link::dumpUtil(std::stringstream& ss, const Key& key, ui32 currentDepth, std::vector<bool>& indents) {
|
||||
std::vector<std::shared_ptr<Node>> path;
|
||||
getNodeStraightPath(getLink(), path);
|
||||
std::reverse(path.begin(), path.end());
|
||||
|
||||
indent(ss, currentDepth, indents);
|
||||
|
||||
ss << key;
|
||||
ss << (isHardLink() ? " hlink[" : " dlink[");
|
||||
|
||||
ss << " [h" << mIncomingHardLinks.size() << ": d" << mIncomingDynamicLinks.size() << "] ";
|
||||
|
||||
std::vector<std::shared_ptr<Node>> path;
|
||||
getNodeStraightPath(getLink(), path);
|
||||
std::reverse(path.begin(), path.end());
|
||||
// ss << " [h" << mIncomingHardLinks.size() << ": d" << mIncomingDynamicLinks.size() << "] ";
|
||||
|
||||
for (auto it = path.begin(); it != path.end(); ++it) {
|
||||
ss << (*it)->mKey;
|
||||
|
|
|
|||
10
src/Node.cpp
10
src/Node.cpp
|
|
@ -12,13 +12,7 @@ Node::Node(const Node &node) {
|
|||
mKey = node.mKey;
|
||||
}
|
||||
|
||||
Node::~Node() {
|
||||
// assert(mIncomingHardLinks.empty());
|
||||
// for (auto dynamicLink : mIncomingDynamicLinks) {
|
||||
// dynamicLink->mParent->detachNode(dynamicLink->mTreeNode->key.val);
|
||||
// delete dynamicLink;
|
||||
//
|
||||
}
|
||||
Node::~Node() = default;
|
||||
|
||||
std::shared_ptr<Node> Node::clone() const {
|
||||
return std::make_shared<Node>(*this);
|
||||
|
|
@ -89,7 +83,7 @@ void Node::dump(std::stringstream& ss) {
|
|||
void Node::dumpUtil(std::stringstream& ss, const Key& key, ui32 currentDepth, std::vector<bool>& indents) {
|
||||
indent(ss, currentDepth, indents);
|
||||
ss << key;
|
||||
ss << " [h" << mIncomingHardLinks.size() << ": d" << mIncomingDynamicLinks.size() << "] ";
|
||||
// ss << " [h" << mIncomingHardLinks.size() << ": d" << mIncomingDynamicLinks.size() << "] ";
|
||||
ss << "\n";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,12 +40,13 @@ SUITE(FSE) {
|
|||
|
||||
TEST (CommandNoise) {
|
||||
Interpreter interpreter;
|
||||
interpreter.logType = Interpreter::NONE;
|
||||
|
||||
StringDistribution commands({
|
||||
{ "md", 10 },
|
||||
{ "mf", 10 },
|
||||
{ "mhl", 10 },
|
||||
{ "mdl", 10 },
|
||||
{ "mhl", 20 },
|
||||
{ "mdl", 20 },
|
||||
{ "cd", 5 },
|
||||
{ "rd", 1 },
|
||||
{ "del", 10 },
|
||||
|
|
@ -81,8 +82,6 @@ SUITE(FSE) {
|
|||
if (pathLenDist(rng) % 2) generatePath(ss);
|
||||
return ss.str();
|
||||
});
|
||||
|
||||
interpreter.mFileSystem.log();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@
|
|||
#include <random>
|
||||
#include <chrono>
|
||||
|
||||
const ui64 timeLimitSec = 5;
|
||||
const ui64 timeLimitSec = 3;
|
||||
const ui64 itemLimit = 1e6;
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 rng;
|
||||
std::mt19937 rng(rd());
|
||||
// std::mt19937 rng;
|
||||
|
||||
class StringDistribution {
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -13,57 +13,4 @@ cd C:/
|
|||
copy A123 C:/
|
||||
rd d
|
||||
deltree A123
|
||||
deltree A123_copy
|
||||
md a
|
||||
md a/b
|
||||
md a/b/c
|
||||
mhl a C:/a/b/c/
|
||||
md a/b/c/a/k
|
||||
copy a C:/
|
||||
mdl a/b/c C:/a_copy/k
|
||||
move a/b/c C:/a_copy
|
||||
del C:/a_copy/k/c
|
||||
m
|
||||
mD a
|
||||
mD /
|
||||
MD C:/A123
|
||||
cd C:/A123
|
||||
md asd
|
||||
md asd/b
|
||||
md asd/b/c
|
||||
md asd/b/c/d
|
||||
cd asd/b/c/d
|
||||
cd C:/
|
||||
copy A123 C:/
|
||||
rd d
|
||||
cd A123
|
||||
md a
|
||||
md a/b
|
||||
md a/b/c
|
||||
mhl a C:/a/b/c/
|
||||
md a/b/c/a/k
|
||||
copy a C:/
|
||||
mdl a/b/c C:/a_copy/k
|
||||
move a/b/c C:/a_copy
|
||||
cd a
|
||||
m
|
||||
mD a
|
||||
mD /
|
||||
MD C:/A123
|
||||
cd C:/A123
|
||||
md asd
|
||||
md asd/b
|
||||
md asd/b/c
|
||||
md asd/b/c/d
|
||||
cd asd/b/c/d
|
||||
copy A123 C:/
|
||||
rd d
|
||||
cd C:/A123
|
||||
md a
|
||||
md a/b
|
||||
md a/b/c
|
||||
mhl a C:/a/b/c/
|
||||
md a/b/c/a/k
|
||||
copy a C:/
|
||||
mdl a/b/c C:/a_copy/k
|
||||
move a/b/c C:/a_copy
|
||||
deltree A123_copy
|
||||
Loading…
Add table
Add a link
Reference in a new issue