-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGridViewTests.cs
More file actions
94 lines (83 loc) · 2.99 KB
/
Copy pathGridViewTests.cs
File metadata and controls
94 lines (83 loc) · 2.99 KB
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
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace NETMapnik.Test
{
[TestClass]
public class GridViewTests
{
[TestMethod]
public void GridView_Init()
{
Grid g = new Grid(256, 256);
GridView v = g.View(0, 0, 128, 128);
Assert.IsTrue(v.IsSolid());
long pixel = v.GetPixel(0, 0);
Assert.AreEqual(Grid.BaseMask, pixel);
Assert.AreEqual(128, v.Width());
Assert.AreEqual(128, v.Height());
}
[TestMethod]
public void GridView_IsSolid()
{
Map m = new Map(256, 256);
m.AddLayer(new Layer("test"));
m.ZoomAll();
Grid g = new Grid(256, 256);
m.Render(g);
GridView v1 = g.View(0, 0, 256, 256);
Assert.IsTrue(v1.IsSolid());
m.Clear();
g.Clear();
Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
m.Load(@".\data\test.xml");
m.ZoomAll();
m.Render(g);
GridView v2 = g.View(0, 0, 256, 256);
Assert.IsFalse(v2.IsSolid());
}
[TestMethod]
public void GridView_GetPixel()
{
Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
Map m = new Map(256, 256);
m.Load(@".\data\test.xml");
m.ZoomAll();
Grid g = new Grid(256, 256);
m.Render(g);
GridView v = g.View(0, 0, 256, 256);
long pixel = v.GetPixel(25, 100);
Assert.AreEqual(207, pixel);
}
[TestMethod]
public void GridView_Encode()
{
Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
Map m = new Map(256, 256);
m.Load(@".\data\test.xml");
m.ZoomAll();
Grid g = new Grid(256, 256);
var options = new Dictionary<string, object>()
{
{"Fields", new List<string>() { "FIPS" } },
{"Layer", "world" }
};
m.Render(g, options);
Dictionary<string, object> UTFGridDict = g.Encode();
Assert.AreEqual(UTFGridDict.Keys.Count, 3);
//Test for keys
List<string> keyList = (List<string>)UTFGridDict["keys"];
Assert.AreNotEqual(keyList.Count, 0);
//Test for data
Dictionary<string, object> dataDict = (Dictionary<string, object>)UTFGridDict["data"];
Assert.AreNotEqual(dataDict.Count, 0);
//data count should equal keys + 1
Assert.AreEqual(keyList.Count, dataDict.Count + 1);
//Test grid dimensions
List<string> grid = (List<string>)UTFGridDict["grid"];
Assert.AreEqual(64, grid.Count);
Assert.AreEqual(64, grid[0].Length);
}
}
}