|
| 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