From 638fe14f8ddf19eb493f317c35ad23f701a7b582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sun, 5 May 2024 21:46:03 -0700 Subject: [PATCH] Sync gigasecond tests and stub --- .../practice/gigasecond/.meta/example.el | 7 +-- .../practice/gigasecond/gigasecond-test.el | 47 +++++++------------ exercises/practice/gigasecond/gigasecond.el | 15 +++--- 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/exercises/practice/gigasecond/.meta/example.el b/exercises/practice/gigasecond/.meta/example.el index 57072a5c..7e905732 100644 --- a/exercises/practice/gigasecond/.meta/example.el +++ b/exercises/practice/gigasecond/.meta/example.el @@ -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 @@ -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))) @@ -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 diff --git a/exercises/practice/gigasecond/gigasecond-test.el b/exercises/practice/gigasecond/gigasecond-test.el index 6ca401a5..5d8e398b 100644 --- a/exercises/practice/gigasecond/gigasecond-test.el +++ b/exercises/practice/gigasecond/gigasecond-test.el @@ -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 + diff --git a/exercises/practice/gigasecond/gigasecond.el b/exercises/practice/gigasecond/gigasecond.el index ba92a10f..62978cdc 100644 --- a/exercises/practice/gigasecond/gigasecond.el +++ b/exercises/practice/gigasecond/gigasecond.el @@ -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 +