Debian Codegraph @

topojson/test/prune-test.js

raw
1 var tape = require("tape"),
2 prune = require("../lib/topojson/prune");
3
4 tape("prune preserves arcs that are referenced", function(test) {
5 test.deepEqual(prune({
6 type: "Topology",
7 arcs: [
8 [[0, 0], [1, 0]]
9 ],
10 objects: {
11 foo: {
12 type: "LineString",
13 arcs: [0]
14 }
15 }
16 }), {
17 type: "Topology",
18 arcs: [
19 [[0, 0], [1, 0]]
20 ],
21 objects: {
22 foo: {
23 type: "LineString",
24 arcs: [0]
25 }
26 }
27 });
28 test.end();
29 });
30
31 tape("prune removes arcs that are not referenced", function(test) {
32 test.deepEqual(prune({
33 type: "Topology",
34 arcs: [
35 [[0, 0], [2, 0]],
36 [[1, 0], [1, 0]],
37 [[2, 0], [1, 0]]
38 ],
39 objects: {
40 foo: {
41 type: "LineString",
42 arcs: [0, 2]
43 }
44 }
45 }), {
46 type: "Topology",
47 arcs: [
48 [[0, 0], [2, 0]],
49 [[2, 0], [1, 0]]
50 ],
51 objects: {
52 foo: {
53 type: "LineString",
54 arcs: [0, 1]
55 }
56 }
57 });
58 test.end();
59 });
60
61 tape("prune removes reversed arcs that are not referenced", function(test) {
62 test.deepEqual(prune({
63 type: "Topology",
64 arcs: [
65 [[0, 0], [2, 0]],
66 [[1, 0], [1, 0]],
67 [[2, 0], [1, 0]]
68 ],
69 objects: {
70 foo: {
71 type: "LineString",
72 arcs: [~2, ~0]
73 }
74 }
75 }), {
76 type: "Topology",
77 arcs: [
78 [[2, 0], [1, 0]],
79 [[0, 0], [2, 0]]
80 ],
81 objects: {
82 foo: {
83 type: "LineString",
84 arcs: [~0, ~1]
85 }
86 }
87 });
88 test.end();
89 });
90
91 tape("prune does not remove collapsed arcs", function(test) {
92 test.deepEqual(prune({
93 type: "Topology",
94 arcs: [
95 [[0, 0], [0, 0]],
96 [[0, 0], [2, 0]],
97 [[2, 0], [0, 0]],
98 [[2, 0], [1, 0]],
99 [[3, 0], [0, 0]]
100 ],
101 objects: {
102 foo: {
103 type: "LineString",
104 arcs: [0, 1, 2, 3, 4]
105 }
106 }
107 }), {
108 type: "Topology",
109 arcs: [
110 [[0, 0], [0, 0]],
111 [[0, 0], [2, 0]],
112 [[2, 0], [0, 0]],
113 [[2, 0], [1, 0]],
114 [[3, 0], [0, 0]]
115 ],
116 objects: {
117 foo: {
118 type: "LineString",
119 arcs: [0, 1, 2, 3, 4]
120 }
121 }
122 });
123 test.end();
124 });
125
126 tape("prune does not remove collapsed lines", function(test) {
127 test.deepEqual(prune({
128 type: "Topology",
129 arcs: [
130 [[2, 0], [0, 0]]
131 ],
132 objects: {
133 foo: {
134 type: "LineString",
135 arcs: [0]
136 }
137 }
138 }), {
139 type: "Topology",
140 arcs: [
141 [[2, 0], [0, 0]]
142 ],
143 objects: {
144 foo: {
145 type: "LineString",
146 arcs: [0]
147 }
148 }
149 });
150 test.end();
151 });