forked from jbrwn/NET-Mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorTest.cs
81 lines (75 loc) · 2.4 KB
/
ColorTest.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
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NETMapnik;
namespace NETMapnik.Test
{
[TestClass]
public class ColorTest
{
[TestMethod]
[ExpectedException(typeof(Exception))]
public void Color_Throws()
{
Color c = new Color("foo");
}
[TestMethod]
public void Color_FromText()
{
Color c = new Color("red");
Assert.AreEqual(c.R, 255);
Assert.AreEqual(c.G, 0);
Assert.AreEqual(c.B, 0);
Assert.AreEqual(c.A, 255);
Assert.IsFalse(c.Premultiplied);
Assert.AreEqual(c.Hex(), "#ff0000");
Assert.AreEqual(c.ToString(), "rgb(255,0,0)");
}
[TestMethod]
public void Color_FromRGB()
{
Color c = new Color(255,0,0);
Assert.AreEqual(c.R, 255);
Assert.AreEqual(c.G, 0);
Assert.AreEqual(c.B, 0);
Assert.AreEqual(c.A, 255);
Assert.IsFalse(c.Premultiplied);
Assert.AreEqual(c.Hex(), "#ff0000");
Assert.AreEqual(c.ToString(), "rgb(255,0,0)");
}
[TestMethod]
public void Color_FromRGBA()
{
Color c = new Color(255,0,0,255);
Assert.AreEqual(c.R, 255);
Assert.AreEqual(c.G, 0);
Assert.AreEqual(c.B, 0);
Assert.AreEqual(c.A, 255);
Assert.IsFalse(c.Premultiplied);
Assert.AreEqual(c.Hex(), "#ff0000");
Assert.AreEqual(c.ToString(), "rgb(255,0,0)");
}
[TestMethod]
public void Color_FromRGBAPercent()
{
Color c = new Color("rgba(100%,0%,0%,1)");
Assert.AreEqual(c.R, 255);
Assert.AreEqual(c.G, 0);
Assert.AreEqual(c.B, 0);
Assert.AreEqual(c.A, 255);
Assert.AreEqual(c.Hex(), "#ff0000");
Assert.IsFalse(c.Premultiplied);
Assert.AreEqual(c.ToString(), "rgb(255,0,0)");
}
[TestMethod]
public void Color_Premultiply()
{
Color c = new Color(128,128,128,true);
Assert.AreEqual(c.R, 128);
Assert.AreEqual(c.G, 128);
Assert.AreEqual(c.B, 128);
Assert.AreEqual(c.A, 255);
Assert.IsTrue(c.Premultiplied);
Assert.AreEqual(c.ToString(), "rgb(128,128,128)");
}
}
}