tag:crieit.net,2005:https://crieit.net/tags/%E8%87%AA%E7%BF%92/feed
「自習」の記事 - Crieit
Crieitでタグ「自習」に投稿された最近の記事
2022-07-29T22:06:48+09:00
https://crieit.net/tags/%E8%87%AA%E7%BF%92/feed
tag:crieit.net,2005:PublicArticle/18261
2022-07-25T23:03:09+09:00
2022-07-29T22:06:48+09:00
https://crieit.net/posts/Python-O1o0-Non-numeric-Separated-Value
Python自習O1o0 Non-numeric Separated Value
<h1 id="O_9o0 以前の記事"><a href="#O_9o0+%E4%BB%A5%E5%89%8D%E3%81%AE%E8%A8%98%E4%BA%8B">O_9o0 以前の記事</a></h1>
<p>📖 <a href="https://crieit.net/posts/Python-62de8a581dbea">Python自習O_9o0 目次だぜ(^~^)</a> - 目次<br />
📖 <a href="https://crieit.net/posts/Python-62de830e6dd8e">Python自習O0o0 クラスを動的に読み込もうぜ(^~^)</a> - Dimport クラス</p>
<h1 id="O_8o0 前回の記事までのディレクトリー構成"><a href="#O_8o0+%E5%89%8D%E5%9B%9E%E3%81%AE%E8%A8%98%E4%BA%8B%E3%81%BE%E3%81%A7%E3%81%AE%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%83%BC%E6%A7%8B%E6%88%90">O_8o0 前回の記事までのディレクトリー構成</a></h1>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 dimport
│ │ └── 📄 __init__.py
│ ├── 📂 hello
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
└── 📂 tests
├── 📄 dimport_test.py
├── 📄 dimport_test2.py
└── 📄 hello_test.py
</code></pre>
<h1 id="O0o0 今回の記事"><a href="#O0o0+%E4%BB%8A%E5%9B%9E%E3%81%AE%E8%A8%98%E4%BA%8B">O0o0 今回の記事</a></h1>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 自習しよ」</p>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 勝手にしろだぜ」</p>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👇 最初のお題はこれよ」</p>
<h1 id="O1o0 Non-numeric Separated Value"><a href="#O1o0+Non-numeric+Separated+Value">O1o0 Non-numeric Separated Value</a></h1>
<p>Input:</p>
<pre><code class="plaintext">ABC123DEF456GHI
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 何だぜ これ?」</p>
<p>Output:</p>
<pre><code class="plaintext">["ABC", "123", "DEF", "456", "GHI"]
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👆 文字列と、数字列を区別して スプリットしなさい」</p>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 input 無視して output をそのまま出せばいいのでは?」</p>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 練習をしろ」</p>
<h2 id="O1o1o0 Test"><a href="#O1o1o0+Test">O1o1o0 Test</a></h2>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 テストを書いて置いたから、これに合うようにコードを書きなさい」</p>
<h3 id="O1o1o1o0 quest.py"><a href="#O1o1o1o0+quest.py">O1o1o1o0 quest.py</a></h3>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👇 以下のファイルを新規作成しなさい」</p>
<pre><code class="plaintext"> ├── 📂 tests
│ └── 📂 nonnumsv
│ └── 📂 o1o0g1o1o0
👉 │ └── 📄 quest.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">class Questioner:
"""出題者"""
def make_quiz(self):
"""答えのある問い作成"""
return "ABC123DEF456GHI"
def check(self, answer, quiz):
"""答え合わせ
Returns
-------
str
Error message or None
"""
err_list = []
if answer is None:
err_list.append("[Error] answer is none")
else:
vec_size = len(answer)
if vec_size != 5:
err_list.append(
f"[Error] the size is different. size:{vec_size}")
if answer != ["ABC", "123", "DEF", "456", "GHI"]:
err_list.append(
f"[Error] the response is different. vec:{answer}")
if 0 < len(err_list):
return "\n".join(err_list)
else:
return None
</code></pre>
<h3 id="O1o1o2o0 test.py"><a href="#O1o1o2o0+test.py">O1o1o2o0 test.py</a></h3>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👇 以下のファイルを新規作成しなさい」</p>
<pre><code class="plaintext"> ├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
👉 │ │ └── 📄 test.py
│ └── 📂 nonnumsv
│ └── 📂 o1o0g1o1o0
│ └── 📄 quest.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">"""
Example
-------
python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o2o0 --ac Answerer
"""
import argparse
from src.dimport import Dimport # Dynamic class import
# Command line arguments
ap = argparse.ArgumentParser()
ap.add_argument('--qm', help='questioner module')
ap.add_argument('--qc', help='questioner class')
ap.add_argument('--am', help='answerer module')
ap.add_argument('--ac', help='answerer class')
args = ap.parse_args()
# Plan
Questioner = Dimport.load(args.qm, args.qc)
quest = Questioner()
quiz = quest.make_quiz()
print(f"quiz:{quiz}")
# Do
Answerer = Dimport.load(args.am, args.ac)
answer = Answerer.to_answer(quiz)
print(f"answer:{answer}")
# Check
err = quest.check(answer, quiz)
if err is None:
print("correct!")
else:
print(err)
</code></pre>
<h3 id="O1o1o3o0 検索パス"><a href="#O1o1o3o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o1o3o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👇 以下のファイルを新規作成しなさい」</p>
<pre><code class="plaintext"> ├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
👉 │ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">from .nonnumsv.o1o0g1o1o0.quest import Questioner as QuestionerO1o0g1o1o0
# -------------------------- ---------- --------------------
# 1 2 3
# 1. 同じディレクトリーからの相対パス
# 2. クラス
# 3. クラスの別名
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 これでどこかに <code>Answerer</code> クラスを作って <code>to_answer</code> メソッドを付けてくれれば テストできるわよ」</p>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 フーン じゃあ スケルトンから作るか」</p>
<h2 id="O1o2o0 Skeleton"><a href="#O1o2o0+Skeleton">O1o2o0 Skeleton</a></h2>
<h3 id="O1o2o_1o0 Answerer"><a href="#O1o2o_1o0+Answerer">O1o2o_1o0 Answerer</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のファイルを作ってくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ └── 📂 nonnumsv
│ └── 📂 o1o0g1o2o0
👉 │ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">class Answerer:
"""Non-numeric separated value"""
@staticmethod
def to_answer(quiz):
return []
</code></pre>
<h3 id="O1o2o_2o0 検索パス"><a href="#O1o2o_2o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o2o_2o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のファイルを作ってくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ └── 📂 nonnumsv
│ ├── 📂 o1o0g1o2o0
│ │ └── 📄 __init__.py
👉 │ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">from .o1o0g1o2o0 import Answerer as AnswererO1o0g1o2o0
# ----------- -------- ------------------
# 1 2 3
# 1. 同じディレクトリーにある o1o0g1o2o0 ディレクトリー
# 2. クラス
# 3. クラスの別名
</code></pre>
<h3 id="O1o2o_3o0 検索パス"><a href="#O1o2o_3o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o2o_3o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 前のレッスンで作った、以下の既存ファイルに1行追加してくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
👉 │ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py"># ...略...
from .nonnumsv.o1o0g1o2o0 import Answerer
</code></pre>
<h3 id="O1o2o1o0 コマンド実行"><a href="#O1o2o1o0+%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E5%AE%9F%E8%A1%8C">O1o2o1o0 コマンド実行</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 このコマンドを実行すると」</p>
<p>Input:</p>
<pre><code class="shell">python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o2o0 --ac Answerer
</code></pre>
<p>Output:</p>
<pre><code class="shell">quiz:ABC123DEF456GHI
answer:[]
[Error] the size is different. size:0
[Error] the response is different. vec:[]
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👆 エラーが出るわけだな」</p>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 <code>to_answer</code> 静的メソッドを実装しろだぜ」</p>
<h2 id="O1o3o0 まず、そのまま出そうぜ"><a href="#O1o3o0+%E3%81%BE%E3%81%9A%E3%80%81%E3%81%9D%E3%81%AE%E3%81%BE%E3%81%BE%E5%87%BA%E3%81%9D%E3%81%86%E3%81%9C">O1o3o0 まず、そのまま出そうぜ</a></h2>
<h3 id="O1o3o1o0 answerer"><a href="#O1o3o1o0+answerer">O1o3o1o0 answerer</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のファイルを作ってくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
👉 │ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">"""
Example
-------
python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o3o0 --ac Answerer
"""
class Answerer:
"""Non-numeric separated value"""
@staticmethod
def to_answer(text):
return ["ABC", "123", "DEF", "456", "GHI"]
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 お父んのフォルダー名の付け方 狂ってて わらう」</p>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 クラス名の付け方も 狂ってるわよ」</p>
<h3 id="O1o3o2o0 検索パス"><a href="#O1o3o2o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o3o2o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下の既存ファイルの冒頭に1行追加してくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
👉 │ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py"># ...略...
from .o1o0g1o3o0 import Answerer as AnswererO1o0g1o3o0
# ...略...
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 モジュールの検索パスを 手動で書くの めんどくさいけど 仕方ない」</p>
<h3 id="O1o3o3o0 コマンド"><a href="#O1o3o3o0+%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89">O1o3o3o0 コマンド</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のコマンドを打鍵してくれだぜ」</p>
<p>Input:</p>
<pre><code class="shell">python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o3o0 --ac Answerer
</code></pre>
<p>Output:</p>
<pre><code class="shell">quiz:ABC123DEF456GHI
answer:['ABC', '123', 'DEF', '456', 'GHI']
correct!
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 そりゃ正解よ」</p>
<h2 id="O1o4o0 正規表現を使って出そうぜ"><a href="#O1o4o0+%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E5%87%BA%E3%81%9D%E3%81%86%E3%81%9C">O1o4o0 正規表現を使って出そうぜ</a></h2>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 今までは 練習の枠組みを用意したわけだぜ。<br />
ここからが本番だぜ」</p>
<h3 id="O1o4o1o0 answerer"><a href="#O1o4o1o0+answerer">O1o4o1o0 answerer</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のファイルを作ってくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
👉 │ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">"""
Example
-------
python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o4o0 --ac Answerer
"""
import re
class Answerer:
"""Non-numeric separated value"""
# * `^` - 行頭
# * `( )` - キャプチャーグループ
# * `[A-Z]` - 大文字のAからZ
# * `[ ]+` - 1回以上
# * `[0-9]` - 半角数字の0から9
# * `$` - 行末
__pat = re.compile(r"^([A-Z]+)([0-9]+)([A-Z]+)([0-9]+)([A-Z]+)$")
@staticmethod
def to_answer(quiz):
m = Answerer.__pat.match(quiz)
if m:
# `m.group( )` - 引数の数はパターンの括弧の位置に対応
return [m.group(1), m.group(2), m.group(3), m.group(4), m.group(5)]
return None
</code></pre>
<h3 id="O1o4o2o0 検索パス"><a href="#O1o4o2o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o4o2o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下の既存ファイルの冒頭に1行追加してくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
👉 │ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py"># ...略...
from .o1o0g1o4o0 import Answerer as AnswererO1o0g1o4o0
# ...略...
</code></pre>
<h3 id="O1o4o3o0 コマンド"><a href="#O1o4o3o0+%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89">O1o4o3o0 コマンド</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のコマンドを打鍵してくれだぜ」</p>
<p>Input:</p>
<pre><code class="shell">python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o4o0 --ac Answerer
</code></pre>
<p>Output:</p>
<pre><code class="shell">quiz:ABC123DEF456GHI
answer:['ABC', '123', 'DEF', '456', 'GHI']
correct!
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 でけたな」</p>
<h2 id="O1o5o0 問題のパターンを増やしましょう"><a href="#O1o5o0+%E5%95%8F%E9%A1%8C%E3%81%AE%E3%83%91%E3%82%BF%E3%83%BC%E3%83%B3%E3%82%92%E5%A2%97%E3%82%84%E3%81%97%E3%81%BE%E3%81%97%E3%82%87%E3%81%86">O1o5o0 問題のパターンを増やしましょう</a></h2>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 パターンの数を増やすわよ」</p>
<h3 id="O1o5o1o0 questioner"><a href="#O1o5o1o0+questioner">O1o5o1o0 questioner</a></h3>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👇 以下のファイルを新規作成しなさい」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 quest.py
│ │ └── 📂 o1o0g1o5o0
👉 │ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">"""
Example
-------
python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o5o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o4o0 --ac Answerer
"""
import random
class Questioner:
"""出題者"""
def make_quiz(self):
"""答えのある問い作成"""
quiz = """!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""
# Shuffle
quiz = ''.join(random.sample(quiz, len(quiz)))
return quiz
def check(self, answer, quiz):
"""答え合わせ
Returns
-------
str
Error message or None
"""
err_list = []
if answer is None:
err_list.append("[Error] answer is none")
elif len(answer) < 2:
err_list.append(
f"[Error] answer length is small. len:{len(answer)} (< 2)")
else:
is_error = False
# もとの文字列と一致するかチェック
text2 = ''.join(answer)
if text2 != quiz:
is_error = True
err_list.append("[Error] the string is different")
err_list.append(f"> actual :{text2}")
err_list.append(f"> expected:{quiz}")
if not is_error:
# 数字,非数字が 交互かチェック
is_prev_numeric = answer[0].isnumeric()
for i in range(1, len(answer)):
is_numeric = answer[i].isnumeric()
if is_prev_numeric == is_numeric:
# Error
is_error = True
break
is_prev_numeric = is_numeric
if 0 < len(err_list):
return "\n".join(err_list)
else:
return None
</code></pre>
<h3 id="O1o5o2o0 検索パス"><a href="#O1o5o2o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o5o2o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👇 以下の既存ファイルに1行足しなさい」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 quest.py
│ │ └── 📂 o1o0g1o5o0
│ │ └── 📄 quest.py
👉 │ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py"># ...略...
from .nonnumsv.o1o0g1o5o0.quest import Questioner as QuestionerO1o0g1o5o0
# ...略...
</code></pre>
<h3 id="O1o5o3o0 コマンド"><a href="#O1o5o3o0+%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89">O1o5o3o0 コマンド</a></h3>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 👇 以下のコマンドを打鍵しましょう」</p>
<p>Input:</p>
<pre><code class="shell">python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o5o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o4o0 --ac Answerer
</code></pre>
<p>Output:</p>
<pre><code class="plaintext">quiz:8pyi0tVKZ"n|/hec\+>=BjIdS<),Pvb%3'_ax-sA?;N2#FH76&T]5[MYk(RJE`oluLO:z{DXg}U4m1rfQw@.*$C!WGq^9~
answer:None
[Error] answer is none
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 そりゃ動かないぜ。問題が変わってるからな」</p>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 更新してくれだぜ」</p>
<h2 id="O1o6o0 いろんなパターンに対応しようぜ?"><a href="#O1o6o0+%E3%81%84%E3%82%8D%E3%82%93%E3%81%AA%E3%83%91%E3%82%BF%E3%83%BC%E3%83%B3%E3%81%AB%E5%AF%BE%E5%BF%9C%E3%81%97%E3%82%88%E3%81%86%E3%81%9C%EF%BC%9F">O1o6o0 いろんなパターンに対応しようぜ?</a></h2>
<h3 id="O1o6o1o0 answerer"><a href="#O1o6o1o0+answerer">O1o6o1o0 answerer</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のファイルを作ってくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o6o0
👉 │ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 quest.py
│ │ └── 📂 o1o0g1o5o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">"""
Example
-------
python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o5o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o6o0 --ac Answerer
"""
import re
class Answerer:
"""Non-numeric separated value"""
# * `^` - 文の始端
# * `\d` - 半角数字
# * `\d+` - 半角数字(1つ以上)
# * `( )` - キャプチャーグループ
__pat_num = re.compile(r"^(\d+)")
# * `\D` - 半角数字以外
__pat_nonnum = re.compile(r"^(\D+)")
@staticmethod
def to_answer(quiz):
answer = []
start = 0
# 数字列か?
m = Answerer.__pat_num.match(quiz[start:])
if m:
# 数字列だ
token = m.group(1)
answer.append(token)
start += len(token)
while True:
# 非数字の文字列か?
m = Answerer.__pat_nonnum.match(quiz[start:])
if m is None:
break
# 非数字の文字列だ
token = m.group(1)
answer.append(token)
start += len(token)
# 数字列か?
m = Answerer.__pat_num.match(quiz[start:])
if m is None:
break
# 数字列だ
token = m.group(1)
answer.append(token)
start += len(token)
return answer
</code></pre>
<h3 id="O1o6o2o0 検索パス"><a href="#O1o6o2o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o6o2o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下の既存ファイルの冒頭に1行追加してくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o6o0
│ │ │ └── 📄 __init__.py
👉 │ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 quest.py
│ │ └── 📂 o1o0g1o5o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py"># ...略...
from .o1o0g1o6o0 import Answerer as AnswererO1o0g1o6o0
# ...略...
</code></pre>
<h3 id="O1o6o3o0 コマンド"><a href="#O1o6o3o0+%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89">O1o6o3o0 コマンド</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のコマンドを打鍵してくれだぜ」</p>
<p>Input:</p>
<pre><code class="plaintext">python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o5o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o6o0 --ac Answerer
</code></pre>
<p>Output:</p>
<pre><code class="plaintext">quiz:n*;7'Ip{DKr\A6c&SuW"T=U^)3#PxwN0h$]?La!zsV/1[YjJ49tZ`dRO(_Cm,glef5.%2bkXGQqy|~-Fi8v:BM}>oE<+H@
answer:['n*;', '7', "'Ip{DKr\\A", '6', 'c&SuW"T=U^)', '3', '#PxwN', '0', 'h$]?La!zsV/', '1', '[YjJ', '49', 'tZ`dRO(_Cm,glef', '5', '.%', '2', 'bkXGQqy|~-Fi', '8', 'v:BM}>oE<+H@']
correct!
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 答えは合ってるみたいだが、本当に合ってんのかな?」</p>
<h2 id="O1o7o0 間違った答えを返そうぜ?"><a href="#O1o7o0+%E9%96%93%E9%81%95%E3%81%A3%E3%81%9F%E7%AD%94%E3%81%88%E3%82%92%E8%BF%94%E3%81%9D%E3%81%86%E3%81%9C%EF%BC%9F">O1o7o0 間違った答えを返そうぜ?</a></h2>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 じゃあ、わざと答えの一部を スワップ(入れ替え)して 答えればいいんだぜ」</p>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 テストを試そうってのね」</p>
<h3 id="O1o7o1o0 answerer"><a href="#O1o7o1o0+answerer">O1o7o1o0 answerer</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のファイルを新規作成してくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o6o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o7o0
👉 │ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 quest.py
│ │ └── 📂 o1o0g1o5o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">"""
Example
-------
python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o5o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o7o0 --ac Answerer
"""
import re
import random
from ..o1o0g1o6o0 import Answerer as AnswererG1o6o0
# ------------ -------- --------------
# 1 2 3
# 1. 隣のフォルダー
# 2. クラス
# 3. 別名
class Answerer:
"""Non-numeric separated value"""
# * `^` - 文の始端
# * `\d` - 半角数字
# * `\d+` - 半角数字(1つ以上)
# * `( )` - キャプチャーグループ
__pat_num = re.compile(r"^(\d+)")
# * `\D` - 半角数字以外
__pat_nonnum = re.compile(r"^(\D+)")
@staticmethod
def to_answer(quiz):
answer = AnswererG1o6o0.to_answer(quiz)
# 要素数
length = len(answer)
# 要素が2個に満たなければスワップできません
if length <= 2:
raise ValueError(f"Couldn't swap. length:{length}")
# ランダムなインデックスを2つ取得
i1 = random.randint(1, length-1)
i2 = random.randint(0, i1-1)
# スワップ
temp = answer[i1]
answer[i1] = answer[i2]
answer[i2] = temp
return answer
</code></pre>
<h3 id="O1o7o2o0 検索パス"><a href="#O1o7o2o0+%E6%A4%9C%E7%B4%A2%E3%83%91%E3%82%B9">O1o7o2o0 検索パス</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下の既存ファイルの冒頭に1行追加してくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o6o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o7o0
│ │ │ └── 📄 __init__.py
👉 │ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ └── 📂 o1o0g1o1o0
│ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 quest.py
│ │ └── 📂 o1o0g1o5o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py"># ...略...
from .o1o0g1o7o0 import Answerer as AnswererO1o0g1o7o0
# ...略...
</code></pre>
<h3 id="O1o7o3o0 コマンド"><a href="#O1o7o3o0+%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89">O1o7o3o0 コマンド</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のコマンドを打鍵してくれだぜ」</p>
<p>Input:</p>
<pre><code class="plaintext">python -m tests.general.o1o0g1o1o0.test --qm tests.nonnumsv.o1o0g1o5o0.quest --qc Questioner --am src.nonnumsv.o1o0g1o7o0 --ac Answerer
</code></pre>
<p>Output:</p>
<pre><code class="plaintext">quiz:eV0LI6Ep-AT=[@f,\}">d#:xn/|$t47WORZ.%rN&Kq3;1lQm]9s*5J`bCuG~!oDz8kgF<(+j_ivyc?w^hMP2HUBY'XS{a)
answer:['eV', '0', 'Ep-AT=[@f,\\}">d#:xn/|$t', '6', 'LI', '47', 'WORZ.%rN&Kq', '3', ';', '1', 'lQm]', '9', 's*', '5', 'J`bCuG~!oDz', '8',
'kgF<(+j_ivyc?w^hMP', '2', "HUBY'XS{a)"]
[Error] the string is different
> actual :eV0Ep-AT=[@f,\}">d#:xn/|$t6LI47WORZ.%rN&Kq3;1lQm]9s*5J`bCuG~!oDz8kgF<(+j_ivyc?w^hMP2HUBY'XS{a)
> expected:eV0LI6Ep-AT=[@f,\}">d#:xn/|$t47WORZ.%rN&Kq3;1lQm]9s*5J`bCuG~!oDz8kgF<(+j_ivyc?w^hMP2HUBY'XS{a)
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/31f0f35be3a4b6b05ce597c7aab702b762de606300faf.png?mw=700" alt="202108__character__12--ohkina-hiyoko-futsu2.png" /></a><br />
「 スワップしたのだから、エラーになって当然よ」</p>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 いつも正解って言ったり、いつも間違いというようなプログラムでないことは 分かったが……」</p>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 そんなプログラム、きふわらべ みたいだな」</p>
<h2 id="O1o8o0 連続テストしようぜ?"><a href="#O1o8o0+%E9%80%A3%E7%B6%9A%E3%83%86%E3%82%B9%E3%83%88%E3%81%97%E3%82%88%E3%81%86%E3%81%9C%EF%BC%9F">O1o8o0 連続テストしようぜ?</a></h2>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 テストしたいプログラムを100回、 わざと間違えるプログラムを100回、<br />
ランダムな順序で実行して、<br />
テストしたいプログラムの答えが正解の回数、わざと間違えるプログラムの答えが間違いの回数を加算して、<br />
実行回数当たりの ちゃんと動いた回数の割合を出してくれだぜ」</p>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 じゃあ 100回ずつと言わず、 計2000回やって、小数点1桁の精度の百分率を出すかだぜ」</p>
<h3 id="O1o8o1o0 answerer"><a href="#O1o8o1o0+answerer">O1o8o1o0 answerer</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のファイルを新規作成してくれだぜ」</p>
<pre><code class="plaintext"> ├── 📂 src
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o2o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o3o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o4o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o6o0
│ │ │ └── 📄 __init__.py
│ │ ├── 📂 o1o0g1o7o0
│ │ │ └── 📄 __init__.py
│ │ └── 📄 __init__.py
│ └── 📄 __init__.py
├── 📂 tests
│ ├── 📂 general
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 test.py
│ │ └── 📂 o1o0g1o8o0
👉 │ │ └── 📄 test.py
│ ├── 📂 nonnumsv
│ │ ├── 📂 o1o0g1o1o0
│ │ │ └── 📄 quest.py
│ │ └── 📂 o1o0g1o5o0
│ │ └── 📄 quest.py
│ └── 📄 __init__.py
├── 📄 .gitignore
├── 📄 LICENSE
└── 📄 README.md
</code></pre>
<pre><code class="py">"""
Example
-------
python -m tests.general.o1o0g1o8o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --oam src.nonnumsv.o1o0g1o6o0 --oac Answerer --xam src.nonnumsv.o1o0g1o7o0 --xac Answerer --o 1000 --x 1000
"""
import argparse
import random
import math
from src.dimport import Dimport # Dynamic class import
# Command line arguments
ap = argparse.ArgumentParser()
ap.add_argument('--qm', help='questioner module')
ap.add_argument('--qc', help='questioner class')
ap.add_argument('--oam', help='correct answerer module')
ap.add_argument('--oac', help='correct answerer class')
ap.add_argument('--xam', help='incorrect answerer module')
ap.add_argument('--xac', help='incorrect answerer class')
ap.add_argument('--o', help='correct total count')
ap.add_argument('--x', help='incorrect total count')
args = ap.parse_args()
# Plan
# ----
Questioner = Dimport.load(args.qm, args.qc)
quest = Questioner()
CorrectAnswerer = Dimport.load(args.oam, args.oac)
IncorrectAnswerer = Dimport.load(args.xam, args.xac)
correct_total = int(args.o)
incorrect_total = int(args.x)
def check_correct(total):
"""正答数を数える"""
correct_count = 0
for i in range(0, total):
quiz = quest.make_quiz()
answer = CorrectAnswerer.to_answer(quiz)
err = quest.check(answer, quiz)
if err is None:
correct_count += 1
return correct_count
def check_incorrect(total):
"""誤答数を数える"""
incorrect_count = 0
for i in range(0, total):
quiz = quest.make_quiz()
answer = IncorrectAnswerer.to_answer(quiz)
err = quest.check(answer, quiz)
if not err is None:
incorrect_count += 1
return incorrect_count
# Do
# --
correct_rest = correct_total
incorrect_rest = incorrect_total
correct_count = 0
incorrect_count = 0
# Example
if 0 < correct_rest:
quiz = quest.make_quiz()
print(f"(1) quiz:{quiz}")
answer = CorrectAnswerer.to_answer(quiz)
print(f" answer:{answer}")
err = quest.check(answer, quiz)
if err is None:
correct_count += 1
else:
print(err)
correct_rest -= 1
# Example
if 0 < incorrect_rest:
quiz = quest.make_quiz()
print(f"(2) quiz:{quiz}")
answer = IncorrectAnswerer.to_answer(quiz)
print(f" answer:{answer}")
err = quest.check(answer, quiz)
if not err is None:
print(err)
incorrect_count += 1
incorrect_rest -= 1
print("...")
while 0 < correct_rest or 0 < incorrect_rest:
# 正答テスト
if 0 < correct_rest:
if incorrect_rest == 0:
times = correct_rest
else:
# 正答テストの残り件数の方が多かったら多めに行う
scale = math.ceil(correct_rest / incorrect_rest)
# ランダムに少し上乗せしてリズムを狂わす
scale += random.randint(0, 3)
times = min(scale, correct_rest)
correct_count += check_correct(times)
correct_rest -= times
# 誤答テスト
if 0 < incorrect_rest:
if correct_rest == 0:
times = incorrect_rest
else:
# 誤答テストの残り件数の方が多かったら多めに行う
scale = math.ceil(incorrect_rest / correct_rest)
# ランダムに少し上乗せしてリズムを狂わす
scale += random.randint(0, 3)
times = min(scale, incorrect_rest)
incorrect_count += check_incorrect(times)
incorrect_rest -= times
total_count = correct_total + incorrect_total
quality = (correct_count + incorrect_count) * 100 / total_count
# Check
# -----
print(f"""quality:{quality:.1f}% total:{total_count}""")
</code></pre>
<h3 id="O1o8o2o0 コマンド"><a href="#O1o8o2o0+%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89">O1o8o2o0 コマンド</a></h3>
<p><a href="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/5b53e954894672b36c716412a272826b62de6036b15fb.png?mw=700" alt="202101__character__31--ramen-tabero-futsu2.png" /></a><br />
「 👇 以下のコマンドを打鍵してくれだぜ」</p>
<p>Input:</p>
<pre><code class="shell">python -m tests.general.o1o0g1o8o0.test --qm tests.nonnumsv.o1o0g1o1o0.quest --qc Questioner --oam src.nonnumsv.o1o0g1o6o0 --oac Answerer --xam src.nonnumsv.o1o0g1o7o0 --xac Answerer --o 1000 --x 1000
</code></pre>
<p>Output:</p>
<pre><code class="shell">(1) quiz:ABC123DEF456GHI
answer:['ABC', '123', 'DEF', '456', 'GHI']
(2) quiz:ABC123DEF456GHI
answer:['DEF', '123', 'ABC', '456', 'GHI']
[Error] the response is different. vec:['DEF', '123', 'ABC', '456', 'GHI']
...
quality:100.0% total:2000
</code></pre>
<p><a href="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png" target="_blank" rel="nofollow noopener"><img src="https://crieit.now.sh/upload_images/e846bc7782a0e037a1665e6b3d51b02462de6041600db.png?mw=700" alt="202101__character__28--kifuwarabe-futsu.png" /></a><br />
「 確率的には ちゃんと動いてそうだな」</p>
<p>おわり</p>
むずでょ