File: periodic_test.clj

package info (click to toggle)
clj-time-clojure 0.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 312 kB
  • sloc: makefile: 24; sh: 13
file content (47 lines) | stat: -rw-r--r-- 1,411 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns clj-time.periodic-test
  (:require [clojure.test :refer :all]
            [clj-time.core :refer [date-time hours months]]
            [clj-time.periodic :refer :all]))

(deftest test-periodic-sequence
  (let [d0 (date-time 2012 3 3 20 0)
        d1 (date-time 2012 3 3 21 0)
        d2 (date-time 2012 3 3 22 0)
        d3 (date-time 2012 3 3 23 0)
        d4 (date-time 2012 3 4 0 0)
        d5 (date-time 2012 3 4 1 0)
        d6 (date-time 2012 3 4 2 0)
        uds (periodic-seq d0 (hours 1))]
    (are [a b] (= a b)
         d0 (first uds)
         d1 (second uds)
         d2 (nth uds 2)
         d3 (nth uds 3)
         d4 (nth uds 4)
         d5 (nth uds 5)
         d6 (nth uds 6))))

(deftest test-periodic-sequence-2
  (let [d0 (date-time 2014 1 31)
        d1 (date-time 2014 2 28)
        d2 (date-time 2014 3 31)
        d3 (date-time 2014 4 30)
        uds (periodic-seq d0 (months 1))]
    (are [a b] (= a b)
         d0 (first uds)
         d1 (second uds)
         d2 (nth uds 2)
         d3 (nth uds 3))))

(deftest test-limited-periodic-sequence
  (let [d0 (date-time 2014 1 31)
        d1 (date-time 2014 2 28)
        d2 (date-time 2014 3 31)
        d3 (date-time 2014 4 30)
        uds (periodic-seq d0 d3 (months 1))]
    (are [a b] (= a b)
         d0 (first uds)
         d1 (second uds)
         d2 (nth uds 2))
    (are [i] (thrown? IndexOutOfBoundsException (nth uds i)) 3)))