<commit_before>(ns test.core
  (:require [game.utils :refer [remove-once has? merge-costs zone make-cid to-keyword capitalize
                                costs-to-symbol vdissoc distinct-by]]
            [game.macros :refer [effect req msg]]
            [clojure.string :refer [split-lines split join]]
            [game.core :as core]
            [test.utils :refer [load-card qty default-corp default-runner
                                make-deck]]
            [test.macros :refer [do-game]]
            [clojure.test :refer :all]))

(defn new-game [corp runner]
  (let [states (core/init-game
                 {:gameid 1
                  :players [{:side "Corp"
                             :deck {:identity (load-card (:identity corp))
                                    :cards (:deck corp)}}
                            {:side "Runner"
                             :deck {:identity (load-card (:identity runner))
                                    :cards (:deck runner)}}]})
        state (second (last states))]
    (core/keep-hand state :corp nil)
    (core/keep-hand state :runner nil)
    (core/start-turn state :corp nil)
    state))

(defn take-credits
  ([state side] (take-credits state side nil))
  ([state side n]
    (let [n (or n (if (= side :corp) 3 4))
          other (if (= side :corp) :runner :corp)]
      (dotimes [i n] (core/click-credit state side nil))
      (core/end-turn state side nil)
      (core/start-turn state other nil))))

(defn play-run-event [state card server]
  (core/play state :runner {:card card})
  (is (= [server] (get-in @state [:run :server])))
  (is (get-in @state [:run :run-effect]))
  (core/no-action state :corp nil)
  (core/successful-run state :runner nil)
  (is (get-in @state [:runner :prompt])) ; a prompt is being shown
  (is (get-in @state [:run :successful]))) ; the run was marked successful)

(defn find-card [title from]
  (some #(when (= (:title %) title) %) from))

(defn card-ability
  ([state side card ability] (card-ability state side card ability nil))
  ([state side card ability targets] (core/play-ability state side {:card (core/get-card state card)
                                                                    :ability ability :targets targets})))

(defn play-from-hand
  ([state side title] (play-from-hand state side title nil))
  ([state side title server]
    (core/play state side {:card (find-card title (get-in @state [side :hand]))
                           :server server})))

(load "core-game")
(load "cards")<commit_msg>add test helper to check if last log entry contains a string<commit_after>(ns test.core
  (:require [game.utils :refer [remove-once has? merge-costs zone make-cid to-keyword capitalize
                                costs-to-symbol vdissoc distinct-by]]
            [game.macros :refer [effect req msg]]
            [clojure.string :refer [split-lines split join]]
            [game.core :as core]
            [test.utils :refer [load-card qty default-corp default-runner
                                make-deck]]
            [test.macros :refer [do-game]]
            [clojure.test :refer :all]))

(defn new-game [corp runner]
  (let [states (core/init-game
                 {:gameid 1
                  :players [{:side "Corp"
                             :deck {:identity (load-card (:identity corp))
                                    :cards (:deck corp)}}
                            {:side "Runner"
                             :deck {:identity (load-card (:identity runner))
                                    :cards (:deck runner)}}]})
        state (second (last states))]
    (core/keep-hand state :corp nil)
    (core/keep-hand state :runner nil)
    (core/start-turn state :corp nil)
    state))

(defn take-credits
  ([state side] (take-credits state side nil))
  ([state side n]
    (let [n (or n (if (= side :corp) 3 4))
          other (if (= side :corp) :runner :corp)]
      (dotimes [i n] (core/click-credit state side nil))
      (core/end-turn state side nil)
      (core/start-turn state other nil))))

(defn play-run-event [state card server]
  (core/play state :runner {:card card})
  (is (= [server] (get-in @state [:run :server])))
  (is (get-in @state [:run :run-effect]))
  (core/no-action state :corp nil)
  (core/successful-run state :runner nil)
  (is (get-in @state [:runner :prompt])) ; a prompt is being shown
  (is (get-in @state [:run :successful]))) ; the run was marked successful)

(defn find-card [title from]
  (some #(when (= (:title %) title) %) from))

(defn card-ability
  ([state side card ability] (card-ability state side card ability nil))
  ([state side card ability targets] (core/play-ability state side {:card (core/get-card state card)
                                                                    :ability ability :targets targets})))

(defn play-from-hand
  ([state side title] (play-from-hand state side title nil))
  ([state side title server]
    (core/play state side {:card (find-card title (get-in @state [side :hand]))
                           :server server})))

(defn last-log-contains?
  [state content]
  (not (nil?
         (re-find (re-pattern content)
                     (get (last (get-in @state [:log])) :text)))))

(load "core-game")
(load "cards")
{'fraction_non_alphanumeric': 0.13759026985936906, 'fraction_numerical': 0.0011402508551881414, 'mean_word_length': 2.005711022272987, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2843727', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1543, 'n_words': 515}