Last active
August 29, 2015 14:20
-
-
Save fcanas/39391b6a5670af668862 to your computer and use it in GitHub Desktop.
Shell Game
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
; To run: | |
; | |
; $ lein repl | |
; $ (load-file "shell_game_test.clj") | |
(ns the-shell-game-test | |
(:require [clojure.test :refer :all])) | |
(defn move-the-ball [position, move] | |
(nth (concat [position] (reverse move)) (+ 1 (.indexOf move position))) | |
) | |
(defn find-the-ball [start, moves] | |
(reduce move-the-ball start, moves) | |
) | |
(deftest basic-test | |
(testing "Some games" | |
(is (= 2 (find-the-ball 0 [[0 1] [1 2] [1 0]]))) | |
(is (= 2 (find-the-ball 0 [[0 1] [2 1] [0 1]]))) | |
(is (= 1 (find-the-ball 0 [[0 1]]))) | |
(is (= 0 (find-the-ball 1 [[0 1]]))) | |
(is (= 1 (find-the-ball 0 [[0 1] [1 2] [2 0] [0 1] [1 2] [2 1] [2 0] [0 2]]))) | |
(is (= 2 (find-the-ball 0 [[0 2] [1 0]]))) | |
(is (= 0 (find-the-ball 1 [[0 2] [1 0]]))) | |
(is (= 2 (find-the-ball 0 [[0 9] [9 3] [3 7] [7 8] [8 2] [4 5]]))) | |
(is (= 1 (find-the-ball 1 [[0 9] [9 3] [3 7] [7 8] [8 2] [4 5]]))) | |
(is (= 8 (find-the-ball 2 [[0 9] [9 3] [3 7] [7 8] [8 2] [4 5]]))) | |
(is (= 9 (find-the-ball 3 [[0 9] [9 3] [3 7] [7 8] [8 2] [4 5]]))) | |
(is (= 5 (find-the-ball 4 [[0 9] [9 3] [3 7] [7 8] [8 2] [4 5]]))) | |
(is (= 4 (find-the-ball 5 [[0 9] [9 3] [3 7] [7 8] [8 2] [4 5]]))) | |
(is (= 6 (find-the-ball 6 [[0 9] [9 3] [3 7] [7 8] [8 2] [4 5]]))) | |
)) | |
(run-tests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment