牟田まい
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # チェリー本輪読会番外編 ## やること - チェリー本題7章改札機のプログラムにSuicaを利用した場合の機能追加をする ## 大元のコード ```ruby= # gate.rb class Gate STATIONS = [:umeda, :juso, :mikuni] FARES = [160, 190] def initialize(name) @name = name end def enter(ticket) ticket.stamp(@name) end def exit(ticket) fare = calc_fare(ticket) fare <= ticket.fare end def calc_fare(ticket) from = STATIONS.index(ticket.stamped_at) to = STATIONS.index(@name) distance = to - from FARES[distance - 1] end end ``` ```ruby= # ticket.rb class Ticket attr_reader :fare, :stamped_at def initialize(fare) @fare = fare end def stamp(name) @stamped_at = name end end ``` ```ruby= # gate_test.rb require 'minitest/autorun' require_relative '../lib/gate' require_relative '../lib/ticket' class GateTest < Minitest::Test def setup @umeda = Gate.new(:umeda) @juso = Gate.new(:juso) @mikuni = Gate.new(:mikuni) end def test_umeda_to_juso ticket = Ticket.new(160) @umeda.enter(ticket) assert @juso.exit(ticket) end def test_umeda_to_mikuni_when_fare_is_not_enough ticket = Ticket.new(160) @umeda.enter(ticket) refute @mikuni.exit(ticket) end def test_umeda_to_mikuni_when_fare_is_enough ticket = Ticket.new(190) @umeda.enter(ticket) assert @mikuni.exit(ticket) end def test_juso_to_mikuni ticket = Ticket.new(160) @juso.enter(ticket) assert @mikuni.exit(ticket) end end ``` ### 5月31日にやること #### Suicaって何? - maimu - お金をチャージできる - チャージしたお金で電車に乗れる - チャージした金額が足りないと改札から出られない - Suicaにお金が入っていないと改札に入れない - Suicaを使って買い物ができる - cellotak - お金をチャージして、チャージされた金額から利用した金額が引かれる - 乗り込んだ駅と出る駅の運賃が自動計算される - チャージ額が利用した運賃を下回っていると、改札をでれない - チャージ額が初乗り運賃を下回っていると改札に入れない - moegi - 現金orオートチャージして使えるもの - 確か作成に500円かかる? - チャージが足りていれば改札から出れる - チャージが足りないと改札から出れない - 利用履歴が残る - まっきー - 現金が必要ない - 割引になる - 入った駅が記録される - 同じ駅で出られる - 制限時間がある? - 残高が少なくなるとオートチャージできる - メトロ⇆都営で割引になる - まとめ - チャージできる - 手動チャージ◎ - オートチャージ(チャレンジ!) - 電車に乗れる - 金額が足りないと出れなかったり入れなかったりする - 0円だと入れない◎ - 初乗り(チャレンジ!) - 利用履歴が残る✖️ - 乗車時に残高が減る◎ - どのタイミングで減る? - 降車時 - 乗車方向(時間次第でやる) - 初回のデポジットは考慮しない #### 最終的に完成させたいものは? - Suicaで乗車と降車ができること #### Suicaの場合、どんなストーリー(シナリオ)が考えられる? - maimu - 0円の残高のSuicaがある - 改札に入れない - n円チャージする - 改札に入る - 電車に乗れる - 改札から出られる - 残高が減る - 10円残高のSuicaがある - 改札に入れる - 電車に乗れる - 改札から出られない - moegi - 入場する - 足りていればそのまま入る - 0円だったらチャージ - 電車に乗る - 降車駅で改札から出る - 残高足りていたらそのまま出る - 残高足りなかったらチャージして出る - まっきー - チャージする - 入れた金額が正しくチャージされる? - (入場)入場判定する - 入場できるSuicaか? - (入場)入場駅を記録する - 入場駅がSuicaに記録される? - (出場)出場判定する - 入場駅・出場駅で決まる残高以上か? - (出場)残高を差し引く - 入場駅・出場駅で決まる運賃が引かれる? - cellotak - シナリオ1 - 残高160円以上 - 梅田で入場し、十三で出場する - 出場でき、残高が160円差し引かれている - シナリオ2 - 残高190円未満 - 梅田で入場し、三国で出場する - 出場できず、残高は元のまま - シナリオ3 - 残高190円以上 - 梅田で入場し、三国で出場する - 出場でき、残高が190円差し引かれている - シナリオ4 - 残高160円以上 - 十三で入場し、三国で出場する - 出場でき、残高が160円差し引かれる - シナリオ5 - 残高0円 - 入場できない - シナリオ6 - チャージする - 正しい金額がチャージされている #### どんなクラスを作るか - Suicaクラスを作る - チャージ金額 - 残高が増える - 残高が減る - どこから乗ったかを記録する - Gateクラス - 入場できるか? - 出場できるか? ## 感想 - maimu - みんなで話しながら要件を考えるのは楽しい! - moegi - 実際にテストのシナリオを作るとき、どう考えるのか勉強になりました。 - cellotak - 実現したい機能やその方法をどこから考えて、どう進めていくべきかが、自分ではよく分からなかったので、流れを体験することができて非常に勉強になりました。 - 意外と抜けている視点があることに気づきました! - まっきー - オブジェクト指向の思考プロセスはひとりでやるとそれが正しいのか自信がないところなので、今回皆で議論しながら進められたのはよかった - ある責務をどちらのクラスにやらせるべきかは、コードを書きながら修正していけばよいんだということを学んだ ## 6月1日にやること ### シナリオ #### シナリオ1(1区間) - Suicaの残高が1000円 - 梅田で入場し、十三で出場する - 期待する結果:出場できる - 期待する結果2:残高が840円になる #### シナリオ2(1区間・残高不足) - Suicaの残高が100円 - 梅田で入場し、十三で出場できない - 期待する結果:出場できない - 期待する結果2:残高が100円のまま #### シナリオ3(1区間・チャージする・境界値1) - Suicaの残高が0円 - 160円をチャージする - 梅田で入場し、十三で出場できる - 期待する結果:出場できる - 期待する結果2:残高が0円になる #### シナリオ4(1区間・チャージする・境界値2) - Suicaの残高が0円 - 159円をチャージする - 梅田で入場し、十三で出場できない - 期待する結果:出場できない - 期待する結果2:残高が159円のまま #### シナリオ5(2区間) - Suicaの残高が190円 - 梅田で入場し、三国で出場する - 期待する結果:出場できる - 期待する結果2:残高が0円になる #### シナリオ6(1区間) - Suicaの残高が160円 - 十三で入場し、三国で出場する - 期待する結果:出場できる - 期待する結果2:残高が0円になる #### シナリオ7(残高0円) - 入場できない #### シナリオ8(チャージ) - マイナスの金額はチャージ不可 ## 感想 - maimu - 画面共有して喋りながらコード書くの難しい😂 - 自分はTDD苦手なので、みんなで話して流れを確認できたのはとても良かったです! - cellotak - テストを実際に書くとなると、何から始めたらいいか結構悩んでしまったので、一度流れを体験できて学びになりました。 - テストを書く前についつい機能追加してしまいそうになるので気を付けたいと思います。 - 方向性が決まると、こうした方がいい、というのはなんとなく思いつきますが、その方向性を考えるのがまだできないです。 - assert_equalの使い方を学べました。 - moegi - 手順を踏んでみんなでじっくり考えながらコードを書くことができたのでTDDに対する理解がすこし進みました。 - 想定していた通りにエラーが出て良かったと思うのが面白い。 - assert,refuteの使い方を忘れていた。 - まっきー - ファイルがない→つくる、classがない→つくる、、、、という手順を踏める流れが勉強になった - stamped_atメソッドをTicketクラスと同じ名前にしたことで、calc_fareメソッドの引数にticketインスタンスとsuicaインスタンスの両方を入れられるのがなるほど〜と思った。けど引数名とか工夫の余地がありそうとも思った。 - TDDで赤文字の内容が変わっていくのが謎解き感あって面白そうかも? - ドライバーの方はめっちゃ大変そうだと思いました。。いつもお疲れさまです🙏 ## 6月5日 ### 感想 - maimu - メソッドが決まってくると細かなシナリオのテストは通しやすいと思った - どのクラスにどこまで役割を持たせるか考えるのはいまだに難しい - CelloTAK - どんどんとテストを通していくのが楽しかったです! - balanceの値を引くメソッドをSuicaクラスに定義することで、balanceをreadだけにできたので、いい判断だったことがわかりました - maimuさん、企画・進行・ドライバーすべて兼任してくださってありがとうございます🙏 - まっきー - ひとつずつテストシナリオが通ってくるとだんだん楽しくなると感じた - Suica残高を減らすメソッドは、拡張性を考えSuicaクラスに持たせるのがなるほどと思った(拡張性を考えないとGateクラスにやらせた方がしっくりきただけに) - リファクタリングのたびにアクセサーもメンテする必要性を知った - moegi - シナリオがいくつかある場合、メソッドが決まると当てはめて考えることができるのでサクサクすすんで楽しい - コード内で使っているか不明なメソッドを調べるときテストあると便利 - メソッドの役割を明文化したほうがオブジェクト指向っぽいという考え方がある

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully