aboutsummaryrefslogtreecommitdiff
path: root/tests/test-music-config--bar-fill.el
blob: f6d8dac804bd50f72fc800f07801a116d5eed4c2 (plain)
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
;;; test-music-config--bar-fill.el --- Tests for progress-bar fill math -*- coding: utf-8; lexical-binding: t; -*-
;;
;; Author: Craig Jennings <c@cjennings.net>
;;
;;; Commentary:
;; Unit tests for `cj/music--bar-fill': the pure computation of how many cells
;; of a WIDTH-cell progress bar are filled given ELAPSED and TOTAL seconds.
;; A stream (no duration) is indeterminate; the live elapsed source (mpv) is
;; wired in a later phase, so this helper only does the clamp-and-round math.
;;
;;; Code:

(require 'ert)

(defvar-keymap cj/custom-keymap :doc "Stub keymap for testing")

(let ((emms-dir (car (file-expand-wildcards
                      (expand-file-name "elpa/emms-*" user-emacs-directory)))))
  (when emms-dir (add-to-list 'load-path emms-dir)))

(require 'emms)
(require 'music-config)

;;; Normal

(ert-deftest test-music-config--bar-fill-normal-half ()
  "Normal: halfway through fills half the cells."
  (should (= (cj/music--bar-fill 30 60 20) 10)))

(ert-deftest test-music-config--bar-fill-normal-quarter ()
  "Normal: a quarter elapsed rounds to a quarter of the cells."
  (should (= (cj/music--bar-fill 15 60 20) 5)))

;;; Boundary

(ert-deftest test-music-config--bar-fill-boundary-zero-elapsed ()
  "Boundary: nothing elapsed fills no cells."
  (should (= (cj/music--bar-fill 0 60 20) 0)))

(ert-deftest test-music-config--bar-fill-boundary-full ()
  "Boundary: elapsed equal to total fills every cell."
  (should (= (cj/music--bar-fill 60 60 20) 20)))

(ert-deftest test-music-config--bar-fill-boundary-over-clamps ()
  "Boundary: elapsed past total clamps to full, never overflows."
  (should (= (cj/music--bar-fill 90 60 20) 20)))

(ert-deftest test-music-config--bar-fill-boundary-nil-elapsed ()
  "Boundary: an unknown elapsed (nil) fills no cells."
  (should (= (cj/music--bar-fill nil 60 20) 0)))

;;; Error / indeterminate

(ert-deftest test-music-config--bar-fill-indeterminate-nil-total ()
  "Error: a stream (nil total) is indeterminate, not a cell count."
  (should (eq (cj/music--bar-fill 30 nil 20) 'indeterminate)))

(ert-deftest test-music-config--bar-fill-indeterminate-zero-total ()
  "Error: a zero total is indeterminate rather than a divide-by-zero."
  (should (eq (cj/music--bar-fill 30 0 20) 'indeterminate)))

(provide 'test-music-config--bar-fill)
;;; test-music-config--bar-fill.el ends here