-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
10 changed files
with
141 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ jobs: | |
run: xmake | ||
|
||
- name: xmake run | ||
run: xmake run learn | ||
run: xmake run summary --simple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/build | ||
/build/ | ||
|
||
/log/* | ||
!/log/placeholder | ||
|
||
.*/ | ||
!/.github/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,13 @@ | |
``` | ||
|
||
运行 0 号练习。 | ||
|
||
5. 总结学习 | ||
|
||
使用 | ||
|
||
```shell | ||
xmake run summary | ||
``` | ||
|
||
总结所有练习通过情况。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "test.h" | ||
#include <iostream> | ||
|
||
int main(int argc, char **argv) { | ||
if (argc != 2) { | ||
std::cerr << "Usage: xmake run learn <exercice number>" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
int num; | ||
if (1 != std::sscanf(argv[1], "%d", &num)) { | ||
std::cerr << "Invalid exercise number: " << argv[1] << std::endl; | ||
return EXIT_FAILURE; | ||
}; | ||
if (!test_exercise(num, nullptr)) { | ||
return EXIT_FAILURE; | ||
} | ||
return EXIT_SUCCESS; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "test.h" | ||
#include <chrono> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <vector> | ||
|
||
constexpr auto MAX_EXERCISE = 22; | ||
|
||
int main(int argc, char **argv) { | ||
if (argc == 1) { | ||
std::vector<bool> result(MAX_EXERCISE + 1, false); | ||
auto success = 0; | ||
for (auto i = 0; i <= MAX_EXERCISE; ++i) { | ||
if (test_exercise(i, nullptr)) { | ||
result[i] = true; | ||
++success; | ||
} | ||
} | ||
|
||
std::cout << success << "/" << MAX_EXERCISE + 1 << " ["; | ||
for (auto b : result) { | ||
std::cout << (b ? "\x1b[32m#\x1b[0m" : "\x1b[31mX\x1b[0m"); | ||
} | ||
std::cout << ']' << std::endl; | ||
return EXIT_SUCCESS; | ||
} | ||
if (argc == 2 && std::strcmp(argv[1], "--simple") == 0) { | ||
auto time = std::chrono::system_clock::now(); | ||
auto time_ = std::chrono::system_clock::to_time_t(time); | ||
std::stringstream ss; | ||
ss << std::put_time(std::localtime(&time_), "%Y-%m-%d-%H-%M-%S") << ".log"; | ||
auto log_file = ss.str(); | ||
|
||
auto success = 0; | ||
for (auto i = 0; i <= MAX_EXERCISE; ++i) { | ||
if (test_exercise(i, log_file.c_str())) { | ||
++success; | ||
} | ||
} | ||
|
||
std::cout << success << "/" << MAX_EXERCISE + 1 << std::endl; | ||
return EXIT_SUCCESS; | ||
} | ||
std::cerr << "Usage: xmake run summary [--simple]" << std::endl; | ||
return EXIT_FAILURE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <cstdlib> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
#ifndef __XMAKE__ | ||
#define __XMAKE__ "XMAKE is not defined" | ||
#endif | ||
|
||
namespace fs = std::filesystem; | ||
constexpr static auto XMAKE = __XMAKE__; | ||
|
||
static int process_run(const char *cmd, const char *proj, const char *log) { | ||
static auto exercises = fs::absolute(fs::path(XMAKE) / "exercises"); | ||
auto command = std::string("xmake ") + cmd + " -P " + exercises.string() + ' ' + proj; | ||
if (log) { | ||
command += " >> "; | ||
command += log; | ||
command += " 2>&1"; | ||
} | ||
return std::system(command.c_str()); | ||
} | ||
|
||
bool test_exercise(int n, const char *log) { | ||
char str[] = "exerciseXX"; | ||
std::sprintf(str, "exercise%02d", n); | ||
|
||
if (log) { | ||
static auto log_ = fs::absolute(fs::path(XMAKE) / "log" / log); | ||
std::fstream(log_, std::ios::out | std::ios::app) | ||
<< "Testing " << str << std::endl | ||
<< std::endl; | ||
auto log__ = log_.string(); | ||
auto log___ = log__.c_str(); | ||
return process_run("", str, log___) == EXIT_SUCCESS && process_run("run", str, log___) == EXIT_SUCCESS; | ||
} | ||
|
||
std::cout << "Testing " << str << std::endl | ||
<< std::endl; | ||
return process_run("", str, nullptr) == EXIT_SUCCESS && process_run("run", str, nullptr) == EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef __TEST_H__ | ||
#define __TEST_H__ | ||
|
||
bool test_exercise(int n, const char *log); | ||
|
||
#endif// __TEST_H__ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
add_rules("mode.debug", "mode.release") | ||
set_encodings("utf-8") | ||
|
||
target("test") | ||
set_kind("static") | ||
set_languages("cxx17") | ||
add_defines(string.format("__XMAKE__=\"%s\"", os.scriptdir():gsub("\\", "/"))) | ||
add_files("learn/test.cpp") | ||
|
||
target("learn") | ||
set_kind("binary") | ||
set_languages("cxx17") | ||
add_deps("test") | ||
add_files("learn/learn.cpp") | ||
|
||
add_defines(string.format("__XMAKE__=\"%s\"", os.scriptdir():gsub("\\", "/"))) | ||
|
||
target("summary") | ||
set_kind("binary") | ||
set_languages("cxx17") | ||
add_files("learn/main.cpp") | ||
add_deps("test") | ||
add_files("learn/summary.cpp") |