Skip to content

Commit 9a436ba

Browse files
committed
Move ERT tests to separate file
1 parent a0082f2 commit 9a436ba

File tree

3 files changed

+82
-37
lines changed

3 files changed

+82
-37
lines changed

good-scroll-bezier.el

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535

3636

3737

38-
(require 'ert)
39-
4038
;;;; General Bézier curve calculations
4139

4240
(defvar good-scroll-bezier--epsilon 0.0001
@@ -100,24 +98,6 @@ The value of X must be in the interval [0,1]."
10098
;; Try lower half
10199
(good-scroll-bezier--t-given-x x x1 x2 t-min t-mid)))))
102100

103-
(ert-deftest good-scroll-bezier--test-t-given-x ()
104-
(with-temp-buffer
105-
(cl-flet ((test-case
106-
(x x1 x2)
107-
(let* ((tt (good-scroll-bezier--t-given-x x x1 x2))
108-
(x- (good-scroll-bezier--calc tt x1 x2)))
109-
(should (good-scroll-bezier--approx-eq-p x x-)))))
110-
(test-case 0.0 0.0 0.0)
111-
(test-case 0.5 0.0 0.0)
112-
(test-case 0.0 0.1 3.1)
113-
(test-case 1.0 2.0 3.0)
114-
(test-case 0.0 -0.1 3.1)
115-
(test-case 0.0 0.1 -3.1)
116-
(test-case 1.0 -2.0 -3.0)
117-
(test-case 1.0 2.0 -3.0)
118-
(test-case 0.5 2.0 3.0)
119-
(test-case 1.0 -2.0 3.0))))
120-
121101

122102

123103
;;;; Integration with `good-scroll'

good-scroll-linear.el

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
;;; Code:
3434

35-
(require 'ert)
36-
3735
(defun good-scroll-linear (fraction-done)
3836
"Linear scrolling algorithm.
3937
Return the next position in pixel lines when the scroll is FRACTION-DONE done.
@@ -43,21 +41,6 @@ This works by linearly interpolating position."
4341
good-scroll-destination))
4442
good-scroll-traveled)))
4543

46-
(ert-deftest good-scroll-linear ()
47-
(with-temp-buffer
48-
(cl-flet ((test-case
49-
(traveled destination zero half one)
50-
(set (make-local-variable 'good-scroll-traveled) traveled)
51-
(set (make-local-variable 'good-scroll-destination) destination)
52-
(should (= (good-scroll-linear 0.0) zero))
53-
(should (= (good-scroll-linear 0.5) half))
54-
(should (= (good-scroll-linear 1.0) one))))
55-
(test-case 0 10 0 5 10)
56-
(test-case 0 -10 0 -5 -10)
57-
(test-case 10 20 -10 5 20)
58-
(test-case -10 20 10 15 20)
59-
(test-case 10 -20 -10 -15 -20))))
60-
6144
(provide 'good-scroll-linear)
6245

6346
;;; good-scroll-linear.el ends here

good-scroll-test.el

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
;;; good-scroll-test.el --- Unit testing for good-scroll -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2021 Benjamin Levy - MIT/X11 License
4+
;; Author: Benjamin Levy <blevy@protonmail.com>
5+
;; Homepage: https://github.com/io12/good-scroll.el
6+
;; Package-Requires: ((emacs "27.1"))
7+
8+
;; Permission is hereby granted, free of charge, to any person obtaining a copy
9+
;; of this software and associated documentation files (the "Software"), to deal
10+
;; in the Software without restriction, including without limitation the rights
11+
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
;; copies of the Software, and to permit persons to whom the Software is
13+
;; furnished to do so, subject to the following conditions:
14+
;;
15+
;; The above copyright notice and this permission notice shall be included in all
16+
;; copies or substantial portions of the Software.
17+
;;
18+
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
;; SOFTWARE.
25+
26+
;;; Commentary:
27+
28+
;; This library contains ERT unit tests for good-scroll.
29+
;; They can be run with `ert-run-tests-interactively'.
30+
31+
;;; Code:
32+
33+
(require 'good-scroll)
34+
35+
(require 'ert)
36+
37+
38+
39+
;;; good-scroll-linear.el
40+
41+
(ert-deftest good-scroll-test-linear ()
42+
(with-temp-buffer
43+
(cl-flet ((test-case
44+
(traveled destination zero half one)
45+
(set (make-local-variable 'good-scroll-traveled) traveled)
46+
(set (make-local-variable 'good-scroll-destination) destination)
47+
(should (= (good-scroll-linear 0.0) zero))
48+
(should (= (good-scroll-linear 0.5) half))
49+
(should (= (good-scroll-linear 1.0) one))))
50+
(test-case 0 10 0 5 10)
51+
(test-case 0 -10 0 -5 -10)
52+
(test-case 10 20 -10 5 20)
53+
(test-case -10 20 10 15 20)
54+
(test-case 10 -20 -10 -15 -20))))
55+
56+
57+
58+
;;; good-scroll-bezier.el
59+
60+
(ert-deftest good-scroll-test-bezier-t-given-x ()
61+
(with-temp-buffer
62+
(cl-flet ((test-case
63+
(x x1 x2)
64+
(let* ((tt (good-scroll-bezier--t-given-x x x1 x2))
65+
(x- (good-scroll-bezier--calc tt x1 x2)))
66+
(should (good-scroll-bezier--approx-eq-p x x-)))))
67+
(test-case 0.0 0.0 0.0)
68+
(test-case 0.5 0.0 0.0)
69+
(test-case 0.0 0.1 3.1)
70+
(test-case 1.0 2.0 3.0)
71+
(test-case 0.0 -0.1 3.1)
72+
(test-case 0.0 0.1 -3.1)
73+
(test-case 1.0 -2.0 -3.0)
74+
(test-case 1.0 2.0 -3.0)
75+
(test-case 0.5 2.0 3.0)
76+
(test-case 1.0 -2.0 3.0))))
77+
78+
79+
80+
(provide 'good-scroll-test)
81+
82+
;;; good-scroll-test.el ends here

0 commit comments

Comments
 (0)