<commit_before>;
;  (C) Copyright 2015, 2016  <NAME>
;
;  All rights reserved. This program and the accompanying materials
;  are made available under the terms of the Eclipse Public License v1.0
;  which accompanies this distribution, and is available at
;  http://www.eclipse.org/legal/epl-v10.html
;
;  Contributors:
;      <NAME>
;

(ns clj-calendar.calendar-test
    (:require [clojure.test :refer :all]
              [clj-calendar.calendar :refer :all]))


;
; Common functions used by tests.
;

(defn callable?
    "Test if given function-name is bound to the real function."
    [function-name]
    (clojure.test/function? function-name))



;
; Actual tests that checks if all functions exists.
;

(deftest test-get-calendar-existence
    "Check that the clj-calendar.calendar/get-calendar function definition exists."
    (testing "if the clj-calendar.calendar/get-calendar function definition exists."
        (is (callable? 'clj-calendar.calendar/get-calendar))))

(deftest test-get-calendar-for-week-existence
    "Check that the clj-calendar.calendar/get-calendar-for-week function definition exists."
    (testing "if the clj-calendar.calendar/get-calendar-for-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-calendar-for-week))))

(deftest test-get-year-existence
    "Check that the clj-calendar.calendar/get-year function definition exists."
    (testing "if the clj-calendar.calendar/get-year function definition exists."
        (is (callable? 'clj-calendar.calendar/get-year))))

(deftest test-get-week-existence
    "Check that the clj-calendar.calendar/get-week function definition exists."
    (testing "if the clj-calendar.calendar/get-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-week))))

(deftest test-get-day-of-week-existence
    "Check that the clj-calendar.calendar/get-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/get-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-day-of-week))))

(deftest test-format-date-existence
    "Check that the clj-calendar.calendar/format-date function definition exists."
    (testing "if the clj-calendar.calendar/format-date function definition exists."
        (is (callable? 'clj-calendar.calendar/format-date))))

(deftest test-format-date-time-existence
    "Check that the clj-calendar.calendar/format-date-time function definition exists."
    (testing "if the clj-calendar.calendar/format-date-time function definition exists."
        (is (callable? 'clj-calendar.calendar/format-date-time))))

(deftest test-format-date-using-desired-format-existence
    "Check that the clj-calendar.calendar/format-date-using-desired-format function definition exists."
    (testing "if the clj-calendar.calendar/format-date-using-desired-format function definition exists."
        (is (callable? 'clj-calendar.calendar/format-date-using-desired-format))))

(deftest test-format-from-to-date-for-week-existence
    "Check that the clj-calendar.calendar/format-from-to-date-for-week function definition exists."
    (testing "if the clj-calendar.calendar/format-from-to-date-for-week function definition exists."
        (is (callable? 'clj-calendar.calendar/format-from-to-date-for-week))))

(deftest test-calculate-first-day-of-week-existence
    "Check that the clj-calendar.calendar/calculate-first-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/calculate-first-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/calculate-first-day-of-week))))

(deftest test-get-first-day-of-week-existence
    "Check that the clj-calendar.calendar/get-first-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/get-first-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-first-day-of-week))))

(deftest test-get-last-day-of-week-existence
    "Check that the clj-calendar.calendar/get-last-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/get-last-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-last-day-of-week))))

(deftest test-get-first-day-of-week-formatted-existence
    "Check that the clj-calendar.calendar/get-first-day-of-week-formatted function definition exists."
    (testing "if the clj-calendar.calendar/get-first-day-of-week-formatted function definition exists."
        (is (callable? 'clj-calendar.calendar/get-first-day-of-week-formatted))))

(deftest test-get-last-day-of-week-formatted-existence
    "Check that the clj-calendar.calendar/get-last-day-of-week-formatted function definition exists."
    (testing "if the clj-calendar.calendar/get-last-day-of-week-formatted function definition exists."
        (is (callable? 'clj-calendar.calendar/get-last-day-of-week-formatted))))

;
; Tests for function behaviours
;

(deftest test-get-calendar
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (is (not (nil? (get-calendar))))
        (is (or
            (=  (class (get-calendar)) java.util.Calendar)
            (=  (class (get-calendar)) java.util.GregorianCalendar)))
        (is (or
            (=  (type  (get-calendar)) java.util.Calendar)
            (=  (type  (get-calendar)) java.util.GregorianCalendar)))
        (is (== (.get (get-calendar) (java.util.Calendar/ERA)) java.util.GregorianCalendar/AD))
        (is (>  (.get (get-calendar) (java.util.Calendar/YEAR)) 2000))       ; must be valid in all cases
        (is (>= (.get (get-calendar) (java.util.Calendar/MONTH)) 0))         ; must be valid in all cases
        (is (<  (.get (get-calendar) (java.util.Calendar/MONTH)) 12))        ; must be valid in all cases
        (is (>= (.get (get-calendar) (java.util.Calendar/DAY_OF_MONTH)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/DAY_OF_MONTH)) 31)) ; let's be on the safe side
        (is (>= (.get (get-calendar) (java.util.Calendar/DAY_OF_WEEK_IN_MONTH)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/DAY_OF_WEEK_IN_MONTH)) 4))
        (is (>= (.get (get-calendar) (java.util.Calendar/DAY_OF_YEAR)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/DAY_OF_YEAR)) 366)) ; let's be on the safe side
        (is (>= (.get (get-calendar) (java.util.Calendar/WEEK_OF_YEAR)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/WEEK_OF_YEAR)) 54)) ; let's be on the safe side
))

(deftest test-get-calendar-2
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (not (nil? calendar)))
            (is (or
                (=  (class calendar) java.util.Calendar)
                (=  (class calendar) java.util.GregorianCalendar)))
            (is (or
                (=  (type  calendar) java.util.Calendar)
                (=  (type  calendar) java.util.GregorianCalendar)))
            (is (=  (.get calendar (java.util.Calendar/YEAR)) 2000))
            (is (=  (.get calendar (java.util.Calendar/MONTH)) 1))
            (is (=  (.get calendar (java.util.Calendar/DAY_OF_MONTH)) 1)))
))

(deftest test-get-calendar-3
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (is (not (nil? (get-calendar))))
        (is (>= (.get (get-calendar) (java.util.Calendar/HOUR)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/HOUR)) 11))
        (is (>= (.get (get-calendar) (java.util.Calendar/HOUR_OF_DAY)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/HOUR_OF_DAY)) 23))
        (is (>= (.get (get-calendar) (java.util.Calendar/MINUTE)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/MINUTE)) 59))
        (is (>= (.get (get-calendar) (java.util.Calendar/SECOND)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/SECOND)) 59))
        (is (>= (.get (get-calendar) (java.util.Calendar/MILLISECOND)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/MILLISECOND)) 999))
))

(deftest test-get-calendar-4
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (=  (.get calendar (java.util.Calendar/HOUR)) 10))
            (is (=  (.get calendar (java.util.Calendar/MINUTE)) 20))
            (is (=  (.get calendar (java.util.Calendar/SECOND)) 30)))
))

(deftest test-get-calendar-5
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (>=  (.get calendar (java.util.Calendar/MILLISECOND)) 0))
            (is (<=  (.get calendar (java.util.Calendar/MILLISECOND)) 1000)))
))

(deftest test-format-date-using-desired-format
    "Check the function clj-calendar.calendar/format-date-using-desired-format"
    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (= "2000" (format-date-using-desired-format calendar "yyyy")))
            (is (= "02"   (format-date-using-desired-format calendar "MM")))
            (is (= "01"   (format-date-using-desired-format calendar "dd")))
            (is (= "10"   (format-date-using-desired-format calendar "hh")))
            (is (= "20"   (format-date-using-desired-format calendar "mm")))
            (is (= "30"   (format-date-using-desired-format calendar "ss"))))))

(deftest test-format-date-using-desired-format-2
    "Check the function clj-calendar.calendar/format-date-using-desired-format"
    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (= "2000-02"    (format-date-using-desired-format calendar "yyyy-MM")))
            (is (= "2000-02-01" (format-date-using-desired-format calendar "yyyy-MM-dd")))
            (is (= "02-01"      (format-date-using-desired-format calendar "MM-dd")))
            (is (= "2000-01"    (format-date-using-desired-format calendar "yyyy-dd"))))))

(deftest test-format-date-using-desired-format-3
    "Check the function clj-calendar.calendar/format-date-using-desired-format"
    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (= "10:20"      (format-date-using-desired-format calendar "hh:mm")))
            (is (= "10:20:30"   (format-date-using-desired-format calendar "hh:mm:ss")))
            (is (= "2000-02-01 10"  (format-date-using-desired-format calendar "yyyy-MM-dd hh")))
            (is (= "2000-02-01 10:20"  (format-date-using-desired-format calendar "yyyy-MM-dd hh:mm")))<commit_msg>New test cases added to test-format-date<commit_after>;
;  (C) Copyright 2015, 2016  <NAME>
;
;  All rights reserved. This program and the accompanying materials
;  are made available under the terms of the Eclipse Public License v1.0
;  which accompanies this distribution, and is available at
;  http://www.eclipse.org/legal/epl-v10.html
;
;  Contributors:
;      <NAME>
;

(ns clj-calendar.calendar-test
    (:require [clojure.test :refer :all]
              [clj-calendar.calendar :refer :all]))


;
; Common functions used by tests.
;

(defn callable?
    "Test if given function-name is bound to the real function."
    [function-name]
    (clojure.test/function? function-name))



;
; Actual tests that checks if all functions exists.
;

(deftest test-get-calendar-existence
    "Check that the clj-calendar.calendar/get-calendar function definition exists."
    (testing "if the clj-calendar.calendar/get-calendar function definition exists."
        (is (callable? 'clj-calendar.calendar/get-calendar))))

(deftest test-get-calendar-for-week-existence
    "Check that the clj-calendar.calendar/get-calendar-for-week function definition exists."
    (testing "if the clj-calendar.calendar/get-calendar-for-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-calendar-for-week))))

(deftest test-get-year-existence
    "Check that the clj-calendar.calendar/get-year function definition exists."
    (testing "if the clj-calendar.calendar/get-year function definition exists."
        (is (callable? 'clj-calendar.calendar/get-year))))

(deftest test-get-week-existence
    "Check that the clj-calendar.calendar/get-week function definition exists."
    (testing "if the clj-calendar.calendar/get-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-week))))

(deftest test-get-day-of-week-existence
    "Check that the clj-calendar.calendar/get-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/get-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-day-of-week))))

(deftest test-format-date-existence
    "Check that the clj-calendar.calendar/format-date function definition exists."
    (testing "if the clj-calendar.calendar/format-date function definition exists."
        (is (callable? 'clj-calendar.calendar/format-date))))

(deftest test-format-date-time-existence
    "Check that the clj-calendar.calendar/format-date-time function definition exists."
    (testing "if the clj-calendar.calendar/format-date-time function definition exists."
        (is (callable? 'clj-calendar.calendar/format-date-time))))

(deftest test-format-date-using-desired-format-existence
    "Check that the clj-calendar.calendar/format-date-using-desired-format function definition exists."
    (testing "if the clj-calendar.calendar/format-date-using-desired-format function definition exists."
        (is (callable? 'clj-calendar.calendar/format-date-using-desired-format))))

(deftest test-format-from-to-date-for-week-existence
    "Check that the clj-calendar.calendar/format-from-to-date-for-week function definition exists."
    (testing "if the clj-calendar.calendar/format-from-to-date-for-week function definition exists."
        (is (callable? 'clj-calendar.calendar/format-from-to-date-for-week))))

(deftest test-calculate-first-day-of-week-existence
    "Check that the clj-calendar.calendar/calculate-first-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/calculate-first-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/calculate-first-day-of-week))))

(deftest test-get-first-day-of-week-existence
    "Check that the clj-calendar.calendar/get-first-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/get-first-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-first-day-of-week))))

(deftest test-get-last-day-of-week-existence
    "Check that the clj-calendar.calendar/get-last-day-of-week function definition exists."
    (testing "if the clj-calendar.calendar/get-last-day-of-week function definition exists."
        (is (callable? 'clj-calendar.calendar/get-last-day-of-week))))

(deftest test-get-first-day-of-week-formatted-existence
    "Check that the clj-calendar.calendar/get-first-day-of-week-formatted function definition exists."
    (testing "if the clj-calendar.calendar/get-first-day-of-week-formatted function definition exists."
        (is (callable? 'clj-calendar.calendar/get-first-day-of-week-formatted))))

(deftest test-get-last-day-of-week-formatted-existence
    "Check that the clj-calendar.calendar/get-last-day-of-week-formatted function definition exists."
    (testing "if the clj-calendar.calendar/get-last-day-of-week-formatted function definition exists."
        (is (callable? 'clj-calendar.calendar/get-last-day-of-week-formatted))))

;
; Tests for function behaviours
;

(deftest test-get-calendar
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (is (not (nil? (get-calendar))))
        (is (or
            (=  (class (get-calendar)) java.util.Calendar)
            (=  (class (get-calendar)) java.util.GregorianCalendar)))
        (is (or
            (=  (type  (get-calendar)) java.util.Calendar)
            (=  (type  (get-calendar)) java.util.GregorianCalendar)))
        (is (== (.get (get-calendar) (java.util.Calendar/ERA)) java.util.GregorianCalendar/AD))
        (is (>  (.get (get-calendar) (java.util.Calendar/YEAR)) 2000))       ; must be valid in all cases
        (is (>= (.get (get-calendar) (java.util.Calendar/MONTH)) 0))         ; must be valid in all cases
        (is (<  (.get (get-calendar) (java.util.Calendar/MONTH)) 12))        ; must be valid in all cases
        (is (>= (.get (get-calendar) (java.util.Calendar/DAY_OF_MONTH)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/DAY_OF_MONTH)) 31)) ; let's be on the safe side
        (is (>= (.get (get-calendar) (java.util.Calendar/DAY_OF_WEEK_IN_MONTH)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/DAY_OF_WEEK_IN_MONTH)) 4))
        (is (>= (.get (get-calendar) (java.util.Calendar/DAY_OF_YEAR)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/DAY_OF_YEAR)) 366)) ; let's be on the safe side
        (is (>= (.get (get-calendar) (java.util.Calendar/WEEK_OF_YEAR)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/WEEK_OF_YEAR)) 54)) ; let's be on the safe side
))

(deftest test-get-calendar-2
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (not (nil? calendar)))
            (is (or
                (=  (class calendar) java.util.Calendar)
                (=  (class calendar) java.util.GregorianCalendar)))
            (is (or
                (=  (type  calendar) java.util.Calendar)
                (=  (type  calendar) java.util.GregorianCalendar)))
            (is (=  (.get calendar (java.util.Calendar/YEAR)) 2000))
            (is (=  (.get calendar (java.util.Calendar/MONTH)) 1))
            (is (=  (.get calendar (java.util.Calendar/DAY_OF_MONTH)) 1)))
))

(deftest test-get-calendar-3
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (is (not (nil? (get-calendar))))
        (is (>= (.get (get-calendar) (java.util.Calendar/HOUR)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/HOUR)) 11))
        (is (>= (.get (get-calendar) (java.util.Calendar/HOUR_OF_DAY)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/HOUR_OF_DAY)) 23))
        (is (>= (.get (get-calendar) (java.util.Calendar/MINUTE)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/MINUTE)) 59))
        (is (>= (.get (get-calendar) (java.util.Calendar/SECOND)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/SECOND)) 59))
        (is (>= (.get (get-calendar) (java.util.Calendar/MILLISECOND)) 0))
        (is (<= (.get (get-calendar) (java.util.Calendar/MILLISECOND)) 999))
))

(deftest test-get-calendar-4
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (=  (.get calendar (java.util.Calendar/HOUR)) 10))
            (is (=  (.get calendar (java.util.Calendar/MINUTE)) 20))
            (is (=  (.get calendar (java.util.Calendar/SECOND)) 30)))
))

(deftest test-get-calendar-5
    "Check the function clj-calendar.calendar/get-calendar."
    (testing "the function clj-calendar.calendar/get-calendar."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (>=  (.get calendar (java.util.Calendar/MILLISECOND)) 0))
            (is (<=  (.get calendar (java.util.Calendar/MILLISECOND)) 1000)))
))

(deftest test-format-date-using-desired-format
    "Check the function clj-calendar.calendar/format-date-using-desired-format"
    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (= "2000" (format-date-using-desired-format calendar "yyyy")))
            (is (= "00"   (format-date-using-desired-format calendar "yy")))
            (is (= "02"   (format-date-using-desired-format calendar "MM")))
            (is (= "01"   (format-date-using-desired-format calendar "dd")))
            (is (= "032"  (format-date-using-desired-format calendar "DDD")))   ; day in year
            (is (= "10"   (format-date-using-desired-format calendar "hh")))    ; hour 0..11
            (is (= "10"   (format-date-using-desired-format calendar "HH")))    ; hour 0..23
            (is (= "20"   (format-date-using-desired-format calendar "mm")))
            (is (= "30"   (format-date-using-desired-format calendar "ss")))
            (is (= "AM"   (format-date-using-desired-format calendar "aa")))    ; AM/PM
            (is (= "2"    (format-date-using-desired-format calendar "u")))     ; day number
            (is (= "AD"   (format-date-using-desired-format calendar "GG")))))) ; era

(deftest test-format-date-using-desired-format-2
    "Check the function clj-calendar.calendar/format-date-using-desired-format"
    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (= "2000-02"    (format-date-using-desired-format calendar "yyyy-MM")))
            (is (= "2000-02-01" (format-date-using-desired-format calendar "yyyy-MM-dd")))
            (is (= "02-01"      (format-date-using-desired-format calendar "MM-dd")))
            (is (= "2000-01"    (format-date-using-desired-format calendar "yyyy-dd"))))))

(deftest test-format-date-using-desired-format-3
    "Check the function clj-calendar.calendar/format-date-using-desired-format"
    (testing "the function clj-calendar.calendar/format-date-using-desired-format."
        (let [calendar (get-calendar)]
            (.set calendar 2000 01 01 10 20 30)
            (is (= "10:20"      (format-date-using-desired-format calendar "hh:mm")))
            (is (= "10:20:30"   (format-date-using-desired-format calendar "hh:mm:ss")))
            (is (= "2000-02-01 10"  (format-date-using-desired-format calendar "yyyy-MM-dd hh")))
            (is (= "2000-02-01 10:20"  (format-date-using-desired-format calendar "yyyy-MM-dd hh:mm")))
{'fraction_non_alphanumeric': 0.1530758226037196, 'fraction_numerical': 0.020028612303290415, 'mean_word_length': 2.976555766247199, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5090682', 'n_tokens_mistral': 7925, 'n_tokens_neox': 7326, 'n_words': 1635}