<commit_before>;; Copyright © 2016, JUXT LTD.

(ns tick.core-test
  (:require
   [clojure.test :refer :all]
   [tick.core :refer :all])
  (:import
   [java.time Clock ZoneId Instant Duration DayOfWeek Month ZonedDateTime LocalDate LocalDateTime]
   [java.time.temporal ChronoField ChronoUnit]))

(def LONDON (ZoneId/of "Europe/London"))

(def T0 (-> "2012-12-04T05:21:00" LocalDateTime/parse (.atZone LONDON)))
(def T1 (.plusSeconds T0 10))

(deftest periodic-seq-test
  (let [sq (periodic-seq T0 (minutes 1))]
    (testing "sq starts with start time"
      (is (= T0 (first sq))))
    (testing "sq moves forward by 10 minutes"
      (is (= (-> "2012-12-04T05:31:00" LocalDateTime/parse (.atZone LONDON))
             (first (drop 10 sq)))))))

(defn acceptable-hours [zdt]
  (let [h (.getHour zdt)]
    (<= 7 h 21)))

(deftest composition-test
  (testing "Filter by acceptable hours"
    (is (= 62 (count
               (->> (periodic-seq T0 (hours 1))
                    (take 100)
                    (filter acceptable-hours)))))))

(deftest easter-test
  (is (easter-sunday? (-> "2017-04-16" LocalDate/parse)))
  (is (good-friday? (LocalDate/parse "2017-04-14")))
  (is (easter-monday? (-> "2017-04-17" LocalDate/parse)))
  (is (not (easter-sunday? (-> "2018-04-19" LocalDate/parse))))
  (is (every? easter-sunday? (easter-sundays (-> "1900-01-01" LocalDate/parse))))
  (is (every? good-friday? (good-fridays (-> "1900-01-01" LocalDate/parse))))
  (is (every? easter-monday? (easter-mondays (-> "1900-01-01" LocalDate/parse)))))

(deftest schedule-test
  (let [a (atom 0)
        f (fn [dt] (swap! a inc))
        clk (clock-ticking-in-seconds)
        now (just-now clk)
        timeline (take 10 (periodic-seq now (millis 10)))]
    @(start (schedule f timeline) clk)
    (is (= @a 10))))

(deftest simulate-test
  (let [a (atom 0)
        f (fn [dt] (swap! a inc))
        clk (clock-ticking-in-seconds)
        now (just-now clk)
        timeline (take 1000 (periodic-seq now (seconds 1)))]
    @(start (simulate f timeline) clk)
    (is (= @a 1000))))
<commit_msg>Test for merge-timelines<commit_after>;; Copyright © 2016, JUXT LTD.

(ns tick.core-test
  (:require
   [clojure.test :refer :all]
   [tick.core :refer :all])
  (:import
   [java.time Clock ZoneId Instant Duration DayOfWeek Month ZonedDateTime LocalDate LocalDateTime]
   [java.time.temporal ChronoField ChronoUnit]))

(def LONDON (ZoneId/of "Europe/London"))

(def T0 (-> "2012-12-04T05:21:00" LocalDateTime/parse (.atZone LONDON)))
(def T1 (.plusSeconds T0 10))

(deftest periodic-seq-test
  (let [sq (periodic-seq T0 (minutes 1))]
    (testing "sq starts with start time"
      (is (= T0 (first sq))))
    (testing "sq moves forward by 10 minutes"
      (is (= (-> "2012-12-04T05:31:00" LocalDateTime/parse (.atZone LONDON))
             (first (drop 10 sq)))))))

(defn acceptable-hours [zdt]
  (let [h (.getHour zdt)]
    (<= 7 h 21)))

(deftest composition-test
  (testing "Filter by acceptable hours"
    (is (= 62 (count
               (->> (periodic-seq T0 (hours 1))
                    (take 100)
                    (filter acceptable-hours)))))))

(deftest easter-test
  (is (easter-sunday? (-> "2017-04-16" LocalDate/parse)))
  (is (good-friday? (LocalDate/parse "2017-04-14")))
  (is (easter-monday? (-> "2017-04-17" LocalDate/parse)))
  (is (not (easter-sunday? (-> "2018-04-19" LocalDate/parse))))
  (is (every? easter-sunday? (easter-sundays (-> "1900-01-01" LocalDate/parse))))
  (is (every? good-friday? (good-fridays (-> "1900-01-01" LocalDate/parse))))
  (is (every? easter-monday? (easter-mondays (-> "1900-01-01" LocalDate/parse)))))

(deftest merge-timelines-test
  (let [merged
        (merge-timelines
         [(take 10 (periodic-seq (.plus (just-now) (seconds 10)) (minutes 1)))
          (take 10 (periodic-seq (just-now) (minutes 1)))])]
    (is (distinct? merged))
    (is (= 20 (count merged)))))

(deftest schedule-test
  (let [a (atom 0)
        f (fn [dt] (swap! a inc))
        clk (clock-ticking-in-seconds)
        now (just-now clk)
        timeline (take 10 (periodic-seq now (millis 10)))]
    @(start (schedule f timeline) clk)
    (is (= @a 10))))

(deftest simulate-test
  (let [a (atom 0)
        f (fn [dt] (swap! a inc))
        clk (clock-ticking-in-seconds)
        now (just-now clk)
        timeline (take 1000 (periodic-seq now (seconds 1)))]
    @(start (simulate f timeline) clk)
    (is (= @a 1000))))

{'fraction_non_alphanumeric': 0.17572749830814346, 'fraction_numerical': 0.05955334987593052, 'mean_word_length': 2.9169611307420493, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5360792', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1599, 'n_words': 443}