export const generateBulletData = ( id, max, { title, subtitle, rangeCount = 5, measureCount = 1, markerCount = 1, float = false } = {} ) => { const ranges = range(rangeCount - 1).reduce( acc => { const remaining = max - acc[0] return [random(remaining, float), ...acc] }, [max] ) const measures = range(measureCount).reduce(acc => { if (acc.length === 0) return [random(max, float)] return [random(acc[0], float), ...acc] }, []) const markers = range(markerCount).map(() => max * 0.6 + random(max * 0.4)) return { id, title, subtitle, ranges, measures, markers, } }
constructor(props) { super(props) const date = new Date() date.setMinutes(0) date.setSeconds(0) date.setMilliseconds(0) this.state = { dataA: range(100).map(i => ({ x: time.timeMinute.offset(date, i * 30), y: 10 + Math.round(Math.random() * 20), })), dataB: range(100).map(i => ({ x: time.timeMinute.offset(date, i * 30), y: 30 + Math.round(Math.random() * 20), })), dataC: range(100).map(i => ({ x: time.timeMinute.offset(date, i * 30), y: 60 + Math.round(Math.random() * 20), })), } this.formatTime = timeFormat('%Y %b %d') }
it('-filter', function () { var helper = mock.helper('-filter'); var list = range(1,20); expect(helper('n-even?', list, options)).to.deep.equal(range(2, 20, 2)); expect(helper('n-even?', list, options)).to.not.equal(list); });
function generateDaysGrid(m) { var d1 = m.clone().subtract(1, 'month').endOf('month').date(); var d2 = m.clone().date(1).day(); var d3 = m.clone().endOf('month').date(); return listToGrid([].concat(range(d1 - d2 + 1, d1 + 1), range(1, d3 + 1), range(1, 42 - d3 - d2 + 1))); }
export const bezier = (startPoint, endPoint, extend, num=15) => { // returns Bezier curve starting at first point in pair, curving towards the second point in pair and const midPoint = computeMidpoint(startPoint, endPoint, extend); const pathControl = [startPoint, midPoint, endPoint]; const N = _range(pathControl.length); // number of points in [start, mid, end] that will be used to compute the curve const t = linspace(0.0, 1.0, num); // num points spaced evenly between fractions of the total curve path (0 = beginning, 1 = end) const curve = []; _range(num).forEach((i) => { curve[i] = {x: 0, y: 0}; }); N.forEach((ii) => { // iterate over provided points const B_func = bernstein(N.length - 1, ii); // get Bernstein polynomial const tB = t.map(B_func); // apply Bernstein polynomial to linspace const P = [pathControl[ii].x, pathControl[ii].y]; const prod_idx = outerProducts([_range(tB.length), _range(P.length)]); // get indices for outer product _range(curve.length).forEach((j) => { // iterate over future curve, adjust each point's coordinate curve[j].x += tB[prod_idx[j][0]] * P[prod_idx[j][1]]; // update x coordinate for curve with outer product curve[j].y += tB[prod_idx[j+num][0]] * P[prod_idx[j+num][1]]; // update y coordinate for curve with outer product }); }); return curve; };
it('-take-while', function () { var helper = mock.helper('-take-while'); var list = range(1,20); expect(helper('_lt-3?', list, options)).to.deep.equal([1,2]); expect(helper('_lt-3?', list, options)).to.not.equal(list); expect(helper('n-even?', range(0, 5), options)).to.deep.equal([0]); });
it('-grouped', function () { var helper = mock.helper('-grouped'); expect(helper(3, range(1,11), options)).to.deep.equal([ [1,2,3], [4,5,6], [7,8,9], [10] ]); expect(helper(2, range(1,11), options)).to.deep.equal([ [1,2], [3,4], [5,6], [7,8], [9,10] ]); });
const cellsForEntry = (entry: Clue): Array<Position> => isAcross(entry) ? range(entry.position.x, entry.position.x + entry.length).map(x => ({ x, y: entry.position.y, })) : range(entry.position.y, entry.position.y + entry.length).map(y => ({ x: entry.position.x, y, }));
N.forEach((ii) => { // iterate over provided points const B_func = bernstein(N.length - 1, ii); // get Bernstein polynomial const tB = t.map(B_func); // apply Bernstein polynomial to linspace const P = [pathControl[ii].x, pathControl[ii].y]; const prod_idx = outerProducts([_range(tB.length), _range(P.length)]); // get indices for outer product _range(curve.length).forEach((j) => { // iterate over future curve, adjust each point's coordinate curve[j].x += tB[prod_idx[j][0]] * P[prod_idx[j][1]]; // update x coordinate for curve with outer product curve[j].y += tB[prod_idx[j+num][0]] * P[prod_idx[j+num][1]]; // update y coordinate for curve with outer product }); });
render() { return ( <View style={styles.dotsContainer}> {range(0, this.props.length).map(n => ( <Image source={filledCircle} style={styles.dot} key={n} /> ))} {range(0, 4 - this.props.length).map(n => ( <Image source={emptyCircle} style={styles.dot} key={n} /> ))} </View> ); }
getShowingMonth (from, to, current) { if (from.getFullYear() === to.getFullYear()) { return range(from.getMonth() + 1, to.getMonth() + 2); } if (current.getFullYear() === to.getFullYear()) { return range(1, to.getMonth() + 2) } if (current.getFullYear() === from.getFullYear()) { return range(from.getMonth() + 1, 13) } return range(1, 13); }
getShowingDays (from, to, current) { let daysInCurrentMonth = this.daysInMonth(current.getMonth() + 1, current.getFullYear()); if (from.getFullYear() === to.getFullYear() && from.getMonth() === to.getMonth()) { return range(from.getDate(), to.getDate() + 1); } if (current.getFullYear() === to.getFullYear() && current.getMonth() === to.getMonth()) { return range(1, to.getDate() + 1) } if (current.getFullYear() === from.getFullYear() && current.getMonth() === to.getMonth()) { return range(from.getDate(), daysInCurrentMonth + 1) } return range(1, daysInCurrentMonth + 1); }
const buildGrid = ( rows: number, columns: number, entries: Array<Clue>, savedState: Array<Array<string>> ): Grid => { const grid = range(columns).map(x => range(rows).map(y => ({ isHighlighted: false, isEditable: false, isError: false, isAnimating: false, value: savedState && savedState[x] && savedState[x][y] ? savedState[x][y] : '', })) ); entries.forEach(entry => { const { x, y } = entry.position; grid[x][y].number = entry.number; cellsForEntry(entry).forEach(cell => { grid[cell.x][cell.y].isEditable = true; }); }); // $FlowFixMe return grid; };
getGroupedData() { return range(7).map(() => { return [ { x: "rabbits", y: random(1, 5) }, { x: "cats", y: random(1, 10) }, { x: "dogs", y: random(2, 10) }, { x: "birds", y: random(2, 10) }, { x: "frogs", y: random(2, 15) } ]; }); }
function Stars({count}: {count: number}) { return ( <Box style={globalStyles.flexBoxRow}> {range(count).map(i => <Icon key={i} style={{color: globalColors.green}} type="iconfont-star" />)} </Box> ) }
describe( 'Show new items', function() { var helper = new ScrollHelper(); helper.props = { items: range( 8 ), guessedItemHeight: 300, itemsPerRow: 1, getItemRef: getItemRef, }; helper.reset( { lastRenderedIndex: 4, } ); helper.containerBottom = 900; helper.bottomHideLevelHard = 2000; helper.bottomHideLevelSoft = 3000; helper.bottomPlaceholderHeight = 200; // stored item heighs left to default helper.showItemsBelow(); it( 'placeholder height is never negative', function() { assert.equal( 0, helper.bottomPlaceholderHeight ); } ); it( 'container bottom is increased', function() { assert.equal( 1600, helper.containerBottom ); } ); it( 'shown 3 items', function() { assert.equal( 7, helper.lastRenderedIndex ); } ); } );
describe( 'Completely below context', function() { var helper = new ScrollHelper( function() { return null; } // let it use guessed height ); helper.props = { items: range( 2 ), guessedItemHeight: 300, itemsPerRow: 1, getItemRef: getItemRef, }; helper.reset( { lastRenderedIndex: 1, } ); helper.containerBottom = 5000; helper.bottomHideLevelHard = 2000; helper.bottomPlaceholderHeight = 800; helper.hideItemsBelow(); it( 'created placeholder for 2 items', function() { assert.equal( 1400, helper.bottomPlaceholderHeight ); } ); it( 'hid all items', function() { assert.equal( -1, helper.lastRenderedIndex ); } ); } );
describe( 'Show item longer than context', function() { var helper = new ScrollHelper(); helper.props = { items: range( 8 ), guessedItemHeight: 300, itemsPerRow: 1, getItemRef: getItemRef, }; helper.reset( { lastRenderedIndex: 4, } ); helper.containerBottom = 5000; helper.bottomHideLevelHard = 2000; helper.bottomHideLevelSoft = 3000; helper.bottomPlaceholderHeight = 3100; helper.itemHeights = { i5: 1200, i6: 300 }; // corresponding itemTops: 3100, 3400 helper.showItemsBelow(); it( 'reduced placeholder height', function() { assert.equal( 1900, helper.bottomPlaceholderHeight ); } ); it( 'shown 2 items', function() { assert.equal( 5, helper.lastRenderedIndex ); } ); } );
const createRichTextParagraph = () => { const spans = [ // Emphasized. (word) => `<em>${word}</em>`, // Strong emphasized. (word) => `<strong>${word}</strong>`, // Simple link (word) => `<a href="#" class="Link">${word}</a>`, // Raw link (word) => `<a href="#" class="RawLink">${word}</a>`, // Guider link (word) => `<a href="#" class="GuiderLink">${word}<i class="fa fa-toggle-right"></i></a>`, // In page anchor (word) => `<a href="#" class="AnchorLink">${word}<i class="fa fa-chevron-down"></i></a>`, ]; const words = faker.lorem.paragraph(spans.length * 3).split(' '); const indices = shuffle(range(words.length)).splice(0, spans.length); const richtext = words.map( (value, index) => ( indices.indexOf(index) > -1 ? spans[indices.indexOf(index)](value) : value ) ); return `<p>${richtext.join(' ')}</p>`; };
describe( 'Show items when their real height is higher than stored', function() { var helper = new ScrollHelper(); helper.props = { items: range( 3 ), guessedItemHeight: 300, itemsPerRow: 1, getItemRef: getItemRef, }; helper.reset( { firstRenderedIndex: 2, } ); helper.containerTop = 0; helper.topHideLevelSoft = -2000; // extrame case - no top placeholder, but still items to be shown helper.topPlaceholderHeight = 0; // item heights left to default helper.showItemsAbove(); it( 'placeholder height is never negative', function() { assert.equal( 0, helper.topPlaceholderHeight ); } ); it( 'shown all items', function() { assert.equal( 0, helper.firstRenderedIndex ); } ); } );
onButtonPress = (keyValue) => { const { onChange } = this.props; const { input: prevInput } = this.state; let input = ''; let prefixKeyboard = []; if (keyValue === '0' && prevInput.length === 0) { prefixKeyboard = map(['A', 'B', 'C', 'D'], char => this.prefixKeyboard[char]); } else if (keyValue === 'break') { input = prevInput.substr(0, prevInput.length - 1); } else if (keyValue === 'scan') { this.setState({ isShowScan: true }); } else if (prevInput.length >= 9) { onChange(`${keyValue}${prevInput}`); } else if (prevInput.length < 8) { input = prevInput + keyValue; } else { input = prevInput + keyValue; prefixKeyboard = map(makeup(input), char => this.prefixKeyboard[char]); } if (prefixKeyboard.length % 3 > 0) { range(3, prefixKeyboard.length % 3).forEach( key => prefixKeyboard.push(<View key={key} style={sh.button} />), ); } this.setState({ input, prefixKeyboard }); }
test('<DetailView /> should handle four photo', t => { const context2 = createContextWithSpiedRouter(); const wrapper = shallow(<DetailView chara="zz-zzzzz" />, { context: context2 }); const instance = wrapper.instance(); const photos = range(4).map(i => { const photo = clone(photoTemplate); photo.title = `template${i}`; return new Photo(photo); }); wrapper.setProps({ photos, index: 0 }); instance.moveNext(dummyEvent); t.is(context2.router.history.replace.callCount, 1); t.deepEqual(context2.router.history.replace.lastCall.args, ['/chara/zz-zzzzz/template1']); wrapper.setProps({ index: 1 }); instance.movePrev(dummyEvent); t.is(context2.router.history.replace.callCount, 2); t.deepEqual(context2.router.history.replace.lastCall.args, ['/chara/zz-zzzzz/template0']); wrapper.setProps({ index: 0 }); instance.movePrev(dummyEvent); t.is(context2.router.history.replace.callCount, 3); t.deepEqual(context2.router.history.replace.lastCall.args, ['/chara/zz-zzzzz/template3']); wrapper.setProps({ index: 3 }); instance.moveNext(dummyEvent); t.is(context2.router.history.replace.callCount, 4); t.deepEqual(context2.router.history.replace.lastCall.args, ['/chara/zz-zzzzz/template0']); });
const Description = ({ lineCount }) => ( <div> {range(lineCount).map(i => ( <SkeletonLine key={i} isLast={i === lineCount - 1}/> ))} </div> )
it('-drop', function () { var helper = mock.helper('-drop'); var list = range(1,20); expect(helper(15, list, options)).to.deep.equal([16,17,18,19]); expect(helper(15, list, options)).to.not.equal(list); });
it('-take', function () { var helper = mock.helper('-take'); var list = range(1,20); expect(helper(5, list, options)).to.deep.equal([1,2,3,4,5]); expect(helper(5, list, options)).to.not.equal(list); });
it('-group-by', function () { var helper = mock.helper('-group-by'); expect(helper('n-even?', range(1,5), options)).to.deep.equal({ 'true':[2,4], 'false':[1,3] }); });
it('renders a select', () => { monthDropdown = getMonthDropdown({dropdownMode: 'select'}) var select = monthDropdown.find('.react-datepicker__month-select') expect(select).to.have.length(1) expect(select.prop('value')).to.eq(11) var options = select.find('option') expect(options.map(o => o.prop('value'))).to.eql(range(0, 12)) })
const LeftColumn = ({ nestedLevel = 0, children, ...otherProps }) => ( <div {...otherProps} className={styles.root}> { range(nestedLevel).map((index) => <div key={index} className={styles.line}> </div>) } {children} </div> );
const daysOfWeek = moment => { const m = moment() return map(range(7), day => <option key={day} value={day}> {m.weekday(day).format('dddd')} </option>) }
getMultiTransitionData() { const bars = random(3, 5); return range(4).map(() => { return range(bars).map((bar) => { return {x: bar, y: random(2, 10)}; }); }); }