Skip to content

Commit d4032e1

Browse files
authored
Sync gigasecond tests and stub (#367)
1 parent 4e3c4a5 commit d4032e1

File tree

3 files changed

+26
-43
lines changed

3 files changed

+26
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; gigasecond.el --- Gigasecond exercise (exercism) -*- lexical-binding: t; -*-
1+
;;; gigasecond.el --- Gigasecond (exercism) -*- lexical-binding: t; -*-
22

33
;;; Commentary:
44
;; Calculate the date one gigasecond (10^9 seconds) from the
@@ -9,7 +9,7 @@
99

1010
;;; Code:
1111

12-
(defun from (second minute hour day month year)
12+
(defun add (second minute hour day month year)
1313
"Calculate gigasecond from date given.
1414
Params are SECOND, MINUTE, HOUR, DAY, MONTH, and YEAR."
1515
(let ((gigasecond (seconds-to-time (expt 10 9)))
@@ -19,8 +19,5 @@ Params are SECOND, MINUTE, HOUR, DAY, MONTH, and YEAR."
1919
(butlast end-date (- (length end-date) 6)))))
2020

2121

22-
23-
24-
2522
(provide 'gigasecond)
2623
;;; gigasecond.el ends here
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,34 @@
1-
;;; gigasecond-test.el --- ERT tests for gigasecond (exercism) -*- lexical-binding: t; -*-
1+
;;; gigasecond-test.el --- Gigasecond (exercism) -*- lexical-binding: t; -*-
22

33
;;; Commentary:
4-
;;
5-
;; Tests ported from Common Lisp gigasecond:
6-
;; https://github.com/exercism/xlisp/blob/master/gigasecond/gigasecond-test.lisp
7-
;;
8-
;; To run tests individually: M-x eval-buffer RET, M-x ert RET test-name.
9-
;; If you're using helm or something similar, you should get a menu of test names.
10-
;;
11-
;; To run tests in batch mode, from the command line run:
12-
;; emacs -batch -l ert -l gigasecond-test.el -f ert-run-tests-batch-and-exit
134

145
;;; Code:
156

7+
168
(load-file "gigasecond.el")
17-
(declare-function from "gigasecond.el" (second minute hour day month year))
9+
(declare-function add "gigasecond.el" (moment))
10+
11+
12+
(ert-deftest date-only-specification-of-time ()
13+
(should (equal '(40 46 1 1 1 2043) (add 0 0 0 25 4 2011))))
1814

19-
(ert-deftest from-lisp-epoch ()
20-
(should
21-
(equal '(40 46 1 10 9 1931) (from 0 0 0 1 1 1900))))
2215

23-
(ert-deftest from-unix-epoch ()
24-
(should
25-
(equal '(40 46 1 9 9 2001) (from 0 0 0 1 1 1970))))
16+
(ert-deftest second-test-for-date-only-specification-of-time ()
17+
(should (equal '(40 46 1 19 2 2009) (add 0 0 0 13 6 1977))))
2618

27-
(ert-deftest from-20110425T120000Z ()
28-
(should
29-
(equal '(40 46 13 1 1 2043) (from 0 0 12 25 4 2011))))
3019

31-
(ert-deftest from-19770613T235959Z ()
32-
(should
33-
(equal '(39 46 1 20 2 2009) (from 59 59 23 13 6 1977))))
20+
(ert-deftest third-test-for-date-only-specification-of-time ()
21+
(should (equal '(40 46 1 27 3 1991) (add 0 0 0 19 7 1959))))
3422

35-
(ert-deftest from-19590719T123030Z ()
36-
(should
37-
(equal '(10 17 14 27 3 1991) (from 30 30 12 19 7 1959))))
3823

39-
; customize this test to test your birthday and find your gigasecond date:
40-
; (ert-deftest your-birthday ()
41-
; (should
42-
; (equal '(0 0 0 day2 month2 year2) (from 0 0 0 day1 month1 year1))))
24+
(ert-deftest full-time-specified ()
25+
(should (equal '(40 46 23 2 10 2046) (add 0 0 22 24 1 2015))))
4326

4427

28+
(ert-deftest full-time-with-day-roll-over ()
29+
(should (equal '(39 46 1 3 10 2046) (add 59 59 23 24 1 2015))))
30+
4531

4632
(provide 'gigasecond-test)
4733
;;; gigasecond-test.el ends here
34+
+7-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
;;; gigasecond.el --- Gigasecond exercise (exercism) -*- lexical-binding: t; -*-
1+
;;; gigasecond.el --- Gigasecond (exercism) -*- lexical-binding: t; -*-
22

33
;;; Commentary:
4-
;; Calculate the date one gigasecond (10^9 seconds) from the
5-
;; given date.
6-
;;
7-
;; NB: Pay attention to Emacs' handling of time zones and dst
8-
;; in the encode-time and decode-time functions.
94

10-
(defun from (second minute hour day month year)
115
;;; Code:
12-
)
6+
7+
8+
(defun add (second minute hour day month year)
9+
(error "Delete this S-Expression and write your own implementation"))
10+
1311

1412
(provide 'gigasecond)
1513
;;; gigasecond.el ends here
14+

0 commit comments

Comments
 (0)