<commit_before>(ns nhl-score-api.game-scores-test
  (:require [clojure.test :refer :all]
            [nhl-score-api.game-scores :refer :all]
            [nhl-score-api.resources :as resources]))

(deftest game-score-html-parsing

  (testing "Parsing page with games finished in overtime and in shootout"
    (let [games (parse-game-scores resources/dom-with-ot-and-so-game)]
      (is (= 14
             (count games)) "Parsed game count")
      (is (= [5 6 11 8 7 8 7 2 5 5 9 5 3 2]
             (map #(count (:goals %)) games)) "Parsed goal count")
      (is (= [["TBL" "BUF"] ["MTL" "BOS"] ["OTT" "TOR"] ["PHI" "FLA"]
              ["CBJ" "NYR"] ["NJD" "WSH"] ["DET" "CAR"] ["EDM" "NSH"]
              ["STL" "MIN"] ["NYI" "CHI"] ["DAL" "COL"] ["CGY" "VAN"]
              ["PIT" "ARI"] ["ANA" "SJS"]]
             (map :teams games)) "Parsed team names")
      (is (= [{"TBL" 4 "BUF" 1} {"MTL" 4 "BOS" 2} {"OTT" 5 "TOR" 4 :shootout true} {"PHI" 1 "FLA" 7}
              {"CBJ" 2 "NYR" 5} {"NJD" 3 "WSH" 5} {"DET" 4 "CAR" 3} {"EDM" 0 "NSH" 2}
              {"STL" 2 "MIN" 3} {"NYI" 1 "CHI" 4} {"DAL" 3 "COL" 6} {"CGY" 3 "VAN" 2 :overtime true}
              {"PIT" 1 "ARI" 2} {"ANA" 0 "SJS" 2}]
             (map :scores games)) "Parsed scores")))

  (testing "Parsing page with one game missing goal information"
    (let [games (parse-game-scores resources/dom-with-game-missing-goals)]
      (is (= 8
             (count games)) "Parsed game count")
      (is (= [8 5 9 3 4 6 5 5]
             (map #(count (:goals %)) games)) "Parsed goal count")))

  (testing "Parsing page with games that have not yet started"
    (let [games (parse-game-scores resources/dom-with-not-started-games)]
      (is (= 0
             (count games)) "Parsed game count")))

  (testing "Parsing page with no games"
    (let [games (parse-game-scores resources/dom-without-games)]
      (is (= 0
             (count games)) "Parsed game count")))

  (testing "Parsing game with goals in regulation and overtime"
    (let [goals (:goals (nth (parse-game-scores resources/dom-with-ot-and-so-game) 11))]
      (is (= [{:team "CGY" :time "05:00" :scorer "<NAME>" :goal-count 1 :period "1"}
              {:team "VAN" :time "02:03" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "VAN" :time "11:33" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "CGY" :time "08:49" :scorer "<NAME>" :goal-count 1 :period "3"}
              {:team "CGY" :time "03:03" :scorer "<NAME>" :goal-count 1 :period "OT"}]
             goals) "Parsed goals")))

  (testing "Parsing game with goals in regulation and shootout"
    (let [goals (:goals (nth (parse-game-scores resources/dom-with-ot-and-so-game) 2))]
      (is (= [{:team "OTT" :time "00:46" :scorer "<NAME>" :goal-count 3 :period "2"}
              {:team "OTT" :time "03:38" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "OTT" :time "04:56" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "TOR" :time "07:05" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "TOR" :time "14:33" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "TOR" :time "03:18" :scorer "<NAME>" :goal-count 1 :period "3"}
              {:team "OTT" :time "08:59" :scorer "<NAME>" :goal-count 1 :period "3"}
              {:team "TOR" :time "16:12" :scorer "<NAME>" :goal-count 1 :period "3"}
              {:team "TOR" :scorer "<NAME>" :period "SO"}
              {:team "OTT" :scorer "<NAME>" :period "SO"}
              {:team "OTT" :scorer "<NAME>" :period "SO"}]
             goals) "Parsed goals")))

  (testing "Parsing game without goals"
    (let [dom (parse-dom resources/dom-with-game-missing-goals)
          game (nth (parse-games dom) 7)
          goals (parse-goals game)]
      (is (= []
             goals) "Parsed goals"))))<commit_msg>Drop unnecessary other goals from shootout goal test<commit_after>(ns nhl-score-api.game-scores-test
  (:require [clojure.test :refer :all]
            [nhl-score-api.game-scores :refer :all]
            [nhl-score-api.resources :as resources]))

(deftest game-score-html-parsing

  (testing "Parsing page with games finished in overtime and in shootout"
    (let [games (parse-game-scores resources/dom-with-ot-and-so-game)]
      (is (= 14
             (count games)) "Parsed game count")
      (is (= [5 6 11 8 7 8 7 2 5 5 9 5 3 2]
             (map #(count (:goals %)) games)) "Parsed goal count")
      (is (= [["TBL" "BUF"] ["MTL" "BOS"] ["OTT" "TOR"] ["PHI" "FLA"]
              ["CBJ" "NYR"] ["NJD" "WSH"] ["DET" "CAR"] ["EDM" "NSH"]
              ["STL" "MIN"] ["NYI" "CHI"] ["DAL" "COL"] ["CGY" "VAN"]
              ["PIT" "ARI"] ["ANA" "SJS"]]
             (map :teams games)) "Parsed team names")
      (is (= [{"TBL" 4 "BUF" 1} {"MTL" 4 "BOS" 2} {"OTT" 5 "TOR" 4 :shootout true} {"PHI" 1 "FLA" 7}
              {"CBJ" 2 "NYR" 5} {"NJD" 3 "WSH" 5} {"DET" 4 "CAR" 3} {"EDM" 0 "NSH" 2}
              {"STL" 2 "MIN" 3} {"NYI" 1 "CHI" 4} {"DAL" 3 "COL" 6} {"CGY" 3 "VAN" 2 :overtime true}
              {"PIT" 1 "ARI" 2} {"ANA" 0 "SJS" 2}]
             (map :scores games)) "Parsed scores")))

  (testing "Parsing page with one game missing goal information"
    (let [games (parse-game-scores resources/dom-with-game-missing-goals)]
      (is (= 8
             (count games)) "Parsed game count")
      (is (= [8 5 9 3 4 6 5 5]
             (map #(count (:goals %)) games)) "Parsed goal count")))

  (testing "Parsing page with games that have not yet started"
    (let [games (parse-game-scores resources/dom-with-not-started-games)]
      (is (= 0
             (count games)) "Parsed game count")))

  (testing "Parsing page with no games"
    (let [games (parse-game-scores resources/dom-without-games)]
      (is (= 0
             (count games)) "Parsed game count")))

  (testing "Parsing game with goals in regulation and overtime"
    (let [goals (:goals (nth (parse-game-scores resources/dom-with-ot-and-so-game) 11))]
      (is (= [{:team "CGY" :time "05:00" :scorer "<NAME>" :goal-count 1 :period "1"}
              {:team "VAN" :time "02:03" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "VAN" :time "11:33" :scorer "<NAME>" :goal-count 1 :period "2"}
              {:team "CGY" :time "08:49" :scorer "<NAME>" :goal-count 1 :period "3"}
              {:team "CGY" :time "03:03" :scorer "<NAME>" :goal-count 1 :period "OT"}]
             goals) "Parsed goals")))

  (testing "Parsing game with goals in shootout"
    (let [goals (:goals (nth (parse-game-scores resources/dom-with-ot-and-so-game) 2))]
      (is (= [{:team "TOR" :scorer "<NAME>" :period "SO"}
              {:team "OTT" :scorer "<NAME>" :period "SO"}
              {:team "OTT" :scorer "<NAME>" :period "SO"}]
             (take-last 3 goals)) "Parsed shootout goals")))

  (testing "Parsing game without goals"
    (let [dom (parse-dom resources/dom-with-game-missing-goals)
          game (nth (parse-games dom) 7)
          goals (parse-goals game)]
      (is (= []
             goals) "Parsed goals"))))
{'fraction_non_alphanumeric': 0.1923458540042523, 'fraction_numerical': 0.03217576187101347, 'mean_word_length': 2.441951219512195, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4998075', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2520, 'n_words': 811}