~ubuntu-branches/ubuntu/saucy/whoopsie-daisy/saucy

« back to all changes in this revision

Viewing changes to backend/stats/static/js/d3/test/svg/area-test.js

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-10 14:28:58 UTC
  • Revision ID: package-import@ubuntu.com-20120410142858-nk453o1z7t7py3bs
Tags: 0.1.26
* Take ownership of the NetworkManager state variant on setup and
  unref it, plugging a memory leak.
* Log the reason the server rejected the submitted crash report.
* Send the Whoopsie version with each crash submission.
* Delete both .upload and .uploaded files after 14 days. Thanks
  Marc Deslauriers (LP: #973687).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require("../env");
 
2
 
 
3
var vows = require("vows"),
 
4
    assert = require("assert");
 
5
 
 
6
var suite = vows.describe("d3.svg.area");
 
7
 
 
8
suite.addBatch({
 
9
  "area": {
 
10
    topic: function() {
 
11
      return d3.svg.area;
 
12
    },
 
13
 
 
14
    "x is an alias for setting x0 and x1": function(area) {
 
15
      var a = area().x(f);
 
16
      function f() {}
 
17
      assert.equal(a.x(), f);
 
18
      assert.equal(a.x0(), f);
 
19
      assert.equal(a.x1(), f);
 
20
    },
 
21
    "x is an alias for getting x1": function(area) {
 
22
      var a = area().x1(f);
 
23
      function f() {}
 
24
      assert.equal(a.x(), f);
 
25
    },
 
26
 
 
27
    "y is an alias for setting y0 and y1": function(area) {
 
28
      var a = area().y(f);
 
29
      function f() {}
 
30
      assert.equal(a.y(), f);
 
31
      assert.equal(a.y0(), f);
 
32
      assert.equal(a.y1(), f);
 
33
    },
 
34
    "y is an alias for getting x1": function(area) {
 
35
      var a = area().y1(f);
 
36
      function f() {}
 
37
      assert.equal(a.y(), f);
 
38
    },
 
39
 
 
40
    "x0 defaults to a function accessor": function(area) {
 
41
      var a = area();
 
42
      assert.pathEqual(a([[1, 2], [4, 3]]), "M1,2L4,3L4,0L1,0Z");
 
43
      assert.typeOf(a.x0(), "function");
 
44
    },
 
45
    "x0 can be defined as a constant": function(area) {
 
46
      var a = area().x0(0);
 
47
      assert.pathEqual(a([[1, 2], [4, 3]]), "M1,2L4,3L0,0L0,0Z");
 
48
      assert.equal(a.x0(), 0);
 
49
    },
 
50
    "x0 can be defined as a function": function(area) {
 
51
      var a = area().x0(f), t = {}, dd = [], ii = [], tt = [];
 
52
      function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 0; }
 
53
      assert.pathEqual(a.call(t, [[1, 2], [4, 3]]), "M1,2L4,3L0,0L0,0Z");
 
54
      assert.deepEqual(dd, [[1, 2], [4, 3]], "expected data, got {actual}");
 
55
      assert.deepEqual(ii, [0, 1], "expected index, got {actual}");
 
56
      assert.deepEqual(tt, [t, t], "expected this, got {actual}");
 
57
    },
 
58
 
 
59
    "x1 defaults to a function accessor": function(area) {
 
60
      var a = area();
 
61
      assert.pathEqual(a([[1, 2], [4, 3]]), "M1,2L4,3L4,0L1,0Z");
 
62
      assert.typeOf(a.x1(), "function");
 
63
    },
 
64
    "x1 can be defined as a constant": function(area) {
 
65
      var a = area().x1(0);
 
66
      assert.pathEqual(a([[1, 2], [4, 3]]), "M0,2L0,3L4,0L1,0Z");
 
67
      assert.equal(a.x1(), 0);
 
68
    },
 
69
    "x1 can be defined as a function": function(area) {
 
70
      var a = area().x1(f), t = {}, dd = [], ii = [], tt = [];
 
71
      function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 0; }
 
72
      assert.pathEqual(a.call(t, [[1, 2], [4, 3]]), "M0,2L0,3L4,0L1,0Z");
 
73
      assert.deepEqual(dd, [[1, 2], [4, 3]], "expected data, got {actual}");
 
74
      assert.deepEqual(ii, [0, 1], "expected index, got {actual}");
 
75
      assert.deepEqual(tt, [t, t], "expected this, got {actual}");
 
76
    },
 
77
 
 
78
    "y0 defaults to zero": function(area) {
 
79
      var a = area();
 
80
      assert.pathEqual(a([[1, 2], [4, 3]]), "M1,2L4,3L4,0L1,0Z");
 
81
      assert.equal(a.y0(), 0);
 
82
    },
 
83
    "y0 can be defined as a constant": function(area) {
 
84
      var a = area().y0(1);
 
85
      assert.pathEqual(a([[1, 2], [4, 3]]), "M1,2L4,3L4,1L1,1Z");
 
86
      assert.equal(a.y0(), 1);
 
87
    },
 
88
    "y0 can be defined as a function": function(area) {
 
89
      var a = area().y0(f), t = {}, dd = [], ii = [], tt = [];
 
90
      function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 1; }
 
91
      assert.pathEqual(a.call(t, [[1, 2], [4, 3]]), "M1,2L4,3L4,1L1,1Z");
 
92
      assert.deepEqual(dd, [[1, 2], [4, 3]], "expected data, got {actual}");
 
93
      assert.deepEqual(ii, [0, 1], "expected index, got {actual}");
 
94
      assert.deepEqual(tt, [t, t], "expected this, got {actual}");
 
95
    },
 
96
 
 
97
    "y1 defaults to a function accessor": function(area) {
 
98
      var a = area();
 
99
      assert.pathEqual(a([[1, 2], [4, 3]]), "M1,2L4,3L4,0L1,0Z");
 
100
      assert.typeOf(a.y1(), "function");
 
101
    },
 
102
    "y1 can be defined as a constant": function(area) {
 
103
      var a = area().y1(1);
 
104
      assert.pathEqual(a([[1, 2], [4, 3]]), "M1,1L4,1L4,0L1,0Z");
 
105
      assert.equal(a.y1(), 1);
 
106
    },
 
107
    "y1 can be defined as a function": function(area) {
 
108
      var a = area().y1(f), t = {}, dd = [], ii = [], tt = [];
 
109
      function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 1; }
 
110
      assert.pathEqual(a.call(t, [[1, 2], [4, 3]]), "M1,1L4,1L4,0L1,0Z");
 
111
      assert.deepEqual(dd, [[1, 2], [4, 3]], "expected data, got {actual}");
 
112
      assert.deepEqual(ii, [0, 1], "expected index, got {actual}");
 
113
      assert.deepEqual(tt, [t, t], "expected this, got {actual}");
 
114
    },
 
115
 
 
116
    "if x0 === x1, x is only evaluated once per point": function(area) {
 
117
      var a = area().x(f), t = {}, dd = [], ii = [], tt = [];
 
118
      function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 0; }
 
119
      assert.pathEqual(a.call(t, [[1, 2], [4, 3]]), "M0,2L0,3L0,0L0,0Z");
 
120
      assert.deepEqual(dd, [[1, 2], [4, 3]], "expected data, got {actual}");
 
121
      assert.deepEqual(ii, [0, 1], "expected index, got {actual}");
 
122
      assert.deepEqual(tt, [t, t], "expected this, got {actual}");
 
123
    },
 
124
    "if y0 === y1, y is only evaluated once per point": function(area) {
 
125
      var a = area().y(f), t = {}, dd = [], ii = [], tt = [];
 
126
      function f(d, i) { dd.push(d); ii.push(i); tt.push(this); return 1; }
 
127
      assert.pathEqual(a.call(t, [[1, 2], [4, 3]]), "M1,1L4,1L4,1L1,1Z");
 
128
      assert.deepEqual(dd, [[1, 2], [4, 3]], "expected data, got {actual}");
 
129
      assert.deepEqual(ii, [0, 1], "expected index, got {actual}");
 
130
      assert.deepEqual(tt, [t, t], "expected this, got {actual}");
 
131
    },
 
132
 
 
133
    "interpolate defaults to linear": function(area) {
 
134
      assert.equal(area().interpolate(), "linear");
 
135
    },
 
136
    "interpolate can be defined as a constant": function(area) {
 
137
      var a = area().interpolate("step-before");
 
138
      assert.pathEqual(a([[0, 0], [1, 1]]), "M0,0V1H1L1,0H0V0Z");
 
139
      assert.equal(a.interpolate(), "step-before");
 
140
    },
 
141
    "invalid interpolates fallback to linear": function(area) {
 
142
      assert.equal(area().interpolate("__proto__").interpolate(), "linear");
 
143
    },
 
144
 
 
145
    "tension defaults to .7": function(area) {
 
146
      assert.equal(area().tension(), .7);
 
147
    },
 
148
    "tension can be specified as a constant": function(area) {
 
149
      var a = area().tension(.5);
 
150
      assert.equal(a.tension(), .5);
 
151
    },
 
152
 
 
153
    "returns null if input points array is empty": function(area) {
 
154
      assert.isNull(area()([]));
 
155
    },
 
156
 
 
157
    "interpolate(linear)": {
 
158
      "supports linear interpolation": testInterpolation("linear")
 
159
    },
 
160
 
 
161
    "interpolate(step)": {
 
162
      "supports step-before interpolation": testInterpolation("step-before", "step-after"),
 
163
      "supports step-after interpolation": testInterpolation("step-after", "step-before")
 
164
    },
 
165
 
 
166
    "interpolate(basis)": {
 
167
      "supports basis interpolation": testInterpolation("basis"),
 
168
      "supports basis-open interpolation": testInterpolation("basis-open")
 
169
    },
 
170
 
 
171
    "interpolate(cardinal)": {
 
172
      "supports cardinal interpolation": testInterpolation("cardinal"),
 
173
      "supports cardinal-open interpolation": testInterpolation("cardinal-open")
 
174
    },
 
175
 
 
176
    "interpolate(monotone)": {
 
177
      "supports monotone interpolation": testInterpolation("monotone")
 
178
    }
 
179
  }
 
180
});
 
181
 
 
182
// An area is just two lines, with one reversed.
 
183
function testInterpolation(i0, i1) {
 
184
  if (arguments.length < 2) i1 = i0;
 
185
  return function(area) {
 
186
    var a = area().interpolate(i0),
 
187
        d = [[0, 0], [1, 1], [2, 0], [3, 1], [4, 0]],
 
188
        l0 = d3.svg.line().interpolate(i1).x(a.x0()).y(a.y0()),
 
189
        l1 = d3.svg.line().interpolate(i0).x(a.x1()).y(a.y1());
 
190
    assert.pathEqual(a(d), l1(d) + "L" + l0(d.reverse()).substring(1) + "Z");
 
191
  };
 
192
}
 
193
 
 
194
suite.export(module);