Skip to content

Instantly share code, notes, and snippets.

@craftybones
Last active December 27, 2016 13:26
Show Gist options
  • Save craftybones/936f4161621fd1ddf5d599e918ac031b to your computer and use it in GitHub Desktop.
Save craftybones/936f4161621fd1ddf5d599e918ac031b to your computer and use it in GitHub Desktop.
(deftest team-score-updation
(testing "Keeps team score when no run scored"
(on-game (helper/add-dot-ball-to-game-on-over game [0 1])
(is-total-score? 0)
(is-on-over? [0 1])
(is-striker? "Kirat Boli")
(is-non-striker? "N S Nodhi")))
(testing "Updates team score and rotates strike when single run scored"
(on-game (helper/add-single-run-to-game-on-over game [0 1])
(is-total-score? 1)
(is-on-over? [0 1])
(is-striker? "N S Nodhi")
(is-non-striker? "Kirat Boli")))
(testing "Updates team score and keeps strike when two runs scored"
(on-game (helper/add-two-runs-to-game-on-over game [0 1])
(is-total-score? 2)
(is-on-over? [0 1])
(is-striker? "Kirat Boli")
(is-non-striker? "N S Nodhi"))))
(deftest rotation-on-last-ball
(testing "Rotates players if last ball of over was a dot ball"
(on-game (helper/add-dot-ball-to-game-on-over game [0 6])
(is-striker? "N S Nodhi")
(is-non-striker? "Kirat Boli")))
(testing "Does not rotate players if last ball of over was a single"
(on-game (helper/add-single-run-to-game-on-over game [0 6])
(is-striker? "Kirat Boli")
(is-non-striker? "N S Nodhi")))
(testing "Rotates players if two runs scored off last ball of over"
(on-game (helper/add-two-runs-to-game-on-over game [0 6])
(is-striker? "N S Nodhi")
(is-non-striker? "Kirat Boli"))))
(deftest consecutive-balls-with-runs-scored
(testing "Adds two to score after two singles are scored"
(on-game (-> game
(helper/add-single-run-to-game-on-over [0 1])
(helper/add-single-run-to-game-on-over [0 2]))
(is-total-score? 2)
(is-striker? "Kirat Boli")
(is-non-striker? "N S Nodhi")))
(testing "Adds three to score after three singles are scored"
(on-game (-> game
(helper/add-single-run-to-game-on-over [0 1])
(helper/add-single-run-to-game-on-over [0 2])
(helper/add-single-run-to-game-on-over [0 3]))
(is-total-score? 3)
(is-striker? "N S Nodhi")
(is-non-striker? "Kirat Boli"))))
(deftest wicket-taken
(testing "Striker changes when wicket taken"
(on-game (helper/take-wicket-on-over game [0 1])
(is-striker? "R Rumrah")
(is-non-striker? "N S Nodhi")))
(testing "Striker changes and rotates when wicket taken on last ball"
(on-game (helper/take-wicket-on-over game [0 6])
(is-striker? "N S Nodhi")
(is-non-striker? "R Rumrah"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment