OSDN Git Service

8e3a6f4e57e56b2fe7f0edeedb8b1ef25710f906
[sie/sie.git] / tool / Spec / spec / SvgDomSpec.js
1 /*SIE under the MIT Lisence\r
2  *公式ページは http://sie.osdn.jp/\r
3  */\r
4 /*\r
5  *Copyright (c) 2008-2010 Pivotal Labs\r
6 \r
7 Permission is hereby granted, free of charge, to any person obtaining\r
8 a copy of this software and associated documentation files (the\r
9 "Software"), to deal in the Software without restriction, including\r
10 without limitation the rights to use, copy, modify, merge, publish,\r
11 distribute, sublicense, and/or sell copies of the Software, and to\r
12 permit persons to whom the Software is furnished to do so, subject to\r
13 the following conditions:\r
14 \r
15 The above copyright notice and this permission notice shall be\r
16 included in all copies or substantial portions of the Software.\r
17 \r
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
25  */\r
26 \r
27 describe("SMIL Animation Spec", function() {\r
28   describe("$frame object", function() {\r
29     var frame = base("$frame");\r
30     beforeEach( function() {\r
31         frame.timelines = [];\r
32         frame.isPaused = false;\r
33     } );\r
34     afterEach( function() {\r
35         frame.timelines = [];\r
36     } );\r
37     /*境界条件を調べておく (limit value analysis)*/\r
38     it("should be this for the value  (limit value analysis)", function() {\r
39       expect(typeof frame.setFrame).toBe("function");\r
40       expect(frame.timelines.length).toBe(0);\r
41       expect(frame.isBegin).toBeFalsy();\r
42       expect(frame.startAnimation()).toBeUndefined();\r
43       frame.setFrame();\r
44       frame.setFrame(0);\r
45       /*負の値も許される*/\r
46       frame.setFrame(-1);\r
47       \r
48       expect(frame.addLine()).toBe(false);\r
49       expect(frame.addLine({})).toBe(false);\r
50       expect(frame.addLine({\r
51         begin: 0\r
52       })).toBe(false);\r
53       expect(frame.addLine({\r
54         activeTime: 1\r
55       })).toBe(false);\r
56       \r
57       expect(frame.removeLine()).toBeUndefined();\r
58       expect(frame.removeLine({})).toBeUndefined();\r
59       \r
60       frame.setFrame(0);\r
61       expect(frame.currentFrame).toBe(0);\r
62       frame.setFrame(1);\r
63       expect(frame.currentFrame).toBe(1);\r
64       \r
65       expect(frame.isPaused).toBeFalsy();\r
66       expect(frame.pauseAnimation()).toBeUndefined();\r
67       expect(frame.isPaused).toBeTruthy();\r
68 \r
69     });\r
70     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
71     it("should be this for the value (the valid partion)", function() {\r
72       frame.setFrame(0);\r
73       expect(frame.currentFrame).toBe(0);\r
74       frame.startTime = Date.now();\r
75       for (var i=0;i<100000;i++) {\r
76         /*負荷をかけて、時間を進める*/\r
77         1;\r
78       }\r
79       expect(frame.begin).toBe(0);\r
80       expect(frame.activeTime).toBe(Number.MAX_VALUE);\r
81       frame.begin = 10;\r
82       frame.setFrame(0);\r
83       frame.begin = -10;\r
84       frame.setFrame(0);\r
85 \r
86       expect(frame.addLine( {\r
87         begin: 0,\r
88         activeTime: 0\r
89       })).toBe(true);\r
90       expect(frame.addLine( {\r
91         begin: null,\r
92         activeTime: null\r
93       })).toBe(false);\r
94       expect(frame.addLine( {\r
95         begin: 0,\r
96         activeTime: null\r
97       })).toBe(false);\r
98       expect(frame.addLine( {\r
99         begin: null,\r
100         activeTime: 0\r
101       })).toBe(false);\r
102       \r
103       expect(frame.timelines.length).toBe(1);\r
104       var timeline = frame.timelines[0];\r
105       expect(timeline.begin).toBe(0);\r
106       expect(timeline.activeTime).toBe(0);\r
107       /*timelineの再追加*/\r
108       expect(frame.timelines[0]).toBe(timeline);\r
109       frame.addLine({begin:1, activeTime:1});\r
110       expect(frame.timelines[1]).not.toBe(timeline);\r
111       frame.addLine(timeline);\r
112       expect(frame.timelines[0]).not.toBe(timeline);\r
113       expect(frame.timelines[1]).toBe(timeline);\r
114 \r
115       timeline = frame.timelines[0];\r
116       frame.removeLine({});\r
117       expect(frame.timelines[0]).toBe(timeline);\r
118       frame.removeLine(timeline);\r
119       expect(frame.timelines[0]).not.toBe(timeline);\r
120       \r
121       frame.addLine(frame.up().mix( {\r
122         timelines: [] \r
123         } ));\r
124       expect(frame.timelines).not.toBe(frame.$1.timelines);\r
125       \r
126       frame.timelines.length = 0;\r
127       frame.addLine( {\r
128         begin: 1,\r
129         activeTime: 1\r
130       } );\r
131       frame.addLine( {\r
132         begin: 1,\r
133         activeTime: 1\r
134       } );\r
135       frame.addLine( {\r
136         begin: 1,\r
137         activeTime: 2\r
138       } );\r
139       expect(frame.timelines[2].activeTime).toBe(2);\r
140     });\r
141     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
142     it("should be this for the value (the invalid partion)", function() {\r
143       expect(frame.addLine(12)).toBeFalsy();\r
144       /*循環参照にならず、スタック領域不足にならない*/\r
145       frame.addLine(frame);\r
146       frame.setFrame(0);\r
147     });\r
148   } );\r
149   describe("the $frame.$list object", function() {\r
150     var frame = base("$frame").$list.up("$2");\r
151     beforeEach( function() {\r
152         frame.timelines = [];\r
153         frame.isPaused = false;\r
154         frame.state = frame.WAITING;\r
155         frame.begin = 0;\r
156     } );\r
157     afterEach( function() {\r
158         frame.timelines = [];\r
159     } );\r
160     /*境界条件を調べておく (limit value analysis)*/\r
161     it("should be this for the value  (limit value analysis)", function() {\r
162             \r
163       expect(frame.WAITING).toBe(0);\r
164       expect(frame.BEGINNING).toBe(1);\r
165       expect(frame.PLAYING).toBe(2);\r
166       expect(frame.ENDING).toBe(3);\r
167       expect(frame.POSTWAITING).toBe(4);\r
168       expect(frame.state).toBe(frame.WAITING);\r
169       expect(frame.end).toBe(0);\r
170       expect(frame.beginEnd).toBe(Number.MAX_VALUE);\r
171       \r
172       expect(frame.beginList).toEqual({\r
173               next: null,\r
174               value: Number.MAX_VALUE\r
175             });\r
176       expect(frame.endList).toEqual({\r
177               next: null,\r
178               value: Number.MAX_VALUE\r
179             });\r
180             \r
181       expect(typeof frame.getMaxList).toBe("function");\r
182       \r
183       expect(typeof frame.updateState).toBe("function");\r
184       expect(frame.updateState(0).state).toBe(frame.WAITING);\r
185       expect(frame.state).toBe(frame.WAITING);\r
186       expect(frame.updateState(0).state).toBe(frame.WAITING);\r
187       expect(frame.state).toBe(frame.WAITING);\r
188       expect(frame.updateState(0).state).toBe(frame.WAITING);\r
189       expect(frame.state).toBe(frame.WAITING);\r
190       expect(frame.updateState(0).state).toBe(frame.WAITING);\r
191       expect(frame.state).toBe(frame.WAITING);\r
192       \r
193       frame.state = 100;\r
194       expect(frame.updateState(0).state).toBe(frame.BEGINNING);\r
195       expect(frame.state).toBe(frame.BEGINNING);\r
196       expect(frame.updateState().state).toBe(frame.BEGINNING);\r
197       expect(frame.state).toBe(frame.BEGINNING);\r
198       \r
199       expect(frame.beginList).toEqual({\r
200           next: null,\r
201           value: Number.MAX_VALUE\r
202         });\r
203       expect(frame.endList).toEqual({\r
204           next: null,\r
205           value: Number.MAX_VALUE\r
206         });\r
207         \r
208       expect(frame.getMaxList(0, frame.beginList)).toBe(-1);\r
209       expect(frame.getMaxList(0, frame.endList)).toBe(-1);\r
210       \r
211       frame.begin = 12;\r
212       frame.init();\r
213       expect(frame.state).toBe(frame.WAITING);\r
214       expect(frame.begin).toBe(0);\r
215       expect(frame.init()).toBe(frame);\r
216 \r
217     } );\r
218     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
219     it("should be this for the value (the valid partion)", function() {\r
220       \r
221       function appendBegin(num) {\r
222         frame.state = frame.WAITING;\r
223         frame.beginList = {\r
224           value: num,\r
225           next: frame.beginList\r
226         };\r
227       };\r
228       appendBegin(0);\r
229       expect(frame.getMaxList(0, frame.beginList)).toBe(0);\r
230       expect(frame.updateState(0).state).toBe(frame.BEGINNING);\r
231       expect(frame.begin).toBe(0);\r
232       expect(frame.updateState(0).state).toBe(frame.PLAYING);\r
233       expect(frame.state).toBe(frame.PLAYING);\r
234       expect(frame.updateState(0).state).toBe(frame.PLAYING);\r
235       expect(frame.state).toBe(frame.PLAYING);\r
236       \r
237       frame.state = frame.WAITING;\r
238       expect(frame.getMaxList(0, frame.beginList)).toBe(0);\r
239       expect(frame.updateState(0).state).toBe(frame.BEGINNING);\r
240       expect(frame.state).toBe(frame.BEGINNING);\r
241       expect(frame.updateState(1).state).toBe(frame.PLAYING);\r
242       expect(frame.state).toBe(frame.PLAYING);\r
243       expect(frame.updateState(2).state).toBe(frame.PLAYING);\r
244       expect(frame.state).toBe(frame.PLAYING);\r
245       expect(frame.updateState(3).state).toBe(frame.PLAYING);\r
246       expect(frame.state).toBe(frame.PLAYING);\r
247       expect(frame.updateState(4).state).toBe(frame.PLAYING);\r
248       expect(frame.state).toBe(frame.PLAYING);\r
249       \r
250       appendBegin(1);\r
251       expect(frame.getMaxList(1, frame.beginList)).toBe(1);\r
252       expect(frame.updateState(0).state).toBe(frame.BEGINNING);\r
253       expect(frame.updateState(0).state).toBe(frame.PLAYING);\r
254       expect(frame.updateState(0).state).toBe(frame.PLAYING);\r
255       expect(frame.updateState(1).state).toBe(frame.ENDING);\r
256       expect(frame.updateState(1).state).toBe(frame.BEGINNING);\r
257       expect(frame.state).toBe(frame.BEGINNING);\r
258       expect(frame.updateState(1).state).toBe(frame.PLAYING);\r
259       expect(frame.state).toBe(frame.PLAYING);\r
260       expect(frame.updateState(1).state).toBe(frame.PLAYING);\r
261       expect(frame.state).toBe(frame.PLAYING);\r
262       expect(frame.updateState(2).state).toBe(frame.PLAYING);\r
263       \r
264       frame.begin = 0;\r
265       frame.state = frame.WAITING;\r
266       expect(frame.updateState(0).state).toBe(frame.BEGINNING);\r
267       expect(frame.begin).toBe(0);\r
268       expect(frame.updateState(0).state).toBe(frame.PLAYING);\r
269       expect(frame.updateState(0).state).toBe(frame.PLAYING);\r
270       expect(frame.begin).toBe(0);\r
271       expect(frame.updateState(1).state).toBe(frame.ENDING);\r
272       expect(frame.end).toBe(0);\r
273       expect(frame.beginEnd).toBe(Number.MAX_VALUE);\r
274       expect(frame.updateState(1).state).toBe(frame.BEGINNING);\r
275       expect(frame.begin).toBe(1);\r
276       expect(frame.updateState(1).state).toBe(frame.PLAYING);\r
277       expect(frame.updateState(1).state).toBe(frame.PLAYING);\r
278       \r
279       function appendEnd(num) {\r
280         frame.state = frame.WAITING;\r
281         frame.begin = 0;\r
282         frame.endList = {\r
283             value: num,\r
284             next: frame.endList\r
285         };\r
286       };\r
287       appendEnd(3);\r
288       expect(frame.updateState(1).state).toBe(frame.BEGINNING);\r
289       expect(frame.state).toBe(frame.BEGINNING);\r
290       expect(frame.updateState(2).state).toBe(frame.PLAYING);\r
291       expect(frame.updateState(2).state).toBe(frame.PLAYING);\r
292       expect(frame.state).toBe(frame.PLAYING);\r
293       expect(frame.updateState(3).state).toBe(frame.ENDING);\r
294       expect(frame.state).toBe(frame.ENDING);\r
295       expect(frame.end).toBe(3);\r
296       expect(frame.beginEnd).toBe(2);\r
297       expect(frame.updateState(4).state).toBe(frame.POSTWAITING);\r
298       expect(frame.state).toBe(frame.POSTWAITING);\r
299       \r
300       appendEnd(4);\r
301       expect(frame.updateState(1).state).toBe(frame.BEGINNING);\r
302       expect(frame.state).toBe(frame.BEGINNING);\r
303       expect(frame.updateState(2).state).toBe(frame.PLAYING);\r
304       expect(frame.updateState(2).state).toBe(frame.PLAYING);\r
305       expect(frame.state).toBe(frame.PLAYING);\r
306       expect(frame.updateState(3).state).toBe(frame.ENDING);\r
307       expect(frame.state).toBe(frame.ENDING);\r
308       expect(frame.end).toBe(3);\r
309       expect(frame.beginEnd).toBe(2);\r
310       expect(frame.updateState(4).state).toBe(frame.POSTWAITING);\r
311       expect(frame.state).toBe(frame.POSTWAITING);\r
312       expect(frame.updateState(4).state).toBe(frame.POSTWAITING);\r
313       expect(frame.state).toBe(frame.POSTWAITING);\r
314       \r
315       appendEnd(1);\r
316       expect(frame.updateState(1).state).toBe(frame.BEGINNING);\r
317       expect(frame.updateState(1).state).toBe(frame.ENDING);\r
318       expect(frame.end).toBe(1);\r
319       expect(frame.beginEnd).toBe(0);\r
320       expect(frame.updateState(1).state).toBe(frame.POSTWAITING);\r
321     } );\r
322     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
323     it("should be this for the value (the invalid partion)", function() {\r
324       expect(frame.updateState()).toBe(frame);\r
325       expect(frame.updateState(null)).toBe(frame);\r
326     });\r
327     describe("the setFrame method (override)", function() {\r
328       var frame = base("$frame").$list.up("$3");\r
329       beforeEach( function() {\r
330           frame.timelines = [];\r
331           frame.isPaused = false;\r
332           frame.state = frame.WAITING;\r
333           frame.begin = 0;\r
334       } );\r
335       afterEach( function() {\r
336           frame.timelines = [];\r
337           frame.beginList = frame.$list.beginList;\r
338           frame.endList = frame.$list.endList;\r
339           frame.currentFrame = 0;\r
340       } );\r
341       /*境界条件を調べておく (limit value analysis)*/\r
342       it("should be this for the value  (limit value analysis)", function() {\r
343         expect(typeof frame.setFrame).toBe("function");\r
344         expect(frame.currentFrame).toBe(0);\r
345         \r
346         frame.setFrame(0);\r
347         expect(frame.state).toBe(frame.WAITING);\r
348         expect(frame.currentFrame).toBe(0);\r
349         frame.setFrame(1);\r
350         expect(frame.state).toBe(frame.WAITING);\r
351         expect(frame.currentFrame).toBe(1);\r
352         \r
353         expect(typeof frame.addEvent).toBe("function");\r
354         expect(typeof frame.addBeginList).toBe("function");\r
355         expect(typeof frame.addEndList).toBe("function");\r
356         \r
357         expect(frame.addBeginList(1).value).toBe(1);\r
358         expect(frame.beginList.next.value).toBe(Number.MAX_VALUE);\r
359         expect(frame.addEndList(1).value).toBe(1);\r
360         expect(frame.endList.next.value).toBe(Number.MAX_VALUE);\r
361         \r
362 \r
363 \r
364       } );\r
365       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
366       it("should be this for the value (the valid partion)", function() {\r
367         function appendBegin(num) {\r
368           frame.state = frame.WAITING;\r
369           frame.addBeginList(num);\r
370         };\r
371         appendBegin(0);\r
372         expect(frame.currentFrame).toBe(0);\r
373         frame.setFrame(0);\r
374         expect(frame.currentFrame).toBe(0);\r
375         expect(frame.state).toBe(frame.PLAYING);\r
376         frame.setFrame(1);\r
377         expect(frame.currentFrame).toBe(1);\r
378         expect(frame.state).toBe(frame.PLAYING);\r
379         \r
380         frame.begin = 0;\r
381         appendBegin(1);\r
382         frame.setFrame(0);\r
383         expect(frame.state).toBe(frame.PLAYING);\r
384         frame.setFrame(1);\r
385         expect(frame.state).toBe(frame.PLAYING);\r
386         frame.setFrame(2);\r
387         expect(frame.state).toBe(frame.PLAYING);\r
388         \r
389         function appendEnd(num) {\r
390           frame.state = frame.WAITING;\r
391           frame.begin = 0;\r
392           frame.addEndList(num);\r
393         };\r
394         \r
395         appendEnd(3);\r
396         frame.setFrame(0);\r
397         expect(frame.state).toBe(frame.PLAYING);\r
398         frame.setFrame(1);\r
399         expect(frame.state).toBe(frame.PLAYING);\r
400         frame.setFrame(2);\r
401         expect(frame.state).toBe(frame.PLAYING);\r
402         frame.setFrame(3);\r
403         expect(frame.state).toBe(frame.POSTWAITING);\r
404         frame.setFrame(4);\r
405         expect(frame.state).toBe(frame.POSTWAITING);\r
406         \r
407         appendBegin(5);\r
408         frame.setFrame(0);\r
409         expect(frame.state).toBe(frame.PLAYING);\r
410         frame.setFrame(1);\r
411         expect(frame.state).toBe(frame.PLAYING);\r
412         frame.setFrame(2);\r
413         expect(frame.state).toBe(frame.PLAYING);\r
414         frame.setFrame(3);\r
415         expect(frame.state).toBe(frame.POSTWAITING);\r
416         frame.setFrame(4);\r
417         expect(frame.state).toBe(frame.POSTWAITING);\r
418         frame.setFrame(5);\r
419         expect(frame.state).toBe(frame.PLAYING);\r
420         frame.setFrame(6);\r
421         expect(frame.state).toBe(frame.PLAYING);\r
422         \r
423         appendEnd(6);\r
424         frame.setFrame(0);\r
425         expect(frame.state).toBe(frame.PLAYING);\r
426         expect(frame.currentFrame).toBe(0);\r
427         frame.setFrame(1);\r
428         expect(frame.state).toBe(frame.PLAYING);\r
429         expect(frame.currentFrame).toBe(1);\r
430         frame.setFrame(2);\r
431         expect(frame.state).toBe(frame.PLAYING);\r
432         expect(frame.currentFrame).toBe(2);\r
433         frame.setFrame(3);\r
434         expect(frame.state).toBe(frame.POSTWAITING);\r
435         frame.setFrame(4);\r
436         expect(frame.state).toBe(frame.POSTWAITING);\r
437         frame.setFrame(5);\r
438         expect(frame.state).toBe(frame.PLAYING);\r
439         frame.setFrame(6);\r
440         expect(frame.state).toBe(frame.POSTWAITING);\r
441         expect(frame.currentFrame).toBe(6);\r
442         \r
443         /*負荷テスト*/\r
444         for (var i=0;i<10000;++i) {\r
445           frame.setFrame(i);\r
446         }\r
447         \r
448         frame.beginList = base("$frame").$listbeginList;\r
449         frame.endList = base("$frame").$list.endList;\r
450         frame.state = frame.WAITING;\r
451         frame.begin = 0;\r
452         var obj = { name: "", value: 0};\r
453         frame.addEvent("begin", function(evt) { obj.name = "a";});\r
454         frame.beginList = {\r
455             value: 0,\r
456             next: frame.beginList\r
457         };\r
458         frame.setFrame(0);\r
459         expect(frame.currentFrame).toBe(0);\r
460         expect(frame.state).toBe(frame.PLAYING);\r
461         expect(obj.name).toBe("a");\r
462         frame.addEvent("play", function(evt) { obj.name = "b";});\r
463         frame.setFrame(1);\r
464         expect(frame.state).toBe(frame.PLAYING);\r
465         expect(obj.name).toBe("b");\r
466         frame.addEvent("end", function(evt) { obj.value = 1;});\r
467         frame.endList = {\r
468             value: 0,\r
469             next: frame.endList\r
470         };\r
471         frame.setFrame(0);\r
472         expect(frame.currentFrame).toBe(0);\r
473         expect(frame.state).toBe(frame.POSTWAITING);\r
474         expect(obj.value).toBe(1);\r
475         var t = 0;\r
476         frame.addEvent("begin", function(evt) {\r
477           expect(evt.state).toBe(frame.BEGINNING);\r
478           t = 1;\r
479         });\r
480         frame.addEvent("end", function(evt) {\r
481           expect(evt.state).toBe(frame.ENDING);\r
482           t = 2;\r
483         });\r
484         frame.addEvent("play", function(evt) {\r
485           expect(evt.state).toBe(frame.PLAYING);\r
486           t = 3;\r
487         });\r
488         frame.setFrame(0);\r
489         expect(t).toBe(2);\r
490         \r
491         t=0;\r
492         frame.begin = 0;\r
493         frame.state = frame.WAITING;\r
494         expect(frame.getMaxList(12, frame.endList)).toBe(0);\r
495         frame.setFrame(12);\r
496         expect(frame.state).toBe(frame.POSTWAITING);\r
497         expect(t).toBe(2);\r
498         \r
499         /*addBeginListメソッドのチェックなど*/\r
500         expect(frame.addBeginList(1).value).toBe(1);\r
501         expect(frame.addBeginList(0).value).toBe(0);\r
502         expect(frame.beginList.next.value).toBe(1);\r
503         expect(frame.addBeginList(2).value).toBe(2);\r
504         expect(frame.beginList.next.value).toBe(0);\r
505         \r
506         expect(frame.addEndList(1).value).toBe(1);\r
507         expect(frame.addEndList(0).value).toBe(0);\r
508         expect(frame.endList.next.value).toBe(1);\r
509         expect(frame.addEndList(2).value).toBe(2);\r
510         expect(frame.endList.next.value).toBe(0);\r
511       } );\r
512     } );\r
513   } );\r
514   describe("$begin object", function() {\r
515     var begin = base("$frame").$begin.up();\r
516     /*境界条件を調べておく (limit value analysis)*/\r
517     it("should be this for the value  (limit value analysis)", function() {\r
518       expect(begin.string).toBe("");\r
519       expect(begin.isResolved).toBeFalsy();\r
520       expect(begin.eventTarget).toBe(document.documentElement);\r
521       expect(begin.eventOffset).toBe(0);\r
522       expect(begin.repeat).toBe(0);\r
523       expect(begin.accessKey).toBe("");\r
524     } );\r
525     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
526     it("should be this for the value (the valid partion)", function() {\r
527       begin.string = " hoge ";\r
528       expect(begin.string).toBe(" hoge ");\r
529       var $list = begin.$list;\r
530       expect(begin.$list).toBe($list);\r
531       expect(begin.updateList().$list).not.toBe($list);\r
532     } );\r
533     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
534     it("should be this for the value (the invalid partion)", function() {\r
535     } );\r
536     \r
537     describe("A trim method in $begin object", function() {\r
538       /*境界条件を調べておく (limit value analysis)*/\r
539       beforeEach( function() {\r
540         begin.string = "";\r
541       } );\r
542       it("should be this for the value  (limit value analysis)", function() {\r
543         delete begin.string;\r
544         expect(begin.trim(" ")).toBe("");\r
545         expect( function() {\r
546           begin.trim();\r
547         } ).toThrow();\r
548       } );\r
549       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
550       it("should be this for the value (the valid partion)", function() {\r
551         expect(begin.trim(" hoge ")).toBe("hoge");\r
552         expect(begin.trim(" h o g e ")).toBe("hoge");\r
553         expect(begin.trim(" h  o  g     e ")).toBe("hoge");\r
554         expect(begin.trim("   h  o  g    12 +  e   ")).toBe("hog12+e");\r
555       } );\r
556       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
557       it("should be this for the value (the invalid partion)", function() {\r
558         expect( function() {\r
559           begin.trim(1);\r
560         } ).toThrow();\r
561         expect( function() {\r
562           begin.trim({});\r
563         } ).toThrow();\r
564       } );\r
565     } );\r
566 \r
567     describe("An offset method in $begin object", function() {\r
568       beforeEach( function() {\r
569         begin.string = "";\r
570       } );\r
571       /*境界条件を調べておく (limit value analysis)*/\r
572       it("should be this for the value  (limit value analysis)", function() {\r
573         expect(begin.offset(begin.trim(" "))).toBe(0);\r
574         expect(begin.offset(begin.trim(" 0 "))).toBe(0);\r
575         expect(begin.offset(begin.trim("+0ms"))).toBe(0);\r
576         expect(begin.offset(begin.trim("-0ms"))).toBe(0);\r
577         expect(begin.offset(begin.trim("1ms"))).toBe(1);\r
578         expect(begin.offset(begin.trim("-1ms"))).toBe(-1);\r
579 \r
580         expect(begin.offset("+0s")).toBe(0);\r
581         expect(begin.offset("-0s")).toBe(0);\r
582         expect(begin.offset("1s")).toBe(1000);\r
583         expect(begin.offset("-1s")).toBe(-1000);\r
584 \r
585         expect(begin.offset("+0min")).toBe(0);\r
586         expect(begin.offset("-0min")).toBe(0);\r
587         expect(begin.offset("1min")).toBe(60000);\r
588         expect(begin.offset("-1min")).toBe(-60000);\r
589 \r
590         expect(begin.offset("+0h")).toBe(0);\r
591         expect(begin.offset("-0h")).toBe(0);\r
592         expect(begin.offset("1h")).toBe(60*60*1000);\r
593         expect(begin.offset("-1h")).toBe(-3600000);\r
594 \r
595         expect(begin.offset("00:0")).toBe(0);\r
596         expect(begin.offset("00:00:0.0")).toBe(0);\r
597         expect(begin.offset("-00:0")).toBe(0);\r
598         expect(begin.offset("-00:00:0.0")).toBe(0);\r
599         expect(begin.offset("00:1")).toBe(1000);\r
600         expect(begin.offset("-00:1")).toBe(-1000);\r
601         expect(begin.offset("00:00:1")).toBe(1000);\r
602         expect(begin.offset("-00:00:1")).toBe(-1000);\r
603 \r
604         expect(begin.offset()).toBe(0);\r
605       } );\r
606       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
607       it("should be this for the value (the valid partion)", function() {\r
608         expect(begin.offset(begin.trim(" + 0 ms"))).toBe(0);\r
609         expect(begin.offset(begin.trim(" -1m s "))).toBe(-1);\r
610         expect(begin.offset(begin.trim("1000ms"))).toBe(1000);\r
611         expect(begin.offset(begin.trim(" -1212ms"))).toBe(-1212);\r
612 \r
613         expect(begin.offset("+100s")).toBe(100 * 1000);\r
614         expect(begin.offset("-121s")).toBe(-121 * 1000);\r
615         expect(begin.offset("1.25s")).toBe(1.25 * 1000);\r
616         expect(begin.offset("-0.20s")).toBe(-0.20 * 1000);\r
617         expect(begin.offset(".20s")).toBe(0.20 * 1000);\r
618 \r
619         expect(begin.offset("+100min")).toBe(100 * 60000);\r
620         expect(begin.offset("-121min")).toBe(-121 * 60000);\r
621         expect(begin.offset("1.25min")).toBe(1.25 * 60000);\r
622         expect(begin.offset("-0.20min")).toBe(-0.20 * 60000);\r
623         expect(begin.offset(".20min")).toBe(0.20 * 60000);\r
624 \r
625         expect(begin.offset("+100h")).toBe(100 * 3600000);\r
626         expect(begin.offset("-121h")).toBe(-121 * 3600000);\r
627         expect(begin.offset("1.25h")).toBe(1.25 * 3600000);\r
628         expect(begin.offset("-0.20h")).toBe(-0.20 * 3600000);\r
629         expect(begin.offset(".20h")).toBe(0.20 * 3600000);\r
630 \r
631         expect(begin.offset("01:0")).toBe(60000);\r
632         expect(begin.offset("-01:0")).toBe(-60000);\r
633         expect(begin.offset("00:00:1")).toBe(1000);\r
634         expect(begin.offset("-00:00:1")).toBe(-1000);\r
635         expect(begin.offset("00:01:0")).toBe(60000);\r
636         expect(begin.offset("-00:01:0")).toBe(-60000);\r
637         expect(begin.offset("01:00:0")).toBe(3600000);\r
638         expect(begin.offset("-01:00:0")).toBe(-3600000);\r
639         expect(begin.offset("00:10")).toBe(10000);\r
640         expect(begin.offset("00:0.01")).toBe(10);\r
641         expect(begin.offset("01:0.01")).toBe(60010);\r
642         expect(begin.offset("10:0")).toBe(600000);\r
643         expect(begin.offset("-00:10")).toBe(-10000);\r
644         expect(begin.offset("-00:0.01")).toBe(-10);\r
645         expect(begin.offset("-01:0.01")).toBe(-60010);\r
646         expect(begin.offset("-10:0")).toBe(-600000);\r
647         expect(begin.offset("00:00:20")).toBe(20000);\r
648         expect(begin.offset("00:11:20")).toBe(11*60*1000 + 20000);\r
649         expect(begin.offset("12:11:20")).toBe(12*60*60*1000 + 11*60*1000 + 20000);\r
650         expect(begin.offset("-10:0")).toBe(-600000);\r
651         expect(begin.offset("-01:01:0.1")).toBe(-1*60*60*1000 - 60000 - 100);\r
652       } );\r
653       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
654       it("should be this for the value (the invalid partion)", function() {\r
655         expect(begin.offset(begin.trim(" h  o  g     1e "))).toBe(0);\r
656         expect(begin.offset("ms")).toBe(0);\r
657         expect(begin.offset(".s")).toBe(0);\r
658         expect(begin.offset("10:")).toBe(0);\r
659         expect(begin.offset("::")).toBe(0);\r
660         expect(begin.offset("-:0")).toBe(0);\r
661         expect(begin.offset("-::0")).toBe(0);\r
662       } );\r
663     } );\r
664     describe("An event method in $begin object", function() {\r
665       /*境界条件を調べておく (limit value analysis)*/\r
666       it("should be this for the value  (limit value analysis)", function() {\r
667         var evt = begin.event();\r
668         expect(evt.id).toBe("");\r
669         expect(evt.event).toBe("");\r
670         evt = begin.event("");\r
671         expect(evt.id).toBe("");\r
672         expect(evt.event).toBe("");\r
673         evt = begin.event(".");\r
674         expect(evt.id).toBe("");\r
675         expect(evt.event).toBe("");\r
676 \r
677         evt = begin.event("a");\r
678         expect(evt.id).toBe("");\r
679         expect(evt.event).toBe("a");\r
680         evt = begin.event("a.b");\r
681         expect(evt.id).toBe("a");\r
682         expect(evt.event).toBe("b");\r
683       } );\r
684       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
685       it("should be this for the value (the valid partion)", function() {\r
686         var evt = begin.event("id.event");\r
687         expect(evt.id).toBe("id");\r
688         expect(evt.event).toBe("event");\r
689         evt = begin.event("event");\r
690         expect(evt.id).toBe("");\r
691         expect(evt.event).toBe("event");\r
692         \r
693         evt = begin.event("event+0s");\r
694         expect(evt.id).toBe("");\r
695         expect(evt.event).toBe("event");\r
696         evt = begin.event("event-0s");\r
697         expect(evt.id).toBe("");\r
698         expect(evt.event).toBe("event");\r
699       } );\r
700       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
701       it("should be this for the value (the invalid partion)", function() {\r
702         evt = begin.event("...");\r
703         expect(evt.id).toBe("");\r
704         expect(evt.event).toBe("");\r
705         evt = begin.event(".event");\r
706         expect(evt.id).toBe("");\r
707         expect(evt.event).toBe("");\r
708         evt = begin.event("id.");\r
709         expect(evt.id).toBe("");\r
710         expect(evt.event).toBe("");\r
711       } );\r
712     } );\r
713     \r
714     describe("An parse method in $begin object", function() {\r
715        beforeEach( function() {\r
716         begin.string = "";\r
717       } );\r
718       /*境界条件を調べておく (limit value analysis)*/\r
719       it("should be this for the value  (limit value analysis)", function() {\r
720         expect(begin.parse().begin).toBe(0);\r
721         expect(begin.isResolved).toBeTruthy();\r
722         begin.string="+0";\r
723         expect(begin.parse().begin).toBe(0);\r
724         begin.string = "+1";\r
725         expect(begin.parse().begin).toBe(1000*begin.fpms);\r
726         begin.string = " ";\r
727         expect(begin.parse().begin).toBe(0);\r
728         begin.string = "1";\r
729         expect(begin.parse().begin).toBe(1000*begin.fpms);\r
730         begin.string = "+0ms";\r
731         expect(begin.parse().begin).toBe(0);\r
732         begin.string = "-0ms";\r
733         expect(begin.parse().begin).toBe(0);\r
734         begin.string = "-0ms;-0ms";\r
735         expect(begin.parse().begin).toBe(0);\r
736         begin.string = "-0ms;1";\r
737         expect(begin.parse().begin).toBe(1000*begin.fpms);\r
738         \r
739         expect(begin.eventOffset).toBe(0);\r
740         begin.string = "click";\r
741         expect(begin.parse().begin).toBe(0);\r
742         expect(begin.eventOffset).toBe(0);\r
743         expect(begin.repeat).toBe(0);\r
744         expect(begin.accessKey).toBe("");\r
745         begin.string = "id.click";\r
746         expect(begin.parse().begin).toBe(0);\r
747         expect(begin.eventOffset).toBe(0);\r
748         expect(begin.repeat).toBe(0);\r
749         expect(begin.accessKey).toBe("");\r
750         \r
751         begin.string = "repeat";\r
752         expect(begin.parse().begin).toBe(0);\r
753         expect(begin.eventOffset).toBe(0);\r
754         expect(begin.repeat).toBe(0);\r
755         expect(begin.accessKey).toBe("");\r
756         begin.string = "repeat(1)";\r
757         expect(begin.parse().begin).toBe(0);\r
758         expect(begin.eventOffset).toBe(0);\r
759         expect(begin.repeat).toBe(1);\r
760         expect(begin.accessKey).toBe("");\r
761         \r
762         begin.string = "accessKey(a)";\r
763         expect(begin.parse().begin).toBe(0);\r
764         expect(begin.eventOffset).toBe(0);\r
765         expect(begin.repeat).toBe(0);\r
766         expect(begin.accessKey).toBe("a");\r
767       } );\r
768       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
769       it("should be this for the value (the valid partion)", function() {\r
770         begin.string = " 1 0 0 m s";\r
771         expect(begin.parse().begin).toBe(Math.floor(100*begin.fpms));\r
772 \r
773         begin.string = "1ms";\r
774         begin.isResolved = false;\r
775         expect(begin.parse().begin).toBe(Math.floor(1*begin.fpms));\r
776         expect(begin.isResolved).toBeTruthy();\r
777         expect(begin.eventOffset).toBe(0);\r
778 \r
779         begin.string="click+0";\r
780         expect(begin.parse().begin).toBe(0);\r
781         expect(begin.eventOffset).toBe(0);\r
782         expect(begin.isResolved).toBeFalsy();\r
783         begin.string = "click+1";\r
784         expect(begin.parse().begin).toBe(1000*begin.fpms);\r
785         expect(begin.eventOffset).toBe(1000*begin.fpms);\r
786         begin.string = " click ";\r
787         expect(begin.parse().begin).toBe(0);\r
788         expect(begin.eventOffset).toBe(0);\r
789         begin.string = "click+0ms";\r
790         expect(begin.parse().begin).toBe(0);\r
791         expect(begin.eventOffset).toBe(0);\r
792         expect(begin.isResolved).toBeFalsy();\r
793         begin.string = "click-0ms";\r
794         expect(begin.parse().begin).toBe(0);\r
795         expect(begin.eventOffset).toBe(0);\r
796         begin.string = "click+100ms";\r
797         expect(begin.parse().begin).toBe(Math.floor(100*begin.fpms));\r
798         expect(begin.eventOffset).toBe(Math.floor(100*begin.fpms));\r
799         begin.string = "click-100ms";\r
800         expect(begin.parse().begin).toBe(Math.floor(-100*begin.fpms));\r
801         expect(begin.eventOffset).toBe(Math.floor(-100*begin.fpms));\r
802 \r
803         begin.string="id.click+0";\r
804         expect(begin.parse().begin).toBe(0);\r
805         expect(begin.eventOffset).toBe(0);\r
806         expect(begin.isResolved).toBeFalsy();\r
807         begin.string = "id.click+1";\r
808         expect(begin.parse().begin).toBe(1000*begin.fpms);\r
809         expect(begin.eventOffset).toBe(1000*begin.fpms);\r
810         expect(begin.isResolved).toBeFalsy();\r
811         begin.string = " id . click ";\r
812         expect(begin.parse().begin).toBe(0);\r
813         expect(begin.eventOffset).toBe(0);\r
814         expect(begin.isResolved).toBeFalsy();\r
815         begin.string = "id.click+0ms";\r
816         expect(begin.parse().begin).toBe(0);\r
817         expect(begin.eventOffset).toBe(0);\r
818         begin.string = "id.click-0ms";\r
819         expect(begin.parse().begin).toBe(0);\r
820         expect(begin.eventOffset).toBe(0);\r
821         begin.string = "id.click+100ms";\r
822         expect(begin.parse().begin).toBe(Math.floor(100*begin.fpms));\r
823         expect(begin.eventOffset).toBe(Math.floor(100*begin.fpms));\r
824         begin.string = "id.click-100ms";\r
825         expect(begin.parse().begin).toBe(Math.floor(-100*begin.fpms));\r
826         expect(begin.eventOffset).toBe(Math.floor(-100*begin.fpms));\r
827       } );\r
828       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
829       it("should be this for the value (the invalid partion)", function() {\r
830         begin.string = "ms";\r
831         begin.isResolved = false;\r
832         expect(begin.parse().begin).toBe(0);\r
833         expect(begin.isResolved).toBeFalsy();\r
834         \r
835         begin.isResolved = true;\r
836         begin.string = "indefinite";\r
837         expect(begin.parse().begin).toBe(Math.floor( Number.MAX_VALUE * begin.fpms));\r
838         expect(begin.isResolved).toBeFalsy();\r
839       } );\r
840     } );\r
841   } );\r
842   describe("A $end object", function() {\r
843     var end = base("$frame").$begin.$end.up();\r
844     end.startTime = 0;\r
845     beforeEach( function() {\r
846       end.string = "";\r
847       end.startTime = Date.now();\r
848       end.setFrame(0);\r
849     } );\r
850     /*境界条件を調べておく (limit value analysis)*/\r
851     it("should be this for the value  (limit value analysis)", function() {\r
852       expect(end.up().call()).toBeNull();\r
853       end.string = "0";\r
854       expect(end.up().call()).toBe(0);\r
855       end.string = "hoge";\r
856       expect(end.up().call()).toBe("indefinite");\r
857       \r
858     } );\r
859     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
860     it("should be this for the value (the valid partion)", function() {\r
861       end.string = "hoge+0";\r
862       expect(end.up().call()).toBe("indefinite");\r
863       end.string = "12ms";\r
864       expect(end.up().call()).toBe(Math.floor(12*end.fpms));\r
865       end.string = "hoge+12ms";\r
866       expect(end.up().call()).toBe("indefinite");\r
867 \r
868     } );\r
869     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
870     it("should be this for the value (the invalid partion)", function() {\r
871       end.string = null;\r
872       expect(end.up().call()).toBeNull();\r
873     } );\r
874   } );\r
875   describe("A $activate object", function() {\r
876     var act = base("$frame").$begin.$activate.up();\r
877      beforeEach( function() {\r
878       act.dur = "indefinite";\r
879       act.begin = 0;\r
880       act.repeatCount = null;\r
881       act.repeatDur = null;\r
882       act.end = act.$begin.$end;\r
883       act.simpleDur = base("$frame").$begin.$activate.simpleDur;\r
884     } );\r
885     /*境界条件を調べておく (limit value analysis)*/\r
886     it("should be this for the value  (limit value analysis)", function() {\r
887       expect(act.dur).toBe("indefinite");\r
888       expect(typeof act.resolvedTime).toBe("function");\r
889       expect(act.end).toBe(act.$begin.$end);\r
890       expect(act.repeatCount).toBeNull();\r
891       expect(act.repeatDur).toBeNull();\r
892       expect(act.simpleDur()).toBeNull();\r
893       expect(act.min).toBe("0");\r
894       expect(act.max).toBe("indefinite");\r
895 \r
896       act.up("$a");\r
897       expect(act.$a.call()).toBeNull();\r
898       expect(act.$a.end).toBeNull();\r
899     } );\r
900     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
901     it("should be this for the value (the valid partion)", function() {\r
902       expect(act.resolvedTime()).not.toBe(0);\r
903 \r
904       /*Activate Duration = dur*/\r
905       act.up("$b");\r
906       act.$b.dur = "132ms";\r
907       var abc = act.$b.call();\r
908       expect(abc).toBe(Math.floor(132*act.fpms));\r
909       expect(abc).toBe(act.$b.simpleDur);\r
910       act.dur = null;\r
911       expect(act.up().call()).toBeNull();\r
912 \r
913       act.up("$c");\r
914       act.$c.mix( {\r
915         dur: "10",\r
916         simpleDur: act.simpleDur,
917         repeatCount: null,\r
918         repeatDur: null\r
919       } );\r
920       expect(act.$c.call()).toBe(Math.floor(10000*act.fpms));\r
921       expect(act.$c.call()).toBe(act.$c.simpleDur);\r
922       act.$c.mix( {\r
923         dur: "15",\r
924         simpleDur: act.simpleDur,
925         repeatCount: null,\r
926         repeatDur: null\r
927       } );\r
928       expect(act.$c.call()).toBe(Math.floor(15000*act.fpms));\r
929 \r
930       /*AD = repeatCount*dur*/\r
931       act.$c.mix( {\r
932         dur: "10",\r
933         simpleDur: act.simpleDur,
934         repeatCount: 2,\r
935         repeatDur: null\r
936       } );\r
937       act.$c.call();\r
938       expect(act.$c.simpleDur).toBe(Math.floor(10000*act.fpms));\r
939       act.$c.mix( {\r
940         dur: "10",\r
941         simpleDur: act.simpleDur,
942         repeatCount: 1,\r
943         repeatDur: null\r
944       } );\r
945       expect(act.$c.call()).toBe(Math.floor(10000*act.fpms));\r
946       expect(act.$c.simpleDur).toBe(Math.floor(10000*act.fpms));\r
947 \r
948       /*AD = repeatDur*/\r
949       act.$c.mix( {\r
950         dur: "indefinite",\r
951         simpleDur: act.simpleDur,
952         repeatCount: 2,\r
953         repeatDur: "15"\r
954       } );\r
955       act.$c.call();\r
956       expect(act.$c.simpleDur).toBeNull();\r
957       act.$c.mix( {\r
958         dur: "indefinite",\r
959         simpleDur: act.simpleDur,
960         repeatCount: 2,\r
961         repeatDur: "10"\r
962       } );\r
963       expect(act.$c.call()).toBe(Math.floor(10000*act.fpms));\r
964       expect(act.$c.simpleDur).toBeNull();\r
965       act.$c.mix( {\r
966         dur: "10",\r
967         simpleDur: act.simpleDur,
968         repeatCount: null,\r
969         repeatDur: "15"\r
970       } );\r
971       act.$c.call();\r
972       expect(act.$c.simpleDur).toBe(Math.floor(10000*act.fpms));\r
973       act.$c.mix( {\r
974         dur: "10",\r
975         simpleDur: act.simpleDur,
976         repeatCount: null,\r
977         repeatDur: "11"\r
978       } );\r
979       expect(act.$c.call()).toBe(Math.floor(11000*act.fpms));\r
980       expect(act.$c.simpleDur).toBe(Math.floor(10000*act.fpms));\r
981       \r
982       /*AD = Min(repeatCount*d, repeatDur)*/\r
983       act.$c.mix( {\r
984         dur: "10",\r
985         simpleDur: act.simpleDur,
986         repeatCount: 2,\r
987         repeatDur: "15"\r
988       } );\r
989       act.$c.call();\r
990       expect(act.$c.simpleDur).toBe(Math.floor(10000*act.fpms));\r
991       act.$c.mix( {\r
992         dur: "10",\r
993         simpleDur: act.simpleDur,
994         repeatCount: 1,\r
995         repeatDur: "15"\r
996       } );\r
997       expect(act.$c.call()).toBe(Math.floor(10000*act.fpms));\r
998       expect(act.$c.simpleDur).toBe(Math.floor(10000*act.fpms));\r
999       act.$c.mix( {\r
1000         dur: "11",\r
1001         simpleDur: act.simpleDur,
1002         repeatCount: 1,\r
1003         repeatDur: "9"\r
1004       } );\r
1005       expect(act.$c.call()).toBe(Math.floor(9000*act.fpms));\r
1006       expect(act.$c.simpleDur).toBe(Math.floor(11000*act.fpms));\r
1007 \r
1008       /*AD = repeatDur,*/\r
1009       act.$c.mix( {\r
1010         end: null,\r
1011         dur: "10",\r
1012         simpleDur: act.simpleDur,
1013         repeatCount: null,\r
1014         repeatDur: "15"\r
1015       } );\r
1016       expect(act.$c.call()).toBe(Math.floor(15000*act.fpms));\r
1017       expect(act.$c.simpleDur).toBe(Math.floor(10000*act.fpms));\r
1018       act.$c.mix( {\r
1019         dur: "indefinite",\r
1020         simpleDur: act.simpleDur,
1021         repeatCount: 2,\r
1022         repeatDur: "10"\r
1023       } );\r
1024       expect(act.$c.call()).toBe(Math.floor(10000*act.fpms));\r
1025       expect(act.$c.simpleDur).toBeNull();\r
1026 \r
1027       act.end.string = null;\r
1028       act.up("$cd").mix( {\r
1029         dur: "10",\r
1030         end: act.end,\r
1031         repeatCount: 2\r
1032       } );\r
1033       expect(act.$cd.call()).toBe(Math.floor(10000*act.fpms) * 2);\r
1034       \r
1035       act.$cd.end = act.end;\r
1036       act.$cd.repeatCount = null;\r
1037       act.$cd.repeatDur = "12";\r
1038       expect(act.$cd.call()).toBe(Math.floor(12000*act.fpms));\r
1039       \r
1040       act.up("$d").mix( {\r
1041         min: "2",\r
1042         max: "3",\r
1043         dur: "1",\r
1044         simpleDur: act.simpleDur\r
1045       } );\r
1046       expect(act.$d.call()).toBe(Math.floor(2000*act.fpms));\r
1047       act.up("$d").mix( {\r
1048         min: "1",\r
1049         max: "2",\r
1050         dur: "12",\r
1051         simpleDur: act.simpleDur\r
1052       } );\r
1053       expect(act.$d.call()).toBe(Math.floor(2000*act.fpms));\r
1054       \r
1055       /*endで0が指定されている場合*/\r
1056       act.begin = 0;\r
1057       act.end = 0;\r
1058       act.repeatDur = null;\r
1059       act.repeatCount = "indefinite";\r
1060       act.dur = "1";\r
1061       expect(act.call()).toBeNull();\r
1062       act.repeatCount = null;\r
1063       act.repeatDur = "indefinite";\r
1064       act.dur = "1";\r
1065       expect(act.call()).toBeNull();\r
1066       act.repeatDur = "indefinite";\r
1067       act.repeatCount = "indefinite";\r
1068       act.dur = "1";\r
1069       expect(act.call()).toBeNull();\r
1070     } );\r
1071     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1072     it("should be this for the value (the invalid partion)", function() {\r
1073       /*min > max*/\r
1074       act.up("$d").mix( {\r
1075         min: "3",\r
1076         max: "2",\r
1077         dur: "1",\r
1078         simpleDur: act.simpleDur\r
1079       } );\r
1080       expect(act.$d.call()).toBe(Math.floor(1000*act.fpms));\r
1081       \r
1082       act.repeatDur = null;\r
1083       act.repeatCount = "indefinite";\r
1084       act.dur = "1";\r
1085       expect(act.call()).toBeNull();\r
1086       act.repeatCount = null;\r
1087       act.repeatDur = "indefinite";\r
1088       act.dur = "1";\r
1089       expect(act.call()).toBeNull();\r
1090       act.repeatDur = "indefinite";\r
1091       act.repeatCount = "indefinite";\r
1092       act.dur = "1";\r
1093       expect(act.call()).toBeNull();\r
1094     } );\r
1095   } );\r
1096   describe("A $from object", function() {\r
1097     var from = base("$from");\r
1098      beforeEach( function() {\r
1099        from = base("$from").up();\r
1100        from.from = from.from.up();\r
1101        from.string = "";\r
1102      } );\r
1103     /*境界条件を調べておく (limit value analysis)*/\r
1104     it("should be this for the value  (limit value analysis)", function() {\r
1105       expect(from.string).toBe("");\r
1106       expect(from.numList()).toEqual([]);\r
1107       expect(from.strList()).toBeNull();\r
1108 \r
1109       from.string = "0";\r
1110       expect(from.numList()[0]).toBe(0);\r
1111       expect(from.strList()).toBeNull();\r
1112       \r
1113       from.string = " 0 ";\r
1114       expect(from.numList()[0]).toBe(0);\r
1115       expect(from.strList().join("")).toBe("  ");\r
1116 \r
1117       from.string = "a";\r
1118       expect(from.numList()).toEqual([]);\r
1119       expect(from.strList()[0]).toBe("a");\r
1120       \r
1121       /*前後の空白を除去する処理をしない。なぜなら、文字列リストの空白は保持するのが望ましいから\r
1122        * 文字列リストの空白を除去した例: "M 20 20 M M" -> "M20 20 MM"となってしまう*/\r
1123       \r
1124       from.string = null;\r
1125       expect( function() {\r
1126         from.numList();\r
1127       } ).toThrow();\r
1128       expect( function() {\r
1129         from.strList();\r
1130       } ).toThrow();\r
1131       \r
1132       expect(from.additive[0]).toBe(0);\r
1133       expect(from.accumulate[0]).toBe(0);\r
1134     } );\r
1135     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1136     it("should be this for the value (the valid partion)", function() {\r
1137       from.string = "0a";\r
1138       expect(from.numList()[0]).toBe(0);\r
1139       expect(from.strList()[0]).toBe("a");\r
1140 \r
1141       from.string = "a0";\r
1142       expect(from.numList()[0]).toBe(0);\r
1143       expect(from.strList()[0]).toBe("a");\r
1144 \r
1145       from.string = "0.1";\r
1146       expect(from.numList()[0]).toBe(0.1);\r
1147       expect(from.strList()).toBeNull();\r
1148 \r
1149       from.string = "+0.1";\r
1150       expect(from.numList()[0]).toBe(0.1);\r
1151       expect(from.strList()).toBeNull();\r
1152 \r
1153       from.string = "-0.1";\r
1154       expect(from.numList()[0]).toBe(-0.1);\r
1155       expect(from.strList()).toBeNull();\r
1156 \r
1157       from.string = "1e-1";\r
1158       expect(from.numList()[0]).toBe(1e-1);\r
1159       expect(from.strList()).toBeNull();\r
1160 \r
1161       from.string = "1E-1";\r
1162       expect(from.numList()[0]).toBe(1E-1);\r
1163       expect(from.strList()).toBeNull();\r
1164 \r
1165       from.string = "0,0";\r
1166       expect(from.numList().toString()).toBe("0,0");\r
1167       expect(from.strList().join("")).toBe(",");\r
1168 \r
1169       from.string = "a00a";\r
1170       expect(from.numList()[0]).toBe(0);\r
1171       expect(from.strList().join("")).toBe("aa");\r
1172 \r
1173       from.string = "a0b0a";\r
1174       expect(from.numList().toString()).toBe("0,0");\r
1175       expect(from.strList().join("")).toBe("aba");\r
1176 \r
1177       from.string = "0b0a";\r
1178       expect(from.numList().toString()).toBe("0,0");\r
1179       expect(from.strList().join("")).toBe("ba");\r
1180 \r
1181       from.string = "0b-1.0a";\r
1182       expect(from.numList()[1]).toBe(-1);\r
1183       expect(from.strList().join("")).toBe("ba");\r
1184 \r
1185       expect(from.up().call()).toBe(from.$1.numList);\r
1186       expect(from.$1.numList[1]).toBe(-1);\r
1187       expect(from.$1.strList.join("")).toBe("ba");\r
1188 \r
1189       from.string = "あ 0b-1.0a12";\r
1190       expect(from.numList()[1]).toBe(-1);\r
1191       expect(from.strList().join("")).toBe("あ ba12");\r
1192 \r
1193       from.string = "0b-1.0a0";\r
1194       expect(from.numList().join(",")).toBe("0,-1,0");\r
1195       expect(from.strList().join("")).toBe("ba");\r
1196 \r
1197       from.string = "0b .1a";\r
1198       expect(from.numList()[1]).toBe(0.1);\r
1199       expect(from.strList().join("")).toBe("b a");\r
1200     } );\r
1201     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1202     it("should be this for the value (the invalid partion)", function() {\r
1203       from.string = NaN;\r
1204       expect(function(){\r
1205         from.numList();\r
1206       } ).toThrow();\r
1207       expect(function(){\r
1208         from.strList();\r
1209       } ).toThrow();      \r
1210       \r
1211       from.string = "currentColor";\r
1212       expect(from.numList()).toEqual([]);\r
1213       expect(from.strList()[0]).toBe("currentColor");\r
1214 \r
1215       from.string = "eE";\r
1216       expect(from.numList()).toEqual([]);\r
1217       expect(from.strList()[0]).toBe("eE");\r
1218       expect(from.strList()[0]).toBe("eE");\r
1219     } )\r
1220   } );\r
1221   describe("A $to object", function() {\r
1222     var from = base("$from");\r
1223      beforeEach( function() {\r
1224        from = base("$from").up();\r
1225        from.up("$to");\r
1226        from.string = "";\r
1227      } );\r
1228     /*境界条件を調べておく (limit value analysis)*/\r
1229     it("should be this for the value  (limit value analysis)", function() {\r
1230       expect(from.$to instanceof from.constructor).toBeTruthy();\r
1231       expect(from.up().call()).toBe(from.$1.numList);\r
1232       expect(from.$to.up().call()).toBe(from.$to.$1.numList);\r
1233     } );\r
1234     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1235     it("should be this for the value (the valid partion)", function() {\r
1236       from.up("$to");\r
1237       from.$to.from = from;\r
1238       from.$to.string = "12cm-7";\r
1239       expect(from.$to.numList().join(",")).toBe("12,-7");\r
1240       expect(from.$to.strList().toString()).toBe("cm");\r
1241       \r
1242       from.string = "7cm+8";\r
1243       from.$to.call();\r
1244       expect(from.call()).toBe(from.numList);\r
1245       expect(from.$to.numList.join(",")).toBe("12,-7");\r
1246       expect(from.$to.strList.join("")).toBe("cm");\r
1247       expect(from.numList.join(",")).toBe("7,8");\r
1248       expect(from.strList.join("")).toBe("cm");\r
1249       expect(from.$to.from).toBe(from.numList);\r
1250 \r
1251     } );\r
1252     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1253     it("should be this for the value (the invalid partion)", function() {\r
1254       from.call();\r
1255       from.up("$to").mix( function() {\r
1256         this.string = "12cm";\r
1257         this.call();\r
1258         var arr = [];\r
1259         arr.string = this.string;\r
1260         expect(this.numList).toEqual(arr);\r
1261         expect(this.strList).toBeNull();\r
1262       } );\r
1263     } );\r
1264     \r
1265     describe("An advance method", function() {\r
1266       var from = base("$from");\r
1267        beforeEach( function() {\r
1268          from = base("$from").up();\r
1269          from.string = "";\r
1270          from.up("$to");\r
1271          from.$to.from = from;\r
1272        } );\r
1273       /*境界条件を調べておく (limit value analysis)*/\r
1274       it("should be this for the value  (limit value analysis)", function() {\r
1275         expect(from.advance()).toBe("");\r
1276         expect(from.$to.advance()).toBe("");\r
1277         expect(from.$to.advance(0)).toBe("");\r
1278         expect(from.$to.advance(1)).toBe("");\r
1279         expect(function(){\r
1280           from.$to.advance(1.01);\r
1281         }).toThrow("An Invalid Number Error");\r
1282         expect(function(){\r
1283           from.$to.advance(-0.01);\r
1284         }).toThrow("An Invalid Number Error");\r
1285         \r
1286         var arr = [];\r
1287         \r
1288         from = base("$from").up();\r
1289         from.up("$to");\r
1290         from.$to.from = from;\r
1291         arr.string = from.string = "0";\r
1292         from.$to.string = "1";\r
1293         expect(from.$to.call()).toBe(from.$to.numList);\r
1294         expect(from.$to.numList[0]).toBe(1);\r
1295         expect(from.$to.strList).toBeNull();\r
1296         expect(from.numList[0]).toBe(0);\r
1297         expect(from.strList).toBeNull();\r
1298         expect(from.advance(0)).toBe("");\r
1299         expect(from.$to.from).toBe(from.numList);\r
1300         expect(from.$to.advance(0)).toBe("0");       \r
1301         expect(from.call()).toBe(from.numList);\r
1302         \r
1303         from = base("$from").up();\r
1304         f(from.up(), "inline", "block");\r
1305         f(from.up(), " inline", " block ");\r
1306         function f(from, inline, block) {\r
1307           from.up("$to");\r
1308           from.$to.from = from;\r
1309           from.string = inline;\r
1310           arr.string = from.$to.string = block;\r
1311           expect(from.$to.call()).toBe(from.$to.numList);\r
1312           expect(from.$to.numList).toEqual(arr);\r
1313           expect(from.$to.strList).toEqual([block]);\r
1314           arr.string = from.string;\r
1315           expect(from.numList).toEqual(arr);\r
1316           expect(from.strList).toEqual([inline]);\r
1317           expect(from.advance(0)).toBe("");\r
1318           expect(from.$to.from).toBe(from.numList);\r
1319           expect(from.$to.advance(0)).toBe("inline");\r
1320           expect(from.$to.advance(1)).toBe("block");\r
1321           expect(from.call()).toBe(from.numList);\r
1322         }\r
1323       } );\r
1324       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1325       it("should be this for the value (the valid partion)", function() {\r
1326         var deg = 3;\r
1327         \r
1328         from.string = "0s";\r
1329         from.$to.string = "1s";\r
1330         expect(from.$to.call()).toBe(from.$to.numList);\r
1331         expect(from.$to.numList[0]).toBe(1);\r
1332         expect(from.$to.strList[0]).toBe("");\r
1333         expect(from.numList[0]).toBe(0);\r
1334         expect(from.strList[0]).toBe("");\r
1335         expect(from.advance(0)).toBe("");\r
1336         expect(from.$to.from).toBe(from.numList);\r
1337         expect(from.$to.advance(0)).toBe("0s");\r
1338         from.$to.degit = deg;\r
1339         for (var i=0;i<1;i+=0.01) {\r
1340           expect(from.$to.advance(i)).toBe(i.toFixed(deg)+"s");\r
1341         }\r
1342         expect(from.call()).toBe(from.numList);\r
1343         \r
1344         from = base("$from").up();\r
1345         from.up("$to");\r
1346         from.string = "a0S";\r
1347         from.$to.string = "a1S";\r
1348         from.$to.from = from;\r
1349         expect(from.$to.call()).toBe(from.$to.numList);\r
1350         expect(from.$to.numList[0]).toBe(1);\r
1351         expect(from.$to.strList[0]).toBe("a");\r
1352         expect(from.numList[0]).toBe(0);\r
1353         expect(from.strList[0]).toBe("a");\r
1354         expect(from.advance(0)).toBe("");\r
1355         expect(from.$to.from).toBe(from.numList);\r
1356         expect(from.$to.advance(0)).toBe("a0S");\r
1357 \r
1358         from.$to.degit = deg;\r
1359         for (var i=0;i<1;i+=0.01) {\r
1360           expect(from.$to.advance(i)).toBe("a" +i.toFixed(deg)+ "S");\r
1361         }\r
1362         expect(from.call()).toBe(from.numList);\r
1363         \r
1364         from = base("$from").up();\r
1365         f(from.up(), "a-10s1.5", "a10s-3");\r
1366         f(from.up(), " a-10s1.5", " a10s-3 ");\r
1367         function f(from, fromString, toString) {\r
1368           from.up("$to");\r
1369           from.string = fromString;\r
1370           from.$to.string = toString;\r
1371           from.$to.from = from;\r
1372           from.$to.call();\r
1373           from.$to.degit = 1;\r
1374           expect(from.$to.advance(0)).toBe("a-10.0s1.5");\r
1375           expect(from.$to.advance(0.4)).toBe("a-2.0s-0.3");\r
1376           expect(from.$to.advance(1)).toBe("a10.0s-3.0");\r
1377 \r
1378           from.$to.additive[0] = 1;\r
1379           from.$to.accumulate[1] = 2;\r
1380           expect(from.$to.advance(0.4)).toBe("a-1.0s1.7");\r
1381           from.$to.additive[0] = 0.5;\r
1382           from.$to.accumulate[1] = 0.8;\r
1383           expect(from.$to.advance(1)).toBe("a10.5s-2.2");\r
1384         }\r
1385       } );\r
1386       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1387       it("should be this for the value (the invalid partion)", function() {\r
1388         expect(function(){\r
1389           from.$to.advance(10);\r
1390         }).toThrow("An Invalid Number Error");\r
1391         expect(function(){\r
1392           from.$to.advance(-10);\r
1393         }).toThrow("An Invalid Number Error");\r
1394       } );\r
1395     } )\r
1396   } );\r
1397   describe("A distance method", function() {\r
1398       var from = base("$from");\r
1399        beforeEach( function() {\r
1400          from = base("$from").up();\r
1401          from.string = "";\r
1402          from.up("$to");\r
1403        } );\r
1404       /*境界条件を調べておく (limit value analysis)*/\r
1405       it("should be this for the value  (limit value analysis)", function() {\r
1406         expect(from.distance()).toBe(0)\r
1407         expect(from.$to.distance()).toBe(0);\r
1408         \r
1409         from.string = "0";\r
1410         from.$to.string = "1";\r
1411         expect(from.distance()).toBe(0);\r
1412         expect(from.$to.distance(from)).toBe(1);\r
1413       } );\r
1414       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1415       it("should be this for the value (the valid partion)", function() {\r
1416         from.string = "s 0 s 12";\r
1417         from.$to.string = "s 0 s 0";\r
1418         expect(from.distance()).toBe(0);\r
1419         expect(from.$to.distance(from)).toBe(12);\r
1420         expect(from.$to.distance(from)).toBe(12);\r
1421         expect(from.$to.distance(from.call())).toBe(12);\r
1422   \r
1423         from = base("$from").up();\r
1424         from.up("$to");\r
1425         from.string = "rgb(1, 0, 0)";\r
1426         from.$to.string = "rgb(0, 0, 1)";\r
1427         expect(from.distance()).toBe(0);\r
1428         expect(from.$to.distance(from)).toBe(Math.sqrt(2));\r
1429       } );\r
1430       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1431       it("should be this for the value (the invalid partion)", function() {\r
1432         from.string = "s";\r
1433         from.$to.string = "s";\r
1434         expect(from.$to.distance(from)).toBe(0);\r
1435       } );\r
1436   } );\r
1437   describe("A setAdditive method", function() {\r
1438       var from = base("$from");\r
1439        beforeEach( function() {\r
1440          from = base("$from").up();\r
1441          from.string = "";\r
1442          from.up("$to");\r
1443        } );\r
1444       /*境界条件を調べておく (limit value analysis)*/\r
1445       it("should be this for the value  (limit value analysis)", function() {\r
1446         expect(from.setAdditive()).toBe(0);\r
1447         expect(from.setAdditive("")).toBe(0);\r
1448         expect(from.additive).toEqual([0]);\r
1449         var arr = [1];\r
1450         arr.string = "1";\r
1451         expect(from.setAdditive("1")).toEqual(arr);\r
1452         expect(from.additive).toEqual(arr);\r
1453       } );\r
1454       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1455       it("should be this for the value (the valid partion)", function() {\r
1456         var arr = [1, 2, 3];\r
1457         arr.string = "1 2, 3";\r
1458         expect(from.setAdditive("1 2, 3")).toEqual(arr);\r
1459         expect(from.additive).toEqual(arr);\r
1460       } );\r
1461       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1462       it("should be this for the value (the invalid partion)", function() {\r
1463       } );\r
1464   } );\r
1465   describe("A setAccumulate method", function() {\r
1466       var from = base("$from");\r
1467        beforeEach( function() {\r
1468          from = base("$from").up();\r
1469          from.string = "0 1";\r
1470          from.up("$to");\r
1471          from.call();\r
1472        } );\r
1473       /*境界条件を調べておく (limit value analysis)*/\r
1474       it("should be this for the value  (limit value analysis)", function() {\r
1475         expect(from.setAccumulate()).toBe(0);\r
1476         expect(from.setAccumulate(0)).toBe(0);\r
1477         expect(from.accumulate).toEqual([0, 0]);\r
1478         expect(from.setAccumulate(1)).toEqual([0, 1]);\r
1479         expect(from.accumulate).toEqual([0, 1]);\r
1480       } );\r
1481       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1482       it("should be this for the value (the valid partion)", function() {\r
1483         expect(from.setAccumulate(2)).toEqual([0, 2]);\r
1484         expect(from.accumulate).toEqual([0, 2]);\r
1485       } );\r
1486       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1487       it("should be this for the value (the invalid partion)", function() {\r
1488         expect(from.setAccumulate(NaN)).toEqual(0);\r
1489       } );\r
1490   } );\r
1491   describe("A $calcMode object", function() {\r
1492     var calc = base("$calcMode"),\r
1493         to = calc.to,\r
1494         from;\r
1495      beforeEach( function() {\r
1496        calc = base("$calcMode").up();\r
1497        calc.to = base("$from").up().mix( {string: "1"} );\r
1498        from = calc.to.from = base("$from").up().mix( {string: "0"} );\r
1499      } );\r
1500     /*境界条件を調べておく (limit value analysis)*/\r
1501     it("should be this for the value  (limit value analysis)", function() {\r
1502       expect(calc.mode).toBe("linear");\r
1503       expect(calc.keyTime).toBe(1);\r
1504       expect(calc.keySplines).toBeNull();\r
1505       expect(calc.string).toBe("");\r
1506 \r
1507       expect(calc.call()(0)).toBe("0");\r
1508       expect(calc.keyTime).toBe(1);\r
1509       expect(calc.call()(1)).toBe("1");\r
1510       \r
1511       calc.keyTime = 0;\r
1512       expect(calc.call()(1)).toBe("0");\r
1513       \r
1514       /*paced mode*/\r
1515       calc.mode = "paced";\r
1516       expect(calc.norm).toBe(1);\r
1517       calc.to.from = from;\r
1518       expect(calc.call()(0)).toBe("0");\r
1519       expect(calc.keyTime).toBe(1);\r
1520       calc.to.from = from;\r
1521       expect(calc.call()(1)).toBe("1");\r
1522       \r
1523       calc.keyTime = 0;\r
1524       calc.to.from = from;\r
1525       expect(calc.call()(1)).toBe("1");\r
1526       \r
1527       /*discrete mode*/\r
1528       calc.mode = "discrete";\r
1529       calc.to.from = from;\r
1530       calc.keyTime = 1;\r
1531       expect(calc.call()(0)).toBe("0");\r
1532       expect(calc.call()(1)).toBe("1");\r
1533     } );\r
1534     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1535     it("should be this for the value (the valid partion)", function() {\r
1536       calc.mode = "linear";\r
1537       calc.keyTime = 0.5;\r
1538       calc.to.degit = 1;\r
1539       expect(calc.call()(0.2)).toBe("0.4");\r
1540       expect(calc.call()(0.3)).toBe("0.6");\r
1541       /*もう一度確かめる*/\r
1542       expect(calc.call()(0.2)).toBe("0.4");\r
1543       \r
1544       calc = base("$calcMode").up();\r
1545       calc.keyTime = 0.2;\r
1546       calc.to = base("$from").up();\r
1547       calc.to.from = base("$from").up();    \r
1548       calc.to.from.string = "0s";\r
1549       calc.to.string = "1s";\r
1550       calc.to.degit = 1;\r
1551       expect(calc.call()(0.1)).toBe("0.5s");\r
1552 \r
1553       calc = base("$calcMode").up();\r
1554       calc.keyTime = 0.5;\r
1555       calc.to = base("$from").up();\r
1556       calc.to.from = base("$from").up();    \r
1557       calc.to.from.string = "rgb(100, 20, 32)";\r
1558       calc.to.string = "rgb(0, 10, 50)";\r
1559       expect(calc.call()(0.25)).toBe("rgb(50, 15, 41)");\r
1560       \r
1561       /*paced mode*/\r
1562       calc.to = base("$from").up();\r
1563       calc.to.from = base("$from").up();    \r
1564       calc.mode = "paced";\r
1565       calc.norm = 100;\r
1566       calc.to.from.string = "0s";\r
1567       calc.to.string = "20s";\r
1568       calc.to.degit = 1;\r
1569       expect(calc.call()(0.1)).toBe("10.0s");\r
1570       expect(calc.keyTime).toBe(0.2);\r
1571 \r
1572       calc.to = base("$from").up();\r
1573       calc.to.from = base("$from").up();    \r
1574       calc.mode = "paced";\r
1575       calc.norm = 100;\r
1576       calc.to.from.string = "rgb(0, 0, 20)";\r
1577       calc.to.string = "rgb(0, 0, 0)";\r
1578       expect(calc.call()(0.1)).toBe("rgb(0, 0, 10)");\r
1579       expect(calc.keyTime).toBe(0.2);\r
1580       \r
1581       /*discrete mode*/\r
1582       calc.to = base("$from").up();\r
1583       calc.to.from = base("$from").up();    \r
1584       calc.mode = "discrete";\r
1585       calc.keyTime = 0.5;\r
1586       calc.to.degit = 1;\r
1587       calc.to.string = "1";\r
1588       calc.to.from.string = "0.5";\r
1589       expect(calc.call()(0.2)).toBe("0.5");\r
1590       expect(calc.call()(0.3)).toBe("0.5");\r
1591       /*もう一度確かめる*/\r
1592       expect(calc.call()(0.2)).toBe("0.5");\r
1593       \r
1594       calc.to = base("$from").up();\r
1595       calc.to.from = base("$from").up();    \r
1596       calc.mode = "discrete";\r
1597       calc.keyTime = 0.5;\r
1598       calc.to.degit = 1;\r
1599       calc.to.string = "block";\r
1600       calc.to.from.string = "inline";\r
1601       expect(calc.call()(0.2)).toBe("inline");\r
1602       expect(calc.call()(0.3)).toBe("inline");\r
1603       \r
1604       calc.to = base("$from").up();\r
1605       calc.to.from = base("$from").up();    \r
1606       calc.mode = "linear";\r
1607       calc.keyTime = 1;\r
1608       calc.to.degit = 1;\r
1609       calc.to.string = "1 1";\r
1610       calc.to.from.string = "0.0 1";\r
1611       expect(calc.call()(0.2)).toBe("0.2 1.0");\r
1612       expect(calc.call()(0.3)).toBe("0.3 1.0");\r
1613     } );\r
1614     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1615     it("should be this for the value (the invalid partion)", function() {\r
1616       calc.keyTime = null;\r
1617       expect(calc.call()(1)).toBe(calc.string);\r
1618       \r
1619       calc.keyTime = void 0;\r
1620       expect(calc.call()(1)).toBe(calc.string);\r
1621       \r
1622       calc.keyTime = 1/0;\r
1623       expect(calc.call()(1)).toBe(calc.string);\r
1624 \r
1625       expect(calc.call()()).toBe(calc.string);\r
1626 \r
1627       calc = base("$calcMode").up();\r
1628       calc.mode = "paced";\r
1629       calc.to.from = from;\r
1630       expect(calc.call()()).toBe(calc.string);\r
1631       \r
1632       calc = base("$calcMode").up();\r
1633       calc.mode = "discrete";\r
1634       expect(calc.call()()).toBe(calc.string);\r
1635     } );\r
1636     \r
1637     /*splineモードの境界条件を調べておく (limit value analysis)*/\r
1638     it("should be this for the value  (spline mode limit value analysis)", function() {\r
1639       /*3次ベジェ曲線の数式はこのページを参考にした http://opentype.jp/fontguide_doc3.htm*/\r
1640       var x = 0,\r
1641           y = 0,\r
1642           bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) {\r
1643             return function (t) {\r
1644               x = (x4-3*(x3-x2)-x1)*t*t*t + 3*(x3-2*x2+x1)*t*t + 3*(x2-x1)*t + x1;\r
1645               y = (y4-3*(y3-y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1;\r
1646               return y;\r
1647             };\r
1648           };\r
1649       expect(calc.keySplines).toBeNull();\r
1650       calc.mode = "spline";\r
1651       expect( calc.call()("undef")).toBe(Math.PI);\r
1652       calc.keySplines = [0, 0, 1, 1];\r
1653       calc.to.degit = 1;\r
1654       calc.to.from = from;\r
1655       expect(calc.call()(0)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(0)+".0");\r
1656       calc.to.from = from;\r
1657       expect(calc.call()(1)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(1)+".0");\r
1658       calc.to.from = from;\r
1659       expect(calc.call()(0.5)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(0.5)+"");\r
1660       \r
1661       df(0,0, 0,0, 1,1, 1,1, 0.1);\r
1662       df(0,0, 0,0, 1,1, 1,1, 0.5);\r
1663       df(0,0, 0,0, 1,1, 1,1, 0.8);\r
1664       df(0,0, 0,0, 1,1, 1,1, 0.9);\r
1665       df(0,0, 0.75,0, 0,0.75, 1,1, 0.1);\r
1666       df(0,0, 0.75,0, 0,0.75, 1,1, 0.5);\r
1667       df(0,0, 0.75,0, 0,0.75, 1,1, 0.8);\r
1668       df(0,0, 0.75,0, 0,0.75, 1,1, 0.9);\r
1669       function df (x1, y1, x2, y2, x3, y3, x4, y4, t) {\r
1670       /*自作のニュートン法*/\r
1671         var a = y4-3*(y3-y2)-y1,\r
1672             b = 3*(y3-2*y2+y1),\r
1673             c = 3*(y2-y1),\r
1674             d = y1 - bezier.apply(null, arguments)(t);\r
1675         expect(Math.abs(Math.qubicnewton(a, b, c, d, t) - t)).toBeLessThan(1e-5);\r
1676       };\r
1677     } );\r
1678     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1679     it("should be this for the value (the valid partion on a spline mode )", function() {\r
1680       var x = 0,\r
1681           y = 0,\r
1682           bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) {\r
1683             return function (t) {\r
1684               return {\r
1685                   x: (x4-3*(x3-x2)-x1)*t*t*t + 3*(x3-2*x2+x1)*t*t + 3*(x2-x1)*t + x1,\r
1686                   y: (y4-3*(y3-y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1\r
1687                 };\r
1688             };\r
1689           };\r
1690       calc.mode = "spline";\r
1691       calc.keySplines = [0, 0.5, 0.5, 1];\r
1692       calc.to.degit = 1;\r
1693       var b = bezier(0,0, 0,0.5, 0.5,1, 1,1);\r
1694       expect(calc.call()(0)).toBe(b(0).y+".0");\r
1695       calc.to.from = from;\r
1696       expect(calc.call()(1)).toBe(b(1).y+".0");\r
1697       calc.to.from = from;\r
1698       expect(calc.call()( b(0.5).x )).toBe(b(0.5).y.toFixed(1));\r
1699       \r
1700       var ff = function(k) {\r
1701         calc.keySplines = k;\r
1702         calc.to.degit = 10;\r
1703         var b = bezier(0,0, k[0],k[1], k[2],k[3], 1,1),\r
1704             epsilon = 1e-5; //誤差\r
1705         expect(calc.call()(0)).toBe(b(0).y.toFixed(10));\r
1706         calc.to.from = from;\r
1707         expect(calc.call()(1)).toBe(b(1).y.toFixed(10));\r
1708         calc.to.from = from;\r
1709         b = b(Math.random());\r
1710         expect(Math.abs(calc.call()(b.x) - b.y.toFixed(10))).toBeLessThan(epsilon);\r
1711       };\r
1712       for (var i=0;i<10000;++i) {\r
1713         var rand = [Math.random(), Math.random(), Math.random(), Math.random()].sort(function(a,b){return a-b;});\r
1714         ff(rand);\r
1715       }\r
1716     } );\r
1717     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1718     it("should be this for the value (the invalid partion on a spline mode )", function() {\r
1719       calc.mode = "spline";\r
1720       calc.keySplines = [0, NaN, 1, 1];\r
1721       calc.to.degit = 1;\r
1722       calc.to.from = from;\r
1723       expect( calc.up().call()("undef")).toBe(Math.PI);\r
1724 \r
1725       \r
1726       calc.keySplines = [0, 0, 1, 2];\r
1727       calc.to.degit = 1;\r
1728       calc.to.from = from;\r
1729       expect( calc.up().call()("undef")).toBe(Math.PI);\r
1730       \r
1731       calc.keySplines = null;\r
1732       calc.to.degit = 1;\r
1733       calc.to.from = from;\r
1734       expect( calc.up().call()("undef")).toBe(Math.PI);\r
1735     } );\r
1736   } );\r
1737   describe("A $attribute object", function() {\r
1738     describe("A push method", function() {\r
1739       var attr, s;\r
1740       beforeEach( function() {\r
1741         attr = base("$calcMode").$attribute.up("width");\r
1742         base("$frame").timelines.length = 0;\r
1743         s = document.createElementNS("http:///www.w3.org/2000/svg", "animate");\r
1744       } );\r
1745       afterEach( function() {\r
1746         attr.isCSS = false;\r
1747       } );\r
1748       /*境界条件を調べておく (limit value analysis)*/\r
1749       it("should be this for the value  (limit value analysis)", function() {\r
1750         expect(attr.element).toBeNull();\r
1751         expect(attr.push()).toBeNull();\r
1752         expect(attr.element).toBeNull();\r
1753         expect(attr.isCSS).toBeFalsy();\r
1754         expect(base("$frame").timelines.length).toBe(0);\r
1755         \r
1756         expect(attr.push(s)).toBeNull();\r
1757         expect(attr.element).toBeNull();\r
1758         expect(base("$frame").timelines.length).toBe(0);\r
1759         expect(attr.hasAttrValues()).toBeFalsy();\r
1760         \r
1761         var p = document.createElement("g");\r
1762         p.appendChild(s);\r
1763         expect(attr.push(s)).toBeNull();\r
1764         expect(attr.element).toBe(p);\r
1765         expect(base("$frame").timelines.length).toBe(0);\r
1766         \r
1767         s.setAttribute("end", "0");\r
1768         check("from", 1);\r
1769         check("to", 2);\r
1770         check("by", 3);\r
1771         check("values", 4);\r
1772         function check(attrName, num) {\r
1773           s.setAttribute(attrName, "1");\r
1774           expect(s.hasAttributeNS(null, attrName)).toBeTruthy();\r
1775           var fr = attr.push(s);\r
1776           expect(attr.element).toBe(p);\r
1777           var timelines = base("$frame").timelines;\r
1778           expect(timelines.length).toBe(num);\r
1779           var line = timelines[num-1];\r
1780           expect(line).not.toBe(fr);\r
1781           var act = fr.$activate;\r
1782           expect(act.dur).toBeNull();\r
1783           expect(act.repeatCount).toBeNull();\r
1784           expect(act.repeatDur).toBeNull();\r
1785           expect(act.min).toBe("0");\r
1786           expect(act.max).toBe("indefinite");\r
1787           expect(act.simpleDur).toBeNull();\r
1788           expect(attr.hasAttrValues()).toBeTruthy();\r
1789           \r
1790           s.removeAttribute(attrName);\r
1791           expect(s.hasAttributeNS(null, attrName)).toBeFalsy();\r
1792           attr.push(s);\r
1793           expect(attr.element).toBe(p);\r
1794           expect(timelines.length).toBe(num);\r
1795         };\r
1796           \r
1797         /*targetElement属性のサポート*/\r
1798         var p2 = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
1799         document.documentElement.appendChild(p2);\r
1800         p2.setAttributeNS(null, "id", "p23");\r
1801         s.setAttributeNS(null, "targetElement", "p23");\r
1802         attr.push(s);\r
1803         expect(attr.element).toBe(p2);\r
1804         \r
1805         /*ハイパーリンクのサポート*/\r
1806         var p3 = document.createElementNS("http://www.w3.org/2000/svg", "a");\r
1807         document.documentElement.appendChild(p3);\r
1808         p3.setAttributeNS(null, "id", "p34");\r
1809         s.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "#p34");\r
1810         attr.push(s);\r
1811         expect(attr.element).toBe(p3);\r
1812         \r
1813         /*attributeType属性のサポート*/\r
1814         s.setAttributeNS(null, "attributeType", "CSS");\r
1815         s.setAttributeNS(null, "values", "a;b;c");\r
1816         attr.push(s);\r
1817         expect(attr.isCSS).toBeTruthy();\r
1818       } );\r
1819       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1820       it("should be this for the value (the valid partion )", function() {\r
1821         s.setAttribute("from", "1");\r
1822         var p = document.createElement("g");\r
1823         p.appendChild(s);\r
1824         var values = [ "0",\r
1825                       "0", null, null, null, \r
1826                       "0", "indefinite", null\r
1827                     ];\r
1828         values[7] = 0;\r
1829         check2("dur", "0");\r
1830         check2("begin", "0");\r
1831         values[0] = "1";\r
1832         check2("begin", "1");\r
1833         values[2] = 0;\r
1834         check2("end", "0");\r
1835         values[3] = "0";\r
1836         check2("repeatCount", "0");\r
1837         values[4] = "0";\r
1838         check2("repeatDur", "0");\r
1839         values[5] = "0";\r
1840         check2("min", "0");\r
1841         values[6] = "0";\r
1842         check2("max", "0");\r
1843         values[0] = "12";\r
1844         check2("begin", "12");\r
1845         values[7] = 1000 * base("$frame").fpms;\r
1846         values[1] = "1";\r
1847         check2("dur", "1");\r
1848         function check2(attrName, value) {\r
1849           s.setAttribute(attrName, value);\r
1850           expect(s.hasAttributeNS(null, attrName)).toBeTruthy();\r
1851           var fr = attr.push(s);\r
1852           expect(attr.element).toBe(p);\r
1853           var timelines = base("$frame").timelines;\r
1854           var line = timelines[timelines.length-1];\r
1855           expect(fr.string).toBe(values[0]);\r
1856           var act = fr.$activate;\r
1857           expect(act.dur).toBe(values[1]);\r
1858           expect(act.repeatCount).toBe(values[3]);\r
1859           expect(act.repeatDur).toBe(values[4]);\r
1860           expect(act.min).toBe(values[5]);\r
1861           expect(act.max).toBe(values[6]);\r
1862           expect(act.simpleDur).toBe(values[7]);\r
1863         };\r
1864         \r
1865                 \r
1866         var p4 = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
1867         document.documentElement.appendChild(p4);\r
1868         p4.appendChild(s);\r
1869         p4.setAttributeNS(null, "style", "display: none");\r
1870         attr.push(s);\r
1871         expect(attr.setAttribute()).toBeUndefined();\r
1872         expect(attr.setAttribute("block")).toBeUndefined();\r
1873         expect(p4.hasAttributeNS(null, "display")).toBeFalsy();\r
1874         expect(attr.isCSS).toBeFalsy();\r
1875         \r
1876         s.setAttributeNS(null, "attributeName", "display");\r
1877         attr.push(s);\r
1878         expect(attr.setAttribute("block")).toBeUndefined();\r
1879         expect(p4.hasAttributeNS(null, "display")).toBeFalsy();\r
1880         expect(attr.isCSS).toBeTruthy();\r
1881         expect(p4.style.getPropertyValue("display")).toBe("block");\r
1882         \r
1883         p4 = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
1884         document.documentElement.appendChild(p4);\r
1885         p4.appendChild(s);\r
1886         p4.setAttributeNS(null, "style", "display: none");\r
1887         attr.push(s);\r
1888         expect(attr.setAttribute("block")).toBeUndefined();\r
1889         expect(p4.hasAttributeNS(null, "display")).toBeFalsy();\r
1890         expect(p4.style.getPropertyValue("display")).toBe("block");\r
1891         expect(attr.removeAttribute()).toBeUndefined();\r
1892         expect(p4.hasAttributeNS(null, "display")).toBeFalsy();\r
1893         expect(p4.style.getPropertyValue("display")).toBe("none");\r
1894         \r
1895         /*attributeType属性のサポート*/\r
1896         s.setAttributeNS(null, "values", "a;b;c");\r
1897         s.setAttributeNS(null, "attributeName", "display");\r
1898         attr.isCSS = false;\r
1899         attr.push(s);\r
1900         expect(attr.isCSS).toBeTruthy();\r
1901       } );\r
1902       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1903       it("should be this for the value (the invalid partion )", function() {\r
1904         var p = document.createElement("g");\r
1905         p.appendChild(s);\r
1906         \r
1907         s.setAttributeNS(null, "begin", "1");\r
1908         attr.push(s);\r
1909         var timelines = base("$frame").timelines;\r
1910         expect(timelines.length).toBe(0);\r
1911         s.setAttributeNS(null, "from", "0");\r
1912         attr.push(s);\r
1913         expect(timelines.length).toBe(1);\r
1914         expect(attr.push(12)).toBeNull();\r
1915       } );\r
1916     } );\r
1917     describe("A setValues method", function() {\r
1918       var attr, s;\r
1919       beforeEach( function() {\r
1920         attr = base("$calcMode").$attribute.up("width");\r
1921         base("$frame").timelines.length = 0;\r
1922         s = document.createElement("animate");\r
1923       } );\r
1924       /*境界条件を調べておく (limit value analysis)*/\r
1925       it("should be this for the value  (limit value analysis)", function() {\r
1926         expect(attr.$from).not.toBeUndefined();\r
1927         expect(attr.setValues()).toBeNull();\r
1928         expect(attr.setValues("")).toBeNull();\r
1929 \r
1930         expect(attr.setValues("0;1")[0].to.string).toBe("1");\r
1931         expect(attr.setValues("0;1")[0].to.from.string).toBe("0");\r
1932         expect(attr.setValues("0;1", "0", "1", "1")[0].to.from.string).toBe("0");\r
1933         expect(attr.setValues("0;1", null, "1", "0")[0].to.from.string).toBe("0"); \r
1934                \r
1935         /*from-to アニメーション*/\r
1936         expect(attr.setValues(null, "0", "1")[0].to.string).toBe("1");\r
1937         expect(attr.setValues(null, "0", "1")[0].to.from.string).toBe("0");\r
1938         \r
1939         /*from-by アニメーション*/\r
1940         expect(attr.setValues(null, "1", null, "1")[0].to.string).toBe("1");\r
1941         expect(attr.setValues(null, "1", null, "1")[0].to.from[0]).toBe(1);\r
1942         expect(attr.setValues(null, "1", null, "1")[0].to.numList[0]).toBe(2);\r
1943         \r
1944         /*fromなしto アニメーション*/\r
1945         expect(attr.setValues(null, null, "1")[0].to.string).toBe("1");\r
1946         expect(attr.setValues(null, null, "1")[0].to.from.string).toBe("0");\r
1947         var aset = attr.setValues(null, null, "1")[0].to;\r
1948         aset.call();\r
1949         expect(aset.from[0]).toBe(0);\r
1950         \r
1951         /*fromなしby アニメーション*/\r
1952         expect(attr.setValues(null, null, null, "1")[0].to.string).toBe("1");\r
1953         expect(attr.setValues(null, null, null, "1")[0].to.from[0]).toBe(0);\r
1954         var aset = attr.setValues(null, null, null, "1")[0].to;\r
1955         aset.call();\r
1956         expect(aset.from[0]).toBe(0);\r
1957       } );\r
1958       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
1959       it("should be this for the value (the valid partion on a spline mode )", function() {\r
1960         attr.$from.degit = 1;\r
1961         var setv = attr.setValues("0;1")[0].call();\r
1962         expect(setv(0.5)).toBe("0.5");\r
1963         expect(setv(1)).toBe("1.0");\r
1964         \r
1965         setv = attr.setValues(" 0;1; 2 ")[0].call();\r
1966         expect(setv(0.5)).toBe("0.5");\r
1967         expect(setv(1)).toBe("1.0");\r
1968         setv = attr.setValues("0;1;2")[1].call();\r
1969         expect(setv(0.4)).toBe("1.4");\r
1970         expect(setv(1)).toBe("2.0");\r
1971         \r
1972         attr.$from.degit = 2;\r
1973         setv = attr.setValues("1;1;1;1 ;1;15.1")[4].call();\r
1974         expect(setv(0.5)).toBe("8.05");\r
1975         expect(setv(1)).toBe("15.10");\r
1976         \r
1977         var v = attr.setValues("1;1;2;1;1;15.1");\r
1978         setv = v[4].mix( {\r
1979          keyTime: 0.1\r
1980         } ).call();\r
1981         expect(setv(0.05)).toBe("8.05");\r
1982         expect(setv(0.1)).toBe("15.10");\r
1983         setv = v[3].mix( {\r
1984          keyTime: 0.1\r
1985         } ).call();\r
1986         expect(setv(0.01)).toBe("1.00");\r
1987         expect(setv(0.1)).toBe("1.00");\r
1988         setv = v[2].mix( {\r
1989          keyTime: 0.5\r
1990         } ).call();\r
1991         expect(setv(0.25)).toBe("1.50");\r
1992         expect(setv(0.5)).toBe("1.00");\r
1993       } );\r
1994       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
1995       it("should be this for the value (the invalid partion on a spline mode )", function() {\r
1996         attr.$from.degit = 1;\r
1997         expect(attr.setValues("")).toBeNull();\r
1998         expect(attr.setValues(null, null, null, null)).toBeNull();\r
1999       } );\r
2000     } );\r
2001     describe("A setKey method", function() {\r
2002       var attr, s;\r
2003       beforeEach( function() {\r
2004         attr = base("$calcMode").$attribute.up("width");\r
2005         base("$frame").timelines.length = 0;\r
2006         s = document.createElement("animate");\r
2007         document.createElement("g").appendChild(s);\r
2008       } );\r
2009       /*境界条件を調べておく (limit value analysis)*/\r
2010       it("should be this for the value  (limit value analysis)", function() {\r
2011         expect(attr.setKey(s)).toBeNull();\r
2012         \r
2013         s.setAttributeNS(null, "from", "0");\r
2014         attr.setKey(s);\r
2015         s.setAttributeNS(null, "to", "0");\r
2016         expect(attr.setKey(s)[0].to.from.string).toBe("0");\r
2017         expect(attr.setKey(s)[0].to.string).toBe("0");\r
2018         s.setAttributeNS(null, "by", "0");\r
2019         attr.setKey(s);\r
2020         s.setAttributeNS(null, "values", "0;2");\r
2021         expect(attr.setKey(s)[0].to.from.string).toBe("0");\r
2022         expect(attr.setKey(s)[0].to.string).toBe("2");\r
2023         \r
2024         s.setAttributeNS(null, "keyTimes", "0;0.1");\r
2025         expect(attr.setKey(s)[0].keyTime).toBe(0.1);\r
2026         \r
2027         s.setAttributeNS(null, "keySplines", "0,0.1,0.3,0.4");\r
2028         expect(attr.setKey(s)[0].keySplines[0]).toBe(0);\r
2029         expect(attr.setKey(s)[0].keySplines[1]).toBe(0.1);\r
2030         expect(attr.setKey(s)[0].keySplines[2]).toBe(0.3);\r
2031         expect(attr.setKey(s)[0].keySplines[3]).toBe(0.4);\r
2032         \r
2033         s.setAttributeNS(null, "keySplines", "0 0.1 0.3 0.4");\r
2034         expect(attr.setKey(s)[0].keySplines[0]).toBe(0);\r
2035         expect(attr.setKey(s)[0].keySplines[1]).toBe(0.1);\r
2036         expect(attr.setKey(s)[0].keySplines[2]).toBe(0.3);\r
2037         expect(attr.setKey(s)[0].keySplines[3]).toBe(0.4);\r
2038       } );\r
2039       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
2040       it("should be this for the value (the valid partion on a spline mode )", function() {\r
2041         s.setAttributeNS(null, "values", "0;2;12;30");\r
2042         expect(attr.setKey(s)[0].keyTime.toFixed(3)).toBe("0.333");\r
2043         s.setAttributeNS(null, "keyTimes", "0;0.1;0.2;1");\r
2044         expect(attr.setKey(s)[0].keyTime).toBe(0.1);\r
2045         expect(attr.setKey(s)[1].keyTime).toBe(0.1);\r
2046         expect(attr.setKey(s)[2].keyTime).toBe(0.8);\r
2047         s.setAttributeNS(null, "values", " 0; 2;12 ;30 ");\r
2048         s.setAttributeNS(null, "keyTimes", " 0; 0.1; 0.2 ; 1 ");\r
2049         expect(attr.setKey(s)[0].keyTime).toBe(0.1);\r
2050         expect(attr.setKey(s)[1].keyTime).toBe(0.1);\r
2051         expect(attr.setKey(s)[2].keyTime).toBe(0.8);\r
2052         \r
2053         s.setAttributeNS(null, "keyTimes", " 0; .1; .2 ; 1 ");\r
2054         expect(attr.setKey(s)[0].keyTime).toBe(0.1);\r
2055         expect(attr.setKey(s)[1].keyTime).toBe(0.1);\r
2056         expect(attr.setKey(s)[2].keyTime).toBe(0.8);\r
2057         \r
2058         s.setAttributeNS(null, "keySplines", " 0,0.1,0.3,1; 0.1,0.4,0.5,0.7; 0.2,0.2,0.1  , 1 ;");\r
2059         f(0, 0,0.1,0.3,1);\r
2060         f(1, 0.1,0.4,0.5,0.7);\r
2061         f(2, 0.2,0.2,0.1,1);\r
2062         \r
2063         s.setAttributeNS(null, "keySplines", " 0,.1,.3,1; .1,.4, .5,.7; .2,  .2, .1  , 1 ;");\r
2064         f(0, 0,0.1,0.3,1);\r
2065         f(1, 0.1,0.4,0.5,0.7);\r
2066         f(2, 0.2,0.2,0.1,1);\r
2067         \r
2068         s.setAttributeNS(null, "keySplines", " 0 .1 .333,1; .1 .4  .5 .7; .2   .2  .1    1 ;");\r
2069         f(0, 0,0.1,0.333,1);\r
2070         f(1, 0.1,0.4,0.5,0.7);\r
2071         f(2, 0.2,0.2,0.1,1);\r
2072         function f (i, a, b, c, d) {\r
2073           var splines = attr.setKey(s)[i].keySplines;\r
2074           expect(splines[0]).toBe(a);\r
2075           expect(splines[1]).toBe(b);\r
2076           expect(splines[2]).toBe(c);\r
2077           expect(splines[3]).toBe(d);\r
2078         };\r
2079       } );\r
2080       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
2081       it("should be this for the value (the invalid partion on a spline mode )", function() {\r
2082         s.setAttributeNS(null, "keyTimes", "0;0.1;0.2;1");\r
2083         expect(attr.setKey(s)).toBeNull();\r
2084         s.setAttributeNS(null, "values", "0;2;12");\r
2085         expect(attr.setKey(s)).toBeNull();\r
2086         s.setAttributeNS(null, "values", "0;2;12;20");\r
2087         s.setAttributeNS(null, "keyTimes", "0;0.1;0.2");\r
2088         expect(attr.setKey(s)).toBeNull();\r
2089       } );\r
2090     } );\r
2091   } );\r
2092   describe("A $setElement object", function() {\r
2093     describe("A timeline property", function() {\r
2094       var $set, ele, frame;\r
2095       beforeEach( function() {\r
2096         $set = base("$calcMode").$attribute.$setElement.up();\r
2097         var p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
2098         ele = document.createElementNS("http://www.w3.org/2000/svg", "set");\r
2099         p.appendChild(ele);\r
2100         frame = base("$frame");\r
2101       } );\r
2102       /*境界条件を調べておく (limit value analysis)*/\r
2103       it("should be this for the value  (limit value analysis)", function() {\r
2104         expect($set.timeline).toBe(frame.$begin);\r
2105         \r
2106         $set.init();\r
2107         expect($set.timeline).toBe(frame.$begin);\r
2108         expect($set.element).toBeNull();\r
2109       } );\r
2110     } );\r
2111     \r
2112       describe("An init method", function() {\r
2113       var $set, ele, frame;\r
2114       beforeEach( function() {\r
2115         $set = base("$calcMode").$attribute.$setElement.up();\r
2116         var p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
2117         ele = document.createElementNS("http://www.w3.org/2000/svg", "set");\r
2118         p.appendChild(ele);\r
2119         frame = base("$frame");\r
2120       } );\r
2121       /*境界条件を調べておく (limit value analysis)*/\r
2122       it("should be this for the value  (limit value analysis)", function() {\r
2123         expect($set.to).toBe("");\r
2124         expect($set.attrName).toBe("");\r
2125         expect($set.defaultValue).toBe("");\r
2126         expect($set.isDefault).toBeFalsy();\r
2127         expect($set.attrNameSpace).toBeNull();\r
2128         $set.init();\r
2129         expect($set.timeline).toBe(frame.$begin);\r
2130         $set.init(ele);\r
2131         expect($set.to).toBe("");\r
2132         expect($set.attrName).toBe("");\r
2133         expect($set.isDefault).toBeFalsy();\r
2134         expect($set.attrNameSpace).toBeNull();\r
2135         expect($set.timeline).toBe(frame.$begin);\r
2136       } );\r
2137       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
2138       it("should be this for the value (the valid partion  )", function() {\r
2139         ele.setAttributeNS(null, "to", "t1");\r
2140         $set.init(ele);\r
2141         expect($set.to).toBe("t1");\r
2142         expect($set.attrName).toBe("");\r
2143         expect($set.defaultValue).toBe("");\r
2144 \r
2145         ele.setAttributeNS(null, "attributeName", "tt1");\r
2146         $set.init(ele);\r
2147         expect($set.to).toBe("t1");\r
2148         expect($set.attrName).toBe("tt1");\r
2149         expect($set.defaultValue).toBe("");\r
2150 \r
2151         ele.parentNode.setAttributeNS(null, "tt1", "undef");\r
2152         $set.init(ele);\r
2153         expect($set.defaultValue).toBe("undef");\r
2154         expect($set.isDefault).toBeTruthy();\r
2155 \r
2156         ele.setAttributeNS(null, "attributeName", "font-size");\r
2157         ele.parentNode.style.setProperty("font-size", "12px");\r
2158         $set.init(ele);\r
2159         expect($set.defaultValue).toBe("12px");\r
2160         expect($set.isDefault).toBeFalsy();\r
2161         \r
2162         ele.setAttributeNS(null, "attributeName", "xlink:href");\r
2163         $set.init(ele);\r
2164         expect($set.to).toBe("t1");\r
2165         expect($set.attrName).toBe("xlink:href");\r
2166         expect($set.defaultValue).toBe("");\r
2167         ele.parentNode.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "undef");\r
2168         $set.init(ele);\r
2169         expect($set.attrNameSpace).toBe("http://www.w3.org/1999/xlink");\r
2170       } );\r
2171       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
2172       it("should be this for the value (the invalid partion on a spline mode )", function() {\r
2173         $set.init(null);\r
2174         expect($set.to).toBe("");\r
2175         expect($set.attrName).toBe("");\r
2176         expect($set.defaultValue).toBe("");\r
2177 \r
2178         $set.init(12);\r
2179         expect($set.to).toBe("");\r
2180         expect($set.attrName).toBe("");\r
2181         expect($set.defaultValue).toBe("");\r
2182       } );\r
2183     } );\r
2184     describe("Frame Set", function() {\r
2185       var $set, ele, frame;\r
2186       beforeEach( function() {\r
2187         $set = base("$calcMode").$attribute.$setElement.up();\r
2188         var p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
2189         ele = document.createElementNS("http://www.w3.org/2000/svg", "set");\r
2190         p.appendChild(ele);\r
2191         frame = base("$frame");\r
2192         frame.timelines.length = 0; //配列の初期化\r
2193         frame.startTime = Date.now();\r
2194         frame.setFrame(0);\r
2195       } );\r
2196       afterEach( function() {\r
2197         $set.isCSS = false;\r
2198       } );\r
2199       /*境界条件を調べておく (limit value analysis)*/\r
2200       it("should be this for the value  (limit value analysis)", function() {\r
2201         expect($set.isEnd).toBeFalsy();\r
2202         ele.setAttributeNS(null, "dur", "1s");\r
2203         ele.setAttributeNS(null, "attributeName", "fill");\r
2204         ele.setAttributeNS(null, "to", "red");\r
2205         $set.init(ele);\r
2206         /*テストしやすくするために、CSSではなくXML属性として扱う*/\r
2207         $set.isCSS = false;\r
2208         expect($set.timeline).not.toBe(frame.$begin);\r
2209         frame.setFrame(0);\r
2210         expect(ele.parentNode.getAttributeNS(null, "fill")).toBe("red");\r
2211         \r
2212         var line = $set.timeline;\r
2213         expect(line.$list.state).toBe(line.$list.PLAYING);\r
2214         frame.setFrame(24);\r
2215         expect(line.$list.state).toBe(line.$list.POSTWAITING);\r
2216         expect(ele.parentNode.hasAttributeNS(null, "fill")).toBeFalsy();\r
2217       } );\r
2218       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
2219       it("should be this for the value (the valid partion)", function() {\r
2220         ele.setAttributeNS(null, "begin", "1s");\r
2221         ele.setAttributeNS(null, "dur", "1s");\r
2222         ele.setAttributeNS(null, "attributeName", "fill");\r
2223         ele.setAttributeNS(null, "to", "red");\r
2224         $set.init(ele);\r
2225         /*テストしやすくするために、CSSではなくXML属性として扱う*/\r
2226         $set.isCSS = false;\r
2227         var f = function(num) {\r
2228           frame.setFrame(num);\r
2229           expect(ele.parentNode.getAttributeNS(null, "fill") || null).toBeNull();\r
2230         }\r
2231         f(0);\r
2232         f(1);\r
2233         f(23);\r
2234         frame.setFrame(24);\r
2235         expect(ele.parentNode.getAttributeNS(null, "fill")).toBe("red");\r
2236         frame.setFrame(25);\r
2237         expect(ele.parentNode.getAttributeNS(null, "fill")).toBe("red");\r
2238         f(48);\r
2239         f(49);\r
2240         \r
2241         ele.setAttributeNS(null, "fill", "freeze");\r
2242         $set.init(ele);\r
2243         $set.isCSS = false;\r
2244         f(0);\r
2245         f(1);\r
2246         f(23);\r
2247         frame.setFrame(24);\r
2248         expect(ele.parentNode.getAttributeNS(null, "fill")).toBe("red");\r
2249         frame.setFrame(25);\r
2250         expect(ele.parentNode.getAttributeNS(null, "fill")).toBe("red");\r
2251         frame.setFrame(48);\r
2252         expect(ele.parentNode.getAttributeNS(null, "fill") || null).toBe("red");\r
2253         frame.setFrame(49);\r
2254         expect(ele.parentNode.getAttributeNS(null, "fill") || null).toBe("red");\r
2255         ele.setAttributeNS(null, "begin", "1s");\r
2256         ele.setAttributeNS(null, "attributeName", "fill");\r
2257         ele.setAttributeNS(null, "to", "red");\r
2258         /*eleにはdur属性やendなどが設定されていなくとも、アニメーションが有効*/\r
2259         $set.init(ele);\r
2260         $set.isCSS = false;\r
2261         var f = function(num) {\r
2262           frame.setFrame(num);\r
2263           expect(ele.parentNode.getAttributeNS(null, "fill") || null).toBe("red");\r
2264         }\r
2265         f(0);\r
2266         f(1);\r
2267         f(23);\r
2268         f(24);\r
2269         f(25);\r
2270         f(48);      } );\r
2271       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
2272       it("should be this for the value (the invalid partion)", function() {\r
2273 \r
2274       } );\r
2275     } );\r
2276   } );\r
2277     describe("A $animateElement object", function() {\r
2278       describe("An init method", function() {\r
2279         var $animate, ele, frame;\r
2280         beforeEach( function() {\r
2281           $animate = base("$calcMode").$attribute.$setElement.$animateElement.up();\r
2282           var p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
2283           ele = document.createElementNS("http://www.w3.org/2000/svg", "animate");\r
2284           p.appendChild(ele);\r
2285           frame = base("$frame");\r
2286           frame.pauseAnimation();\r
2287           frame.timelines.length = 0;\r
2288           frame.startTime = Date.now();\r
2289           frame.setFrame(0);\r
2290         } );\r
2291         /*境界条件を調べておく (limit value analysis)*/\r
2292         it("should be this for the value  (limit value analysis)", function() {\r
2293           $animate.init();\r
2294           \r
2295           ele.setAttributeNS(null, "begin", "1s");\r
2296           ele.setAttributeNS(null, "dur", "1s");\r
2297           ele.setAttributeNS(null, "attributeName", "d");\r
2298           ele.setAttributeNS(null, "from", "M20 0 L20 30");\r
2299           ele.setAttributeNS(null, "to", "M20 20 L10 30");\r
2300           $animate.init(ele);\r
2301           expect($animate.isCSS).toBeFalsy();\r
2302           frame.setFrame(0);\r
2303           var p = ele.parentNode;\r
2304           /*getAttributeNSメソッドは、IE11では空文字列を返す(DOM 2に準拠)のに対して、\r
2305            * 他のブラウザではnullを返すため、その対策をする*/\r
2306           expect(p.getAttributeNS(null, "d") || null).toBeNull();\r
2307           \r
2308           function f(fr, result) {\r
2309             frame.setFrame(fr);\r
2310             expect(p.getAttributeNS(null, "d") || "").toBe(result);\r
2311           };\r
2312           \r
2313           f(24, "M20.0 0.0 L20.0 30.0");\r
2314           f(36, "M20.0 10.0 L15.0 30.0");\r
2315           f(48, "");\r
2316                     \r
2317           ele.setAttributeNS(null, "fill", "freeze");\r
2318           $animate.init(ele);\r
2319           f(24, "M20.0 0.0 L20.0 30.0");\r
2320           f(36, "M20.0 10.0 L15.0 30.0");\r
2321           f(48, "M20.0 20.0 L10.0 30.0");\r
2322           \r
2323           frame.timelines.length = 0;\r
2324           ele.setAttributeNS(null, "calcMode", "discrete");\r
2325           $animate.init(ele);\r
2326           expect($animate.isCSS).toBeFalsy();\r
2327           expect($animate.mode).toBe("discrete");\r
2328           f(24, "M20.0 0.0 L20.0 30.0");\r
2329           f(25, "M20.0 0.0 L20.0 30.0");\r
2330           f(37, "M20.0 20.0 L10.0 30.0");\r
2331           f(48, "M20.0 20.0 L10.0 30.0");\r
2332           \r
2333           [ ["display", "inline", "none"],\r
2334             ["visibility", "hidden", "visible"],\r
2335             ["stroke-linecap", "round", "square"],\r
2336             ["font-style", "italic", "normal"]\r
2337           ].forEach( function(attr) {\r
2338             var attrName = attr[0],\r
2339                 from = attr[1],\r
2340                 to = attr[2];\r
2341             function g(fr, result) {\r
2342               frame.setFrame(fr);\r
2343               expect(p.style.getPropertyValue(attrName) || p.getAttribute(attrName) || "").toBe(result);\r
2344             };\r
2345 \r
2346             \r
2347             ele.setAttributeNS(null, "from", from);\r
2348             ele.setAttributeNS(null, "to", to);\r
2349             frame.timelines.length = 0;\r
2350             ele.setAttributeNS(null, "calcMode", "linear");\r
2351             ele.setAttributeNS(null, "attributeName", attrName);\r
2352             $animate.init(ele);\r
2353             expect($animate.mode).toBe("discrete");\r
2354             g(24, from);\r
2355             g(25, from);\r
2356             g(37, to);\r
2357             g(48, to);\r
2358           } );\r
2359         } );\r
2360         /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
2361         it("should be this for the value (the valid partion )", function() {\r
2362           /*24FPSが前提*/\r
2363           ele.setAttributeNS(null, "begin", "0s");\r
2364           ele.setAttributeNS(null, "dur", "100s");\r
2365           ele.setAttributeNS(null, "attributeName", "d");\r
2366           ele.setAttributeNS(null, "fill", "freeze");\r
2367           ele.setAttributeNS(null, "from", "M20 0 L20 30");\r
2368           ele.setAttributeNS(null, "to", "M20 2400 L20 30");\r
2369           $animate.init(ele);\r
2370           \r
2371           var p = ele.parentNode;\r
2372           expect(p.getAttributeNS(null, "d") || null).toBeNull();\r
2373           \r
2374           function f(fr, result) {\r
2375             frame.setFrame(fr);\r
2376             expect(p.getAttributeNS(null, "d")).toBe(result);\r
2377           };\r
2378           \r
2379           for (var i=0;i<2400;++i) {\r
2380             f(i, "M20.0 " +i+ ".0 L20.0 30.0");\r
2381           }\r
2382           f(2401, "M20.0 2400.0 L20.0 30.0");\r
2383           \r
2384           \r
2385           frame.timelines.length = 0;\r
2386           ele.setAttributeNS(null, "begin", "0s");\r
2387           ele.setAttributeNS(null, "dur", "1s");\r
2388           ele.setAttributeNS(null, "repeatDur", "2s");\r
2389           ele.setAttributeNS(null, "attributeName", "d");\r
2390           ele.setAttributeNS(null, "fill", "freeze");\r
2391           ele.setAttributeNS(null, "from", "M20 0 L20 30");\r
2392           ele.setAttributeNS(null, "to", "M20 24 L20 30");\r
2393           $animate.init(ele);\r
2394           f(23, "M20.0 23.0 L20.0 30.0");\r
2395           f(24, "M20.0 0.0 L20.0 30.0");\r
2396           f(25, "M20.0 1.0 L20.0 30.0");\r
2397           f(48, "M20.0 24.0 L20.0 30.0");\r
2398 \r
2399           frame.timelines.length = 0;\r
2400           ele.setAttributeNS(null, "begin", "0s");\r
2401           ele.setAttributeNS(null, "dur", "2s");\r
2402           ele.setAttributeNS(null, "attributeName", "d");\r
2403           ele.setAttributeNS(null, "fill", "freeze");\r
2404           ele.setAttributeNS(null, "values", "M20 0 L20 30;M20 24 L20 30;M20 26.4 L20 30");\r
2405           $animate.init(ele);\r
2406           f(0, "M20.0 0.0 L20.0 30.0");\r
2407           f(1, "M20.0 1.0 L20.0 30.0");\r
2408           f(24, "M20.0 24.0 L20.0 30.0");\r
2409           f(25, "M20.0 24.1 L20.0 30.0");\r
2410           f(47, "M20.0 26.3 L20.0 30.0");\r
2411           f(48, "M20.0 26.4 L20.0 30.0");\r
2412           f(49, "M20.0 26.4 L20.0 30.0");\r
2413           f(50, "M20.0 26.4 L20.0 30.0");\r
2414           \r
2415           frame.timelines.length = 0;\r
2416           ele.setAttributeNS(null, "begin", "0s");\r
2417           ele.setAttributeNS(null, "end", "2s");\r
2418           ele.removeAttributeNS(null, "dur"); //単純継続時間が設定されていない場合\r
2419           ele.removeAttributeNS(null, "repeatDur");\r
2420           ele.setAttributeNS(null, "attributeName", "d");\r
2421           ele.setAttributeNS(null, "fill", "freeze");\r
2422           ele.setAttributeNS(null, "values", "M20 0 L20 30;M20 24 L20 30;M20 26.4 L20 30");\r
2423           $animate.init(ele);\r
2424           f(0, "M20.0 0.0 L20.0 30.0");\r
2425           f(1, "M20.0 0.0 L20.0 30.0");\r
2426           f(24, "M20.0 0.0 L20.0 30.0");\r
2427           f(25, "M20.0 0.0 L20.0 30.0");\r
2428           f(47, "M20.0 0.0 L20.0 30.0");\r
2429           f(48, "M20.0 0.0 L20.0 30.0");\r
2430           f(49, "M20.0 0.0 L20.0 30.0");\r
2431           f(50, "M20.0 0.0 L20.0 30.0");\r
2432           \r
2433           frame.timelines.length = 0;\r
2434           ele.setAttributeNS(null, "dur", "2s");\r
2435           ele.setAttributeNS(null, "fill", "remove");\r
2436           var attrValue = p.getAttributeNS(null, "d");\r
2437           $animate.init(ele);\r
2438           f(48, attrValue);\r
2439           \r
2440           frame.timelines.length = 0;\r
2441           p.removeAttributeNS(null, "d");\r
2442           ele.setAttributeNS(null, "fill", "freeze");\r
2443           ele.setAttributeNS(null, "keyTimes", "0;0.1;1");\r
2444           $animate.init(ele);\r
2445           f(1, "M20.0 5.0 L20.0 30.0");\r
2446           f(48, "M20.0 26.4 L20.0 30.0");\r
2447           \r
2448           frame.timelines.length = 0;\r
2449           ele.setAttributeNS(null, "fill", "freeze");\r
2450           ele.setAttributeNS(null, "calcMode", "discrete");\r
2451           ele.setAttributeNS(null, "keyTimes", "0;0.5;0.6");\r
2452           $animate.init(ele);\r
2453           f(1, "M20.0 0.0 L20.0 30.0");\r
2454           f(4, "M20.0 0.0 L20.0 30.0");\r
2455           /*本来は24フレーム目で、変化するはずだが、不具合があるため、そうならない\r
2456            * 修正の余地あり*/\r
2457           f(24, "M20.0 24.0 L20.0 30.0");\r
2458           f(25, "M20.0 24.0 L20.0 30.0");\r
2459           f(29, "M20.0 26.4 L20.0 30.0");\r
2460           f(48, "M20.0 26.4 L20.0 30.0");\r
2461           \r
2462           frame.timelines.length = 0;\r
2463           ele.setAttributeNS(null, "calcMode", "spline");\r
2464           ele.removeAttributeNS(null, "keyTimes");\r
2465           ele.setAttributeNS(null, "keySplines", "0,0,1,1;0,0,1,1;.75,0,0,.75");\r
2466           ele.removeAttributeNS(null, "end");\r
2467           ele.setAttributeNS(null, "dur", "9s");\r
2468           ele.setAttributeNS(null, "values", "210;177;121;10");\r
2469           $animate.init(ele);\r
2470           f(0, "210.0");\r
2471           f(72, "177.0");\r
2472           f(144, "121.0");\r
2473           f(216, "10.0");\r
2474           f(300, "10.0");\r
2475           \r
2476           frame.timelines.length = 0;\r
2477           ele.setAttributeNS(null, "calcMode", "spline");\r
2478           ele.setAttributeNS(null, "keyTimes", "0;.25;.5;1");\r
2479           ele.setAttributeNS(null, "keySplines", "0,0,1,1;0,0,1,1;1,0,0,1");\r
2480           ele.setAttributeNS(null, "dur", "8s");\r
2481           ele.setAttributeNS(null, "values", "300;255;180;30");\r
2482           $animate.init(ele);\r
2483           f(0, "300.0");\r
2484           f(48, "255.0");\r
2485           f(96, "180.0");\r
2486           f(192, "30.0");\r
2487           f(300, "30.0");\r
2488           \r
2489           /*開始時刻が未解決の場合*/\r
2490           frame.timelines.length = 0;\r
2491           ele.setAttributeNS(null, "begin", "click");\r
2492           ele.setAttributeNS(null, "calcMode", "spline");\r
2493           ele.setAttributeNS(null, "keyTimes", "0;.25;.5;1");\r
2494           ele.setAttributeNS(null, "keySplines", "0,0,1,1;0,0,1,1;1,0,0,1");\r
2495           ele.setAttributeNS(null, "dur", "8s");\r
2496           ele.setAttributeNS(null, "values", "300;255;180;30");\r
2497           ele.parentNode.setAttributeNS(null, "d", "300");\r
2498           $animate.init(ele);\r
2499           f(0, "300");\r
2500           f(48, "300");\r
2501           f(96, "300");\r
2502           f(192, "300");\r
2503           f(300, "300");\r
2504           \r
2505           ( function(attrName) {\r
2506             function g(fr, result) {\r
2507               frame.setFrame(fr);\r
2508               expect(p.style.getPropertyValue(attrName)).toBe(result);\r
2509             };\r
2510 \r
2511             frame.timelines.length = 0;\r
2512             ele.setAttributeNS(null, "begin", "0s");\r
2513             ele.setAttributeNS(null, "calcMode", "linear");\r
2514             ele.setAttributeNS(null, "attributeName", attrName);\r
2515             ele.setAttributeNS(null, "keyTimes", "0;.25;.5;1");\r
2516             ele.setAttributeNS(null, "keySplines", "0,0,1,1;0,0,1,1;1,0,0,1");\r
2517             ele.setAttributeNS(null, "dur", "8s");\r
2518             ele.setAttributeNS(null, "values", "inline;block;inline;block");\r
2519             $animate.init(ele);\r
2520             expect($animate.mode).toBe("discrete");\r
2521             g(0, "inline");\r
2522             g(48, "block");\r
2523             g(96, "inline");\r
2524             g(192, "block");\r
2525             g(300, "block");\r
2526             \r
2527             frame.timelines.length = 0;\r
2528             ele.setAttributeNS(null, "begin", "click");\r
2529             ele.setAttributeNS(null, "calcMode", "linear");\r
2530             ele.setAttributeNS(null, "attributeName", attrName);\r
2531             ele.setAttributeNS(null, "keyTimes", "0;.25;.5;1");\r
2532             ele.setAttributeNS(null, "keySplines", "0,0,1,1;0,0,1,1;1,0,0,1");\r
2533             ele.setAttributeNS(null, "dur", "8s");\r
2534             ele.setAttributeNS(null, "values", "inline;block;inline;block");\r
2535             $animate.init(ele);\r
2536             var evt = ele.ownerDocument.createEvent("MouseEvents");\r
2537             evt.initMouseEvent("click",true, true, window, 0, 0, 0, 0, 0, false, false, false, false,0, p);\r
2538             p.dispatchEvent(evt);\r
2539             var cur = base("$frame").currentFrame;\r
2540             expect($animate.mode).toBe("discrete");\r
2541             g(cur+0, "inline");\r
2542             g(cur+48, "block");\r
2543             g(cur+96, "inline");\r
2544             g(cur+192, "block");\r
2545             g(cur+300, "block");\r
2546           } )("display");\r
2547         } );\r
2548         /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
2549         it("should be this for the value (the invalid partion )", function() {\r
2550           ele.setAttributeNS(null, "begin", "0s");\r
2551           ele.setAttributeNS(null, "dur", "100s");\r
2552           ele.setAttributeNS(null, "attributeName", "d");\r
2553           ele.setAttributeNS(null, "fill", "freeze");\r
2554           ele.setAttributeNS(null, "from", "M20 0 L20 30");\r
2555           ele.setAttributeNS(null, "to", "M20 2400 L20 30");\r
2556           ele.setAttributeNS(null, "keyTimes", "0;0.1;1");\r
2557           $animate.init(ele);\r
2558           \r
2559           var p = ele.parentNode;\r
2560           expect(p.getAttributeNS(null, "d") || null).toBeNull();\r
2561           \r
2562           function f(fr, result) {\r
2563             frame.setFrame(fr);\r
2564             expect(p.getAttributeNS(null, "d") || null).toBe(result);\r
2565           };\r
2566           f(0, null);\r
2567           f(1, null);\r
2568           \r
2569            frame.timelines.length = 0;\r
2570           /*keyTimes属性のリストの個数がvaluesリストと合致しない*/\r
2571           ele.setAttributeNS(null, "keyTimes", "0;0.1;0.5;1");\r
2572           ele.setAttributeNS(null, "values", "M20 0 L20 30;M20 24 L20 30;M20 26.4 L20 30");\r
2573           $animate.init(ele);\r
2574           f(0, null);\r
2575           f(1, null);\r
2576           \r
2577           /*keyTimes属性が0から始まっていない*/\r
2578           frame.timelines.length = 0;\r
2579           ele.setAttributeNS(null, "keyTimes", "0.1;0.3;1");\r
2580           ff("linear");\r
2581           ff("splines");\r
2582           ff("discrete");\r
2583           function ff(mode) {\r
2584             ele.setAttributeNS(null, "calcMode", mode);\r
2585             $animate.init(ele);\r
2586             f(0, null);\r
2587             f(1, null);\r
2588           }\r
2589           \r
2590           frame.timelines.length = 0;\r
2591           ele.setAttributeNS(null, "calcMode", "spline");\r
2592           $animate.init(ele);\r
2593           expect($animate.mode).toBe("spline");\r
2594           f(0, null);\r
2595           f(0.2, null);\r
2596           f(1, null); \r
2597         } );\r
2598       } );\r
2599       describe("RGB Color", function() {\r
2600         var $animate, ele, frame, f;\r
2601         beforeEach( function() {\r
2602           $animate = base("$calcMode").$attribute.$setElement.$animateElement.up();\r
2603           var p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
2604           ele = document.createElementNS("http://www.w3.org/2000/svg", "animate");\r
2605           p.appendChild(ele);\r
2606           frame = base("$frame");\r
2607           frame.timelines.length = 0;\r
2608           \r
2609           f = function (fr, result, attr) {\r
2610             frame.setFrame(fr);\r
2611             expect(p.style.getPropertyValue(attr).replace(/\s/g, "")).toBe(result.replace(/\s/g, ""));\r
2612           };\r
2613         } );\r
2614         /*境界条件を調べておく (limit value analysis)*/\r
2615         it("should be this for the value  (limit value analysis)", function() {\r
2616           ele.setAttributeNS(null, "begin", "0s");\r
2617           ele.setAttributeNS(null, "dur", "1s");\r
2618           ele.setAttributeNS(null, "attributeName", "fill");\r
2619           ele.setAttributeNS(null, "fill", "remove");\r
2620           ele.setAttributeNS(null, "from", "rgb(0, 0, 0)");\r
2621           ele.setAttributeNS(null, "to", "rgb(10, 10, 1)");\r
2622           $animate.init(ele);\r
2623           \r
2624           f(0, "rgb(0, 0, 0)", "fill");\r
2625           f(23, "rgb(10, 10, 1)", "fill");\r
2626           \r
2627           frame.timelines.length = 0;\r
2628           ele.setAttributeNS(null, "attributeName", "stroke");\r
2629           $animate.init(ele);\r
2630           f(0, "rgb(0, 0, 0)", "stroke");\r
2631           f(23, "rgb(10, 10, 1)", "stroke");\r
2632 \r
2633           frame.timelines.length = 0;\r
2634           ele.setAttributeNS(null, "attributeName", "stop-color");\r
2635           $animate.init(ele);\r
2636           f(0, "rgb(0,0,0)", "stop-color");\r
2637           f(23, "rgb(10,10,1)", "stop-color");\r
2638 \r
2639           frame.timelines.length = 0;\r
2640           ele.setAttributeNS(null, "attributeName", "color");\r
2641           $animate.init(ele);\r
2642           f(0, "rgb(0,0,0)", "color");\r
2643           f(23, "rgb(10,10,1)", "color");\r
2644         } );\r
2645         /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
2646         it("should be this for the value (the valid partion )", function() {\r
2647           ele.setAttributeNS(null, "begin", "0s");\r
2648           ele.setAttributeNS(null, "dur", "1s");\r
2649           ele.setAttributeNS(null, "attributeName", "fill");\r
2650           ele.setAttributeNS(null, "fill", "remove");\r
2651           ele.setAttributeNS(null, "values", "rgb(0, 0, 0);rgb(24, 2.4, 1)");\r
2652           $animate.init(ele);\r
2653           \r
2654           f(0, "rgb(0, 0, 0)", "fill");\r
2655           f(1, "rgb(1, 0, 0)", "fill");\r
2656           f(23, "rgb(23, 2, 1)", "fill");\r
2657 \r
2658           frame.timelines.length = 0;\r
2659           ele.setAttributeNS(null, "values", "#00083C;#18203C");\r
2660           $animate.init(ele);\r
2661           /*rgb形式に変換*/\r
2662           \r
2663           f(0, "rgb(0, 8, 60)", "fill");\r
2664           f(1, "rgb(1, 9, 60)", "fill");\r
2665           f(23, "rgb(23, 31, 60)", "fill");\r
2666           \r
2667           frame.timelines.length = 0;\r
2668           ele.setAttributeNS(null, "fill", "freeze");\r
2669           ele.setAttributeNS(null, "values", "black;white");\r
2670           $animate.init(ele);\r
2671           /*色キーワードをrgb形式に変換*/\r
2672           \r
2673           f(0, "rgb(0, 0, 0)", "fill");\r
2674           f(12, "rgb(128, 128, 128)", "fill");\r
2675           f(24, "rgb(255, 255, 255)", "fill");\r
2676         } );\r
2677         /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
2678         it("should be this for the value (the invalid partion )", function() {\r
2679           ele.setAttributeNS(null, "begin", "0s");\r
2680           ele.setAttributeNS(null, "dur", "1s");\r
2681           ele.setAttributeNS(null, "attributeName", "fi");\r
2682           ele.setAttributeNS(null, "fill", "remove");\r
2683           ele.setAttributeNS(null, "values", "#00083C;#00107C");\r
2684           $animate.init(ele);\r
2685           /*rgb形式に変換しない*/\r
2686           \r
2687           function f (fr, result, attr) {\r
2688             frame.setFrame(fr);\r
2689             expect(ele.parentNode.getAttributeNS(null,attr)).toBe(result);\r
2690           };\r
2691           f(0, "#83.0C", "fi");\r
2692           f(1, "#84.0C", "fi");\r
2693           f(23, "#106.0C", "fi");   \r
2694         } );\r
2695       } );\r
2696     describe("$frame.$svgEvent object", function() {\r
2697       var frame = base("$frame").$svgEvent,\r
2698           p, ele;\r
2699       base("$frame").pauseAnimation();\r
2700       beforeEach( function() {\r
2701         base("$frame").pauseAnimation();\r
2702         frame = frame.up().mix( {isResolved: true} );\r
2703         frame.first = null;\r
2704         /*firstプロパティとtimelinesプロパティは$frameオブジェクトのフレーム進行に\r
2705          * 影響を受けるため、新たに初期化しておく*/\r
2706         base("$frame").timelines = frame.timelines = [];\r
2707         frame.lastTimeLine = null;\r
2708         p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
2709         ele = document.createElementNS("http://www.w3.org/2000/svg", "animate");\r
2710         p.appendChild(ele);\r
2711       } );\r
2712       /*境界条件を調べておく (limit value analysis)*/\r
2713       it("should be this for the value  (limit value analysis)", function() {\r
2714         base("$frame").pauseAnimation();\r
2715         frame.lastTimeLine = null;\r
2716         expect(frame.lastTimeLine).toBeNull();\r
2717         expect(frame.first).toBeNull();\r
2718         frame.setTimeTable();\r
2719         expect(frame.first).toBeNull();\r
2720         frame.addLine( base("$frame").$begin.up().mix({\r
2721           isResolved: true,\r
2722           timelines: [],\r
2723           begin: 0,\r
2724           activeTime: 0,\r
2725           target: ele\r
2726         }) );\r
2727         frame.setTimeTable();\r
2728         expect(frame.first).toEqual(\r
2729           { frame: 0,\r
2730             eventType: "begin",\r
2731             target: ele,\r
2732           \r
2733             next: { frame: 0,\r
2734               eventType: "end",\r
2735               target: ele,\r
2736               next: null\r
2737             }\r
2738           }\r
2739         );\r
2740       } );\r
2741       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
2742       it("should be this for the value (the valid partion )", function() {\r
2743         base("$frame").pauseAnimation();\r
2744         frame.addLine( base("$frame").$begin.up().mix({\r
2745           isResolved: true,\r
2746           timelines: [],\r
2747           begin: 0,\r
2748           activeTime: 0,\r
2749           target: ele\r
2750         }) );\r
2751         frame.setTimeTable();\r
2752         frame.setTimeTable();\r
2753         expect(frame.first).toEqual(\r
2754           { frame: 0,\r
2755             eventType: "begin",\r
2756             target: ele,\r
2757           \r
2758             next: { frame: 0,\r
2759               eventType: "end",\r
2760               target: ele,\r
2761               next: null\r
2762             }\r
2763           }\r
2764         );\r
2765         frame.setTimeTable();\r
2766         frame.setTimeTable();\r
2767         expect(frame.first).toEqual(\r
2768           { frame: 0,\r
2769             eventType: "begin",\r
2770             target: ele,\r
2771           \r
2772             next: { frame: 0,\r
2773               eventType: "end",\r
2774               target: ele,\r
2775               next: null\r
2776             }\r
2777           }\r
2778         );\r
2779         \r
2780         var isFiredBeginEvent = false;\r
2781         ele.addEventListener("beginEvent", function(evt) {\r
2782           isFiredBeginEvent = true;\r
2783           expect(evt.target).toBe(ele);\r
2784         } );\r
2785         ele.addEventListener("endEvent", function(evt) {\r
2786           expect(evt.target).toBe(ele);\r
2787           expect(isFiredBeginEvent).toBeTruthy();\r
2788         } );\r
2789         frame.setFrame(0);\r
2790         expect(frame.first).toBeNull();\r
2791         frame.setFrame(0);\r
2792         expect(frame.first).toBeNull();\r
2793         \r
2794         frame.timelines = [];\r
2795         frame.addLine( base("$frame").$begin.up().mix({\r
2796           isResolved: true,\r
2797           timelines: [],\r
2798           begin: 0,\r
2799           activeTime: 10,\r
2800           target: ele\r
2801         }) );\r
2802         frame.setTimeTable();\r
2803         var a = { frame: 0,\r
2804             eventType: "begin",\r
2805             target: ele,\r
2806           \r
2807             next: { frame: 10,\r
2808               eventType: "end",\r
2809               target: ele,\r
2810               next: null\r
2811             }\r
2812           };\r
2813         expect(frame.first).toEqual(a);\r
2814         \r
2815         frame.addLine( base("$frame").$begin.up().mix({\r
2816           isResolved: true,\r
2817           timelines: [],\r
2818           begin: 1,\r
2819           simpleDuration: 9,\r
2820           activeTime: 11,\r
2821           target: ele\r
2822         }) );\r
2823         frame.setTimeTable();\r
2824         a.next.next = { frame: 1,\r
2825             eventType: "begin",\r
2826             target: ele,\r
2827           \r
2828             next: {\r
2829               frame: 10,\r
2830               eventType: "repeat",\r
2831               count: 1,\r
2832               target: ele,\r
2833             \r
2834               next: { frame: 12,\r
2835                 eventType: "end",\r
2836                 target: ele,\r
2837                 next: null\r
2838               }\r
2839             }\r
2840           };\r
2841         expect(frame.first).toEqual(a);\r
2842         frame.setFrame(11);\r
2843         expect(frame.first).toEqual( {frame: 12,\r
2844                 eventType: "end",\r
2845                 target: ele,\r
2846                 next: null\r
2847               } );\r
2848               \r
2849         frame.timelines = [];\r
2850         frame.first = null;\r
2851         frame.addLine( base("$frame").$begin.up().mix({\r
2852           isResolved: true,\r
2853           timelines: [],\r
2854           begin: 1,\r
2855           simpleDuration: 4,\r
2856           activeTime: 10,\r
2857           target: ele\r
2858         }) );\r
2859         frame.setTimeTable();\r
2860         a =  { frame: 1,\r
2861             eventType: "begin",\r
2862             target: ele,\r
2863           \r
2864             next: {\r
2865               frame: 5,\r
2866               eventType: "repeat",\r
2867               count: 1,\r
2868               target: ele,\r
2869             \r
2870               next: {\r
2871                 frame: 9,\r
2872                 eventType: "repeat",\r
2873                 count: 2,\r
2874                 target: ele,\r
2875               \r
2876                 next: { frame: 11,\r
2877                   eventType: "end",\r
2878                   target: ele,\r
2879                   next: null\r
2880                 }\r
2881               }\r
2882             }\r
2883           };\r
2884         expect(frame.first).toEqual(a);\r
2885         frame.setFrame(0);\r
2886         expect(frame.first).toEqual(a);\r
2887         frame.setFrame(1);\r
2888         a = a.next;\r
2889         expect(frame.first).toEqual(a);\r
2890         frame.setFrame(5);\r
2891         expect(frame.first).toEqual(a.next);\r
2892 \r
2893         ele.addEventListener("repeatEvent", function(evt) {\r
2894           expect(evt.target).toBe(ele);\r
2895         } );\r
2896         frame.timelines = [];\r
2897         frame.first = null;\r
2898         frame.addLine( base("$frame").$begin.up().mix({\r
2899           isResolved: true,\r
2900           timelines: [],\r
2901           begin: 1,\r
2902           simpleDuration: 4,\r
2903           activeTime: 15,\r
2904           target: ele\r
2905         }) );\r
2906         frame.setFrame(9);\r
2907         expect(frame.first).toEqual({\r
2908                 frame: 13,\r
2909                 eventType: "repeat",\r
2910                 count: 3,\r
2911                 target: ele,\r
2912               \r
2913                 next: { frame: 16,\r
2914                   eventType: "end",\r
2915                   target: ele,\r
2916                   next: null\r
2917                 }\r
2918               } );\r
2919       } );\r
2920       afterEach( function() {\r
2921         base("$frame").startAnimation();\r
2922       } );\r
2923     } );\r
2924     describe("A $animateTransformElemenet object", function() {\r
2925       describe("An init method", function() {\r
2926         var $animate, ele, frame, p;\r
2927         beforeEach( function() {\r
2928           $animate = base("$calcMode").$attribute.$setElement.$animateElement.$animateTransformElement.up();\r
2929           /*ここでは、データ量を削るため、degitsプロパティを小数点以下1桁に設定*/\r
2930           $animate.degits = 1;\r
2931           p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
2932           ele = document.createElementNS("http://www.w3.org/2000/svg", "animateTransform");\r
2933           p.appendChild(ele);\r
2934           frame = base("$frame");\r
2935           frame.timelines.length = 0;\r
2936           frame.startTime = Date.now();\r
2937           frame.setFrame(0);\r
2938         } );\r
2939         afterEach( function() {\r
2940           $animate.numberOfList = -1;\r
2941         } );\r
2942         /*境界条件を調べておく (limit value analysis)*/\r
2943         it("should be this for the value  (limit value analysis)", function() {\r
2944           expect($animate.numberOfList).toBe(-1);\r
2945           expect($animate.type).toBe("translate");\r
2946           expect(p.__transformList).toBeUndefined();\r
2947           expect($animate.isCSS).toBeFalsy();\r
2948           expect($animate.isSum).toBeFalsy();\r
2949           expect($animate.attrName).toBe("transform");\r
2950           \r
2951           $animate.init();\r
2952           expect($animate.numberOfList).toBe(-1);\r
2953           expect(p.__transformList).toBeUndefined();\r
2954           expect($animate.isCSS).toBeFalsy();\r
2955           expect($animate.type).toBe("translate");\r
2956           expect($animate.attrName).toBe("transform");\r
2957           \r
2958           $animate.init(p);\r
2959           expect($animate.numberOfList).toBe(-1);\r
2960           expect(p.__transformList).toBeUndefined();\r
2961           expect($animate.isCSS).toBeFalsy();\r
2962           expect($animate.type).toBe("translate");\r
2963           expect($animate.attrName).toBe("transform");\r
2964           \r
2965           $animate.init(ele);\r
2966           expect($animate.numberOfList).toBe(-1);\r
2967           expect(p.__transformList).toEqual([]);\r
2968           expect($animate.isCSS).toBeFalsy();\r
2969           expect($animate.type).toBe("translate");\r
2970           expect($animate.attrName).toBe("transform");\r
2971           \r
2972           ele.setAttributeNS(null, "values", "0;1");\r
2973           ele.setAttributeNS(null, "attributeName", "");\r
2974           $animate.init(ele);\r
2975           expect($animate.isCSS).toBeFalsy();\r
2976           expect($animate.type).toBe("translate");\r
2977           expect($animate.type).toBe("translate");\r
2978           expect($animate.numberOfList).toBe(0);\r
2979           expect(p.__transformList).toEqual([ {isPlaying: false,\r
2980                                                value: "translate(0)",\r
2981                                                isSum: false,\r
2982                                                isRemove: true\r
2983                                               } ]);\r
2984           \r
2985           ele.setAttributeNS(null, "type", "translate");\r
2986           $animate.init(ele);\r
2987           expect($animate.numberOfList).toBe(0);\r
2988           expect($animate.isCSS).toBeFalsy();\r
2989           expect($animate.type).toBe("translate");\r
2990           expect(p.__transformList).toEqual([ {isPlaying: false,\r
2991                                                value: "translate(0)",\r
2992                                                isSum: false,\r
2993                                                isRemove: true\r
2994                                               } ]);\r
2995           $animate.tocall(0);\r
2996           expect(p.__transformList[0].isPlaying).toBeTruthy();\r
2997           \r
2998           ele.parentNode.appendChild(ele.cloneNode(true));\r
2999           $animate.numberOfList = -1;\r
3000           $animate.init(ele.parentNode.lastChild);\r
3001           expect($animate.numberOfList).toBe(1);\r
3002           expect(p.__transformList[0].isPlaying).toBeTruthy();\r
3003           expect(p.__transformList[1].isPlaying).toBeFalsy();\r
3004 \r
3005           expect($animate.type).toBe("translate");\r
3006           $animate.tocall(0);\r
3007           expect(p.__transformList[0].isPlaying).toBeTruthy();\r
3008           expect(p.__transformList[1].isPlaying).toBeTruthy();\r
3009           $animate._setEndFrame(1);\r
3010           expect(p.__transformList[0].isPlaying).toBeTruthy();\r
3011           expect(p.__transformList[1].isPlaying).toBeFalsy();\r
3012           \r
3013           delete p.__transformList;\r
3014           ele.setAttributeNS(null, "type", "scale");\r
3015           $animate.numberOfList = -1;\r
3016           $animate.init(ele);\r
3017           expect($animate.numberOfList).toBe(0);\r
3018           expect(p.__transformList).toEqual([ {isPlaying: false,\r
3019                                                value: "translate(0)",\r
3020                                                isSum: false,\r
3021                                                isRemove: true\r
3022                                               } ]);\r
3023           expect($animate.type).toBe("scale");\r
3024 \r
3025           delete p.__transformList;\r
3026           $animate.numberOfList = -1;\r
3027           ele.setAttributeNS(null, "additive", "sum");\r
3028           ele.setAttributeNS(null, "fill", "freeze");\r
3029           $animate.init(ele);\r
3030           expect($animate.isSum).toBeTruthy();\r
3031           expect(p.__transformList).toEqual([ {isPlaying: false,\r
3032                                                value: "translate(0)",\r
3033                                                isSum: true,\r
3034                                                isRemove: false\r
3035                                               } ]);\r
3036           delete p.__transformList;\r
3037           $animate.numberOfList = -1;\r
3038           ele.setAttributeNS(null, "additive", "replace");\r
3039           ele.setAttributeNS(null, "fill", "remove");\r
3040           $animate.init(ele);\r
3041           expect(p.__transformList).toEqual([ {isPlaying: false,\r
3042                                                value: "translate(0)",\r
3043                                                isSum: false,\r
3044                                                isRemove: true\r
3045                                               } ]);\r
3046         } );\r
3047         /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
3048         it("should be this for the value (the valid partion )", function() {\r
3049           ele.setAttributeNS(null, "type", "scale");\r
3050           ele.setAttributeNS(null, "values", "0;1");\r
3051           $animate.init(ele);\r
3052           expect($animate.isCSS).toBeFalsy();\r
3053           expect($animate.numberOfList).toBe(0);\r
3054           expect($animate.tocall(0)).toBe("scale(0.0)");\r
3055           expect($animate.tocall(0.5)).toBe("scale(0.5)");\r
3056           expect($animate.tocall(0.9)).toBe("scale(0.9)");\r
3057           expect($animate.tocall(1)).toBe("scale(1.0)");\r
3058 \r
3059           ele.parentNode.appendChild(ele.cloneNode(true));\r
3060           $animate.numberOfList = -1;\r
3061           $animate.init(ele.parentNode.lastChild);\r
3062           expect($animate.numberOfList).toBe(1);\r
3063           expect($animate.tocall(0)).toBe("scale(0.0)");\r
3064           expect($animate.tocall(1)).toBe("scale(1.0)");\r
3065           \r
3066           ele.parentNode.appendChild(ele.cloneNode(true));\r
3067           $animate.up("$a").numberOfList = -1;\r
3068           ele.parentNode.setAttribute("transform", "matrix(0 0 0 0 0 0)");\r
3069           $animate.$a.init(ele.parentNode.lastChild);\r
3070           expect($animate.$a.numberOfList).toBe(2);\r
3071           expect($animate.$a.isDefault).toBeTruthy();\r
3072           expect($animate.$a.defaultValue).toBe("matrix(0 0 0 0 0 0)");\r
3073           expect($animate.$a.tocall(0)).toBe("scale(0.0)");\r
3074           expect($animate.$a.tocall(1)).toBe("scale(1.0)");\r
3075           $animate.defaultValue = $animate.$a.defaultValue;\r
3076           expect($animate.$a.tocall(0.1)).toBe("scale(0.1)");\r
3077           \r
3078           ele.setAttributeNS(null, "additive", "sum");\r
3079           var parentNode = ele.parentNode;\r
3080           parentNode.appendChild(ele.cloneNode(true));\r
3081           parentNode.__transformList = [];\r
3082           /*additive属性のsumとreplaceの混合を避けるため、eleを削除*/\r
3083           parentNode.removeChild(ele);\r
3084           $animate.numberOfList = -1;\r
3085           $animate.init(parentNode.lastChild);\r
3086           expect($animate.numberOfList).toBe(0);\r
3087           expect($animate.tocall(0)).toBe("matrix(0 0 0 0 0 0) scale(0.0)");\r
3088           expect($animate.tocall(1)).toBe("matrix(0 0 0 0 0 0) scale(1.0)");\r
3089           \r
3090           parentNode.appendChild(ele.cloneNode(true));\r
3091           $animate.up("$a").numberOfList = -1;\r
3092           parentNode.__transformList = [];\r
3093           parentNode.setAttribute("transform", "matrix(0 0 0 0 0 0)");\r
3094           $animate.$a.init(parentNode.lastChild);\r
3095           expect($animate.$a.numberOfList).toBe(0);\r
3096           expect($animate.$a.isDefault).toBeTruthy();\r
3097           expect($animate.$a.defaultValue).toBe("matrix(0 0 0 0 0 0)");\r
3098           expect($animate.$a.tocall(0)).toBe("matrix(0 0 0 0 0 0) scale(0.0)");\r
3099           expect($animate.$a.tocall(1)).toBe("matrix(0 0 0 0 0 0) scale(1.0)");\r
3100           $animate.defaultValue = $animate.$a.defaultValue;\r
3101           expect($animate.tocall(0.1)).toBe("matrix(0 0 0 0 0 0) scale(0.1)");\r
3102           \r
3103           ele.removeAttributeNS(null, "additive");\r
3104           ad("replace", "sum", "scale(0.0) translate(0)", "scale(0.0) scale(0.0)",\r
3105            "scale(1.0) scale(0.0)", "scale(1.0) scale(1.0)");\r
3106           ad("sum", "replace", "matrix(0 0 0 0 0 0) scale(0.0)", "scale(0.0)",\r
3107            "scale(0.0)", "scale(1.0)");\r
3108           function ad(first, second, a, b, c, d) {\r
3109             /*子要素を全部消す*/\r
3110             while (parentNode.firstChild) {\r
3111               parentNode.removeChild(parentNode.firstChild);\r
3112             }\r
3113             \r
3114             /*additive属性のreplaceとsumの混合*/\r
3115             ele.setAttributeNS(null, "additive", first);\r
3116             parentNode.appendChild(ele.cloneNode(true));\r
3117             ele.setAttributeNS(null, "additive", second);\r
3118             parentNode.appendChild(ele.cloneNode(true));\r
3119             parentNode.__transformList = [];\r
3120             $animate.numberOfList = -1;\r
3121             parentNode.setAttribute("transform", "matrix(0 0 0 0 0 0)");\r
3122             $animate.up("$first").init(parentNode.firstChild);\r
3123             $animate.up("$second").init(parentNode.lastChild);\r
3124             expect($animate.$first.numberOfList).toBe(0);\r
3125             expect($animate.$second.numberOfList).toBe(1);\r
3126             expect($animate.$first.tocall(0)).toBe(a);\r
3127             expect($animate.$second.tocall(0)).toBe(b);\r
3128             expect($animate.$first.tocall(1)).toBe(c);\r
3129             expect($animate.$second.tocall(1)).toBe(d);\r
3130           };\r
3131         } );\r
3132         /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
3133         it("should be this for the value (the invalid partion )", function() {\r
3134           $animate.init(ele);\r
3135           ele.parentNode.__transformList = null;\r
3136           expect( function () {\r
3137             $animate.tocall(0);\r
3138           } ).toThrow();\r
3139           \r
3140           $animate.numberOfList = -1;\r
3141           $animate.init(ele);\r
3142           $animate.numberOfList = -1;\r
3143           expect( function () {\r
3144             $animate.tocall(0);\r
3145           } ).toThrow();\r
3146         } );\r
3147       } );\r
3148     } );\r
3149     describe("A $motionElement object", function() {\r
3150       describe("An init method", function() {\r
3151         var $animate, ele, frame, p;\r
3152         beforeEach( function() {\r
3153           $animate = base("$calcMode").$attribute.$setElement.$animateElement.$animateTransformElement.$motionElement.up();\r
3154           /*ここでは、データ量を削るため、degitsプロパティを小数点以下1桁に設定*/\r
3155           $animate.degits = 1;\r
3156           p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
3157           ele = document.createElementNS("http://www.w3.org/2000/svg", "animateMotion");\r
3158           p.appendChild(ele);\r
3159           frame = base("$frame");\r
3160           frame.timelines.length = 0;\r
3161           frame.startTime = Date.now();\r
3162           frame.setFrame(0);\r
3163         } );\r
3164         afterEach( function() {\r
3165           $animate.numberOfList = -1;\r
3166           delete $animate.element;\r
3167           p.__transformList = null;\r
3168         } );\r
3169         /*境界条件を調べておく (limit value analysis)*/\r
3170         it("should be this for the value  (limit value analysis)", function() {\r
3171           expect($animate.type).toBe("translate");\r
3172           expect($animate.mode).toBe("paced");\r
3173           ele.setAttributeNS(null, "type", "scale");\r
3174           expect($animate.rotate).toBe("0");\r
3175           $animate.init(ele);\r
3176           expect($animate.type).toBe("translate");\r
3177           expect($animate.mode).toBe("paced");\r
3178           expect($animate.rotate).toBe("0");\r
3179           \r
3180           ele.setAttributeNS(null, "values", "0,0;1,0");\r
3181           $animate.up("$a").init(ele);\r
3182           expect($animate.$a.tocall(0)).toBe("translate(0.0,0.0)");\r
3183           expect($animate.$a.tocall(0.5)).toBe("translate(0.5,0.0)");\r
3184           expect($animate.$a.tocall(1)).toBe("translate(1.0,0.0)");\r
3185           \r
3186           var ec = ele.cloneNode(true);\r
3187           p.appendChild(ec);\r
3188           ec.removeAttributeNS(null, "values");\r
3189           ec.setAttributeNS(null, "from", "0,0");\r
3190           ec.setAttributeNS(null, "to", "1,0");\r
3191           $animate.up("$a").init(ec);\r
3192           expect($animate.$a.tocall(0)).toBe("translate(0.0,0.0)");\r
3193           expect($animate.$a.tocall(0.5)).toBe("translate(0.5,0.0)");\r
3194           expect($animate.$a.tocall(1)).toBe("translate(1.0,0.0)");\r
3195         } );\r
3196         /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
3197         it("should be this for the value (the invalid partion )", function() {\r
3198           $animate.init();\r
3199         } );\r
3200       } );\r
3201       describe("A hasAttrValues method", function() {\r
3202         var $animate, ele, frame, p;\r
3203         beforeEach( function() {\r
3204           $animate = base("$calcMode").$attribute.$setElement.$animateElement.$animateTransformElement.$motionElement.up();\r
3205           /*ここでは、データ量を削るため、degitsプロパティを小数点以下1桁に設定*/\r
3206           $animate.degits = 1;\r
3207           p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
3208           ele = document.createElementNS("http://www.w3.org/2000/svg", "animateMotion");\r
3209           p.appendChild(ele);\r
3210           frame = base("$frame");\r
3211           frame.timelines.length = 0;\r
3212           frame.startTime = Date.now();\r
3213           frame.setFrame(0);\r
3214         } );\r
3215         afterEach( function() {\r
3216           $animate.numberOfList = -1;\r
3217           delete $animate.element;\r
3218           p.__transformList = null;\r
3219         } );\r
3220         /*境界条件を調べておく (limit value analysis)*/\r
3221         it("should be this for the value  (limit value analysis)", function() {\r
3222                     \r
3223           expect($animate.up("$a").hasAttrValues()).toBeFalsy();\r
3224           $animate.up("$a").init(ele);\r
3225           expect($animate.$a.hasAttrValues()).toBeFalsy();\r
3226           \r
3227           ele.setAttributeNS(null, "path", "M");\r
3228           expect($animate.$a.hasAttrValues()).toBeTruthy();\r
3229           $animate.$animateTransformElement.up("$b").init(ele);\r
3230           expect($animate.$animateTransformElement.$b.hasAttrValues()).toBeFalsy();\r
3231         } );\r
3232       } );\r
3233     } );\r
3234     describe("Event", function() {\r
3235       var $animate, ele, frame, p;\r
3236       beforeEach( function() {\r
3237         \r
3238         $animate = base("$calcMode").$attribute.$setElement.$animateElement.up();\r
3239         p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
3240         ele = document.createElementNS("http://www.w3.org/2000/svg", "animate");\r
3241         p.appendChild(ele);\r
3242         frame = base("$frame");\r
3243         frame.pauseAnimation();\r
3244         frame.timelines.length = 0; //配列の初期化\r
3245         frame.setFrame(0);\r
3246       } );\r
3247       /*境界条件を調べておく (limit value analysis)*/\r
3248       it("should be this for the value  (limit value analysis)", function() {\r
3249         ele.addEventListener("beginEvent", function(evt) {\r
3250           expect(evt.target).toBe(ele);\r
3251         } );\r
3252         var evt = ele.ownerDocument.createEvent("MouseEvents");\r
3253         evt.initMouseEvent("beginEvent",true, true, window, 0, 0, 0, 0, 0, false, false, false, false,0, ele);\r
3254         ele.dispatchEvent(evt);\r
3255         \r
3256         ele.setAttributeNS(null, "begin", "mousedown");\r
3257         ele.setAttributeNS(null, "dur", "1s");\r
3258         ele.setAttributeNS(null, "attributeName", "fill");\r
3259         ele.setAttributeNS(null, "fill", "freeze");\r
3260         ele.setAttributeNS(null, "from", "rgb(0,0,0)");\r
3261         ele.setAttributeNS(null, "to", "rgb(10,10,1)");\r
3262         $animate.init(ele);\r
3263         $animate.isCSS = false;\r
3264         expect(p.getAttributeNS(null, "fill") || null).toBeNull();\r
3265         evt = ele.ownerDocument.createEvent("MouseEvents");\r
3266         evt.initMouseEvent("beginEvent",true, true, window, 0, 0, 0, 0, 0, false, false, false, false,0, ele);\r
3267         p.dispatchEvent(evt);\r
3268         expect(p.getAttributeNS(null, "fill") || null).toBeNull();\r
3269         \r
3270         evt = ele.ownerDocument.createEvent("MouseEvents");\r
3271         evt.initMouseEvent("mousedown",true, true, window, 0, 0, 0, 0, 0, false, false, false, false,0, p);\r
3272         frame.setFrame(frame.currentFrame);\r
3273         expect($animate.isEnd).toBeFalsy();\r
3274         p.dispatchEvent(evt);\r
3275         frame.setFrame(frame.currentFrame + 1);\r
3276         frame.setFrame(frame.currentFrame + 24);\r
3277         expect(evt.target.getAttributeNS(null, "fill") || null).toBe("rgb(10, 10, 1)");\r
3278       } );\r
3279     } );\r
3280       describe("a beginElement method and an endElement method", function() {\r
3281         var $animate, ele, frame, p;\r
3282         beforeEach( function() {\r
3283           $animate = base("$calcMode").$attribute.$setElement.$animateElement.up();\r
3284           p = document.createElementNS("http://www.w3.org/2000/svg", "g");\r
3285           ele = document.createElementNS("http://www.w3.org/2000/svg", "animate");\r
3286           p.appendChild(ele);\r
3287           frame = base("$frame");\r
3288           frame.timelines.length = 0; //配列の初期化\r
3289           frame.setFrame(0);\r
3290           ele.setAttributeNS(null, "begin", "indefinite");\r
3291           ele.setAttributeNS(null, "dur", "1s");\r
3292           ele.setAttributeNS(null, "dur", "1s");\r
3293           ele.setAttributeNS(null, "attributeName", "fill");\r
3294           ele.setAttributeNS(null, "fill", "freeze");\r
3295           ele.setAttributeNS(null, "from", "rgb(0,0,0)");\r
3296           ele.setAttributeNS(null, "to", "rgb(10,10,1)");\r
3297           $animate.init(ele);\r
3298         } );\r
3299         /*境界条件を調べておく (limit value analysis)*/\r
3300         it("should be this for the value  (limit value analysis)", function() {\r
3301           expect(ele.beginElement()).toBeUndefined();\r
3302           var cur = frame.currentFrame,\r
3303               begin = frame.$begin.$1;\r
3304           expect(begin.string).toBe("indefinite");\r
3305           expect(begin.begin).toBe(cur);\r
3306           expect(ele.endElement()).toBeUndefined();\r
3307         } );\r
3308         /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
3309         it("should be this for the value (the valid partion )", function() {\r
3310           ele.addEventListener("beginEvent", function(evt){\r
3311             expect(evt.target.nodeName).toBe("animate");\r
3312           }, false );\r
3313           ele.beginElement();\r
3314         } );\r
3315       });\r
3316     } );\r
3317 } );\r