Skip to content

Commit

Permalink
데이터 구조 변경 준비를 위한 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sungsik819 committed Oct 10, 2024
1 parent 1a5e71a commit 5f8e7fe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lotto/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
;; (def remote-data (map #(get-data %) (range 1 (inc last-round))))

;; 파일에 있는 정보 읽기
(def ^:private file-data (read-string (slurp "lotto.edn")))
(def file-data (read-string (slurp "lotto.edn")))

;; 회차 데이터 가져오기
(def ^:private get-round #(nth file-data (dec %)))
Expand Down Expand Up @@ -128,6 +128,11 @@
([start end]
(map #(map get-color %) (lotto-data start end))))

;; 자리에 해당하는 [숫자 횟수] 형태의 데이터 가져오기
(defn get-digit-count [df]
(let [d (map df (lotto-data))]
(group-by-number d)))

;; 위 함수를 만들기 위한 테스트
(comment
;; 첫째 자리수 가져오기
Expand Down
31 changes: 31 additions & 0 deletions src/lotto/test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(ns lotto.test

(:require [clojure.test :refer [deftest is testing]]
[lotto.core :refer [file-data lotto-data group-by-number
get-digit-count first-d lotto-colors
unincluded-numbers]]))


(def dummy-data
[{:firstWinamnt 0, :drwtNo4 33, :totSellamnt 3681782000, :firstAccumamnt 863604600, :returnValue "success", :drwtNo2 23, :drwtNo5 37, :drwtNo3 29, :firstPrzwnerCo 0, :bnusNo 16, :drwNoDate "2002-12-07", :drwtNo6 40, :drwtNo1 10, :drwNo 1}
{:firstWinamnt 2002006800, :drwtNo4 25, :totSellamnt 4904274000, :firstAccumamnt 0, :returnValue "success", :drwtNo2 13, :drwtNo5 32, :drwtNo3 21, :firstPrzwnerCo 1, :bnusNo 2, :drwNoDate "2002-12-14", :drwtNo6 42, :drwtNo1 9, :drwNo 2}])

(deftest test-test
(with-redefs [file-data dummy-data]
(testing "[1 2 3 4 5 6 보너스] 형태 확인"
(is (= (lotto-data)
[[10 23 29 33 37 40 16] [9 13 21 25 32 42 2]])))
(testing "전체 자릿수에 대한 [숫자 횟수] 형태 확인"
(is (= ((group-by-number (flatten (lotto-data))) 0)
[21 1])))
(testing "첫째 자릿수에 대한 [숫자 횟수] 형태 확인"
(is (= (get-digit-count first-d)
[[10 1] [9 1]])))
(testing "전체 자릿수에 대한 [색이름 횟수] 형태 확인"
(is (= ((group-by-number (flatten (lotto-colors))) 0)
[:yellow 3])))
(testing "로또 번호에서 안나온 숫자 확인"
(is (= (unincluded-numbers (flatten (lotto-data)))
[1 3 4 5 6 7 8 11 12 14 15 17 18 19 20 22 24 26 27 28 30 31 34 35 36 38 39 41 43 44 45])))))

(clojure.test/run-tests 'lotto.test)

0 comments on commit 5f8e7fe

Please sign in to comment.