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