<commit_before>(ns frontend.test-datetime
  (:require [frontend.datetime :as datetime])
  (:require-macros [cemerick.cljs.test :refer (is deftest testing)]))

(deftest milli-to-float-duration-works
  (testing "basic"
    (is (= (first (datetime/millis-to-float-duration 100))
           "100.0ms")))
  (testing "unit detection"
    (is (= (first (datetime/millis-to-float-duration 6000))
           "6.0s")))
  (testing "huge millis"
    (is (= (first (datetime/millis-to-float-duration 60000000))
           "16.7h")))
  (testing "tiny millis"
    (is (= (first (datetime/millis-to-float-duration 0.6))
           "0.6ms")))
  (testing "less greater or equal to 1 should stay at smaller unit"
    (is (= (first (datetime/millis-to-float-duration 1000))
           "1.0s")))
  (testing "zero"
    (is (= (first (datetime/millis-to-float-duration 0))
           "0")))
  (testing "accepts options"
    (is (= (first (datetime/millis-to-float-duration 60000000
                                                     {:unit :seconds
                                                      :decimals 0}))
           "60000s")))
  (testing "returns unit-hash"
    (is (= (-> (datetime/millis-to-float-duration 60000000)
               (last)
               (:unit))
           :hours))))


(deftest nice-floor-duration-works
  (testing "basic"
    (let [result (datetime/nice-floor-duration 6600)
          [result-str] (datetime/millis-to-float-duration result)]
      (is (= result-str
             "6.0s")))))

(deftest format-duration-works
  (testing "full units"
    (testing "singular"
      (is (= (datetime/time-ago 1000) "1 second")))
    (testing "plural"
      (is (= (datetime/time-ago 480000) "8 minutes"))))
  (testing "abbreviated  units"
    (testing "singular"
      (is (= (datetime/time-ago 3600000) "1 hour")))
    (testing "plural"
      (is (= (datetime/time-ago (* 3600000 48)) "2 days")))))
<commit_msg>Better test current behavior.<commit_after>(ns frontend.test-datetime
  (:require [frontend.datetime :as datetime])
  (:require-macros [cemerick.cljs.test :refer (is are deftest testing)]))

(deftest milli-to-float-duration-works
  (testing "basic"
    (is (= (first (datetime/millis-to-float-duration 100))
           "100.0ms")))
  (testing "unit detection"
    (is (= (first (datetime/millis-to-float-duration 6000))
           "6.0s")))
  (testing "huge millis"
    (is (= (first (datetime/millis-to-float-duration 60000000))
           "16.7h")))
  (testing "tiny millis"
    (is (= (first (datetime/millis-to-float-duration 0.6))
           "0.6ms")))
  (testing "less greater or equal to 1 should stay at smaller unit"
    (is (= (first (datetime/millis-to-float-duration 1000))
           "1.0s")))
  (testing "zero"
    (is (= (first (datetime/millis-to-float-duration 0))
           "0")))
  (testing "accepts options"
    (is (= (first (datetime/millis-to-float-duration 60000000
                                                     {:unit :seconds
                                                      :decimals 0}))
           "60000s")))
  (testing "returns unit-hash"
    (is (= (-> (datetime/millis-to-float-duration 60000000)
               (last)
               (:unit))
           :hours))))


(deftest nice-floor-duration-works
  (testing "basic"
    (let [result (datetime/nice-floor-duration 6600)
          [result-str] (datetime/millis-to-float-duration result)]
      (is (= result-str
             "6.0s")))))

(deftest format-duration-works
  (testing "full units"
    (are [ms formatted] (= (datetime/time-ago ms) formatted)
      1000 "1 second"
      2000 "2 seconds"
      (* 60 1000) "1 minute"
      (* 60 2000) "2 minutes"
      (* 60 60 1000) "1 hour"
      (* 60 60 2000) "2 hours"
      (* 24 60 60 1000) "1 day"
      (* 24 60 60 2000) "2 days"
      (* 30 24 60 60 1000) "1 month"
      (* 30 24 60 60 2000) "2 months"
      (* 12 30 24 60 60 1000) "1 year"
      (* 12 30 24 60 60 2000) "2 years"))
  (testing "abbreviated units"
    (are [ms formatted] (= (datetime/time-ago-abbreviated ms) formatted)
      1000 "1 sec"
      2000 "2 secs"
      (* 60 1000) "1 min"
      (* 60 2000) "2 mins"
      (* 60 60 1000) "1 hr"
      (* 60 60 2000) "2 hrs"
      (* 24 60 60 1000) "1 day"
      (* 24 60 60 2000) "2 days"
      (* 30 24 60 60 1000) "1 month"
      (* 30 24 60 60 2000) "2 months"
      (* 12 30 24 60 60 1000) "1 year"
      (* 12 30 24 60 60 2000) "2 years")))

{'fraction_non_alphanumeric': 0.15632754342431762, 'fraction_numerical': 0.09023234829686443, 'mean_word_length': 2.1093969144460027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '5985666', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1428, 'n_words': 401}