Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 1 | |
| 2 | function addToBody (msg) { |
| 3 | var body = document.getElementsByTagName('body')[0]; |
| 4 | var p = body.appendChild(document.createElement('p')) |
| 5 | p.appendChild(document.createTextNode(msg)); |
| 6 | }; |
| 7 | |
| 8 | define({ |
| 9 | menuSuite : function (menuClass) { |
| 10 | // add tests |
| 11 | var suite = new Benchmark.Suite; |
| 12 | var menu; |
| 13 | suite.add('Menu#creation', function () { |
| 14 | |
| 15 | menu = menuClass.create([ |
| 16 | ['Titel', 'title'], |
| 17 | ['Untertitel', 'subTitle'], |
| 18 | ['Veröffentlichungsdatum', 'pubDate'], |
| 19 | ['Länge', 'length'], |
| 20 | ['Autor', 'author'] |
| 21 | ]); |
| 22 | |
| 23 | menu.limit(3).show(); |
| 24 | }); |
| 25 | |
| 26 | suite.add('Menu#next', function () { |
| 27 | // Some actions |
| 28 | menu.next(); |
| 29 | }); |
| 30 | |
| 31 | suite.add('Menu#prev', function () { |
| 32 | menu.prev(); |
| 33 | }); |
| 34 | |
| 35 | suite.add('Menu#paging', function () { |
| 36 | var j = 0; |
| 37 | while (j < 2) { |
| 38 | var i = 0; |
| 39 | while (i < 5) { |
| 40 | menu.pageUp(); |
| 41 | i++; |
| 42 | }; |
| 43 | while (i > 0) { |
| 44 | menu.pageDown(); |
| 45 | i--; |
| 46 | }; |
| 47 | j++; |
| 48 | }; |
| 49 | }); |
| 50 | |
| 51 | suite.add('Menu#prefix', function () { |
| 52 | menu.prefix('e').show(4); |
| 53 | menu.next(); |
| 54 | menu.next(); |
| 55 | menu.next(); |
| 56 | menu.prev(); |
| 57 | menu.prev(); |
| 58 | menu.prev(); |
| 59 | }); |
| 60 | |
| 61 | suite.on('error', function(event) { |
| 62 | console.log(event.target.error); |
| 63 | }); |
| 64 | suite.on('cycle', function(event) { |
| 65 | addToBody(String(event.target)); |
| 66 | }); |
| 67 | |
| 68 | return suite; |
| 69 | } |
| 70 | }); |