Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: sky/tests/framework/observe.sky

Issue 695413003: Remove ArrayFuzzer from observe.sky test (was timing out). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sky/tests/framework/observe-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <html> 1 <html>
2 <import src="../resources/chai.sky" /> 2 <import src="../resources/chai.sky" />
3 <import src="../resources/mocha.sky" /> 3 <import src="../resources/mocha.sky" />
4 <import src="/sky/framework/sky-element/observe.sky" as="observe" /> 4 <import src="/sky/framework/sky-element/observe.sky" as="observe" />
5 5
6 <script> 6 <script>
7 7
8 var Path = observe.Path; 8 var Path = observe.Path;
9 var PathObserver = observe.PathObserver; 9 var PathObserver = observe.PathObserver;
10 var ArrayObserver = observe.ArrayObserver; 10 var ArrayObserver = observe.ArrayObserver;
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 observer = new ArrayObserver(model); 1703 observer = new ArrayObserver(model);
1704 observer.open(callback); 1704 observer.open(callback);
1705 1705
1706 model.splice(1,1); 1706 model.splice(1,1);
1707 model.splice(0,2,1,7); 1707 model.splice(0,2,1,7);
1708 model.splice(1,0,3,7); 1708 model.splice(1,0,3,7);
1709 1709
1710 applySplicesAndAssertDeepEqual(model, copy); 1710 applySplicesAndAssertDeepEqual(model, copy);
1711 }); 1711 });
1712 1712
1713 function ArrayFuzzer() {}
1714
1715 ArrayFuzzer.valMax = 16;
1716 ArrayFuzzer.arrayLengthMax = 128;
1717 ArrayFuzzer.operationCount = 64;
1718
1719 function randDouble(start, end) {
1720 return Math.random()*(end-start) + start;
1721 }
1722
1723 function randInt(start, end) {
1724 return Math.round(randDouble(start, end));
1725 }
1726
1727 function randASCIIChar() {
1728 return String.fromCharCode(randInt(32, 126));
1729 }
1730
1731 function randValue() {
1732 switch(randInt(0, 5)) {
1733 case 0:
1734 return {};
1735 case 1:
1736 return undefined;
1737 case 2:
1738 return null;
1739 case 3:
1740 return randInt(0, ArrayFuzzer.valMax);
1741 case 4:
1742 return randDouble(0, ArrayFuzzer.valMax);
1743 case 5:
1744 return randASCIIChar();
1745 }
1746 }
1747
1748 function randArray() {
1749 var args = [];
1750 var count = randInt(0, ArrayFuzzer.arrayLengthMax);
1751 while(count-- > 0)
1752 args.push(randValue());
1753
1754 return args;
1755 }
1756
1757 function randomArrayOperation(arr) {
1758 function empty() {
1759 return [];
1760 }
1761
1762 var operations = {
1763 push: randArray,
1764 unshift: randArray,
1765 pop: empty,
1766 shift: empty,
1767 splice: function() {
1768 var args = [];
1769 args.push(randInt(-arr.length*2, arr.length*2), randInt(0, arr.length*2) );
1770 args = args.concat(randArray());
1771 return args;
1772 }
1773 };
1774
1775 // Do a splice once for each of the other operations.
1776 var operationList = ['splice', 'update',
1777 'splice', 'delete',
1778 'splice', 'push',
1779 'splice', 'pop',
1780 'splice', 'shift',
1781 'splice', 'unshift'];
1782
1783 var op = {
1784 name: operationList[randInt(0, operationList.length - 1)]
1785 };
1786
1787 switch(op.name) {
1788 case 'delete':
1789 op.index = randInt(0, arr.length - 1);
1790 delete arr[op.index];
1791 break;
1792
1793 case 'update':
1794 op.index = randInt(0, arr.length);
1795 op.value = randValue();
1796 arr[op.index] = op.value;
1797 break;
1798
1799 default:
1800 op.args = operations[op.name]();
1801 arr[op.name].apply(arr, op.args);
1802 break;
1803 }
1804
1805 return op;
1806 }
1807
1808 function randomArrayOperations(arr, count) {
1809 var ops = []
1810 for (var i = 0; i < count; i++) {
1811 ops.push(randomArrayOperation(arr));
1812 }
1813
1814 return ops;
1815 }
1816
1817 ArrayFuzzer.prototype.go = function() {
1818 var orig = this.arr = randArray();
1819 randomArrayOperations(this.arr, ArrayFuzzer.operationCount);
1820 var copy = this.copy = this.arr.slice();
1821 this.origCopy = this.copy.slice();
1822
1823 var observer = new ArrayObserver(this.arr);
1824 observer.open(function(splices) {
1825 ArrayObserver.applySplices(copy, orig, splices);
1826 });
1827
1828 this.ops = randomArrayOperations(this.arr, ArrayFuzzer.operationCount);
1829 observer.deliver();
1830 observer.close();
1831 }
1832
1833
1834 it('Array Tracker Fuzzer', function() {
1835 var testCount = 64;
1836
1837 for (var i = 0; i < testCount; i++) {
1838 var fuzzer = new ArrayFuzzer();
1839 fuzzer.go();
1840 ensureNonSparse(fuzzer.arr);
1841 ensureNonSparse(fuzzer.copy);
1842 assert.deepEqual(fuzzer.arr, fuzzer.copy);
1843 }
1844 });
1845
1846 it('Array Tracker No Proxies Edits', function() { 1713 it('Array Tracker No Proxies Edits', function() {
1847 var model = []; 1714 var model = [];
1848 observer = new ArrayObserver(model); 1715 observer = new ArrayObserver(model);
1849 observer.open(callback); 1716 observer.open(callback);
1850 model.length = 0; 1717 model.length = 0;
1851 model.push(1, 2, 3); 1718 model.push(1, 2, 3);
1852 assertEditDistance(model, 3); 1719 assertEditDistance(model, 3);
1853 observer.close(); 1720 observer.close();
1854 1721
1855 model = ['x', 'x', 'x', 'x', '1', '2', '3']; 1722 model = ['x', 'x', 'x', 'x', '1', '2', '3'];
1856 observer = new ArrayObserver(model); 1723 observer = new ArrayObserver(model);
1857 observer.open(callback); 1724 observer.open(callback);
1858 model.length = 0; 1725 model.length = 0;
1859 model.push('1', '2', '3', 'y', 'y', 'y', 'y'); 1726 model.push('1', '2', '3', 'y', 'y', 'y', 'y');
1860 assertEditDistance(model, 8); 1727 assertEditDistance(model, 8);
1861 observer.close(); 1728 observer.close();
1862 1729
1863 model = ['1', '2', '3', '4', '5']; 1730 model = ['1', '2', '3', '4', '5'];
1864 observer = new ArrayObserver(model); 1731 observer = new ArrayObserver(model);
1865 observer.open(callback); 1732 observer.open(callback);
1866 model.length = 0; 1733 model.length = 0;
1867 model.push('a', '2', 'y', 'y', '4', '5', 'z', 'z'); 1734 model.push('a', '2', 'y', 'y', '4', '5', 'z', 'z');
1868 assertEditDistance(model, 7); 1735 assertEditDistance(model, 7);
1869 observer.close(); 1736 observer.close();
1870 }); 1737 });
1871 }); 1738 });
1872 </script> 1739 </script>
OLDNEW
« no previous file with comments | « no previous file | sky/tests/framework/observe-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698