-
Notifications
You must be signed in to change notification settings - Fork 0
/
TinyColorModificationsTest.cs
650 lines (576 loc) · 34.4 KB
/
TinyColorModificationsTest.cs
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
namespace TinyColorLib
{
public class TinyColorModificationsTest
{
#region Test data for red color
private static readonly string[] DESATURATIONS =
{
"#FF0000", "#FE0101", "#FC0303", "#FB0404", "#FA0505", "#F90606", "#F70808", "#F60909", "#F50A0A", "#F40B0B",
"#F20D0D", "#F10E0E", "#F00F0F", "#EE1111", "#ED1212", "#EC1313", "#EB1414", "#E91616", "#E81717", "#E71818",
"#E61A1A", "#E41B1B", "#E31C1C", "#E21D1D", "#E01F1F", "#DF2020", "#DE2121", "#DD2222", "#DB2424", "#DA2525",
"#D92626", "#D72828", "#D62929", "#D52A2A", "#D42B2B", "#D22D2D", "#D12E2E", "#D02F2F", "#CF3030", "#CD3232",
"#CC3333", "#CB3434", "#C93636", "#C83737", "#C73838", "#C63939", "#C43B3B", "#C33C3C", "#C23D3D", "#C13E3E",
"#BF4040", "#BE4141", "#BD4242", "#BB4444", "#BA4545", "#B94646", "#B84747", "#B64949", "#B54A4A", "#B44B4B",
"#B24C4D", "#B14E4E", "#B04F4F", "#AF5050", "#AD5252", "#AC5353", "#AB5454", "#AA5555", "#A85757", "#A75858",
"#A65959", "#A45B5B", "#A35C5C", "#A25D5D", "#A15E5E", "#9F6060", "#9E6161", "#9D6262", "#9C6363", "#9A6565",
"#996666", "#986767", "#966969", "#956A6A", "#946B6B", "#936C6C", "#916E6E", "#906F6F", "#8F7070", "#8E7171",
"#8C7373", "#8B7474", "#8A7575", "#887777", "#877878", "#867979", "#857A7A", "#837C7C", "#827D7D", "#817E7E",
"#808080"
};
private static readonly string[] SATURATIONS =
{
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000",
"#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000"
};
private static readonly string[] LIGHTENS =
{
"#FF0000", "#FF0505", "#FF0A0A", "#FF0F0F", "#FF1414", "#FF1A1A", "#FF1F1F", "#FF2424",
"#FF2929", "#FF2E2E", "#FF3333", "#FF3838", "#FF3D3D", "#FF4242", "#FF4747", "#FF4C4D",
"#FF5252", "#FF5757", "#FF5C5C", "#FF6161", "#FF6666", "#FF6B6B", "#FF7070", "#FF7575",
"#FF7A7A", "#FF8080", "#FF8585", "#FF8A8A", "#FF8F8F", "#FF9494", "#FF9999", "#FF9E9E",
"#FFA3A3", "#FFA8A8", "#FFADAD", "#FFB3B3", "#FFB8B8", "#FFBDBD", "#FFC2C2", "#FFC7C7",
"#FFCCCC", "#FFD1D1", "#FFD6D6", "#FFDBDB", "#FFE0E0", "#FFE6E6", "#FFEBEB", "#FFF0F0",
"#FFF5F5", "#FFFAFA", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF",
"#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF",
"#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF",
"#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF",
"#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF",
"#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF",
"#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF"
};
private static readonly string[] BRIGHTENS =
{
"#FF0000", "#FF0303", "#FF0505", "#FF0808", "#FF0A0A", "#FF0D0D", "#FF0F0F", "#FF1212",
"#FF1414", "#FF1717", "#FF1A1A", "#FF1C1C", "#FF1F1F", "#FF2121", "#FF2424", "#FF2626",
"#FF2929", "#FF2B2B", "#FF2E2E", "#FF3030", "#FF3333", "#FF3636", "#FF3838", "#FF3B3B",
"#FF3D3D", "#FF4040", "#FF4242", "#FF4545", "#FF4747", "#FF4A4A", "#FF4C4C", "#FF4F4F",
"#FF5252", "#FF5454", "#FF5757", "#FF5959", "#FF5C5C", "#FF5E5E", "#FF6161", "#FF6363",
"#FF6666", "#FF6969", "#FF6B6B", "#FF6E6E", "#FF7070", "#FF7373", "#FF7575", "#FF7878",
"#FF7A7A", "#FF7D7D", "#FF8080", "#FF8282", "#FF8585", "#FF8787", "#FF8A8A", "#FF8C8C",
"#FF8F8F", "#FF9191", "#FF9494", "#FF9696", "#FF9999", "#FF9C9C", "#FF9E9E", "#FFA1A1",
"#FFA3A3", "#FFA6A6", "#FFA8A8", "#FFABAB", "#FFADAD", "#FFB0B0", "#FFB2B2", "#FFB5B5",
"#FFB8B8", "#FFBABA", "#FFBDBD", "#FFBFBF", "#FFC2C2", "#FFC4C4", "#FFC7C7", "#FFC9C9",
"#FFCCCC", "#FFCFCF", "#FFD1D1", "#FFD4D4", "#FFD6D6", "#FFD9D9", "#FFDBDB", "#FFDEDE",
"#FFE0E0", "#FFE3E3", "#FFE6E6", "#FFE8E8", "#FFEBEB", "#FFEDED", "#FFF0F0", "#FFF2F2",
"#FFF5F5", "#FFF7F7", "#FFFAFA", "#FFFCFC", "#FFFFFF"
};
private static readonly string[] DARKENS =
{
"#FF0000", "#FA0000", "#F50000", "#F00000", "#EB0000", "#E60000", "#E00000", "#DB0000",
"#D60000", "#D10000", "#CC0000", "#C70000", "#C20000", "#BD0000", "#B80000", "#B20000",
"#AD0000", "#A80000", "#A30000", "#9E0000", "#990000", "#940000", "#8F0000", "#8A0000",
"#850000", "#800000", "#7A0000", "#750000", "#700000", "#6B0000", "#660000", "#610000",
"#5C0000", "#570000", "#520000", "#4C0000", "#470000", "#420000", "#3D0000", "#380000",
"#330000", "#2E0000", "#290000", "#240000", "#1F0000", "#1A0000", "#140000", "#0F0000",
"#0A0000", "#050000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000",
"#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000",
"#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000",
"#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000",
"#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000",
"#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000",
};
private static readonly string[] TINTS =
{
"#FF0000", "#FF0303", "#FF0505", "#FF0808", "#FF0A0A", "#FF0D0D", "#FF0F0F", "#FF1212",
"#FF1414", "#FF1717", "#FF1A1A", "#FF1C1C", "#FF1F1F", "#FF2121", "#FF2424", "#FF2626",
"#FF2929", "#FF2B2B", "#FF2E2E", "#FF3030", "#FF3333", "#FF3636", "#FF3838", "#FF3B3B",
"#FF3D3D", "#FF4040", "#FF4242", "#FF4545", "#FF4747", "#FF4A4A", "#FF4C4C", "#FF4F4F",
"#FF5252", "#FF5454", "#FF5757", "#FF5959", "#FF5C5C", "#FF5E5E", "#FF6161", "#FF6363",
"#FF6666", "#FF6969", "#FF6B6B", "#FF6E6E", "#FF7070", "#FF7373", "#FF7575", "#FF7878",
"#FF7A7A", "#FF7D7D", "#FF8080", "#FF8282", "#FF8585", "#FF8787", "#FF8A8A", "#FF8C8C",
"#FF8F8F", "#FF9191", "#FF9494", "#FF9696", "#FF9999", "#FF9C9C", "#FF9E9E", "#FFA1A1",
"#FFA3A3", "#FFA6A6", "#FFA8A8", "#FFABAB", "#FFADAD", "#FFB0B0", "#FFB2B2", "#FFB5B5",
"#FFB8B8", "#FFBABA", "#FFBDBD", "#FFBFBF", "#FFC2C2", "#FFC4C4", "#FFC7C7", "#FFC9C9",
"#FFCCCC", "#FFCFCF", "#FFD1D1", "#FFD4D4", "#FFD6D6", "#FFD9D9", "#FFDBDB", "#FFDEDE",
"#FFE0E0", "#FFE3E3", "#FFE6E6", "#FFE8E8", "#FFEBEB", "#FFEDED", "#FFF0F0", "#FFF2F2",
"#FFF5F5", "#FFF7F7", "#FFFAFA", "#FFFCFC", "#FFFFFF"
};
private static readonly string[] SHADES =
{
"#FF0000", "#FC0000", "#FA0000", "#F70000", "#F50000", "#F20000", "#F00000", "#ED0000",
"#EB0000", "#E80000", "#E60000", "#E30000", "#E00000", "#DE0000", "#DB0000", "#D90000",
"#D60000", "#D40000", "#D10000", "#CF0000", "#CC0000", "#C90000", "#C70000", "#C40000",
"#C20000", "#BF0000", "#BD0000", "#BA0000", "#B80000", "#B50000", "#B20000", "#B00000",
"#AD0000", "#AB0000", "#A80000", "#A60000", "#A30000", "#A10000", "#9E0000", "#9C0000",
"#990000", "#960000", "#940000", "#910000", "#8F0000", "#8C0000", "#8A0000", "#870000",
"#850000", "#820000", "#800000", "#7D0000", "#7A0000", "#780000", "#750000", "#730000",
"#700000", "#6E0000", "#6B0000", "#690000", "#660000", "#630000", "#610000", "#5E0000",
"#5C0000", "#590000", "#570000", "#540000", "#520000", "#4F0000", "#4C0000", "#4A0000",
"#470000", "#450000", "#420000", "#400000", "#3D0000", "#3B0000", "#380000", "#360000",
"#330000", "#300000", "#2E0000", "#2B0000", "#290000", "#260000", "#240000", "#210000",
"#1F0000", "#1C0000", "#1A0000", "#170000", "#140000", "#120000", "#0F0000", "#0D0000",
"#0A0000", "#080000", "#050000", "#030000", "#000000"
};
#endregion
[Test]
public void ConstructByName()
{
Assert.AreEqual("red", TinyColor.ParseFromName("red").ToName()); // create by name and then internally convert to name again
Assert.AreEqual("blue", TinyColor.ParseFromName("blue").ToName()); // create by name and then internally convert to name again
Assert.AreEqual("blue", TinyColor.ParseFromName("BlUe").ToName()); // create by name and then internally convert to name again
Assert.AreEqual("green", TinyColor.ParseFromName("green").ToName()); // create by name and then internally convert to name again
Assert.AreEqual("green", TinyColor.ParseFromName("GrEeN").ToName()); // create by name and then internally convert to name again
Assert.IsNull(TinyColor.ParseFromName("qqqqqqq"));
Assert.IsNull(TinyColor.ParseFromName(string.Empty));
}
[Test]
public void ShouldClone()
{
// Instantiate the initial color
TinyColor color1 = TinyColor.ParseFromName("red");
// Clone the color
TinyColor color2 = TinyColor.ParseFromName("red").Clone() as TinyColor;
Assert.IsNotNull(color2);
// Set alpha on the cloned color
color2.A = 0.5f;
// Assert the string representation of the cloned color
Assert.AreEqual("1 0 0 0.5", color2.ToRGBA().ToString());
// Assert the string representation of the original color is unchanged
Assert.AreEqual("red", color1.ToName());
}
[Test]
public void FromRGB()
{
Assert.IsTrue(new TinyColor(new TinyColor.RGB(1, 1, 1)).ToHex8String() == "#FFFFFFFF");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0, 0, 0.5f)).ToRGBA().ToString() == "1 0 0 0.5");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0, 0, 1f)).ToRGB().ToString() == "1 0 0");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0, 0, 10f)).ToRGB().ToString() == "1 0 0");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0, 0, -10f)).ToRGB().ToString() == "1 0 0");
Assert.IsTrue(new TinyColor(new TinyColor.RGB(0.1f, 0.1f, 0.1f)).ToHex8String() == "#1A1A1AFF");
// 0.1 * 255 = 25.5f. If the number ends in .5 so it is halfway between two integers,
// one of which is even and the other odd, the even number is returned ( Mathf.RoundToInt docs)
// 26 to hex 1A
// note:
// This type of rounding is often used to minimize the overall rounding error introduced by rounding multiple numbers.
// It tends to spread the rounding error equally in both directions(up and down).
}
[Test]
public void ShouldParseHex()
{
Assert.IsTrue(TinyColor.ParseFromHex("#000").ToHex6String() == "#000000");
Assert.IsTrue(TinyColor.ParseFromHex("#0000").ToHex6String() == "#000000");
Assert.IsTrue(TinyColor.ParseFromHex("#000").A == 1.0f);
Assert.IsTrue(TinyColor.ParseFromHex("#0000").A == 0.0f);
}
[Test]
public void ParseRGB()
{
Assert.IsTrue(TinyColor.ParseFromRGB("1 0 0").ToHex6String() == "#FF0000");
Assert.IsTrue(new TinyColor(new TinyColor.RGB(1, 0, 0)).ToHex6String() == "#FF0000");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA256(255, 0, 0, 255)).ToHex6String() == "#FF0000");
Assert.IsTrue(new TinyColor(new TinyColor.RGB256(200, 100, 0)).ToRGB256().ToString() == "200 100 0");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA256(200, 100, 0, 8)).ToRGBA256().ToString() == "200 100 0 8");
}
[Test]
public void ShouldParseHSL()
{
// to hex
Assert.IsTrue(new TinyColor(new TinyColor.HSL(251, 1.0f, 0.38f)).ToHex6String() == "#2400C2");
// to rgb
Assert.IsTrue(new TinyColor(new TinyColor.HSL(251, 1.0f, 0.38f)).ToRGB256().ToString() == "36 0 194");
// to hsl
Assert.IsTrue(new TinyColor(new TinyColor.HSL(251, 1.0f, 0.38f)).ToHSL().ToString() == "251 1 0.38");
Assert.IsTrue(new TinyColor(new TinyColor.HSLA(251, 1.0f, 0.38f, 0.38f)).ToHSLA().ToString() ==
"251 1 0.38 0.38");
// problematic hsl
Assert.IsTrue(new TinyColor(new TinyColor.HSL(100, 0.2f, 0.1f)).ToHSL().ToString() == "100 0.2 0.1");
Assert.IsTrue(new TinyColor(new TinyColor.HSLA(100, 0.2f, 0.1f, 0.38f)).ToHSLA().ToString() ==
"100 0.2 0.1 0.38");
// wrap out of bounds hue
Assert.IsTrue(new TinyColor(new TinyColor.HSL(-700, 0.2f, 0.1f)).ToHSL().ToString() == "20 0.2 0.1");
Assert.IsTrue(new TinyColor(new TinyColor.HSL(-490, 1.0f, 0.5f)).ToHSL().ToString() == "230 1 0.5");
}
[Test]
public void ShouldParseRGBString()
{
Assert.IsTrue(TinyColor.ParseFromRGB256("255 0 0").ToHex6String() == "#FF0000");
Assert.IsTrue(TinyColor.ParseFromRGB256("255 0 0 128").ToHex8String() == "#FF000080");
Assert.IsTrue(TinyColor.ParseFromRGB256("255 0 0 0").ToHex8String() == "#FF000000");
Assert.IsTrue(TinyColor.ParseFromRGB256("255 0 0 255").ToHex8String() == "#FF0000FF");
Assert.IsTrue(TinyColor.ParseFromRGB256("255 0 0 0").ToHex8String() == "#FF000000");
}
[Test]
public void ShouldParseHSVString()
{
Assert.IsTrue(TinyColor.ParseFromHSV("251.1 0.887 .918").ToHSV().ToString() == "251.1 0.887 0.918");
Assert.IsTrue(TinyColor.ParseFromHSV("251.1 0.887 0.918").ToHSV().ToString() == "251.1 0.887 0.918");
Assert.IsTrue(
TinyColor.ParseFromHSV("251.1 0.887 0.918 0.5").ToHSVA().ToString() == "251.1 0.887 0.918 0.5");
}
[Test]
public void ShouldParseInvalidInput()
{
Assert.IsNull(TinyColor.ParseFromName("not a color"));
Assert.IsNull(TinyColor.ParseFromHex("not a color"));
Assert.IsNull(TinyColor.ParseFromRGB("not a color"));
Assert.IsNull(TinyColor.ParseFromRGB256("not a color"));
Assert.IsNull(TinyColor.ParseFromHSL("not a color"));
Assert.IsNull(TinyColor.ParseFromHSV("not a color"));
}
[Test]
public void ShouldParseNamedColor()
{
Assert.IsTrue(TinyColor.ParseFromName("aliceblue").ToHex6String() == "#F0F8FF");
Assert.IsTrue(TinyColor.ParseFromName("antiquewhite").ToHex6String() == "#FAEBD7");
Assert.IsTrue(TinyColor.ParseFromName("aqua").ToHex6String() == "#00FFFF");
Assert.IsTrue(TinyColor.ParseFromName("aquamarine").ToHex6String() == "#7FFFD4");
Assert.IsTrue(TinyColor.ParseFromName("azure").ToHex6String() == "#F0FFFF");
Assert.IsTrue(TinyColor.ParseFromName("beige").ToHex6String() == "#F5F5DC");
Assert.IsTrue(TinyColor.ParseFromName("bisque").ToHex6String() == "#FFE4C4");
Assert.IsTrue(TinyColor.ParseFromHex("#F00").ToName() == "red");
Assert.IsTrue(TinyColor.ParseFromHex("#FA0A0A").ToName() == null);
}
[Test]
public void ShouldNormalizeInvalidAlpha()
{
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0.078f, 0.039f, -1)).Normalize().ToRGB256().ToString() ==
"255 20 10"); // Negative value
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0.078f, 0.039f, -0)).Normalize().ToRGB256().ToString() ==
"255 20 10"); // Negative 0
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0.078f, 0.039f, 0)).Normalize().ToRGBA256().ToString() ==
"255 20 10 0");
Assert.IsTrue(
new TinyColor(new TinyColor.RGBA(1, 0.078f, 0.039f, 0.5f)).Normalize().ToRGBA256().ToString() ==
"255 20 10 128");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0.078f, 0.039f, 1)).Normalize().ToRGBA256().ToString() ==
"255 20 10 255");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0.078f, 0.039f, 1)).Normalize().ToRGB256().ToString() ==
"255 20 10");
Assert.IsTrue(new TinyColor(new TinyColor.RGBA(1, 0.078f, 0.039f, 1)).Normalize().ToRGB256().ToString() ==
"255 20 10");
Assert.IsTrue(TinyColor.ParseFromHex("#FFF").ToRGB256().ToString() == "255 255 255");
Assert.IsTrue(TinyColor.ParseFromRGB256("255 0 0 258").ToRGB256().ToString() ==
"255 0 0"); // Greater than 1 in string parsing
}
[Test]
public void ShouldTranslateToStringWithAlphaSet()
{
//const redNamed = fromRatio({ r: 255, g: 0, b: 0, a: 0.6 }, { format: 'name' });
var redNamed = new TinyColor(new TinyColor.RGBA(1f, 0f, 0f, 0.6f));
var redHex = new TinyColor(new TinyColor.RGBA(1f, 0f, 0f, 0.4f));
Assert.IsTrue(redNamed.ToRGBA().ToString() == "1 0 0 0.6");
Assert.IsTrue(redHex.ToRGBA().ToString() == "1 0 0 0.4");
Assert.IsTrue(redNamed.ToHex6String() == "#FF0000");
Assert.IsTrue(redNamed.ToHex8String() == "#FF000099");
Assert.IsNull(redNamed.ToName());
var transparentNamed = new TinyColor(new TinyColor.RGBA(1, 0, 0, 0));
Assert.IsTrue(transparentNamed.ToName() == "transparent");
}
[Test]
public void ShouldGetAlpha()
{
var hexSetter = TinyColor.ParseFromRGB256("255 0 0 255");
Assert.IsTrue(Mathf.Approximately(hexSetter.A, 1f));
}
[Test]
public void ShouldSetAlpha()
{
var hexSetter = TinyColor.ParseFromRGB256("255 0 0 255");
Assert.IsTrue(Mathf.Approximately(hexSetter.A, 1f));
hexSetter.A = -1;
hexSetter = hexSetter.Normalize();
Assert.IsTrue(Mathf.Approximately(hexSetter.A, 0f));
hexSetter.A = 2f;
hexSetter = hexSetter.Normalize();
Assert.IsTrue(Mathf.Approximately(hexSetter.A, 1f));
}
[Test]
public void ShouldGetBrightness()
{
foreach (var kv in Color.Colors)
{
var brightness = kv.Value.GetBrightness();
Assert.IsTrue(brightness <= 1f);
Assert.IsTrue(brightness >= 0f);
}
Assert.IsTrue(TinyColor.ParseFromHex("#000").GetBrightness() == 0f);
Assert.IsTrue(TinyColor.ParseFromHex("#FFF").GetBrightness() == 1f);
}
[Test]
public void ShouldGetLuminance()
{
Assert.IsTrue(TinyColor.ParseFromHex("#000").GetLuminance() == 0f);
Assert.IsTrue(TinyColor.ParseFromHex("#FFF").GetLuminance() == 1f);
}
[Test]
public void IsDark()
{
Assert.IsTrue(TinyColor.ParseFromHex("#000").IsDark());
Assert.IsTrue(TinyColor.ParseFromHex("#111").IsDark());
Assert.IsTrue(TinyColor.ParseFromHex("#222").IsDark());
Assert.IsTrue(TinyColor.ParseFromHex("#333").IsDark());
Assert.IsTrue(TinyColor.ParseFromHex("#444").IsDark());
Assert.IsTrue(TinyColor.ParseFromHex("#555").IsDark());
Assert.IsTrue(TinyColor.ParseFromHex("#666").IsDark());
Assert.IsTrue(TinyColor.ParseFromHex("#777").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#888").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#999").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#AAA").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#BBB").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#CCC").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#DDD").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#EEE").IsDark());
Assert.IsFalse(TinyColor.ParseFromHex("#FFF").IsDark());
}
[Test]
public void IsLight()
{
Assert.IsFalse(TinyColor.ParseFromHex("#000").IsLight());
Assert.IsFalse(TinyColor.ParseFromHex("#111").IsLight());
Assert.IsFalse(TinyColor.ParseFromHex("#222").IsLight());
Assert.IsFalse(TinyColor.ParseFromHex("#333").IsLight());
Assert.IsFalse(TinyColor.ParseFromHex("#444").IsLight());
Assert.IsFalse(TinyColor.ParseFromHex("#555").IsLight());
Assert.IsFalse(TinyColor.ParseFromHex("#666").IsLight());
Assert.IsFalse(TinyColor.ParseFromHex("#777").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#888").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#999").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#AAA").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#BBB").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#CCC").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#DDD").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#EEE").IsLight());
Assert.IsTrue(TinyColor.ParseFromHex("#FFF").IsLight());
}
[Test]
public void ColorEquality()
{
Assert.IsTrue(TinyColor.ParseFromHex("#FF0000").Equals(TinyColor.ParseFromHex("#Ff0000")));
Assert.IsTrue(TinyColor.ParseFromHex("#FF0000").Equals(TinyColor.ParseFromRGB256("255 0 0")));
Assert.IsTrue(TinyColor.ParseFromHex("#FF0000").Equals(TinyColor.ParseFromRGB("1 0 0")));
Assert.IsFalse(TinyColor.ParseFromHex("#FF0000").Equals(TinyColor.ParseFromRGB256("255 0 0 1")));
Assert.IsTrue(TinyColor.ParseFromHex("#FF000066").Equals(TinyColor.ParseFromRGB("1 0 0 .4")));
Assert.IsTrue(TinyColor.ParseFromHex("#f009").Equals(TinyColor.ParseFromRGB("1 0 0 .6")));
Assert.IsTrue(TinyColor.ParseFromHex("#336699CC").Equals(TinyColor.ParseFromHex("#369C")));
Assert.IsTrue(TinyColor.ParseFromHex("#ffffff").Equals(TinyColor.ParseFromHex("#ffffff")));
Assert.IsTrue(TinyColor.ParseFromHex("#f00").Equals(TinyColor.ParseFromHex("#ff0000")));
Assert.IsTrue(TinyColor.ParseFromHex("#fff").Equals(TinyColor.ParseFromHex("#ffffff")));
Assert.IsTrue(TinyColor.ParseFromHex("#00f").Equals(TinyColor.ParseFromHex("#0000ff")));
Assert.IsTrue(TinyColor.ParseFromHex("#010101").Equals(TinyColor.ParseFromHex("#010101ff")));
Assert.IsFalse(TinyColor.ParseFromHex("#ff0000").Equals(TinyColor.ParseFromHex("#00ff00")));
Assert.IsTrue(TinyColor.ParseFromHex("#ff8000").Equals(TinyColor.ParseFromRGB("1 0.5 0")));
}
[Test]
public void ColorIsReadable()
{
// "#ff0088", "#8822aa" (values used in old WCAG1 tests)
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#000000"), TinyColor.ParseFromHex("#ffffff"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#5c1a72")));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#8822aa"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#8822aa"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Large));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#8822aa"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#8822aa"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Small));
// values derived from and validated using the calculators at http://www.dasplankton.de/ContrastA/
// and http://webaim.org/resources/contrastchecker/
// "#ff0088", "#5c1a72": contrast ratio 3.04
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#5c1a72"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#5c1a72"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Large));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#5c1a72"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#5c1a72"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Large));
// "#ff0088", "#2e0c3a": contrast ratio 4.56
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Large));
Assert.IsFalse(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#ff0088"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Large));
// "#db91b8", "#2e0c3a": contrast ratio 7.12
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#db91b8"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#db91b8"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AA, ReadabilityHelpers.WCAGSize.Large));
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#db91b8"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Small));
Assert.IsTrue(ReadabilityHelpers.IsReadable(TinyColor.ParseFromHex("#db91b8"), TinyColor.ParseFromHex("#2e0c3a"), ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Large));
}
[Test]
public void Readabilty()
{
// check return values from readability function. See isReadable above for standards tests.
Assert.IsTrue(Mathf.Approximately(ReadabilityHelpers.Readability(TinyColor.ParseFromHex("#000"), TinyColor.ParseFromHex("#000")), 1f));
Assert.IsTrue(Mathf.Approximately(ReadabilityHelpers.Readability(TinyColor.ParseFromHex("#000"), TinyColor.ParseFromHex("#111")), 1.1121078324840545f));
Assert.IsTrue(Mathf.Approximately(ReadabilityHelpers.Readability(TinyColor.ParseFromHex("#000"), TinyColor.ParseFromHex("#fff")), 21f));
}
[Test]
public void MostReadable()
{
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#000"),
new List<TinyColor> { TinyColor.ParseFromHex("#111"), TinyColor.ParseFromHex("#222") })
.ToHex6String() == "#222222");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#f00"),
new List<TinyColor> { TinyColor.ParseFromHex("#d00"), TinyColor.ParseFromHex("#0d0") })
.ToHex6String() == "#00DD00");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#fff"),
new List<TinyColor> { TinyColor.ParseFromHex("#fff"), TinyColor.ParseFromHex("#fff") })
.ToHex6String() == "#FFFFFF");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#fff"),
new List<TinyColor> { TinyColor.ParseFromHex("#fff"), TinyColor.ParseFromHex("#fff") }, true)
.ToHex6String() == "#000000");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#123"),
new List<TinyColor> { TinyColor.ParseFromHex("#124"), TinyColor.ParseFromHex("#125") }, false)
.ToHex6String() == "#112255");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#123"),
new List<TinyColor> { TinyColor.ParseFromHex("#000"), TinyColor.ParseFromHex("#fff") }, false)
.ToHex6String() == "#FFFFFF");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#123"),
new List<TinyColor> { TinyColor.ParseFromHex("#124"), TinyColor.ParseFromHex("#125") }, true)
.ToHex6String() == "#FFFFFF");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#ff0088"),
new List<TinyColor> { TinyColor.ParseFromHex("#000"), TinyColor.ParseFromHex("#fff") }, false)
.ToHex6String() == "#000000");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#ff0088"),
new List<TinyColor> { TinyColor.ParseFromHex("#2e0c3a") }, true, ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Large)
.ToHex6String() == "#2E0C3A");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#ff0088"),
new List<TinyColor> { TinyColor.ParseFromHex("#2e0c3a") }, true, ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Small)
.ToHex6String() == "#000000");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#371b2c"),
new List<TinyColor> { TinyColor.ParseFromHex("#000"), TinyColor.ParseFromHex("#fff") }, false)
.ToHex6String() == "#FFFFFF");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#371b2c"),
new List<TinyColor> { TinyColor.ParseFromHex("#a9acb6") }, true, ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Large)
.ToHex6String() == "#A9ACB6");
Assert.IsTrue(ReadabilityHelpers.MostReadable(TinyColor.ParseFromHex("#371b2c"),
new List<TinyColor> { TinyColor.ParseFromHex("#a9acb6") }, true, ReadabilityHelpers.WCAGLevel.AAA, ReadabilityHelpers.WCAGSize.Small)
.ToHex6String() == "#FFFFFF");
}
[Test]
public void Modification()
{
for (var i = 0; i <= 100; i++)
Assert.IsTrue(TinyColor.ParseFromName("red").Desaturate(i / 100f).ToHex6String() == DESATURATIONS[i]);
for (var i = 0; i <= 100; i++)
Assert.IsTrue(TinyColor.ParseFromName("red").Saturate(i / 100f).ToHex6String() == SATURATIONS[i]);
for (var i = 0; i <= 100; i++)
Assert.IsTrue(TinyColor.ParseFromName("red").Lighten(i / 100f).ToHex6String() == LIGHTENS[i]);
for (var i = 0; i <= 100; i++)
Assert.IsTrue(TinyColor.ParseFromName("red").Brighten(i / 100f).ToHex6String() == BRIGHTENS[i]);
for (var i = 0; i <= 95; i++)
Assert.IsTrue(TinyColor.ParseFromName("red").Darken(i / 100f).ToHex6String() == DARKENS[i]);
for (var i = 0; i <= 100; i++)
Assert.IsTrue(TinyColor.ParseFromName("red").Tint(i / 100f).ToHex6String() == TINTS[i]);
for (var i = 0; i <= 100; i++)
Assert.IsTrue(TinyColor.ParseFromName("red").Shade(i / 100f).ToHex6String() == SHADES[i]);
Assert.IsTrue(TinyColor.ParseFromName("red").Greyscale().ToHex6String() == "#808080");
}
[Test]
public void Spin()
{
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#f00").Spin(-1234).ToHSL().H, 206f));
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#f00").Spin(-360).ToHSL().H, 0f));
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#f00").Spin(-120).ToHSL().H, 240f));
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#f00").Spin(0).ToHSL().H, 0f));
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#f00").Spin(10).ToHSL().H, 10f));
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#f00").Spin(360).ToHSL().H, 0f));
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#f00").Spin(2345).ToHSL().H, 185f));
foreach (var delta in new[] { -360f, 0f, 360f })
{
foreach (var kv in Color.Colors)
{
TinyColor originalColor = kv.Value;
TinyColor spunColor = originalColor.Spin(delta);
Assert.AreEqual(originalColor.ToHex8String(), spunColor.ToHex8String());
}
}
}
[Test]
public void Mix()
{
Assert.IsTrue(Mathf.Approximately(TinyColor.ParseFromHex("#000").Mix(TinyColor.ParseFromHex("#fff")).ToHSL().L, 0.5f));
Assert.IsTrue(TinyColor.ParseFromHex("#f00").Mix(TinyColor.ParseFromHex("#000"), 0).ToHex6String() == "#FF0000");
// This case checks the the problem with floating point numbers (eg 255/90)
Assert.IsTrue(TinyColor.ParseFromHex("#fff").Mix(TinyColor.ParseFromHex("#000"), 0.9f).ToHex6String() == "#1A1A1A");
for (var i = 0; i <= 100; ++i)
{
var tBlack = TinyColor.ParseFromHex("#000");
var tWhite = TinyColor.ParseFromHex("#fff");
Mathf.Approximately(
tBlack.Mix(tWhite, i / 100f).ToHSL().L,
(i / 100f)
);
}
for (int i = 0; i <= 100; i++)
{
string newHex = Mathf.RoundToInt((255 * (100 - i)) / 100f).ToString("X");
if (newHex.Length == 1)
newHex = "0" + newHex;
Assert.AreEqual(TinyColor.ParseFromHex("#FF0000").Mix(TinyColor.ParseFromHex("#000000"), i / 100f).ToHex6String(), "#" + newHex + "0000");
Assert.AreEqual(TinyColor.ParseFromHex("#00FF00").Mix(TinyColor.ParseFromHex("#000000"), i / 100f).ToHex6String(), "#00" + newHex + "00");
Assert.AreEqual(TinyColor.ParseFromHex("#0000FF").Mix(TinyColor.ParseFromHex("#000000"), i / 100f).ToHex6String(), "#0000" + newHex);
var tWhite = TinyColor.ParseFromName("white");
tWhite.A = 0f;
Assert.AreEqual(i / 100f, tWhite.Mix(TinyColor.ParseFromHex("#000000"), i / 100f).ToRGBA().A, 0.001f);
}
}
[Test]
public void OnBackground()
{
Assert.AreEqual(TinyColor.ParseFromHex("#ffffff").OnBackground(TinyColor.ParseFromHex("#000")).ToHex6String(), "#FFFFFF");
Assert.AreEqual(TinyColor.ParseFromHex("#ffffff00").OnBackground(TinyColor.ParseFromHex("#000")).ToHex6String(), "#000000");
Assert.AreEqual(TinyColor.ParseFromHex("#ffffff77").OnBackground(TinyColor.ParseFromHex("#000")).ToHex6String(), "#777777");
Assert.AreEqual(TinyColor.ParseFromHex("#262a6d82").OnBackground(TinyColor.ParseFromHex("#644242")).ToHex6String(), "#443658");
Assert.AreEqual(TinyColor.ParseFromRGB("1 0 0 0.5").OnBackground(TinyColor.ParseFromRGB("0 1 0 0.5")).ToRGBA256().ToString(), "170 85 0 191");
Assert.AreEqual(TinyColor.ParseFromRGB256("255 0 0 127").OnBackground(TinyColor.ParseFromRGB("0 0 255 255")).ToRGB256().ToString(), "127 0 128");
Assert.AreEqual(TinyColor.ParseFromRGB256("0 0 255 255").OnBackground(TinyColor.ParseFromRGB("0 0 0 127")).ToRGB256().ToString(), "0 0 255");
}
[Test]
public void Compliment()
{
var tRed = TinyColor.ParseFromName("red");
Assert.AreEqual("#00FFFF", tRed.Complement().ToHex6String()); // todo: expected always should go first as here, also replace '==' to AreEqual everywhere in tests
Assert.AreEqual("#FF0000", tRed.ToHex6String());
}
[Test]
public void Analogous()
{
var tRed = TinyColor.ParseFromName("red");
var combination = tRed.Analogous();
var expect = new List<string> { "#FF0000", "#FF0066", "#FF0033", "#FF0000", "#FF3300", "#FF6600" };
for (var i=0; i < expect.Count; ++i)
Assert.AreEqual(expect[i], combination[i].ToHex6String());
}
[Test]
public void Monochromatic()
{
var tRed = TinyColor.ParseFromName("red");
var combination = tRed.Monochromatic();
var expect = new List<string> { "#FF0000", "#2A0000", "#550000", "#800000", "#AA0000", "#D40000" };
for (var i = 0; i < expect.Count; ++i)
Assert.AreEqual(expect[i], combination[i].ToHex6String());
}
[Test]
public void SplitComplement()
{
var tRed = TinyColor.ParseFromName("red");
var combination = tRed.SplitComplement();
var expect = new List<string> { "#FF0000", "#CCFF00", "#0066FF" };
for (var i = 0; i < expect.Count; ++i)
Assert.AreEqual(expect[i], combination[i].ToHex6String());
}
[Test]
public void Triad()
{
var tRed = TinyColor.ParseFromName("red");
var combination = tRed.Triad();
var expect = new List<string> { "#FF0000", "#00FF00", "#0000FF" };
for (var i = 0; i < expect.Count; ++i)
Assert.AreEqual(expect[i], combination[i].ToHex6String());
}
[Test]
public void Tetrad()
{
var tRed = TinyColor.ParseFromName("red");
var combination = tRed.Tetrad();
var expect = new List<string> { "#FF0000", "#7FFF00", "#00FFFF", "#8000FF" };
for (var i = 0; i < expect.Count; ++i)
Assert.AreEqual(expect[i], combination[i].ToHex6String());
}
}
}