Skip to content

Commit

Permalink
Sync gigasecond tests and stub (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras authored May 7, 2024
1 parent 4e3c4a5 commit d4032e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
7 changes: 2 additions & 5 deletions exercises/practice/gigasecond/.meta/example.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; gigasecond.el --- Gigasecond exercise (exercism) -*- lexical-binding: t; -*-
;;; gigasecond.el --- Gigasecond (exercism) -*- lexical-binding: t; -*-

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

;;; Code:

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





(provide 'gigasecond)
;;; gigasecond.el ends here
47 changes: 17 additions & 30 deletions exercises/practice/gigasecond/gigasecond-test.el
Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
;;; gigasecond-test.el --- ERT tests for gigasecond (exercism) -*- lexical-binding: t; -*-
;;; gigasecond-test.el --- Gigasecond (exercism) -*- lexical-binding: t; -*-

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

;;; Code:


(load-file "gigasecond.el")
(declare-function from "gigasecond.el" (second minute hour day month year))
(declare-function add "gigasecond.el" (moment))


(ert-deftest date-only-specification-of-time ()
(should (equal '(40 46 1 1 1 2043) (add 0 0 0 25 4 2011))))

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

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

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

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

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

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


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


(provide 'gigasecond-test)
;;; gigasecond-test.el ends here

15 changes: 7 additions & 8 deletions exercises/practice/gigasecond/gigasecond.el
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
;;; gigasecond.el --- Gigasecond exercise (exercism) -*- lexical-binding: t; -*-
;;; gigasecond.el --- Gigasecond (exercism) -*- lexical-binding: t; -*-

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

(defun from (second minute hour day month year)
;;; Code:
)


(defun add (second minute hour day month year)
(error "Delete this S-Expression and write your own implementation"))


(provide 'gigasecond)
;;; gigasecond.el ends here

0 comments on commit d4032e1

Please sign in to comment.