unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24384: [PATCH] Add tests for ring.el
@ 2016-09-06 18:58 Simen Heggestøyl
  2016-09-08 17:21 ` Simen Heggestøyl
  0 siblings, 1 reply; 2+ messages in thread
From: Simen Heggestøyl @ 2016-09-06 18:58 UTC (permalink / raw)
  To: 24384

[-- Attachment #1: Type: text/plain, Size: 233 bytes --]

Hello,

I saw that ring.el didn't have any tests, so I wrote some.

Unless anyone has any objections, I'll install them within a few days.

After the tests are in place I also plan to turn on lexical binding for
ring.el.

-- Simen



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-tests-for-ring.el.patch --]
[-- Type: text/x-patch, Size: 7663 bytes --]

From 9213fba393ffa5f163398c46b923cea2fed9add5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Sat, 3 Sep 2016 20:35:23 +0200
Subject: [PATCH] Add tests for ring.el

* test/lisp/emacs-lisp/ring-tests.el: New file with tests for ring.el.
---
 test/lisp/emacs-lisp/ring-tests.el | 204 +++++++++++++++++++++++++++++++++++++
 1 file changed, 204 insertions(+)
 create mode 100644 test/lisp/emacs-lisp/ring-tests.el

diff --git a/test/lisp/emacs-lisp/ring-tests.el b/test/lisp/emacs-lisp/ring-tests.el
new file mode 100644
index 0000000..705bfe5
--- /dev/null
+++ b/test/lisp/emacs-lisp/ring-tests.el
@@ -0,0 +1,204 @@
+;;; ring-tests.el --- Tests for ring.el  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Simen Heggestøyl <simenheg@gmail.com>
+;; Keywords:
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'ring)
+
+(ert-deftest ring-tests-make-ring-ring-p ()
+  (should (ring-p (make-ring 5))))
+
+(ert-deftest ring-tests-insert-at-beginning ()
+  (let ((ring (make-ring 5)))
+    (ring-insert-at-beginning ring 'foo)
+    (ring-insert-at-beginning ring 'bar)
+    (should (equal (ring-elements ring) '(foo bar)))))
+
+(ert-deftest ring-tests-plus1 ()
+  (should (= (ring-plus1 0 5) 1))
+  (should (= (ring-plus1 4 5) 0)))
+
+(ert-deftest ring-tests-minus1 ()
+  (should (= (ring-minus1 0 5) 4))
+  (should (= (ring-minus1 4 5) 3)))
+
+(ert-deftest ring-tests-length ()
+  (let ((ring (make-ring 2)))
+    (should (= (ring-length ring) 0))
+    (ring-insert ring 'a)
+    (should (= (ring-length ring) 1))
+    (ring-insert ring 'b)
+    (should (= (ring-length ring) 2))
+    (ring-insert ring 'c)
+    (should (= (ring-length ring) 2))))
+
+(ert-deftest ring-tests-index ()
+  (should (= (ring-index 0 0 3 3) 2))
+  (should (= (ring-index 0 0 3 5) 2))
+  (should (= (ring-index 0 2 3 3) 1))
+  (should (= (ring-index 1 2 3 3) 0))
+  (should (= (ring-index 2 2 3 3) 2)))
+
+(ert-deftest ring-tests-empty-p ()
+  (let ((ring (make-ring 5)))
+    (should (ring-empty-p ring))
+    (ring-insert ring 1)
+    (should-not (ring-empty-p ring))
+    (ring-remove ring)
+    (should (ring-empty-p ring))))
+
+(ert-deftest ring-tests-size ()
+  (let ((ring (make-ring 2)))
+    (should (= (ring-size ring) 2))
+    (ring-insert ring "a")
+    (ring-insert ring "b")
+    (ring-insert ring "c")
+    (should (= (ring-size ring) 2))
+    (ring-extend ring 3)
+    (should (= (ring-size ring) 5))))
+
+(ert-deftest ring-tests-copy ()
+  (let ((ring1 (make-ring 3)))
+    (ring-insert ring1 1)
+    (ring-insert ring1 2)
+    (let ((ring2 (ring-copy ring1)))
+      (should-not (eq ring1 ring2))
+      (should (= (ring-size ring1) (ring-size ring2)))
+      (should (equal (ring-elements ring1) (ring-elements ring2))))))
+
+(ert-deftest ring-tests-insert ()
+  (let ((ring (make-ring 2)))
+    (ring-insert ring :a)
+    (should (equal (ring-elements ring) '(:a)))
+    (ring-insert ring :b)
+    (should (equal (ring-elements ring) '(:b :a)))
+    (ring-insert ring :c)
+    (should (equal (ring-elements ring) '(:c :b)))))
+
+(ert-deftest ring-tests-remove ()
+  (let ((ring (make-ring 2)))
+    (should-error (ring-remove ring))
+    (ring-insert ring 'foo)
+    (ring-insert ring 'bar)
+    (should (eq (ring-remove ring) 'foo))
+    (should (equal (ring-elements ring) '(bar)))
+    (ring-insert ring 'baz)
+    (should (eq (ring-remove ring 0) 'baz))
+    (should (equal (ring-elements ring) '(bar)))))
+
+(ert-deftest ring-tests-ref ()
+  (let ((ring (make-ring 2)))
+    (should-error (ring-ref ring 0))
+    (ring-insert ring :a)
+    (should (eq (ring-ref ring 0) :a))
+    (ring-insert ring :b)
+    (should (eq (ring-ref ring 0) :b))
+    (should (eq (ring-ref ring 1) :a))
+    (should (eq (ring-ref ring 2) :b))))
+
+(ert-deftest ring-tests-elements ()
+  (let ((ring (make-ring 5)))
+    (ring-insert ring 3)
+    (ring-insert ring 2)
+    (ring-insert ring 1)
+    (should (equal (ring-elements ring) '(1 2 3)))))
+
+(ert-deftest ring-tests-member ()
+  (let ((ring (make-ring 3)))
+    (ring-insert ring "foo")
+    (ring-insert ring "bar")
+    (should (= (ring-member ring "foo") 1))
+    (should (= (ring-member ring "bar") 0))
+    (should-not (ring-member ring "baz"))))
+
+(ert-deftest ring-tests-next ()
+  (let ((ring (make-ring 3)))
+    (ring-insert ring 'a)
+    (ring-insert ring 'b)
+    (should (eq (ring-next ring 'b) 'a))
+    (should (eq (ring-next ring 'a) 'b))
+    (should-error (ring-next ring 'c))))
+
+(ert-deftest ring-tests-previous ()
+  (let ((ring (make-ring 3)))
+    (ring-insert ring 'a)
+    (ring-insert ring 'b)
+    (should (eq (ring-previous ring 'b) 'a))
+    (should (eq (ring-previous ring 'a) 'b))
+    (should-error (ring-previous ring 'c))))
+
+(ert-deftest ring-tests-extend ()
+  (let ((ring (make-ring 2)))
+    (ring-insert ring 1)
+    (ring-insert ring 2)
+    (should (= (ring-size ring) 2))
+    (should (= (ring-length ring) 2))
+    (ring-extend ring 3)
+    (ring-insert ring 3)
+    (should (= (ring-size ring) 5))
+    (should (equal (ring-elements ring) '(3 2 1)))))
+
+(ert-deftest ring-tests-insert ()
+  (let ((ring (make-ring 2)))
+    (ring-insert+extend ring :a)
+    (ring-insert+extend ring :b)
+    (should (equal (ring-elements ring) '(:b :a)))
+    (ring-insert+extend ring :c)
+    (should (equal (ring-elements ring) '(:c :b)))
+    (ring-insert+extend ring :d t)
+    (should (equal (ring-elements ring) '(:d :c :b)))))
+
+(ert-deftest ring-tests-remove+insert+extend ()
+  (let ((ring (make-ring 3)))
+    (ring-insert ring 1)
+    (ring-insert ring 1)
+    (ring-insert ring 2)
+    (ring-remove+insert+extend ring 1)
+    (should (equal (ring-elements ring) '(1 2)))
+    (ring-remove+insert+extend ring 0)
+    (should (equal (ring-elements ring) '(0 1 2)))
+    (ring-remove+insert+extend ring 3)
+    (should (equal (ring-elements ring) '(3 0 1)))
+    (ring-remove+insert+extend ring 4 t)
+    (should (equal (ring-elements ring) '(4 3 0 1)))
+    (ring-remove+insert+extend ring 1 t)
+    (should (equal (ring-elements ring) '(1 4 3 0)))))
+
+(ert-deftest ring-tests-convert-sequence-to-ring ()
+  (let ((ring (ring-convert-sequence-to-ring '(a b c))))
+    (should (equal (ring-elements ring) '(a b c))))
+  (let ((ring (ring-convert-sequence-to-ring [1 2 3])))
+    (should (equal (ring-elements ring) '(1 2 3))))
+  (let ((ring (ring-convert-sequence-to-ring "abc")))
+    (should (equal (ring-elements ring) '(?a ?b ?c))))
+  (let ((ring (make-ring 2)))
+    (ring-insert ring :a)
+    (ring-insert ring :b)
+    (should
+     (equal (ring-elements (ring-convert-sequence-to-ring ring))
+            (ring-elements ring)))))
+
+(provide 'ring-tests)
+;;; ring-tests.el ends here
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#24384: [PATCH] Add tests for ring.el
  2016-09-06 18:58 bug#24384: [PATCH] Add tests for ring.el Simen Heggestøyl
@ 2016-09-08 17:21 ` Simen Heggestøyl
  0 siblings, 0 replies; 2+ messages in thread
From: Simen Heggestøyl @ 2016-09-08 17:21 UTC (permalink / raw)
  To: 24384-done

Installed in master.

-- Simen






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-08 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-06 18:58 bug#24384: [PATCH] Add tests for ring.el Simen Heggestøyl
2016-09-08 17:21 ` Simen Heggestøyl

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).