unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 2f874aa5958106b40165c18b6b4ecf9f856c41b3 12027 bytes (raw)
name: test/lisp/color-tests.el 	 # note: path name is non-authoritative(*)

  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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
 
;;; color-tests.el --- Tests for color.el  -*- lexical-binding: t; -*-

;; Copyright (C) 2017-2024 Free Software Foundation, Inc.

;; Author: Simen Heggestøyl <simenheg@gmail.com>
;; Keywords:

;; This file is part of GNU Emacs.

;; 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 <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'cl-lib)
(require 'color)
(require 'ert)
(require 'seq)

(defun color-tests--approx-equal (color1 color2)
  "Return t if COLOR1 and COLOR2 are approximately equal."
  (seq-every-p
   (lambda (x) (< (abs x) 0.00001))
   (cl-mapcar #'- color1 color2)))

(ert-deftest color-tests-name-to-rgb ()
  (should (equal (color-name-to-rgb "black") '(0.0 0.0 0.0)))
  (should (equal (color-name-to-rgb "white") '(1.0 1.0 1.0)))
  (should (equal (color-name-to-rgb "red") '(1.0 0.0 0.0)))
  (should (equal (color-name-to-rgb "green") '(0.0 1.0 0.0)))
  (should (equal (color-name-to-rgb "blue") '(0.0 0.0 1.0)))
  (should (equal (color-name-to-rgb "#000000000000") '(0.0 0.0 0.0)))
  (should (equal (color-name-to-rgb "#ffffffffffff") '(1.0 1.0 1.0)))
  (should (equal (color-name-to-rgb "#ffff00000000") '(1.0 0.0 0.0)))
  (should (equal (color-name-to-rgb "#0000ffff0000") '(0.0 1.0 0.0)))
  (should (equal (color-name-to-rgb "#00000000ffff") '(0.0 0.0 1.0))))

(ert-deftest color-tests-rgb-to-hex ()
  (should (equal (color-rgb-to-hex 0 0 0) "#000000000000"))
  (should (equal (color-rgb-to-hex 0 0 0 2) "#000000"))
  (should (equal (color-rgb-to-hex 1 0 0) "#ffff00000000"))
  (should (equal (color-rgb-to-hex 1 0 0 2) "#ff0000"))
  (should (equal (color-rgb-to-hex 0.1 0.2 0.3) "#199933334ccc"))
  (should (equal (color-rgb-to-hex 0.1 0.2 0.3 2) "#19334c")))

(ert-deftest color-tests-complement ()
  (should (equal (color-complement "white") '(0.0 0.0 0.0)))
  (should (equal (color-complement "#ffffffffffff") '(0.0 0.0 0.0)))
  (should (equal (color-complement "red") '(0.0 1.0 1.0))))

(ert-deftest color-tests-blend ()
  (should (equal (color-blend '(1.0 0.0 0.0) '(0.0 1.0 0.0)) '(0.5 0.5 0.0)))
  (should (equal (color-blend '(1.0 1.0 1.0) '(0.0 1.0 0.0)) '(0.5 1.0 0.5)))
  (should (equal (color-blend '(0.0 0.39215686274509803 0.0) '(0.9607843137254902 0.8705882352941177 0.7019607843137254))
                 '(0.4803921568627451 0.6313725490196078 0.3509803921568627))))

(ert-deftest color-tests-gradient ()
  (should-not (color-gradient '(0 0 0) '(255 255 255) 0))
  (should
   (equal (color-gradient '(0 0 0) '(255 255 255) 1)
          '((127.5 127.5 127.5))))
  (should
   (equal (color-gradient '(0 0 0) '(255 255 255) 2)
          '((85.0 85.0 85.0) (170.0 170.0 170.0))))
  (should
   (equal
    (color-gradient '(255 192 203) '(250 128 114) 3)
    '((253.75 176.0 180.75) (252.5 160.0 158.5) (251.25 144.0 136.25)))))

(ert-deftest color-tests-hsl-to-rgb ()
  (should (equal (color-hsl-to-rgb 0 0 0) '(0 0 0)))
  (should (equal (color-hsl-to-rgb 360 0.5 0.5) '(0.75 0.25 0.25)))
  (should (equal (color-hsl-to-rgb 123 0.2 0.9) '(0.92 0.88 0.88))))

(ert-deftest color-tests-complement-hex ()
  (should
   (equal (color-complement-hex "#000000000000") "#ffffffffffff"))
  (should
   (equal (color-complement-hex "#ffff00000000") "#0000ffffffff")))

(ert-deftest color-tests-rgb-to-hsv ()
  (should (equal (color-rgb-to-hsv 0 0 0) '(0.0 0.0 0.0)))
  (should (equal (color-rgb-to-hsv 1 1 1) '(0.0 0.0 1.0)))
  (should (equal (color-rgb-to-hsv 1 0 0) '(0.0 1.0 1.0)))
  (should (equal (color-rgb-to-hsv 0.5 0.3 0.3) '(0.0 0.4 0.5))))

(ert-deftest color-tests-rgb-to-hsl ()
  (should (equal (color-rgb-to-hsl 0 0 0) '(0.0 0.0 0.0)))
  (should (equal (color-rgb-to-hsl 1 1 1) '(0.0 0.0 1.0)))
  (should (equal (color-rgb-to-hsl 1 0 0) '(0.0 1 0.5)))
  (should (equal (color-rgb-to-hsl 0.5 0.3 0.3) '(0.0 0.25 0.4))))

(ert-deftest color-tests-srgb-to-xyz ()
  (should (equal (color-srgb-to-xyz 0 0 0) '(0.0 0.0 0.0)))
  (should
   (equal (color-srgb-to-xyz 0 0 1) '(0.1804375 0.072175 0.9503041)))
  (should
   (color-tests--approx-equal
    (color-srgb-to-xyz 0.1 0.2 0.3) '(0.0291865 0.031092 0.073738))))

(ert-deftest color-tests-xyz-to-srgb ()
  (should (equal (color-xyz-to-srgb 0 0 0) '(0.0 0.0 0.0)))
  (should
   (color-tests--approx-equal
    (color-xyz-to-srgb 0.1804375 0.072175 0.9503041) '(0 0 1)))
  (should
   (color-tests--approx-equal
    (color-xyz-to-srgb 0.0291865 0.031092 0.073738) '(0.1 0.2 0.3))))

(ert-deftest color-tests-xyz-to-lab ()
  (should (equal (color-xyz-to-lab 0 0 0) '(0.0 0.0 0.0)))
  (should
   (color-tests--approx-equal
    (color-xyz-to-lab 0.1804375 0.072175 0.9503041)
    '(32.2970109 79.1890315 -107.8646674)))
  (should
   (color-tests--approx-equal
    (color-xyz-to-lab 0.1804375 0.072175 0.9503041 '(1 1 1))
    '(32.2970109 74.3625763 -113.3597823)))
  (should
   (color-tests--approx-equal
    (color-xyz-to-lab 0.0291865 0.031092 0.073738)
    '(20.4760281 -0.6500752 -18.6340169))))

(ert-deftest color-tests-lab-to-xyz ()
  (should (equal (color-lab-to-xyz 0 0 0) '(0.0 0.0 0.0)))
  (should
   (color-tests--approx-equal
    (color-lab-to-xyz 32.2970109 79.1890315 -107.8646674)
    '(0.1804375 0.072175 0.9503041)))
  (should
   (color-tests--approx-equal
    (color-lab-to-xyz 32.2970109 74.3625763 -113.3597823 '(1 1 1))
    '(0.1804375 0.072175 0.9503041)))
  (should
   (color-tests--approx-equal
    (color-lab-to-xyz 20.4760281 -0.6500752 -18.6340169)
    '(0.0291865 0.031092 0.073738))))

(ert-deftest color-tests-srgb-to-lab ()
  (should (equal (color-srgb-to-lab 0 0 0) '(0.0 0.0 0.0)))
  (should
   (color-tests--approx-equal
    (color-srgb-to-lab 0 1 0) '(87.7347223 -86.1808176 83.1770651)))
  (should
   (color-tests--approx-equal
    (color-srgb-to-lab 0.1 0.2 0.3)
    '(20.4762218 -0.6508996 -18.6340085))))

(ert-deftest color-tests-lab-to-srgb ()
  (should (equal (color-lab-to-srgb 0 0 0) '(0.0 0.0 0.0)))
  (should
   (color-tests--approx-equal
    (color-lab-to-srgb 87.7347223 -86.1808176 83.1770651) '(0 1 0)))
  (should
   (color-tests--approx-equal
    (color-lab-to-srgb 20.4762218 -0.6508996 -18.6340085)
    '(0.1 0.2 0.3))))

(ert-deftest color-tests-cie-de2000 ()
  (should (= (color-cie-de2000 '(0 0 0) '(0 0 0)) 0.0))
  (should
   (color-tests--approx-equal
    (list
     (color-cie-de2000
      (color-srgb-to-lab 1 0 0) (color-srgb-to-lab 0 0 1)))
    '(52.8803934)))
  (should
   (color-tests--approx-equal
    (list
     (color-cie-de2000
      (color-srgb-to-lab 0.8 0 0) (color-srgb-to-lab 0.9 0 0)))
    '(5.3844503))))

(ert-deftest color-tests-clamp ()
  (should (= (color-clamp 0) 0.0))
  (should (= (color-clamp -1) 0.0))
  (should (= (color-clamp 0.5) 0.5))
  (should (= (color-clamp 1) 1.0))
  (should (= (color-clamp 1.1) 1.0)))

(ert-deftest color-tests-saturate-hsl ()
  (should (equal (color-saturate-hsl 360 0.5 0.5 0) '(360 0.5 0.5)))
  (should (equal (color-saturate-hsl 360 0.5 0.5 -10) '(360 0.4 0.5)))
  (should
   (equal (color-saturate-hsl 360 0.5 0.5 -500) '(360 0.0 0.5)))
  (should (equal (color-saturate-hsl 120 0.5 0.8 5) '(120 0.55 0.8)))
  (should
   (equal (color-saturate-hsl 120 0.5 0.8 500) '(120 1.0 0.8))))

(ert-deftest color-tests-saturate-name ()
  (should (equal (color-saturate-name "black" 100) "#000000000000"))
  (should (equal (color-saturate-name "white" 100) "#ffffffffffff"))
  (should (equal (color-saturate-name "red" 0) "#ffff00000000"))
  (should (equal (color-saturate-name "red" 50) "#ffff00000000")))

(ert-deftest color-tests-desaturate-hsl ()
  (should (equal (color-desaturate-hsl 360 0.5 0.5 0) '(360 0.5 0.5)))
  (should
   (equal (color-desaturate-hsl 360 0.5 0.5 -10) '(360 0.6 0.5)))
  (should
   (equal (color-desaturate-hsl 360 0.5 0.5 -500) '(360 1.0 0.5)))
  (should
   (equal (color-desaturate-hsl 120 0.5 0.8 5) '(120 0.45 0.8)))
  (should
   (equal (color-desaturate-hsl 120 0.5 0.8 500) '(120 0.0 0.8))))

(ert-deftest color-tests-desaturate-name ()
  (should (equal (color-desaturate-name "black" 100) "#000000000000"))
  (should (equal (color-desaturate-name "white" 100) "#ffffffffffff"))
  (should (equal (color-desaturate-name "red" 0) "#ffff00000000")))

(ert-deftest color-tests-lighten-hsl ()
  (should (equal (color-lighten-hsl 360 0.5 0.5 0) '(360 0.5 0.5)))
  (should (equal (color-lighten-hsl 360 0.5 0.5 -10) '(360 0.5 0.45)))
  (should (equal (color-lighten-hsl 360 0.5 0.5 -500) '(360 0.5 0.0)))
  (should
   (color-tests--approx-equal
    (color-lighten-hsl 120 0.5 0.8 5) '(120 0.5 0.84)))
  (should
   (equal (color-lighten-hsl 120 0.5 0.8 500) '(120 0.5 1.0))))

(ert-deftest color-tests-lighten-name ()
  (should (equal (color-lighten-name "black" 100) "#000000000000"))
  (should (equal (color-lighten-name "white" 100) "#ffffffffffff"))
  (should (equal (color-lighten-name "red" 0) "#ffff00000000"))
  (should (equal (color-lighten-name "red" 10) "#ffff19991999")))

(ert-deftest color-tests-darken-hsl ()
  (should (equal (color-darken-hsl 360 0.5 0.5 0) '(360 0.5 0.5)))
  (should (equal (color-darken-hsl 360 0.5 0.5 -10) '(360 0.5 0.55)))
  (should (equal (color-darken-hsl 360 0.5 0.5 -500) '(360 0.5 1.0)))
  (should (equal (color-darken-hsl 120 0.5 0.8 5) '(120 0.5 0.76)))
  (should (equal (color-darken-hsl 120 0.5 0.8 500) '(120 0.5 0.0))))

(ert-deftest color-tests-darken-name ()
  (should (equal (color-darken-name "black" 100) "#000000000000"))
  (should (equal (color-darken-name "white" 100) "#000000000000"))
  (should (equal (color-darken-name "red" 0) "#ffff00000000"))
  (should (equal (color-darken-name "red" 10) "#e66500000000")))

(ert-deftest color-tests-oklab-to-xyz ()
  (should (color-tests--approx-equal (color-oklab-to-xyz 0 0 0) '(0.0 0.0 0.0)))
  (should (color-tests--approx-equal (color-oklab-to-xyz 1.0 0.0 0.0)
                                     '(0.95047005 1.0 1.0883001)))
  (should (color-tests--approx-equal (color-oklab-to-xyz 0.450 1.236 -0.019) '(1.000604 -0.000008 -0.000038)))
  (should (color-tests--approx-equal (color-oklab-to-xyz 0.922 -0.671 0.263) '(0.000305 1.000504 0.000898)))
  (should (color-tests--approx-equal (color-oklab-to-xyz 0.153 -1.415 -0.449) '(0.000590 0.000057 1.001650))))

(ert-deftest color-tests-xyz-to-oklab ()
  (should (color-tests--approx-equal (color-xyz-to-oklab 0 0 0) '(0.0 0.0 0.0)))
  (should (color-tests--approx-equal (color-xyz-to-oklab 0.95 1.0 1.089)
                                     '(0.999969 -0.000258 -0.000115)))
  (should (color-tests--approx-equal (color-xyz-to-oklab 1.0 0.0 0.0)
                                     '(0.449932 1.235710 -0.019028)))
  (should (color-tests--approx-equal (color-xyz-to-oklab 0.0 1.0 0.0)
                                     '(0.921817 -0.671238 0.263324)))
  (should (color-tests--approx-equal (color-xyz-to-oklab 0.0 0.0 1.0)
                                     '(0.152603 -1.414997 -0.448927))))

(ert-deftest color-tests-srgb-to-oklab ()
  (should (equal (color-srgb-to-oklab 0 0 0) '(0.0 0.0 0.0)))
  (should
   (color-tests--approx-equal (color-srgb-to-oklab 0 0 1) '(0.451978 -0.032430 -0.311611)))
  (should
   (color-tests--approx-equal (color-srgb-to-oklab 0.1 0.2 0.3) '(0.313828 -0.019091 -0.052561))))

(ert-deftest color-tests-oklab-to-srgb ()
  (should (equal (color-oklab-to-srgb 0 0 0) '(0.0 0.0 0.0)))
  (should
   (color-tests--approx-equal (color-oklab-to-srgb 0.451978 -0.032430 -0.311611) '(0.0 0.0 1.0)))
  (should
   (color-tests--approx-equal (color-oklab-to-srgb 0.313828 -0.019091 -0.052561) '(0.1 0.2 0.3))))

(provide 'color-tests)
;;; color-tests.el ends here

debug log:

solving 2f874aa5958 ...
found 2f874aa5958 in https://yhetil.org/emacs-devel/87a5ehldm9.fsf@breatheoutbreathe.in/ ||
	https://yhetil.org/emacs-devel/87wmhmgq4a.fsf@breatheoutbreathe.in/
found 0f53e4332a4 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 0f53e4332a4ea145e8c1351114ccb5b85da50826	test/lisp/color-tests.el

applying [1/1] https://yhetil.org/emacs-devel/87a5ehldm9.fsf@breatheoutbreathe.in/
diff --git a/test/lisp/color-tests.el b/test/lisp/color-tests.el
index 0f53e4332a4..2f874aa5958 100644

Checking patch test/lisp/color-tests.el...
Applied patch test/lisp/color-tests.el cleanly.

skipping https://yhetil.org/emacs-devel/87wmhmgq4a.fsf@breatheoutbreathe.in/ for 2f874aa5958
index at:
100644 2f874aa5958106b40165c18b6b4ecf9f856c41b3	test/lisp/color-tests.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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