Skip to content

Commit

Permalink
Add english language
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCROS committed Dec 20, 2021
1 parent 5b3380b commit 4d7083c
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 46 deletions.
61 changes: 60 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,65 @@
"algorithm": "cpp",
"random": "cpp",
"numeric": "cpp",
"iostream": "cpp"
"iostream": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__functional_base": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tuple": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"exception": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"locale": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp"
}
}
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ override CPPFLAGS := -std=c++17 -Wall -Wextra

# Sources

LANG := fr_FR

override SRCS := \
main.cpp \
exec.cpp \
args.cpp \
print.cpp \
utils.cpp \
lang/$(LANG).cpp \

override HEADERS := \
complexity.hpp \
Expand All @@ -29,6 +32,12 @@ override OBJDIRS := $(sort $(dir $(OBJS)))

all: $(NAME)

fr:
$(MAKE) LANG="fr_FR" re

en:
$(MAKE) LANG="en_GB" re

obj/%.o: src/%.cpp $(HEADERS) |
$(CPPC) $(CPPFLAGS) -c $< -o $@ -Iincludes

Expand Down
3 changes: 3 additions & 0 deletions includes/complexity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const string &assertExecutable(const string &path);
struct program_opts getOptions(int &argc, char **&argv);
struct program_params getParameters(int argc, char **argv);
string exec(char **argv, optional<string> input = nullopt);

// Print
void print_start(program_params params);
void print(program_params params, int done, int total, int best, int worst, int successful, int ok);

#endif
8 changes: 8 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
X=hello

foo:
@echo $(X)

bar: X=world
bar:
@echo $(X)
52 changes: 52 additions & 0 deletions src/lang/en_GB.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "complexity.hpp"

#include <iostream>

using namespace std;

const string getHelp() {
string help;

help += "\033[1mNAME\033[0m\n";
help += " \033[1mcomplexity\033[0m -- starting benchmark for push_swap\n";
help += "\n";
help += "\033[1mSYNOPSIS\033[0m\n";
help += " \033[1m./complexity\033[0m [\033[1m-hs\033[0m] [\033[1m-f\033[0m \033[4mfile\033[0m] \033[4mnumbers\033[0m \033[4miterations\033[0m [\033[4mgoal\033[0m] [\033[4mchecker\033[0m]\n";
help += "\n";
help += "\033[1mDESCRIPTION\033[0m\n";
help += " push_swap executable will be default searched from current and parent directory.\n";
help += " \n";
help += " Following options are available :\n";
help += " \n";
help += " \033[1m-v\033[0m, \033[1m--version\033[0m\n";
help += " Show version of tester.\n";
help += " \n";
help += " \033[1m-h\033[0m, \033[1m--help\033[0m\n";
help += " Show this help.\n";
help += " \n";
help += " \033[1m-s\033[0m, \033[1m--sorted\033[0m\n";
help += " Only pass sorted numbers to program.\n";
help += " \n";
help += " \033[1m-f\033[0m \033[4mpush_swap\033[0m, \033[1m--file\033[0m=\033[4mpush_swap\033[0m\n";
help += " Use \033[4mpush_swap\033[0m for push_swap executable.\n";
return help;
}

void print_start(program_params params) {
cout << "\033[97mStarting the test : \033[95m" << params.numbers << "\033[97m elements, \033[95m" << params.iterations << "\033[97m iterations\033[0m" << endl;
}

void print(program_params params, int done, int total, int best, int worst, int successful, int ok) {
cout << "Worst = \033[31m" << (worst) << "\033[0m instructions" << endl;
cout << "Median = \033[33m" << (total / done) << "\033[0m instructions" << endl;
cout << "Best = \033[36m" << (best) << "\033[0m instructions" << endl;
if (params.objective.has_value())
cout << "Objective = \033[94m" << (successful * 100 / done) << "\033[0m % under \033[94m" << (params.objective.value()) << "\033[0m (\033[91m" << (done - successful) << "\033[0m above) " << endl;
else
cout << "Objective = enter a number as the third argument" << endl;
if (params.checker.has_value())
cout << "Precision = \033[97m" << (ok * 100 / done) << "\033[0m % OK (\033[91m" << (done - ok) << "\033[0m KO) " << endl;
else
cout << "Precision = enter a tester as the fourth argument" << endl;
cout << "\033[32m" << (done * 100 / params.iterations) << "\033[0m % effective" << endl;
}
52 changes: 52 additions & 0 deletions src/lang/fr_FR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "complexity.hpp"

#include <iostream>

using namespace std;

const string getHelp() {
string help;

help += "\033[1mNAME\033[0m\n";
help += " \033[1mcomplexity\033[0m -- lance un benchmark de votre push_swap\n";
help += "\n";
help += "\033[1mSYNOPSIS\033[0m\n";
help += " \033[1m./complexity\033[0m [\033[1m-hs\033[0m] [\033[1m-f\033[0m \033[4mfile\033[0m] \033[4mnumbers\033[0m \033[4miterations\033[0m [\033[4mgoal\033[0m] [\033[4mchecker\033[0m]\n";
help += "\n";
help += "\033[1mDESCRIPTION\033[0m\n";
help += " L'exécutable push_swap est cherché par défaut dans le répertoire courant et parent.\n";
help += " \n";
help += " Les options suivantes sont disponibles :\n";
help += " \n";
help += " \033[1m-v\033[0m, \033[1m--version\033[0m\n";
help += " Affiche la version du testeur.\n";
help += " \n";
help += " \033[1m-h\033[0m, \033[1m--help\033[0m\n";
help += " Affiche l'aide.\n";
help += " \n";
help += " \033[1m-s\033[0m, \033[1m--sorted\033[0m\n";
help += " Envoie uniquement des nombres triés au programme.\n";
help += " \n";
help += " \033[1m-f\033[0m \033[4mpush_swap\033[0m, \033[1m--file\033[0m=\033[4mpush_swap\033[0m\n";
help += " Utilise \033[4mpush_swap\033[0m en tant qu'exécutable push_swap.\n";
return help;
}

void print_start(program_params params) {
cout << "\033[97mDémarrage du test : \033[95m" << params.numbers << "\033[97m éléments, \033[95m" << params.iterations << "\033[97m itérations\033[0m" << endl;
}

void print(program_params params, int done, int total, int best, int worst, int successful, int ok) {
cout << "Pire = \033[31m" << (worst) << "\033[0m instructions" << endl;
cout << "Moyenne = \033[33m" << (total / done) << "\033[0m instructions" << endl;
cout << "Meilleur = \033[36m" << (best) << "\033[0m instructions" << endl;
if (params.objective.has_value())
cout << "Objectif = \033[94m" << (successful * 100 / done) << "\033[0m % sous \033[94m" << (params.objective.value()) << "\033[0m (\033[91m" << (done - successful) << "\033[0m au dessus) " << endl;
else
cout << "Objectif = entrez un nombre en troisième argument" << endl;
if (params.checker.has_value())
cout << "Précision = \033[97m" << (ok * 100 / done) << "\033[0m % OK (\033[91m" << (done - ok) << "\033[0m KO) " << endl;
else
cout << "Précision = entrez un testeur en quatrième argument" << endl;
cout << "\033[32m" << (done * 100 / params.iterations) << "\033[0m % effectué" << endl;
}
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <numeric>
#include <optional>

#include <langinfo.h>

using namespace std;

int main(int argc, char **argv) {
Expand Down Expand Up @@ -56,7 +58,7 @@ int main(int argc, char **argv) {
int ok = 0;

hideCursor();
cout << "\033[97mDémarrage du test : \033[95m" << params.numbers << "\033[97m éléments, \033[95m" << params.iterations << "\033[97m itérations\033[0m" << endl;
print_start(params);
while (done < params.iterations) {
vector<int> nums(params.numbers);
vector<string> args;
Expand Down
45 changes: 1 addition & 44 deletions src/print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,9 @@ void showCursor() {
}

const string getVersion() {
return "Complexity 1.1.0";
return "Complexity 1.2.0";
}

const string getUsage() {
return "usage: ./complexity [-vhs] [-f push_swap] numbers iterations [goal] [checker]";
}

const string getHelp() {
string help;

help += "\033[1mNAME\033[0m\n";
help += " \033[1mcomplexity\033[0m -- lance un benchmark de votre push_swap\n";
help += "\n";
help += "\033[1mSYNOPSIS\033[0m\n";
help += " \033[1m./complexity\033[0m [\033[1m-hs\033[0m] [\033[1m-f\033[0m \033[4mfile\033[0m] \033[4mnumbers\033[0m \033[4miterations\033[0m [\033[4mgoal\033[0m] [\033[4mchecker\033[0m]\n";
help += "\n";
help += "\033[1mDESCRIPTION\033[0m\n";
help += " L'exécutable push_swap est cherché par défaut dans le répertoire courant et parent.\n";
help += " \n";
help += " Les options suivantes sont disponibles :\n";
help += " \n";
help += " \033[1m-v\033[0m, \033[1m--version\033[0m\n";
help += " Affiche la version du testeur.\n";
help += " \n";
help += " \033[1m-h\033[0m, \033[1m--help\033[0m\n";
help += " Affiche l'aide.\n";
help += " \n";
help += " \033[1m-s\033[0m, \033[1m--sorted\033[0m\n";
help += " Envoie uniquement des nombres triés au programme.\n";
help += " \n";
help += " \033[1m-f\033[0m \033[4mpush_swap\033[0m, \033[1m--file\033[0m=\033[4mpush_swap\033[0m\n";
help += " Utilise \033[4mpush_swap\033[0m en tant qu'exécutable push_swap.\n";
return help;
}

void print(program_params params, int done, int total, int best, int worst, int successful, int ok) {
cout << "Pire = \033[31m" << (worst) << "\033[0m instructions" << endl;
cout << "Moyenne = \033[33m" << (total / done) << "\033[0m instructions" << endl;
cout << "Meilleur = \033[36m" << (best) << "\033[0m instructions" << endl;
if (params.objective.has_value())
cout << "Objectif = \033[94m" << (successful * 100 / done) << "\033[0m % sous \033[94m" << (params.objective.value()) << "\033[0m (\033[91m" << (done - successful) << "\033[0m au dessus) " << endl;
else
cout << "Objectif = entrez un nombre en troisième argument" << endl;
if (params.checker.has_value())
cout << "Précision = \033[97m" << (ok * 100 / done) << "\033[0m % OK (\033[91m" << (done - ok) << "\033[0m KO) " << endl;
else
cout << "Précision = entrez un testeur en quatrième argument" << endl;
cout << "\033[32m" << (done * 100 / params.iterations) << "\033[0m % effectué" << endl;
}

0 comments on commit 4d7083c

Please sign in to comment.