Best Python code snippet using ATX
BeforeInputEventPlugin-test.js
Source:BeforeInputEventPlugin-test.js  
1/**2 * Copyright (c) Facebook, Inc. and its affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @emails react-core8 */9'use strict';10let React;11let ReactDOM;12describe('BeforeInputEventPlugin', () => {13  let container;14  function loadReactDOM(envSimulator) {15    jest.resetModules();16    if (envSimulator) {17      envSimulator();18    }19    return require('react-dom');20  }21  function simulateIE11() {22    document.documentMode = 11;23    window.CompositionEvent = {};24  }25  function simulateWebkit() {26    window.CompositionEvent = {};27    window.TextEvent = {};28  }29  function simulateComposition() {30    window.CompositionEvent = {};31  }32  function simulateNoComposition() {33    // no composition event in Window - will use fallback34  }35  function simulateEvent(elem, type, data) {36    const event = new Event(type, {bubbles: true});37    Object.assign(event, data);38    elem.dispatchEvent(event);39  }40  function simulateKeyboardEvent(elem, type, data) {41    const {char, value, ...rest} = data;42    const event = new KeyboardEvent(type, {43      bubbles: true,44      ...rest,45    });46    if (char) {47      event.char = char;48    }49    if (value) {50      elem.value = value;51    }52    elem.dispatchEvent(event);53  }54  function simulatePaste(elem) {55    const pasteEvent = new Event('paste', {56      bubbles: true,57    });58    pasteEvent.clipboardData = {59      dropEffect: null,60      effectAllowed: null,61      files: null,62      items: null,63      types: null,64    };65    elem.dispatchEvent(pasteEvent);66  }67  beforeEach(() => {68    React = require('react');69    container = document.createElement('div');70    document.body.appendChild(container);71  });72  afterEach(() => {73    delete document.documentMode;74    delete window.CompositionEvent;75    delete window.TextEvent;76    delete window.opera;77    document.body.removeChild(container);78    container = null;79  });80  function keyCode(char) {81    return char.charCodeAt(0);82  }83  const scenarios = [84    {85      eventSimulator: simulateEvent,86      eventSimulatorArgs: [87        'compositionstart',88        {detail: {data: 'test'}, data: 'test'},89      ],90    },91    {92      eventSimulator: simulateEvent,93      eventSimulatorArgs: [94        'compositionupdate',95        {detail: {data: 'test string'}, data: 'test string'},96      ],97    },98    {99      eventSimulator: simulateEvent,100      eventSimulatorArgs: [101        'compositionend',102        {detail: {data: 'test string 3'}, data: 'test string 3'},103      ],104    },105    {106      eventSimulator: simulateEvent,107      eventSimulatorArgs: ['textInput', {data: 'abcÃ'}],108    },109    {110      eventSimulator: simulateKeyboardEvent,111      eventSimulatorArgs: ['keypress', {which: keyCode('a')}],112    },113    {114      eventSimulator: simulateKeyboardEvent,115      eventSimulatorArgs: ['keypress', {which: keyCode(' ')}, ' '],116    },117    {118      eventSimulator: simulateEvent,119      eventSimulatorArgs: ['textInput', {data: ' '}],120    },121    {122      eventSimulator: simulateKeyboardEvent,123      eventSimulatorArgs: ['keypress', {which: keyCode('a'), ctrlKey: true}],124    },125    {126      eventSimulator: simulateKeyboardEvent,127      eventSimulatorArgs: ['keypress', {which: keyCode('b'), altKey: true}],128    },129    {130      eventSimulator: simulateKeyboardEvent,131      eventSimulatorArgs: [132        'keypress',133        {which: keyCode('c'), altKey: true, ctrlKey: true},134      ],135    },136    {137      eventSimulator: simulateKeyboardEvent,138      eventSimulatorArgs: [139        'keypress',140        {which: keyCode('X'), char: '\uD83D\uDE0A'},141      ],142    },143    {144      eventSimulator: simulateEvent,145      eventSimulatorArgs: ['textInput', {data: '\uD83D\uDE0A'}],146    },147    {148      eventSimulator: simulateKeyboardEvent,149      eventSimulatorArgs: ['keydown', {keyCode: 229, value: 'foo'}],150    },151    {152      eventSimulator: simulateKeyboardEvent,153      eventSimulatorArgs: ['keydown', {keyCode: 9, value: 'foobar'}],154    },155    {156      eventSimulator: simulateKeyboardEvent,157      eventSimulatorArgs: ['keydown', {keyCode: 229, value: 'foofoo'}],158    },159    {160      eventSimulator: simulateKeyboardEvent,161      eventSimulatorArgs: ['keyup', {keyCode: 9, value: 'fooBARfoo'}],162    },163    {164      eventSimulator: simulateKeyboardEvent,165      eventSimulatorArgs: ['keydown', {keyCode: 229, value: 'foofoo'}],166    },167    {168      eventSimulator: simulateKeyboardEvent,169      eventSimulatorArgs: ['keypress', {keyCode: 60, value: 'Barfoofoo'}],170    },171    {172      eventSimulator: simulatePaste,173      eventSimulatorArgs: [],174    },175  ];176  const environments = [177    {178      emulator: simulateWebkit,179      assertions: [180        {181          run: ({182            beforeInputEvent,183            compositionStartEvent,184            spyOnBeforeInput,185            spyOnCompositionStart,186          }) => {187            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);188            expect(beforeInputEvent).toBeNull();189            expect(spyOnCompositionStart).toHaveBeenCalledTimes(1);190            expect(compositionStartEvent.type).toBe('compositionstart');191            expect(compositionStartEvent.data).toBe('test');192          },193        },194        {195          run: ({196            beforeInputEvent,197            compositionUpdateEvent,198            spyOnBeforeInput,199            spyOnCompositionUpdate,200          }) => {201            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);202            expect(beforeInputEvent).toBeNull();203            expect(spyOnCompositionUpdate).toHaveBeenCalledTimes(1);204            expect(compositionUpdateEvent.type).toBe('compositionupdate');205            expect(compositionUpdateEvent.data).toBe('test string');206          },207        },208        {209          run: ({beforeInputEvent, spyOnBeforeInput}) => {210            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);211            expect(beforeInputEvent.type).toBe('compositionend');212            expect(beforeInputEvent.data).toBe('test string 3');213          },214        },215        {216          run: ({beforeInputEvent, spyOnBeforeInput}) => {217            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);218            expect(beforeInputEvent.type).toBe('textInput');219            expect(beforeInputEvent.data).toBe('abcÃ');220          },221        },222        {223          run: ({beforeInputEvent, spyOnBeforeInput}) => {224            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);225            expect(beforeInputEvent).toBeNull();226          },227        },228        {229          run: ({beforeInputEvent, spyOnBeforeInput}) => {230            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);231            expect(beforeInputEvent.type).toBe('keypress');232            expect(beforeInputEvent.data).toBe(' ');233          },234        },235        {236          run: ({beforeInputEvent, spyOnBeforeInput}) => {237            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);238            expect(beforeInputEvent).toBeNull();239          },240        },241        {242          run: ({beforeInputEvent, spyOnBeforeInput}) => {243            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);244            expect(beforeInputEvent).toBeNull();245          },246        },247        {248          run: ({beforeInputEvent, spyOnBeforeInput}) => {249            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);250            expect(beforeInputEvent).toBeNull();251          },252        },253        {254          run: ({beforeInputEvent, spyOnBeforeInput}) => {255            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);256            expect(beforeInputEvent).toBeNull();257          },258        },259        {260          run: ({beforeInputEvent, spyOnBeforeInput}) => {261            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);262            expect(beforeInputEvent).toBeNull();263          },264        },265        {266          run: ({beforeInputEvent, spyOnBeforeInput}) => {267            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);268            expect(beforeInputEvent.type).toBe('textInput');269            expect(beforeInputEvent.data).toBe('\uD83D\uDE0A');270          },271        },272        {273          run: ({beforeInputEvent, spyOnBeforeInput}) => {274            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);275            expect(beforeInputEvent).toBeNull();276          },277        },278        {279          run: ({beforeInputEvent, spyOnBeforeInput}) => {280            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);281            expect(beforeInputEvent).toBeNull();282          },283        },284        {285          run: ({beforeInputEvent, spyOnBeforeInput}) => {286            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);287            expect(beforeInputEvent).toBeNull();288          },289        },290        {291          run: ({beforeInputEvent, spyOnBeforeInput}) => {292            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);293            expect(beforeInputEvent).toBeNull();294          },295        },296        {297          run: ({beforeInputEvent, spyOnBeforeInput}) => {298            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);299            expect(beforeInputEvent).toBeNull();300          },301        },302        {303          run: ({beforeInputEvent, spyOnBeforeInput}) => {304            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);305            expect(beforeInputEvent).toBeNull();306          },307        },308        {309          run: ({beforeInputEvent, spyOnBeforeInput}) => {310            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);311            expect(beforeInputEvent).toBeNull();312          },313        },314      ],315    },316    {317      emulator: simulateIE11,318      assertions: [319        {320          run: ({beforeInputEvent, spyOnBeforeInput}) => {321            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);322            expect(beforeInputEvent).toBeNull();323          },324        },325        {326          run: ({beforeInputEvent, spyOnBeforeInput}) => {327            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);328            expect(beforeInputEvent).toBeNull();329          },330        },331        {332          run: ({beforeInputEvent, spyOnBeforeInput}) => {333            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);334            expect(beforeInputEvent).toBeNull();335          },336        },337        {338          run: ({beforeInputEvent, spyOnBeforeInput}) => {339            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);340            expect(beforeInputEvent).toBeNull();341          },342        },343        {344          run: ({beforeInputEvent, spyOnBeforeInput}) => {345            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);346            expect(beforeInputEvent.type).toBe('keypress');347            expect(beforeInputEvent.data).toBe('a');348          },349        },350        {351          run: ({beforeInputEvent, spyOnBeforeInput}) => {352            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);353            expect(beforeInputEvent.type).toBe('keypress');354            expect(beforeInputEvent.data).toBe(' ');355          },356        },357        {358          run: ({beforeInputEvent, spyOnBeforeInput}) => {359            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);360            expect(beforeInputEvent).toBeNull();361          },362        },363        {364          run: ({beforeInputEvent, spyOnBeforeInput}) => {365            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);366            expect(beforeInputEvent).toBeNull();367          },368        },369        {370          run: ({beforeInputEvent, spyOnBeforeInput}) => {371            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);372            expect(beforeInputEvent).toBeNull();373          },374        },375        {376          run: ({beforeInputEvent, spyOnBeforeInput}) => {377            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);378            expect(beforeInputEvent.type).toBe('keypress');379            expect(beforeInputEvent.data).toBe('c');380          },381        },382        {383          run: ({beforeInputEvent, spyOnBeforeInput}) => {384            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);385            expect(beforeInputEvent.type).toBe('keypress');386            expect(beforeInputEvent.data).toBe('\uD83D\uDE0A');387          },388        },389        {390          run: ({beforeInputEvent, spyOnBeforeInput}) => {391            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);392            expect(beforeInputEvent).toBeNull();393          },394        },395        {396          run: ({beforeInputEvent, spyOnBeforeInput}) => {397            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);398            expect(beforeInputEvent).toBeNull();399          },400        },401        {402          run: ({beforeInputEvent, spyOnBeforeInput}) => {403            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);404            expect(beforeInputEvent).toBeNull();405          },406        },407        {408          run: ({beforeInputEvent, spyOnBeforeInput}) => {409            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);410            expect(beforeInputEvent).toBeNull();411          },412        },413        {414          run: ({beforeInputEvent, spyOnBeforeInput}) => {415            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);416            expect(beforeInputEvent).toBeNull();417          },418        },419        {420          run: ({beforeInputEvent, spyOnBeforeInput}) => {421            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);422            expect(beforeInputEvent).toBeNull();423          },424        },425        {426          run: ({beforeInputEvent, spyOnBeforeInput}) => {427            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);428            expect(beforeInputEvent).toBeNull();429          },430        },431        {432          run: ({beforeInputEvent, spyOnBeforeInput}) => {433            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);434            expect(beforeInputEvent).toBeNull();435          },436        },437      ],438    },439    {440      emulator: simulateNoComposition,441      assertions: [442        {443          run: ({beforeInputEvent, spyOnBeforeInput}) => {444            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);445            expect(beforeInputEvent).toBeNull();446          },447        },448        {449          run: ({beforeInputEvent, spyOnBeforeInput}) => {450            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);451            expect(beforeInputEvent).toBeNull();452          },453        },454        {455          run: ({beforeInputEvent, spyOnBeforeInput}) => {456            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);457            expect(beforeInputEvent).toBeNull();458          },459        },460        {461          run: ({beforeInputEvent, spyOnBeforeInput}) => {462            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);463            expect(beforeInputEvent).toBeNull();464          },465        },466        {467          run: ({beforeInputEvent, spyOnBeforeInput}) => {468            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);469            expect(beforeInputEvent.type).toBe('keypress');470            expect(beforeInputEvent.data).toBe('a');471          },472        },473        {474          run: ({beforeInputEvent, spyOnBeforeInput}) => {475            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);476            expect(beforeInputEvent.type).toBe('keypress');477            expect(beforeInputEvent.data).toBe(' ');478          },479        },480        {481          run: ({beforeInputEvent, spyOnBeforeInput}) => {482            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);483            expect(beforeInputEvent).toBeNull();484          },485        },486        {487          run: ({beforeInputEvent, spyOnBeforeInput}) => {488            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);489            expect(beforeInputEvent).toBeNull();490          },491        },492        {493          run: ({beforeInputEvent, spyOnBeforeInput}) => {494            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);495            expect(beforeInputEvent).toBeNull();496          },497        },498        {499          run: ({beforeInputEvent, spyOnBeforeInput}) => {500            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);501            expect(beforeInputEvent.type).toBe('keypress');502            expect(beforeInputEvent.data).toBe('c');503          },504        },505        {506          run: ({beforeInputEvent, spyOnBeforeInput}) => {507            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);508            expect(beforeInputEvent.type).toBe('keypress');509            expect(beforeInputEvent.data).toBe('\uD83D\uDE0A');510          },511        },512        {513          run: ({beforeInputEvent, spyOnBeforeInput}) => {514            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);515            expect(beforeInputEvent).toBeNull();516          },517        },518        {519          run: ({beforeInputEvent, spyOnBeforeInput}) => {520            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);521            expect(beforeInputEvent).toBeNull();522          },523        },524        {525          run: ({beforeInputEvent, spyOnBeforeInput}) => {526            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);527            expect(beforeInputEvent.type).toBe('keydown');528            expect(beforeInputEvent.data).toBe('bar');529          },530        },531        {532          run: ({beforeInputEvent, spyOnBeforeInput}) => {533            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);534            expect(beforeInputEvent).toBeNull();535          },536        },537        {538          run: ({beforeInputEvent, spyOnBeforeInput}) => {539            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);540            expect(beforeInputEvent.type).toBe('keyup');541            expect(beforeInputEvent.data).toBe('BAR');542          },543        },544        {545          run: ({beforeInputEvent, spyOnBeforeInput}) => {546            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);547            expect(beforeInputEvent).toBeNull();548          },549        },550        {551          run: ({beforeInputEvent, spyOnBeforeInput}) => {552            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);553            expect(beforeInputEvent.type).toBe('keypress');554            expect(beforeInputEvent.data).toBe('Bar');555          },556        },557        {558          run: ({beforeInputEvent, spyOnBeforeInput}) => {559            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);560            expect(beforeInputEvent).toBeNull();561          },562        },563      ],564    },565    {566      emulator: simulateComposition,567      assertions: [568        {569          run: ({beforeInputEvent, spyOnBeforeInput}) => {570            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);571            expect(beforeInputEvent).toBeNull();572          },573        },574        {575          run: ({beforeInputEvent, spyOnBeforeInput}) => {576            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);577            expect(beforeInputEvent).toBeNull();578          },579        },580        {581          run: ({beforeInputEvent, spyOnBeforeInput}) => {582            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);583            expect(beforeInputEvent.type).toBe('compositionend');584            expect(beforeInputEvent.data).toBe('test string 3');585          },586        },587        {588          run: ({beforeInputEvent, spyOnBeforeInput}) => {589            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);590            expect(beforeInputEvent).toBeNull();591          },592        },593        {594          run: ({beforeInputEvent, spyOnBeforeInput}) => {595            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);596            expect(beforeInputEvent.type).toBe('keypress');597            expect(beforeInputEvent.data).toBe('a');598          },599        },600        {601          run: ({beforeInputEvent, spyOnBeforeInput}) => {602            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);603            expect(beforeInputEvent.type).toBe('keypress');604            expect(beforeInputEvent.data).toBe(' ');605          },606        },607        {608          run: ({beforeInputEvent, spyOnBeforeInput}) => {609            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);610            expect(beforeInputEvent).toBeNull();611          },612        },613        {614          run: ({beforeInputEvent, spyOnBeforeInput}) => {615            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);616            expect(beforeInputEvent).toBeNull();617          },618        },619        {620          run: ({beforeInputEvent, spyOnBeforeInput}) => {621            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);622            expect(beforeInputEvent).toBeNull();623          },624        },625        {626          run: ({beforeInputEvent, spyOnBeforeInput}) => {627            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);628            expect(beforeInputEvent.type).toBe('keypress');629            expect(beforeInputEvent.data).toBe('c');630          },631        },632        {633          run: ({beforeInputEvent, spyOnBeforeInput}) => {634            expect(spyOnBeforeInput).toHaveBeenCalledTimes(1);635            expect(beforeInputEvent.type).toBe('keypress');636            expect(beforeInputEvent.data).toBe('\uD83D\uDE0A');637          },638        },639        {640          run: ({beforeInputEvent, spyOnBeforeInput}) => {641            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);642            expect(beforeInputEvent).toBeNull();643          },644        },645        {646          run: ({beforeInputEvent, spyOnBeforeInput}) => {647            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);648            expect(beforeInputEvent).toBeNull();649          },650        },651        {652          run: ({beforeInputEvent, spyOnBeforeInput}) => {653            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);654            expect(beforeInputEvent).toBeNull();655          },656        },657        {658          run: ({beforeInputEvent, spyOnBeforeInput}) => {659            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);660            expect(beforeInputEvent).toBeNull();661          },662        },663        {664          run: ({beforeInputEvent, spyOnBeforeInput}) => {665            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);666            expect(beforeInputEvent).toBeNull();667          },668        },669        {670          run: ({beforeInputEvent, spyOnBeforeInput}) => {671            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);672            expect(beforeInputEvent).toBeNull();673          },674        },675        {676          run: ({beforeInputEvent, spyOnBeforeInput}) => {677            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);678            expect(beforeInputEvent).toBeNull();679          },680        },681        {682          run: ({beforeInputEvent, spyOnBeforeInput}) => {683            expect(spyOnBeforeInput).toHaveBeenCalledTimes(0);684            expect(beforeInputEvent).toBeNull();685          },686        },687      ],688    },689  ];690  const testInputComponent = (env, scenes) => {691    let beforeInputEvent;692    let compositionStartEvent;693    let compositionUpdateEvent;694    let spyOnBeforeInput;695    let spyOnCompositionStart;696    let spyOnCompositionUpdate;697    ReactDOM = loadReactDOM(env.emulator);698    const node = ReactDOM.render(699      <input700        type="text"701        onBeforeInput={({type, data}) => {702          spyOnBeforeInput();703          beforeInputEvent = {type, data};704        }}705        onCompositionStart={({type, data}) => {706          spyOnCompositionStart();707          compositionStartEvent = {type, data};708        }}709        onCompositionUpdate={({type, data}) => {710          spyOnCompositionUpdate();711          compositionUpdateEvent = {type, data};712        }}713      />,714      container,715    );716    scenes.forEach((s, id) => {717      beforeInputEvent = null;718      compositionStartEvent = null;719      compositionUpdateEvent = null;720      spyOnBeforeInput = jest.fn();721      spyOnCompositionStart = jest.fn();722      spyOnCompositionUpdate = jest.fn();723      s.eventSimulator.apply(null, [node, ...s.eventSimulatorArgs]);724      env.assertions[id].run({725        beforeInputEvent,726        compositionStartEvent,727        compositionUpdateEvent,728        spyOnBeforeInput,729        spyOnCompositionStart,730        spyOnCompositionUpdate,731      });732    });733  };734  const testContentEditableComponent = (env, scenes) => {735    let beforeInputEvent;736    let compositionStartEvent;737    let compositionUpdateEvent;738    let spyOnBeforeInput;739    let spyOnCompositionStart;740    let spyOnCompositionUpdate;741    ReactDOM = loadReactDOM(env.emulator);742    const node = ReactDOM.render(743      <div744        contentEditable={true}745        onBeforeInput={({type, data}) => {746          spyOnBeforeInput();747          beforeInputEvent = {type, data};748        }}749        onCompositionStart={({type, data}) => {750          spyOnCompositionStart();751          compositionStartEvent = {type, data};752        }}753        onCompositionUpdate={({type, data}) => {754          spyOnCompositionUpdate();755          compositionUpdateEvent = {type, data};756        }}757      />,758      container,759    );760    scenes.forEach((s, id) => {761      beforeInputEvent = null;762      compositionStartEvent = null;763      compositionUpdateEvent = null;764      spyOnBeforeInput = jest.fn();765      spyOnCompositionStart = jest.fn();766      spyOnCompositionUpdate = jest.fn();767      s.eventSimulator.apply(null, [node, ...s.eventSimulatorArgs]);768      env.assertions[id].run({769        beforeInputEvent,770        compositionStartEvent,771        compositionUpdateEvent,772        spyOnBeforeInput,773        spyOnCompositionStart,774        spyOnCompositionUpdate,775      });776    });777  };778  it('should extract onBeforeInput when simulating in Webkit on input[type=text]', () => {779    testInputComponent(environments[0], scenarios);780  });781  it('should extract onBeforeInput when simulating in Webkit on contenteditable', () => {782    testContentEditableComponent(environments[0], scenarios);783  });784  it('should extract onBeforeInput when simulating in IE11 on input[type=text]', () => {785    testInputComponent(environments[1], scenarios);786  });787  it('should extract onBeforeInput when simulating in IE11 on contenteditable', () => {788    testContentEditableComponent(environments[1], scenarios);789  });790  it('should extract onBeforeInput when simulating in env with no CompositionEvent on input[type=text]', () => {791    testInputComponent(environments[2], scenarios);792  });793  // in an environment using composition fallback onBeforeInput will not work794  // as expected on a contenteditable as keydown and keyup events are translated795  // to keypress events796  it('should extract onBeforeInput when simulating in env with only CompositionEvent on input[type=text]', () => {797    testInputComponent(environments[3], scenarios);798  });799  it('should extract onBeforeInput when simulating in env with only CompositionEvent on contenteditable', () => {800    testContentEditableComponent(environments[3], scenarios);801  });...Microsoft.py
Source:Microsoft.py  
1from ReadInput import getClosingPrices2from Input_Variables import exponentialMovingAverage,inputRdp,trainingOutputRdp_5,changeInPrice,scale3from sklearn import svm,preprocessing4import numpy as np5from Output_Variables import calculateCorrectPredictions6pathOfMicrosoft = '/home/Documents/dataset/MS'7datePriceDictionary = getClosingPrices(pathOfMicrosoft,'MicrosoftTraining.xlsx')8initialPriceDictionary = getClosingPrices(pathOfMicrosoft,'Training.xlsx')9last5PriceDictionary = getClosingPrices(pathOfMicrosoft,'Last5Days.xlsx')10dateList = datePriceDictionary.keys()11closingPriceList = datePriceDictionary.values()12initialPriceValues = initialPriceDictionary.values()13SVM_trainingInput = []14SVM_trainingOutputValues = []15SVM_trainingOutputClasses = []16SVM_trainingOutputClasses.append(1)17last5List = last5PriceDictionary.values()18changeInPrice(closingPriceList,SVM_trainingOutputClasses)19sumClosingPrices = 0.020for iter in xrange(5,20):21    sumClosingPrices = sumClosingPrices+float(initialPriceValues[iter])22simpleMovingAverage = sumClosingPrices/float(15)23emaYesterDay = simpleMovingAverage24emaList = []25for i in xrange(0,closingPriceList.__len__()):26    ema_15 = exponentialMovingAverage(closingPriceList[i],15,emaYesterDay)27    emaList.append(ema_15)28    emaYesterDay= ema_1529emaLastList = []30for j in xrange(0,5):31    ema_15Last = exponentialMovingAverage(last5List[j],15,emaYesterDay)32    emaLastList.append(ema_15Last)33ema_15_Input_List = []34rdp_5_Input_List = []35rdp_10_Input_List = []36rdp_15_Input_List = []37rdp_20_Input_List = []38for iterator in xrange(0,closingPriceList.__len__()):39    ema15Input = closingPriceList[iterator] - emaList[iterator]40    ema_15_Input_List.append(ema15Input)41    if iterator<5:42        rdp_5_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator+15])43        rdp_5_Input_List.append(rdp_5_Input)44        rdp_10_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator+10])45        rdp_10_Input_List.append(rdp_10_Input)46        rdp_15_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator+5])47        rdp_15_Input_List.append(rdp_15_Input)48        rdp_20_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator])49        rdp_20_Input_List.append(rdp_20_Input)50    elif iterator<10:51        rdp_5_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-5])52        rdp_5_Input_List.append(rdp_5_Input)53        rdp_10_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator+10])54        rdp_10_Input_List.append(rdp_10_Input)55        rdp_15_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator+5])56        rdp_15_Input_List.append(rdp_15_Input)57        rdp_20_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator])58        rdp_20_Input_List.append(rdp_20_Input)59    elif iterator<15:60        rdp_5_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-5])61        rdp_5_Input_List.append(rdp_5_Input)62        rdp_10_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-10])63        rdp_10_Input_List.append(rdp_10_Input)64        rdp_15_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator+5])65        rdp_15_Input_List.append(rdp_15_Input)66        rdp_20_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator])67        rdp_20_Input_List.append(rdp_20_Input)68    elif iterator<20:69        rdp_5_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-5])70        rdp_5_Input_List.append(rdp_5_Input)71        rdp_10_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-10])72        rdp_10_Input_List.append(rdp_10_Input)73        rdp_15_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-15])74        rdp_15_Input_List.append(rdp_15_Input)75        rdp_20_Input = inputRdp(closingPriceList[iterator],initialPriceValues[iterator])76        rdp_20_Input_List.append(rdp_20_Input)77    else:78        rdp_5_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-5])79        rdp_5_Input_List.append(rdp_5_Input)80        rdp_10_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-10])81        rdp_10_Input_List.append(rdp_10_Input)82        rdp_15_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-15])83        rdp_15_Input_List.append(rdp_15_Input)84        rdp_20_Input = inputRdp(closingPriceList[iterator],closingPriceList[iterator-20])85        rdp_20_Input_List.append(rdp_20_Input)86closingPriceListLength = closingPriceList.__len__()87for itr1 in xrange(0,closingPriceListLength):88    if itr1 == 0:89        rdp_5_Output = trainingOutputRdp_5(closingPriceList[itr1],closingPriceList[itr1+5],simpleMovingAverage,emaList[itr1+4])90        SVM_trainingOutputValues.append(rdp_5_Output)91    elif itr1 < (closingPriceListLength-5):92        rdp_5_Output = trainingOutputRdp_5(closingPriceList[itr1],closingPriceList[itr1+5],emaList[itr1-1],emaList[itr1+4])93        SVM_trainingOutputValues.append(rdp_5_Output)94    else:95        rdp_5_Output = trainingOutputRdp_5(closingPriceList[itr1],last5List[abs(closingPriceListLength-iterator-5)],emaList[itr1-1],emaLastList[abs(closingPriceListLength-iterator-5)])96        SVM_trainingOutputValues.append(rdp_5_Output)97print 'DEBUGGING:',ema_15_Input_List.__len__()98'''preprocessing.scale(ema_15_Input_List)99preprocessing.scale(rdp_5_Input_List)100preprocessing.scale(rdp_10_Input_List)101preprocessing.scale(rdp_15_Input_List)102preprocessing.scale(rdp_20_Input_List)'''103for count in xrange(0,ema_15_Input_List.__len__()):104    rowWiseInputList = []105    rowWiseInputList.append(ema_15_Input_List[count])106    rowWiseInputList.append(rdp_5_Input_List[count])107    rowWiseInputList.append(rdp_10_Input_List[count])108    rowWiseInputList.append(rdp_15_Input_List[count])109    rowWiseInputList.append(rdp_20_Input_List[count])110    SVM_trainingInput.append(rowWiseInputList)111testingDictionary = getClosingPrices(pathOfMicrosoft,'MicrosoftTesting.xlsx')112testingInputValues = testingDictionary.values()113emaTestList = []114emaOld=emaList[emaList.__len__()-1]115for it in xrange(0,testingInputValues.__len__()):116    emaTest = exponentialMovingAverage(testingInputValues[it],15,emaOld)117    emaTestList.append(emaTest)118    emaOld=emaTest119ema_15_Test_List = []120rdp_5_Test_List = []121rdp_10_Test_List = []122rdp_15_Test_List = []123rdp_20_Test_List = []124closingPricesLast_20_daysList = []125for itr2 in xrange(closingPriceList.__len__()-20,closingPriceList.__len__()):126    closingPricesLast_20_daysList.append(closingPriceList[itr2])127for iterator_1 in xrange(0,testingInputValues.__len__()):128    ema_15TestInput = testingInputValues[iterator_1] - emaTestList[iterator_1]129    ema_15_Test_List.append(ema_15TestInput)130    if iterator_1 < 5:131        rdp_5_test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1+15])132        rdp_5_Test_List.append(rdp_5_test)133        rdp_10_test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1+10])134        rdp_10_Test_List.append(rdp_10_test)135        rdp_15_test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1+5])136        rdp_15_Test_List.append(rdp_15_test)137        rdp_20_Test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1])138        rdp_20_Test_List.append(rdp_20_Test)139    elif iterator_1<10:140        rdp_5_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-5])141        rdp_5_Test_List.append(rdp_5_test)142        rdp_10_test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1+10])143        rdp_10_Test_List.append(rdp_10_test)144        rdp_15_test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1+5])145        rdp_15_Test_List.append(rdp_15_test)146        rdp_20_Test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1])147        rdp_20_Test_List.append(rdp_20_Test)148    elif iterator_1<15:149        rdp_5_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-5])150        rdp_5_Test_List.append(rdp_5_test)151        rdp_10_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-10])152        rdp_10_Test_List.append(rdp_10_test)153        rdp_15_test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1+5])154        rdp_15_Test_List.append(rdp_15_test)155        rdp_20_Test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1])156        rdp_20_Test_List.append(rdp_20_Test)157    elif iterator_1<20:158        rdp_5_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-5])159        rdp_5_Test_List.append(rdp_5_test)160        rdp_10_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-10])161        rdp_10_Test_List.append(rdp_10_test)162        rdp_15_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-15])163        rdp_15_Test_List.append(rdp_15_test)164        rdp_20_Test = inputRdp(testingInputValues[iterator_1],closingPricesLast_20_daysList[iterator_1])165        rdp_20_Test_List.append(rdp_20_Test)166    else:167        rdp_5_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-5])168        rdp_5_Test_List.append(rdp_5_test)169        rdp_10_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-10])170        rdp_10_Test_List.append(rdp_10_test)171        rdp_15_test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-15])172        rdp_15_Test_List.append(rdp_15_test)173        rdp_20_Test = inputRdp(testingInputValues[iterator_1],testingInputValues[iterator_1-20])174        rdp_20_Test_List.append(rdp_20_Test)175'''preprocessing.scale(ema_15_Test_List)176preprocessing.scale(rdp_5_Test_List)177preprocessing.scale(rdp_10_Test_List)178preprocessing.scale(rdp_15_Test_List)179preprocessing.scale(rdp_20_Test_List)'''180#-------------------------------------------------------181minMaxScaler = preprocessing.MinMaxScaler(feature_range=(-0.9,0.9))182minMaxScaler.fit(SVM_trainingInput)183SVM_trainingInputScaled = minMaxScaler.transform(SVM_trainingInput)184print 'SVM_trainingInputScaled' ,SVM_trainingInputScaled185#--------------------------------------------------------186SVR_TestList = []187for count1 in xrange(0,ema_15_Test_List.__len__()):188    rowWiseTestList = []189    rowWiseTestList.append(ema_15_Test_List[count1])190    rowWiseTestList.append(rdp_5_Test_List[count1])191    rowWiseTestList.append(rdp_10_Test_List[count1])192    rowWiseTestList.append(rdp_15_Test_List[count1])193    rowWiseTestList.append(rdp_20_Test_List[count1])194    SVR_TestList.append(rowWiseTestList)195SVR_TestListExpectedOutput = []196SVR_TestListExpectedOutput.append(1)197changeInPrice(testingInputValues,SVR_TestListExpectedOutput)198#----------------------------------------------Classification----------------------------------------------199#temp = np.array(SVM_trainingInput)200#myGamma = 1/float(np.power(np.var(SVM_trainingInput),2))201#------------------------------------------------------------202minMaxScaler.fit(SVR_TestList)203SVR_TestListScaled = minMaxScaler.transform(SVR_TestList)204#------------------------------------------------------------205classifier = svm.SVC(kernel='rbf',gamma=1/10.0)206classifier.fit(SVM_trainingInputScaled,SVM_trainingOutputClasses)207y = classifier.predict(SVR_TestList)208regression = svm.SVR(kernel='poly',coef0=3,degree=1)#(kernel='rbf',gamma=1/1000.0)209scale(SVM_trainingOutputValues)210regression.fit(SVM_trainingInput,SVM_trainingOutputValues)211print 'SVROUTPUTTRAINING::',SVM_trainingOutputValues212print 'SVRTEST::',SVR_TestList213z = regression.predict(SVR_TestList)214z = np.array(z).tolist()215print z216predictedList = []217predictedList.append(1)218changeInPrice(z,predictedList)219print 'SVR_TestListLength:',SVR_TestList.__len__()220print 'Expected Value:',SVR_TestListExpectedOutput221print 'Predicted::',predictedList222numberOfCorrectPredictions,probabiltyOfCorrectPredictions = calculateCorrectPredictions(SVR_TestListExpectedOutput,predictedList)223print 'NUMBER OF CORRECT CLASSIFICATIONS::',numberOfCorrectPredictions...input.js
Source:input.js  
1import $ from 'dom7';2import { window, document } from 'ssr-window';3import Utils from '../../utils/utils';4import Device from '../../utils/device';5const Input = {6  ignoreTypes: ['checkbox', 'button', 'submit', 'range', 'radio', 'image'],7  createTextareaResizableShadow() {8    const $shadowEl = $(document.createElement('textarea'));9    $shadowEl.addClass('textarea-resizable-shadow');10    $shadowEl.prop({11      disabled: true,12      readonly: true,13    });14    Input.textareaResizableShadow = $shadowEl;15  },16  textareaResizableShadow: undefined,17  resizeTextarea(textareaEl) {18    const app = this;19    const $textareaEl = $(textareaEl);20    if (!Input.textareaResizableShadow) {21      Input.createTextareaResizableShadow();22    }23    const $shadowEl = Input.textareaResizableShadow;24    if (!$textareaEl.length) return;25    if (!$textareaEl.hasClass('resizable')) return;26    if (Input.textareaResizableShadow.parents().length === 0) {27      app.root.append($shadowEl);28    }29    const styles = window.getComputedStyle($textareaEl[0]);30    ('padding-top padding-bottom padding-left padding-right margin-left margin-right margin-top margin-bottom width font-size font-family font-style font-weight line-height font-variant text-transform letter-spacing border box-sizing display').split(' ').forEach((style) => {31      let styleValue = styles[style];32      if (('font-size line-height letter-spacing width').split(' ').indexOf(style) >= 0) {33        styleValue = styleValue.replace(',', '.');34      }35      $shadowEl.css(style, styleValue);36    });37    const currentHeight = $textareaEl[0].clientHeight;38    $shadowEl.val('');39    const initialHeight = $shadowEl[0].scrollHeight;40    $shadowEl.val($textareaEl.val());41    $shadowEl.css('height', 0);42    const scrollHeight = $shadowEl[0].scrollHeight;43    if (currentHeight !== scrollHeight) {44      if (scrollHeight > initialHeight) {45        $textareaEl.css('height', `${scrollHeight}px`);46        $textareaEl.trigger('textarea:resize', { initialHeight, currentHeight, scrollHeight });47      } else if (scrollHeight < currentHeight) {48        $textareaEl.css('height', '');49        $textareaEl.trigger('textarea:resize', { initialHeight, currentHeight, scrollHeight });50      }51    }52  },53  validate(inputEl) {54    const $inputEl = $(inputEl);55    if (!$inputEl.length) return;56    const $itemInputEl = $inputEl.parents('.item-input');57    const $inputWrapEl = $inputEl.parents('.input');58    const validity = $inputEl[0].validity;59    const validationMessage = $inputEl.dataset().errorMessage || $inputEl[0].validationMessage || '';60    if (!validity) return;61    if (!validity.valid) {62      let $errorEl = $inputEl.nextAll('.item-input-error-message, .input-error-message');63      if (validationMessage) {64        if ($errorEl.length === 0) {65          $errorEl = $(`<div class="${$inputWrapEl.length ? 'input-error-message' : 'item-input-error-message'}"></div>`);66          $errorEl.insertAfter($inputEl);67        }68        $errorEl.text(validationMessage);69      }70      if ($errorEl.length > 0) {71        $itemInputEl.addClass('item-input-with-error-message');72        $inputWrapEl.addClass('input-with-eror-message');73      }74      $itemInputEl.addClass('item-input-invalid');75      $inputWrapEl.addClass('input-invalid');76      $inputEl.addClass('input-invalid');77    } else {78      $itemInputEl.removeClass('item-input-invalid item-input-with-error-message');79      $inputWrapEl.removeClass('input-invalid input-with-error-message');80      $inputEl.removeClass('input-invalid');81    }82  },83  validateInputs(el) {84    const app = this;85    $(el).find('input, textarea, select').each((index, inputEl) => {86      app.input.validate(inputEl);87    });88  },89  focus(inputEl) {90    const $inputEl = $(inputEl);91    const type = $inputEl.attr('type');92    if (Input.ignoreTypes.indexOf(type) >= 0) return;93    $inputEl.parents('.item-input').addClass('item-input-focused');94    $inputEl.parents('.input').addClass('input-focused');95    $inputEl.addClass('input-focused');96  },97  blur(inputEl) {98    const $inputEl = $(inputEl);99    $inputEl.parents('.item-input').removeClass('item-input-focused');100    $inputEl.parents('.input').removeClass('input-focused');101    $inputEl.removeClass('input-focused');102  },103  checkEmptyState(inputEl) {104    let $inputEl = $(inputEl);105    if (!$inputEl.is('input, select, textarea')) {106      $inputEl = $inputEl.find('input, select, textarea').eq(0);107    }108    if (!$inputEl.length) return;109    const value = $inputEl.val();110    const $itemInputEl = $inputEl.parents('.item-input');111    const $inputWrapEl = $inputEl.parents('.input');112    if ((value && (typeof value === 'string' && value.trim() !== '')) || (Array.isArray(value) && value.length > 0)) {113      $itemInputEl.addClass('item-input-with-value');114      $inputWrapEl.addClass('input-with-value');115      $inputEl.addClass('input-with-value');116      $inputEl.trigger('input:notempty');117    } else {118      $itemInputEl.removeClass('item-input-with-value');119      $inputWrapEl.removeClass('input-with-value');120      $inputEl.removeClass('input-with-value');121      $inputEl.trigger('input:empty');122    }123  },124  scrollIntoView(inputEl, duration = 0, centered, force) {125    const $inputEl = $(inputEl);126    const $scrollableEl = $inputEl.parents('.page-content, .panel').eq(0);127    if (!$scrollableEl.length) {128      return false;129    }130    const contentHeight = $scrollableEl[0].offsetHeight;131    const contentScrollTop = $scrollableEl[0].scrollTop;132    const contentPaddingTop = parseInt($scrollableEl.css('padding-top'), 10);133    const contentPaddingBottom = parseInt($scrollableEl.css('padding-bottom'), 10);134    const contentOffsetTop = $scrollableEl.offset().top - contentScrollTop;135    const inputOffsetTop = $inputEl.offset().top - contentOffsetTop;136    const inputHeight = $inputEl[0].offsetHeight;137    const min = (inputOffsetTop + contentScrollTop) - contentPaddingTop;138    const max = ((inputOffsetTop + contentScrollTop) - contentHeight) + contentPaddingBottom + inputHeight;139    const centeredPosition = min + ((max - min) / 2);140    if (contentScrollTop > min) {141      $scrollableEl.scrollTop(centered ? centeredPosition : min, duration);142      return true;143    }144    if (contentScrollTop < max) {145      $scrollableEl.scrollTop(centered ? centeredPosition : max, duration);146      return true;147    }148    if (force) {149      $scrollableEl.scrollTop(centered ? centeredPosition : max, duration);150    }151    return false;152  },153  init() {154    const app = this;155    Input.createTextareaResizableShadow();156    function onFocus() {157      const inputEl = this;158      if (app.params.input.scrollIntoViewOnFocus) {159        if (Device.android) {160          $(window).once('resize', () => {161            if (document && document.activeElement === inputEl) {162              app.input.scrollIntoView(inputEl, app.params.input.scrollIntoViewDuration, app.params.input.scrollIntoViewCentered, app.params.input.scrollIntoViewAlways);163            }164          });165        } else {166          app.input.scrollIntoView(inputEl, app.params.input.scrollIntoViewDuration, app.params.input.scrollIntoViewCentered, app.params.input.scrollIntoViewAlways);167        }168      }169      app.input.focus(inputEl);170    }171    function onBlur() {172      const $inputEl = $(this);173      const tag = $inputEl[0].nodeName.toLowerCase();174      app.input.blur($inputEl);175      if ($inputEl.dataset().validate || $inputEl.attr('validate') !== null) {176        app.input.validate($inputEl);177      }178      // Resize textarea179      if (tag === 'textarea' && $inputEl.hasClass('resizable')) {180        if (Input.textareaResizableShadow) Input.textareaResizableShadow.remove();181      }182    }183    function onChange() {184      const $inputEl = $(this);185      const type = $inputEl.attr('type');186      const tag = $inputEl[0].nodeName.toLowerCase();187      if (Input.ignoreTypes.indexOf(type) >= 0) return;188      // Check Empty State189      app.input.checkEmptyState($inputEl);190      // Check validation191      if ($inputEl.dataset().validate || $inputEl.attr('validate') !== null) {192        app.input.validate($inputEl);193      }194      // Resize textarea195      if (tag === 'textarea' && $inputEl.hasClass('resizable')) {196        app.input.resizeTextarea($inputEl);197      }198    }199    function onInvalid(e) {200      const $inputEl = $(this);201      if ($inputEl.dataset().validate || $inputEl.attr('validate') !== null) {202        e.preventDefault();203        app.input.validate($inputEl);204      }205    }206    function clearInput() {207      const $clicked = $(this);208      const $inputEl = $clicked.siblings('input, textarea').eq(0);209      const previousValue = $inputEl.val();210      $inputEl211        .val('')212        .trigger('input change')213        .focus()214        .trigger('input:clear', previousValue);215    }216    $(document).on('click', '.input-clear-button', clearInput);217    $(document).on('change input', 'input, textarea, select', onChange, true);218    $(document).on('focus', 'input, textarea, select', onFocus, true);219    $(document).on('blur', 'input, textarea, select', onBlur, true);220    $(document).on('invalid', 'input, textarea, select', onInvalid, true);221  },222};223export default {224  name: 'input',225  params: {226    input: {227      scrollIntoViewOnFocus: Device.android,228      scrollIntoViewCentered: false,229      scrollIntoViewDuration: 0,230      scrollIntoViewAlways: false,231    },232  },233  create() {234    const app = this;235    Utils.extend(app, {236      input: {237        scrollIntoView: Input.scrollIntoView.bind(app),238        focus: Input.focus.bind(app),239        blur: Input.blur.bind(app),240        validate: Input.validate.bind(app),241        validateInputs: Input.validateInputs.bind(app),242        checkEmptyState: Input.checkEmptyState.bind(app),243        resizeTextarea: Input.resizeTextarea.bind(app),244        init: Input.init.bind(app),245      },246    });247  },248  on: {249    init() {250      const app = this;251      app.input.init();252    },253    tabMounted(tabEl) {254      const app = this;255      const $tabEl = $(tabEl);256      $tabEl.find('.item-input, .input').each((itemInputIndex, itemInputEl) => {257        const $itemInputEl = $(itemInputEl);258        $itemInputEl.find('input, select, textarea').each((inputIndex, inputEl) => {259          const $inputEl = $(inputEl);260          if (Input.ignoreTypes.indexOf($inputEl.attr('type')) >= 0) return;261          app.input.checkEmptyState($inputEl);262        });263      });264      $tabEl.find('textarea.resizable').each((textareaIndex, textareaEl) => {265        app.input.resizeTextarea(textareaEl);266      });267    },268    pageInit(page) {269      const app = this;270      const $pageEl = page.$el;271      $pageEl.find('.item-input, .input').each((itemInputIndex, itemInputEl) => {272        const $itemInputEl = $(itemInputEl);273        $itemInputEl.find('input, select, textarea').each((inputIndex, inputEl) => {274          const $inputEl = $(inputEl);275          if (Input.ignoreTypes.indexOf($inputEl.attr('type')) >= 0) return;276          app.input.checkEmptyState($inputEl);277        });278      });279      $pageEl.find('textarea.resizable').each((textareaIndex, textareaEl) => {280        app.input.resizeTextarea(textareaEl);281      });282    },283  },...t.py
Source:t.py  
1import math2from tkinter import *3from PIL import ImageTk, Image4import matplotlib.pyplot as plt5from scipy. integrate import odeint6import numpy as np7mu0 = 4 * math.pi * (10 ** (-7))8tau = 1.7759l = 3.510wc = 1411wr = 2412delta = 0.06513Rc = 114Rr = 215Lcs = 0.0012616Lrs = 0.00126*217J = 0.118p = 219D = 2*tau/math.pi*p20pi = math.pi21kcc = p*(4*wc*wc*tau*l*mu0)/(pi*delta*pi)22krc = p*(4*wr*wc*tau*l*mu0)/(pi*delta*pi)23krr = p*(4*wr*wr*tau*l*mu0)/(pi*delta*pi)24t_max = 425t_del = 50000026t = np.linspace(0, t_max, t_del)27y0 = [0, 0, 0, 0, 0, 0, 0, 0]28Uc = 40029fc = 5030phic = 031def B_delta(Ica, Icb, Icc, Ira, Irb, Irc, x, phi):32    return (2*mu0/(math.pi*delta)*(wc*Ica*math.cos(math.pi/tau*x)+wc*Icb*math.cos(math.pi/tau*x-2*math.pi/3)+wc*Icc*math.cos(math.pi/tau*x+2*math.pi/3)+wr*Ira*math.cos(math.pi/tau*x-phi*p)+wr*Irb*math.cos(math.pi/tau*x-phi*p-2*math.pi/3)+wr*Irc*math.cos(math.pi/tau*x-phi*p+2*math.pi/3)))33def f(input_variable, t):34    main_det = [[-kcc*(math.sin(pi/2) - (-1)*math.sin(pi/6)) - Lcs, -kcc*(math.sin(pi/2 + 2*pi/3) - (-1)*math.sin(pi/6 - 2*pi/3)) + Lcs, -kcc*(math.sin(pi/2 - 2*pi/3) - (-1)*math.sin(pi/6 + 2*pi/3)), -krc*(math.sin(pi/2 + input_variable[7]*p) - (-1)*math.sin(pi/6 - input_variable[7]*p)), -krc*(math.sin(pi/2 + input_variable[7]*p + 2*pi/3) - (-1)*math.sin(pi/6 - input_variable[7]*p - 2*pi/3)), -krc*(math.sin(pi/2 + input_variable[7]*p - 2*pi/3) - (-1)*math.sin(pi/6 - input_variable[7]*p + 2*pi/3))],35                [-kcc*((-1)*math.sin(pi/6) - math.sin(-pi/6)), -kcc*((-1)*math.sin(pi/6 - 2*pi/3) - math.sin(-pi/6 - 2*pi/3)) - Lcs, -kcc*((-1)*math.sin(pi/6 + 2*pi/3) - math.sin(-pi/6 + 2*pi/3)) + Lcs, -krc*((-1)*math.sin(pi/6 - input_variable[7]*p) - math.sin(-pi/6 - input_variable[7]*p)), -krc*((-1)*math.sin(pi/6 - input_variable[7]*p - 2*pi/3) - math.sin(-pi/6 - input_variable[7]*p - 2*pi/3)), -krc*((-1)*math.sin(pi/6 - input_variable[7]*p + 2*pi/3) - math.sin(-pi/6 - input_variable[7]*p + 2*pi/3))],36                [-kcc*math.sin(-pi/6), -kcc*math.sin(-pi/6 - 2*pi/3), -kcc*math.sin(-pi/6 + 2*pi/3) - Lcs, -krc*math.sin(-pi/6 - input_variable[7]*p), -krc*math.sin(-pi/6 - input_variable[7]*p - 2*pi/3), -krc*math.sin(-pi/6 - input_variable[7]*p + 2*pi/3)],37                [-krc*math.sin(pi/2-input_variable[7]*p-0), -krc*math.sin(pi/2-input_variable[7]*p+2*pi/3), -krc*math.sin(pi/2-input_variable[7]*p-2*pi/3), -krr*math.sin(pi/2-0) - Lrs, -krr*math.sin(pi/2+2*pi/3), -krr*math.sin(pi/2-2*pi/3)],38    			[-krc*(-1)*math.sin(pi/6+input_variable[7]*p-0), -krc*(-1)*math.sin(pi/6+input_variable[7]*p-2*pi/3), -krc*(-1)*math.sin(pi/6+input_variable[7]*p+2*pi/3), -krr*(-1)*math.sin(pi/6+0), -krr*(-1)*math.sin(pi/6-2*pi/3) - Lrs, -krr*(-1)*math.sin(pi/6+2*pi/3)],39    			[-krc*math.sin(-pi/6+input_variable[7]*p-0), -krc*math.sin(-pi/6+input_variable[7]*p-2*pi/3), -krc*math.sin(-pi/6+input_variable[7]*p+2*pi/3), -krr*math.sin(-pi/6+0), -krr*math.sin(-pi/6-2*pi/3), -krr*math.sin(-pi/6+2*pi/3) - Lrs]40               ]41    own_matrix = [input_variable[0]*Rc + Uc*(math.sin(2*math.pi*fc*t + phic) - math.sin(2*math.pi*fc*t + phic - 2*pi/3)) - input_variable[1]*Rc + krc*p*input_variable[6]*(input_variable[3]*math.cos(pi/2 + input_variable[7]*p) + input_variable[4]*math.cos(pi/2 + input_variable[7]*p + 2*pi/3) + input_variable[5]*math.cos(pi/2 + input_variable[7]*p - 2*pi/3) + (-1)*input_variable[3]*math.cos(pi/6 - input_variable[7]*p) + (-1)*input_variable[4]*math.cos(pi/6 - input_variable[7]*p - 2*pi/3) + (-1)*input_variable[5]*math.cos(pi/6 - input_variable[7]*p + 2*pi/3)),42                input_variable[1]*Rc + Uc*(math.sin(2*math.pi*fc*t + phic - 2*pi/3) - math.sin(2*math.pi*fc*t + phic + 2*pi/3)) - input_variable[2]*Rc + krc*p*input_variable[6]*(input_variable[3]*math.cos(pi/6 - input_variable[7]*p) + input_variable[4]*math.cos(pi/6 - input_variable[7]*p - 2*pi/3) + input_variable[5]*math.cos(pi/6 - input_variable[7]*p + 2*pi/3) + input_variable[3]*math.cos(-pi/6 - input_variable[7]*p) + input_variable[4]*math.cos(-pi/6 - input_variable[7]*p - 2*pi/3) + input_variable[5]*math.cos(-pi/6 - input_variable[7]*p + 2*pi/3)),43                input_variable[2]*Rc + Uc*math.sin(2*math.pi*fc*t + phic + 2*pi/3) - krc*p*input_variable[6]*(input_variable[3]*math.cos(-pi/6 - input_variable[7]*p) + input_variable[4]*math.cos(-pi/6 - input_variable[7]*p - 2*pi/3) + input_variable[5]*math.cos(-pi/6 - input_variable[7]*p + 2*pi/3)),44                input_variable[3]*Rr-input_variable[6]*krc*p*(input_variable[0]*math.cos(pi/2-input_variable[7]*p)+input_variable[1]*math.cos(pi/2-input_variable[7]*p+2*pi/3)+input_variable[2]*math.cos(pi/2-input_variable[7]*p-2*pi/3)),45                input_variable[4]*Rr+input_variable[6]*krc*p*(-1)*(input_variable[0]*math.cos(pi/6+input_variable[7]*p)+input_variable[1]*math.cos(pi/6+input_variable[7]*p-2*pi/3)+input_variable[2]*math.cos(pi/6+input_variable[7]*p+2*pi/3)),46                input_variable[5]*Rr+input_variable[6]*krc*p*(input_variable[0]*math.cos(-pi/6+input_variable[7]*p)+input_variable[1]*math.cos(-pi/6+input_variable[7]*p-2*pi/3)+input_variable[2]*math.cos(-pi/6+input_variable[7]*p+2*pi/3))47                ]48    49    Melmag = D*l*wr*(input_variable[3]*B_delta(input_variable[0], input_variable[1], input_variable[2], input_variable[3], input_variable[4], input_variable[5], tau/pi*input_variable[7]*p-tau/2, input_variable[7])+input_variable[4]*B_delta(input_variable[0], input_variable[1], input_variable[2], input_variable[3], input_variable[4], input_variable[5], tau/pi*input_variable[7]*p+tau/6, input_variable[7])+input_variable[5]*B_delta(input_variable[0], input_variable[1], input_variable[2], input_variable[3], input_variable[4], input_variable[5], tau/pi*input_variable[7]*p-7*tau/6, input_variable[7]))50    derw = (-0*math.tanh(input_variable[6]) - p*Melmag)/J51    solve_matrix = np.linalg.solve(main_det, own_matrix)52    print(t/t_max*100)53    return [solve_matrix[0],54    solve_matrix[1],55    solve_matrix[2],56    solve_matrix[3],57    solve_matrix[4],58    solve_matrix[5],59    derw,60    input_variable[6]]61ww = odeint(f, y0, t)62m_f = []63for i in range(len(t)):64    m_f.append(ww[:, 6][i]/2/pi)65plt.subplot(3, 1, 1)66plt.plot(t, ww[:, 0], linewidth=1, color='red')67plt.xlabel('ÐÑемÑ, Ñ', fontsize=12, color='black')68plt.ylabel('Ток ÑÑаÑоÑа, Ð', fontsize=12, color='black')69plt.grid(True)70plt.subplot(3, 1, 2)71plt.plot(t, ww[:, 3], linewidth=1, color='red')72plt.xlabel('ÐÑемÑ, Ñ', fontsize=12, color='black')73plt.ylabel('Ток ÑоÑоÑа, Ð', fontsize=12, color='black')74plt.grid(True)75plt.subplot(3, 1, 3)76plt.plot(t, m_f, linewidth=1, color='red')77plt.xlabel('ÐÑемÑ, Ñ', fontsize=12, color='black')78plt.ylabel('ЧаÑÑоÑа, ÐÑ', fontsize=12, color='black')79plt.grid(True)80plt.show()81[-kcc*(math.sin(pi/2)-(-1)*math.sin(pi/6)-math.sin(pi/2-2*pi/3)+(-1)*math.sin(pi/6+2*pi/3))-Lcs, -kcc*(math.sin(pi/2+2*pi/3)-(-1)*math.sin(pi/6-2*pi/3)-math.sin(pi/2-2*pi/3)+(-1)*math.sin(pi/6+2*pi/3))+Lcs, -krc*(math.sin(pi/2 + input_variable[6]*p) - (-1)*math.sin(pi/6 - input_variable[6]*p)), -krc*(math.sin(pi/2 + input_variable[6]*p + 2*pi/3) - (-1)*math.sin(pi/6 - input_variable[6]*p - 2*pi/3)), -krc*(math.sin(pi/2 + input_variable[6]*p - 2*pi/3) - (-1)*math.sin(pi/6 - input_variable[6]*p + 2*pi/3))],82[-kcc*((-1)*math.sin(pi/6)-math.sin(-pi/6)-(-1)*math.sin(pi/6+2*pi/3)+math.sin(-pi/6+2*pi/3))-Lcs, -kcc*((-1)*math.sin(pi/6-2*pi/3)-math.sin(-pi/6-2*pi/3)-(-1)*math.sin(pi/6+2*pi/3)+math.sin(-pi/6+2*pi/3))-Lcs-Lcs, -krc*((-1)*math.sin(pi/6 - input_variable[6]*p) - math.sin(-pi/6 - input_variable[6]*p)), -krc*((-1)*math.sin(pi/6 - input_variable[6]*p - 2*pi/3) - math.sin(-pi/6 - input_variable[6]*p - 2*pi/3)), -krc*((-1)*math.sin(pi/6 - input_variable[6]*p + 2*pi/3) - math.sin(-pi/6 - input_variable[6]*p + 2*pi/3))],83[-krc*(math.sin(pi/2-input_variable[6]*p-0)-math.sin(pi/2-input_variable[6]*p-2*pi/3)), -krc*(math.sin(pi/2-input_variable[6]*p+2*pi/3)-math.sin(pi/2-input_variable[6]*p-2*pi/3)), -krr*math.sin(pi/2-0) - Lrs, -krr*math.sin(pi/2+2*pi/3), -krr*math.sin(pi/2-2*pi/3)],84[-krc*((-1)*math.sin(pi/6+input_variable[6]*p-0)-(-1)*math.sin(pi/6+input_variable[6]*p+2*pi/3)), -krc*((-1)*math.sin(pi/6+input_variable[6]*p-2*pi/3)-(-1)*math.sin(pi/6+input_variable[6]*p+2*pi/3)), -krr*(-1)*math.sin(pi/6+0), -krr*(-1)*math.sin(pi/6-2*pi/3) - Lrs, -krr*(-1)*math.sin(pi/6+2*pi/3)],85[-krc*(math.sin(-pi/6+input_variable[6]*p-0)-math.sin(-pi/6+input_variable[6]*p+2*pi/3)), -krc*(math.sin(-pi/6+input_variable[6]*p-2*pi/3)-math.sin(-pi/6+input_variable[6]*p+2*pi/3)), -krr*math.sin(-pi/6+0), -krr*math.sin(-pi/6-2*pi/3), -krr*math.sin(-pi/6+2*pi/3) - Lrs]86[input_variable[0]*Rc - input_variable[1]*Rc + krc*p*input_variable[5]*(input_variable[2]*math.cos(pi/2 + input_variable[6]*p) + input_variable[3]*math.cos(pi/2 + input_variable[6]*p + 2*pi/3) + input_variable[4]*math.cos(pi/2 + input_variable[6]*p - 2*pi/3) + (-1)*input_variable[2]*math.cos(pi/6 - input_variable[6]*p) + (-1)*input_variable[3]*math.cos(pi/6 - input_variable[6]*p - 2*pi/3) + (-1)*input_variable[4]*math.cos(pi/6 - input_variable[6]*p + 2*pi/3)),87input_variable[1]*Rc - (-input_variable[0]-input_variable[1])*Rc + krc*p*input_variable[5]*(input_variable[2]*math.cos(pi/6 - input_variable[6]*p) + input_variable[3]*math.cos(pi/6 - input_variable[6]*p - 2*pi/3) + input_variable[4]*math.cos(pi/6 - input_variable[6]*p + 2*pi/3) + input_variable[2]*math.cos(-pi/6 - input_variable[6]*p) + input_variable[3]*math.cos(-pi/6 - input_variable[6]*p - 2*pi/3) + input_variable[4]*math.cos(-pi/6 - input_variable[6]*p + 2*pi/3)),88input_variable[2]*Rr-input_variable[5]*krc*p*(input_variable[0]*math.cos(pi/2-input_variable[6]*p)+input_variable[1]*math.cos(pi/2-input_variable[6]*p+2*pi/3)+(-input_variable[0]-input_variable[1])*math.cos(pi/2-input_variable[6]*p-2*pi/3)),89input_variable[3]*Rr+input_variable[5]*krc*p*(-1)*(input_variable[0]*math.cos(pi/6+input_variable[6]*p)+input_variable[1]*math.cos(pi/6+input_variable[6]*p-2*pi/3)+(-input_variable[0]-input_variable[1])*math.cos(pi/6+input_variable[6]*p+2*pi/3)),90input_variable[4]*Rr+input_variable[5]*krc*p*(input_variable[0]*math.cos(-pi/6+input_variable[6]*p)+input_variable[1]*math.cos(-pi/6+input_variable[6]*p-2*pi/3)+(-input_variable[0]-input_variable[1])*math.cos(-pi/6+input_variable[6]*p+2*pi/3))...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
