hardhat의 test plugin을 활용해 솔리디티 ps 문제풀이 툴을 구현해봤다.
hardhat에 익숙해지고, 솔리디티로도 향후 ps를 해보고 싶었기 때문이다.
이를 통해 hardhat의 여러 기능들을 꼼꼼히 살펴보았고, Mocha를 사용해봤으며, 솔리디티 문법을 많이 배웠다.
hardhat을 활용해서 간단히 ps 문제풀이를 할 수 있는 프로그램을 구현해보았다.
퇴근 후 뚝딱뚝딱 작업했고, 대충 3일정도 걸린 것 같다.
https://github.com/GanziDaeyong/Solidity-PS-Helper
Helps you enjoy PS with solidity, which is never recommended though.
built with Node, Hardhat, Solidity
you need...
then..
$ git clone https://github.com/GanziDaeyong/Solidity-PS-Helper.git
$ cd ./hardhat_tester
$ npm install
First, prepare a ps-problem with a number of testcases and corresponding solutions.
Your testcases and solutions should be numbered in pair.
For example,tc1.txt
should matchsol1.txt
andtc2.txt
should matchsol2.txt
.. so on.
Second, place testcases on ./user/testcases/
and solutions on ./user/solutions/
.
Third, problem-solve at ./user/PS.sol
.
Last, move to ./user
and run run.sh
.
$ cd ./user
$ bash ./run.sh
Then, you'll see result below if you pass all the testcases.
Your testcases will be split by enter and space ("\n" or " "), and will given to function solver
in PS.sol
in the type of string[] memory input
Below is an example testcase
1 10
a b c
alpha beta gamma
this is converted into
string[8] memory input = ["1", "10", "a", "b", "c", "alpha", "beta", "gamma"]
and given to code below as an input
function solver(string[] memory input) private view returns (string memory) {
//// place your code here ////
}
You are welcomed to implement any other functions on your own.
Still, keep in mind that the answer should be returned in function solver()
in PS.sol
.
As you can see code above, the return type should be string memory
.
You might want to take a look at tips below for uint2str
, str2uint
.
It's a mere wrapper for hardhat test library. I basically wanted to use solidity as a PS language which does have print command.
If you want your output (and answer) to be printed, go to ./template_maker/testMaker.py
then modify line 70, content_without_info
to content_with_info
.
You might want to use console.log()
in PS.sol
file, as hardhat-console library supports it while testing.
You might also want to use uint2str
, str2uint
which are library already implemented in PS.sol
.
Still have no idea what you'll be doing? Just install it, and $ bash ./run.sh
in ./user
. I put an example fibonacci problem there.