How to use scope method in ts-auto-mock

Best JavaScript code snippet using ts-auto-mock

Scope.test.js

Source:Scope.test.js Github

copy

Full Screen

1import Scope from 'js_legacy/Scope';2import Lib from 'util/functions';3const def = new Lib();4describe('Scope', function () {5 it('can be constructed using an object', function () {6 let scope = new Scope();7 scope.aProperty = 1;8 expect(scope.aProperty).toBe(1);9 });10 describe('digest', function () {11 let scope;12 beforeEach(function () {13 scope = new Scope();14 });15 it('calls the listener function of a watch o first $digest', function () {16 let watchFn = function () {17 return 'wat';18 };19 let listenerFn = jest.fn(def.noop);20 scope.$watch(watchFn, listenerFn);21 scope.$digest();22 expect(listenerFn).toHaveBeenCalled();23 });24 it('calls the listener function when the watch value changes', function () {25 scope.someValue = 'a';26 scope.counter = 0;27 scope.$watch(28 function (scope) {29 return scope.someValue; //the expression30 },31 function (newValue, oldValue, scope) {32 scope.counter++;33 },34 );35 expect(scope.counter).toBe(0);36 scope.$digest();37 expect(scope.counter).toBe(1);38 scope.$digest();39 expect(scope.counter).toBe(1);40 });41 it('calls listener with new value as old value the first time', function () {42 scope.someValue = 123;43 let testFirstTimeWatch = undefined;44 scope.$watch(45 function (scope) {46 return scope.someValue;47 },48 function (newValue, oldValue) {49 //oldValue === initWatchVal --> newVal50 testFirstTimeWatch = oldValue;51 },52 );53 expect(testFirstTimeWatch).toBeUndefined();54 scope.$digest();55 expect(testFirstTimeWatch).toBe(123);56 scope.someValue = 124;57 scope.$digest();58 expect(testFirstTimeWatch).toBe(123); //oldValue59 });60 it('watch function without any listener function', function () {61 let watchFn = jest.fn().mockReturnValue('hello');62 scope.$watch(watchFn);63 scope.$digest();64 expect(watchFn).toHaveBeenCalled();65 expect(watchFn).toHaveReturnedWith('hello');66 });67 it('keep digesting while dirty one watcher changes the value of another watcher', function () {68 scope.name = 'Bob';69 scope.initial = null;70 //order of $watches are intended so the dependent one will get passover than because of dirty will get rendered again71 scope.$watch(72 function (scope) {73 return scope.nameUpper;74 },75 function (newValue, oldValue, scope) {76 if (newValue) {77 scope.initial = newValue.substring(0, 1) + '.';78 }79 },80 );81 scope.$watch(82 function (scope) {83 return scope.name;84 },85 function (newValue, oldValue, scope) {86 if (newValue) {87 scope.nameUpper = newValue.toUpperCase();88 }89 },90 );91 scope.$digest();92 expect(scope.initial).toBe('B.');93 scope.name = 'George';94 scope.$digest();95 expect(scope.initial).toBe('G.');96 });97 it('unstable digest two watches being dependent from one another', function () {98 scope.first = 0;99 scope.second = 0;100 scope.$watch(101 function (scope) {102 return scope.first;103 },104 function () {105 scope.second++;106 },107 );108 scope.$watch(109 function (scope) {110 return scope.second;111 },112 function () {113 scope.first++;114 },115 );116 expect(function () {117 scope.$digest();118 }).toThrow();119 });120 it('watcher unstable and inefficient digest cycle', function () {121 scope.array = def.Lo.range(100);122 let watchExecution = 0;123 def.Lo.times(100, function (i) {124 scope.$watch(125 function (scope) {126 //setting up 100 watchers127 watchExecution++;128 return scope.array[i]; //setting return value on each value of the array129 },130 function () {},131 );132 });133 //loop goes on all the watchers then the second round to determine whether some watcher was changed in the listener134 scope.$digest();135 expect(watchExecution).toBe(200);136 scope.array[0] = 69;137 scope.$digest();138 expect(watchExecution).toBe(301); //if not with short circuit-ing optimization139 });140 it('does not end digest so that new watches are not run Watch inside a Watch', function () {141 scope.someValue = 'a';142 scope.counter = 0;143 //second watch without reset on every watch will never run because were ending the digest before new watch would run144 //bcz we're ending the digest detecting the first watch as dirty145 scope.$watch(146 function (scope) {147 return scope.someValue;148 },149 function (newValue, oldValue, scope) {150 scope.$watch(151 function (scope) {152 //on ,first it will put the watcher, but it will be lost since it will be terminated153 return scope.someValue;154 },155 function (newValue, oldValue, scope) {156 scope.counter++;157 },158 );159 },160 );161 scope.$digest();162 expect(scope.counter).toBe(1);163 });164 it('watching an array or an object', function () {165 scope.aValue = [1, 2, 3];166 scope.counter = 0;167 scope.$watch(168 function (scope) {169 return scope.aValue;170 },171 function (newValue, oldValue, scope) {172 scope.counter++;173 },174 true,175 );176 scope.$digest();177 expect(scope.counter).toBe(1);178 scope.aValue.push(4);179 scope.$digest();180 expect(scope.counter).toBe(2);181 });182 it('correct handle NAN', function () {183 scope.number = 0 / 0; //NaN184 scope.counter = 0;185 scope.$watch(186 function (scope) {187 return scope.number;188 },189 function (n, o, scope) {190 scope.counter++;191 },192 );193 scope.$digest();194 expect(scope.counter).toBe(1);195 scope.$digest();196 expect(scope.counter).toBe(1);197 });198 it('$eval creating and return of the result with one parameter and with two parameter', function () {199 scope.aValue = 42;200 let result = scope.$eval(function (scope) {201 return scope.aValue;202 });203 expect(result).toBe(42);204 let result2 = scope.$eval(function (scope, arg) {205 return scope.aValue + arg;206 }, 2);207 expect(result2).toBe(44);208 });209 it('apply function which will take and expr or not and trigger a digest cycle', function () {210 scope.aValue = 'someThingShouldBeHere';211 scope.counter = 0;212 scope.$watch(213 function () {214 return scope.aValue;215 },216 function (newValue, oldValue, scope) {217 scope.counter++;218 },219 );220 scope.$digest();221 expect(scope.counter).toBe(1);222 scope.$apply(function (scope) {223 scope.aValue = 'ApplyChangedMe';224 });225 expect(scope.counter).toBe(2);226 expect(scope.aValue).toBe('ApplyChangedMe');227 });228 it('executes evalAsync in function later in the same cycle', function () {229 scope.aValue = [1, 2, 3];230 scope.asyncEvaluated = false;231 scope.asyncEvaluatedImmediately = false;232 scope.$watch(233 function (scope) {234 return scope.aValue;235 },236 function (newValue, oldValue, scope) {237 scope.$evalAsync(function (scope) {238 scope.asyncEvaluated = true;239 });240 scope.asyncEvaluatedImmediately = scope.asyncEvaluated; //won't pick up the new Value here but after the main digest is over241 },242 );243 scope.$digest();244 expect(scope.asyncEvaluatedImmediately).toBeFalsy(); //means it will be evaluated before the evalAsync digest in progress245 expect(scope.asyncEvaluated).toBeTruthy();246 });247 it('executes evalAsync in the watch functions when not dirty!!', function () {248 scope.aValueWorking = 'WorkingCaseEvalAsyncNotDirty';249 scope.asyncEvaluatedTimesWorking = 0;250 scope.aValue = [1, 2, 3];251 scope.asyncEvaluatedTimes = 0;252 scope.$watch(253 function (scope) {254 if (!scope.asyncEvaluatedTimesWorking) {255 scope.$evalAsync(function (scope) {256 //this one will get scheduled when a watch is dirty257 scope.asyncEvaluatedTimesWorking++;258 });259 }260 return scope.aValueWorking;261 },262 function () {},263 );264 //what if we schedule an evalAsync when no watch is dirty265 scope.$watch(266 function (scope) {267 if (scope.asyncEvaluatedTimes < 2) {268 //second time watch won't be dirty , and it will be a problem269 scope.$evalAsync(function (scope) {270 scope.asyncEvaluatedTimes++;271 });272 }273 return scope.aValue;274 },275 function () {},276 );277 scope.$digest();278 expect(scope.asyncEvaluatedTimesWorking).toBeTruthy();279 expect(scope.asyncEvaluatedTimes).toBe(2);280 });281 it('has a $$phase field whose value is the current digest phase', function () {282 scope.aValue = [1, 2, 3];283 scope.phaseInWatch = undefined;284 scope.phaseInListener = undefined;285 scope.phaseInApply = undefined;286 scope.$watch(287 function () {288 scope.phaseInWatch = scope.$$phase;289 return scope.aValue;290 },291 function (newValue, oldValue, scope) {292 scope.phaseInListener = scope.$$phase;293 },294 );295 scope.$apply(function () {296 scope.phaseInApply = scope.$$phase;297 });298 expect(scope.phaseInWatch).toBe('$digest');299 expect(scope.phaseInListener).toBe('$digest');300 expect(scope.phaseInApply).toBe('$apply');301 });302 it('schedules a digest in $evalAsync', function (done) {303 scope.aValue = 'abc';304 scope.counter = 0;305 scope.$watch(306 function (scope) {307 return scope.aValue;308 },309 function () {310 scope.counter++;311 },312 );313 scope.$evalAsync(function () {}); //trigger a digest if none is running314 expect(scope.counter).toBe(0);315 setTimeout(function () {316 expect(scope.counter).toBe(1);317 done();318 }, 50);319 });320 it('allows async $apply with $applyAsync', function (done) {321 scope.counter = 0;322 scope.aValue = 88;323 scope.$watch(324 function () {325 return scope.aValue;326 },327 function (newValue, oldValue, scope) {328 scope.counter++;329 },330 );331 scope.$digest();332 expect(scope.counter).toBe(1);333 scope.$applyAsync(function (scope) {334 scope.aValue = 'somethingHere';335 });336 expect(scope.counter).toBe(1);337 setTimeout(function () {338 expect(scope.counter).toBe(2);339 done();340 }, 50);341 });342 it('never executes $applyAsync!ed function in the same cycle', function (done) {343 scope.aValue = [1, 2, 3];344 scope.asyncApplied = false;345 scope.$watch(346 function (scope) {347 return scope.aValue;348 },349 function (newValue, oldValue, scope) {350 scope.$applyAsync(function (scope) {351 scope.asyncApplied = true;352 });353 },354 );355 scope.$digest();356 expect(scope.asyncApplied).toBe(false);357 setTimeout(function () {358 expect(scope.asyncApplied).toBe(true);359 done();360 }, 50);361 });362 it('coalescing many call of $applyAsync', function (done) {363 scope.counter = 0;364 scope.$watch(365 function (scope) {366 scope.counter++;367 return scope.aValue;368 },369 function () {},370 );371 scope.$applyAsync(function (scope) {372 scope.aValue = 's1';373 });374 scope.$applyAsync(function (scope) {375 scope.aValue = 's2';376 });377 setTimeout(function () {378 expect(scope.counter).toBe(2);379 done();380 }, 50);381 });382 it('runs a $$postDigest function after each digest', function () {383 scope.counter = 0;384 scope.$$postDigest(function () {385 scope.counter++;386 });387 expect(scope.counter).toBeFalsy();388 scope.$digest();389 expect(scope.counter).toBe(1);390 scope.$digest(); //here the Queue is already consumed391 expect(scope.counter).toBe(1);392 });393 it('does not include $postDigest in the the digest cycle', function () {394 scope.aValue = 'someOriginalValue';395 scope.listenerChangedValue = '';396 scope.$$postDigest(function () {397 scope.aValue = 'someChangedValue'; //won't immediately check out by dirty checking mechanism398 });399 scope.$watch(400 function () {401 return scope.aValue;402 },403 function (newValue, oldValue, scope) {404 scope.listenerChangedValue = newValue; //pick up the old Digested then after the listener405 },406 );407 scope.$digest();408 expect(scope.listenerChangedValue).toBe('someOriginalValue');409 scope.$digest();410 expect(scope.listenerChangedValue).toBe('someChangedValue');411 });412 it('catches the exceptions in watch functions and continues', function () {413 scope.aValue = 'abc';414 scope.counter = 0;415 scope.$watch(function () {416 throw 'error';417 });418 scope.$watch(419 function (scope) {420 return scope.aValue;421 },422 function (newValue, oldValue, scope) {423 scope.counter++;424 },425 );426 scope.$digest();427 expect(scope.counter).toBe(1);428 });429 it('catches the exceptions in Listener functions and continues', function () {430 scope.aValue = 'abc';431 scope.counter = 0;432 scope.$watch(433 function () {434 return scope.aValue;435 },436 function () {437 throw 'error';438 },439 );440 scope.$watch(441 function (scope) {442 return scope.aValue;443 },444 function (newValue, oldValue, scope) {445 scope.counter++;446 },447 );448 scope.$digest();449 expect(scope.counter).toBe(1);450 });451 it('catches exceptions in evalAsync', function (done) {452 scope.aValue = 'abc';453 scope.counter = 0;454 scope.$watch(455 function (scope) {456 return scope.aValue;457 },458 function (newValue, oldValue, scope) {459 scope.counter++;460 },461 );462 scope.$evalAsync(function () {463 throw 'Error';464 });465 setTimeout(function () {466 expect(scope.counter).toBe(1);467 done();468 }, 50);469 });470 it('catches exceptions in asyncApply', function (done) {471 scope.$applyAsync(function () {472 throw 'Error';473 });474 scope.$applyAsync(function () {475 throw 'Error2';476 });477 scope.$applyAsync(function () {478 scope.applied = true;479 });480 setTimeout(function () {481 expect(scope.applied).toBeTruthy();482 done();483 }, 50);484 });485 it('catches exceptions in postDigest', function () {486 scope.$$postDigest(function () {487 throw 'Error';488 });489 scope.$$postDigest(function () {490 throw 'Error2';491 });492 scope.$$postDigest(function () {493 scope.run = true;494 });495 scope.$digest();496 expect(scope.run).toBeTruthy();497 });498 it('allows a particular watch to be destroyed', function () {499 scope.aValue = 'abc';500 scope.counter = 0;501 let destroyedWatch = scope.$watch(502 function () {503 return scope.aValue;504 },505 function (newValue, oldValue, scope) {506 scope.counter++;507 },508 );509 scope.$digest();510 expect(scope.counter).toBe(1);511 scope.aValue = 'bcd';512 scope.$digest();513 expect(scope.counter).toBe(2);514 scope.aValue = 'efg';515 destroyedWatch();516 scope.$digest();517 expect(scope.counter).toBe(2);518 });519 it('allows destroying a watching during a digest', function () {520 scope.aValue = 'abc';521 let watchCalls = [];522 scope.$watch(function (scope) {523 watchCalls.push('first');524 return scope.aValue;525 });526 let destroyWatch = scope.$watch(function () {527 watchCalls.push('second');528 destroyWatch(); //this should not trick the order and the shifting order of the watcher, so they won't budge529 });530 scope.$watch(function (scope) {531 watchCalls.push('third');532 return scope.aValue;533 });534 scope.$digest();535 expect(watchCalls).toEqual(['first', 'second', 'third', 'first', 'third']);536 });537 it('allows the $watch to destroy another during digest', function () {538 scope.aValue = 'abc';539 scope.counter = 0;540 scope.$watch(541 function () {542 return scope.aValue;543 },544 function () {545 destroyWatch();546 },547 );548 let destroyWatch = scope.$watch(549 function () {},550 function () {},551 );552 scope.$watch(553 function (scope) {554 return scope.aValue;555 },556 function (newValue, oldValue, scope) {557 scope.counter++;558 },559 );560 scope.$digest();561 expect(scope.counter).toBe(1);562 });563 it('allows in the $watch to destroy multiple watches in te digest', function () {564 scope.aValue = 'abc';565 scope.counter = 0;566 let destroyWatch1 = scope.$watch(function () {567 destroyWatch1();568 destroyWatch2(); //why it makes it undefined rather than deleting it from the array569 });570 let destroyWatch2 = scope.$watch(571 function () {572 return scope.aValue;573 },574 function (newValue, oldValue, scope) {575 scope.counter++;576 },577 );578 scope.$digest();579 expect(scope.counter).toBe(0);580 });581 });582 describe('$watchGroup', function () {583 let scope;584 beforeEach(function () {585 scope = new Scope();586 });587 /*it('takes watches as an array can calls the listener with arrays', function () {588 let gotNewValue = null;589 let gotOldValue = null;590 scope.aValue = 1;591 scope.anotherValue = 2;592 scope.$watchGroup(593 [594 function (scope) {595 return scope.aValue;596 },597 function (scope) {598 return scope.anotherValue;599 },600 ],601 function (newValues, oldValues) {602 gotNewValue = newValues;603 gotOldValue = oldValues;604 },605 );606 scope.$digest();607 expect(gotNewValue).toEqual([1, 2]);608 expect(gotOldValue).toEqual([1, 2]);609 });*/610 /*it('only calls listener once per digest', function () {611 let counter = 0;612 scope.aValue = 1;613 scope.anotherValue = 2;614 scope.$watchGroup(615 [616 function (scope) {617 return scope.aValue;618 },619 function (scope) {620 return scope.anotherValue;621 },622 ],623 function () {624 counter++;625 },626 );627 scope.$digest();628 expect(counter).toEqual(1);629 });*/630 /*it('uses different arrays for old and new Values on subsequent runs', function () {631 let gotNewValues = null;632 let gotOldValues = null;633 scope.aValue = 1;634 scope.anotherValue = 2;635 scope.$watchGroup(636 [637 function (scope) {638 return scope.aValue;639 },640 function (scope) {641 return scope.anotherValue;642 },643 ],644 function (newValues, oldValues) {645 gotNewValues = newValues;646 gotOldValues = oldValues;647 },648 );649 scope.$digest();650 scope.anotherValue = 3;651 scope.$digest();652 expect(gotOldValues).toEqual([1, 2]);653 expect(gotNewValues).toEqual([1, 3]);654 });*/655 it('calls the listener once when the watch array s empty', function () {656 let gotNewsValues = null;657 let gotOldValues = null;658 scope.$watchGroup([], function (newValues, oldValues) {659 gotOldValues = oldValues;660 gotNewsValues = newValues;661 });662 scope.$digest();663 expect(gotNewsValues).toEqual([]);664 expect(gotOldValues).toEqual([]);665 });666 /*it('destroy or deregister a watchGroup', function () {667 let counter = 0;668 scope.aValue = 1;669 scope.anotherValue = 2;670 let destroyGroup = scope.$watchGroup(671 [672 function (scope) {673 return scope.aValue;674 },675 function (scope) {676 return scope.anotherValue;677 },678 ],679 function () {680 counter++;681 },682 );683 scope.$digest(); //it will count me684 scope.anotherValue = 3;685 destroyGroup();686 scope.$digest();687 expect(counter).toBe(1);688 });*/689 it('does not call the zero watch listener when de-registered first', function () {690 scope.counter = 0;691 let destroyGroup = scope.$watchGroup([], function (newValues, oldValues, scope) {692 scope.counter++;693 });694 destroyGroup();695 scope.$digest();696 expect(scope.counter).toBe(0);697 });698 });699 describe('inheritance', function () {700 it("inherits the parent's properties", function () {701 let parent = new Scope();702 parent.aValue = [1, 2, 3];703 let child = parent.$new();704 expect(child.aValue).toEqual([1, 2, 3]);705 });706 it('does not cause a parent to inherit its properties', function () {707 let parent = new Scope();708 let child = parent.$new();709 child.aValue = [1, 2, 3];710 expect(parent.aValue).toBeUndefined();711 });712 it("inherits the parent's properties whenever they are defined", function () {713 let parent = new Scope();714 let child = parent.$new();715 parent.aValue = [1, 2, 3];716 expect(child.aValue).toEqual([1, 2, 3]);717 });718 it('can watch the property of the parent', function () {719 let parent = new Scope();720 let child = parent.$new();721 parent.aValue = [1, 2, 3];722 child.counter = 0;723 child.$watch(724 function (scope) {725 return scope.aValue;726 },727 function (newValue, oldValue, scope) {728 scope.counter++;729 },730 true,731 );732 child.$digest();733 expect(child.counter).toBe(1);734 parent.aValue.push(4);735 child.$digest();736 expect(child.counter).toBe(2);737 });738 it('can be nested at any depth', function () {739 let a = new Scope();740 let aa = a.$new();741 let aa1 = aa.$new();742 let aa2 = aa1.$new();743 let aa3 = aa2.$new();744 let aa4 = aa3.$new();745 a.value = 1;746 expect(aa.value).toBe(1);747 expect(aa1.value).toBe(1);748 expect(aa2.value).toBe(1);749 expect(aa3.value).toBe(1);750 expect(aa4.value).toBe(1);751 aa3.anoterValue = 4;752 expect(aa4.anoterValue).toBe(4);753 expect(aa2.anoterValue).toBeUndefined();754 expect(aa1.anoterValue).toBeUndefined();755 });756 it("shadows a parent's property with the same name", function () {757 let parent = new Scope();758 let child = parent.$new();759 parent.name = 'Joe';760 child.name = 'Joey'; // this is called attribute shadowing it will not change the parent761 expect(parent.name).toBe('Joe');762 expect(child.name).toBe('Joey');763 });764 it('it does not shadow members of the parent scope attributes', function () {765 let parent = new Scope();766 let child = parent.$new();767 parent.user = { name: 'Joe' };768 child.user.name = 'Jill'; // since in the prototype it holds the reference769 expect(child.user.name).toBe('Jill');770 expect(parent.user.name).toBe('Jill');771 });772 it('does not digest its parent(s)', function () {773 let parent = new Scope();774 let child = parent.$new();775 parent.aValue = 'abc';776 parent.$watch(777 function (scope) {778 return scope.aValue;779 },780 function (newValue, oldValue, scope) {781 scope.aValueWas = newValue;782 },783 );784 child.$digest(); // should not trigger the watch of the parent785 expect(child.aValueWas).toBeUndefined();786 });787 it('keeps the record of its Children Scopes', function () {788 let parent = new Scope();789 let child1 = parent.$new();790 let child2 = parent.$new();791 let child2_1 = child2.$new();792 expect(parent.$$children.length).toBe(2);793 expect(parent.$$children[0]).toBe(child1);794 expect(parent.$$children[1]).toBe(child2);795 expect(child1.$$children.length).toBe(0);796 expect(child2.$$children.length).toBe(1);797 expect(child2.$$children[0]).toBe(child2_1);798 });799 it('digest its children', function () {800 let parent = new Scope();801 let child = parent.$new();802 parent.aValue = 'abc';803 child.$watch(804 function (scope) {805 return scope.aValue;806 },807 function (newValue, oldValue, scope) {808 scope.aValueWas = newValue;809 },810 );811 parent.$digest();812 expect(child.aValueWas).toBe('abc');813 });814 it('digest from root on $apply', function () {815 //since digest works from current scope and down816 let parent = new Scope();817 let child = parent.$new();818 let child2 = child.$new();819 parent.aValue = 'abc';820 parent.counter = 0;821 parent.$watch(822 function (scope) {823 return scope.aValue;824 },825 function (newValue, oldValue, scope) {826 scope.counter++;827 },828 );829 child2.$apply(function () {});830 expect(parent.counter).toBe(1);831 });832 it('digest from root on $evalAsync', function (done) {833 let parent = new Scope();834 let child = parent.$new();835 let child2 = child.$new();836 parent.aValue = 'abc';837 parent.counter = 0;838 parent.$watch(839 function (scope) {840 return scope.aValue;841 },842 function (newValue, oldValue, scope) {843 scope.counter++;844 },845 );846 child2.$evalAsync(function () {});847 setTimeout(function () {848 expect(parent.counter).toBe(1);849 done();850 }, 50);851 });852 it('isolated scope does not have access to the parent', function () {853 let parent = new Scope();854 let child = parent.$new(true);855 parent.aValue = 'abc';856 expect(child.aValue).toBeUndefined();857 });858 it('cannot watch parent attribute when isolated', function () {859 let parent = new Scope();860 let child = parent.$new(true);861 parent.aValue = 'abc';862 child.aSomeValue = 'abc';863 child.$watch(864 function (scope) {865 return scope.aValue;866 },867 function (newValue, oldValue, scope) {868 scope.aValueWas = newValue;869 },870 );871 child.$watch(872 function (scope) {873 return scope.aSomeValue;874 },875 function (newValue, oldValue, scope) {876 scope.aSomeValueWas = newValue;877 },878 );879 child.$digest();880 expect(child.aValueWas).toBeUndefined();881 expect(child.aSomeValueWas).toBe('abc');882 });883 it("digest its isolated children's", function () {884 let parent = new Scope();885 let child = parent.$new(true);886 child.aValue = 'abc';887 child.$watch(888 function (scope) {889 return scope.aValue;890 },891 function (newValue, oldValue, scope) {892 scope.aValueWas = newValue;893 },894 );895 parent.$digest(); //works since the everScope function896 expect(child.aValueWas).toBe('abc');897 });898 it('digest from root $apply when isolated', function () {899 //without the root reference in the isolated it won't work900 let parent = new Scope();901 let child = parent.$new(true);902 let child2 = child.$new();903 parent.aValue = 'abc';904 parent.counter = 0;905 parent.$watch(906 function (scope) {907 return scope.aValue;908 },909 function (newValue, oldValue, scope) {910 scope.counter++;911 },912 );913 child2.$apply(function () {});914 expect(parent.counter).toBe(1);915 });916 it('digest from root $evalAsync when isolated', function (done) {917 //without the root reference in the isolated it won't work918 let parent = new Scope();919 let child = parent.$new(true);920 let child2 = child.$new();921 parent.aValue = 'abc';922 parent.counter = 0;923 parent.$watch(924 function (scope) {925 return scope.aValue;926 },927 function (newValue, oldValue, scope) {928 scope.counter++;929 },930 );931 child2.$evalAsync(function () {});932 setTimeout(function () {933 expect(parent.counter).toBe(1);934 done();935 }, 50);936 });937 it('executes $evalAsync on the isolated scope', function (done) {938 let parent = new Scope();939 let child = parent.$new(true);940 child.$evalAsync(function (scope) {941 scope.didEvalAsync = true;942 });943 setTimeout(function () {944 expect(child.didEvalAsync).toBeTruthy();945 done();946 }, 50);947 });948 it('executes $$postDigest functions on isolated scope', function () {949 let parent = new Scope();950 let child = parent.$new(true);951 child.$$postDigest(function () {952 child.didPostDigest = true;953 });954 parent.$digest();955 expect(child.didPostDigest).toBeTruthy();956 });957 it('can take some scope as the parent', function () {958 let prototypeParent = new Scope(); //root for them959 let hierarchyParent = new Scope(); //root for them960 let child = prototypeParent.$new(false, hierarchyParent);961 prototypeParent.a = 42;962 hierarchyParent.b = 42;963 expect(child.a).toBe(42);964 expect(child.n).toBeUndefined(); //is not its prototype965 child.counter = 0;966 child.$watch(967 function (scope) {968 return scope.a;969 },970 function (newValue, oldValue, scope) {971 scope.counter++;972 },973 );974 prototypeParent.$digest();975 expect(child.counter).toBe(0);976 hierarchyParent.$digest();977 expect(child.counter).toBe(1);978 });979 it('no longer get digested when destroy is being called', function () {980 let parent = new Scope();981 let child = parent.$new();982 child.aValue = 'abc';983 child.counter = 0;984 child.$watch(985 function (scope) {986 return scope.aValue;987 },988 function (newValue, oldValue, scope) {989 scope.counter++;990 },991 );992 parent.$digest();993 expect(child.counter).toBe(1);994 child.aValue = 'bcd';995 parent.$digest();996 expect(child.counter).toBe(2);997 child.$destroy();998 child.aValue = 'bdcg';999 parent.$digest(); //since it is already deleted from children array1000 expect(child.counter).toBe(2);1001 child.$digest(); //this is why we are making the current watchers null1002 expect(child.counter).toBe(2);1003 //rest it can be collected by js garbage collector1004 });1005 });1006 describe('$watchCollection', function () {1007 let scope;1008 beforeEach(function () {1009 scope = new Scope();1010 });1011 it('will work like a normal watch for non Collections', function () {1012 let someValue = null;1013 scope.aValue = '42';1014 scope.counter = 0;1015 scope.$watchCollection(1016 function (scope) {1017 return scope.aValue;1018 },1019 function (newValue, oldValue, scope) {1020 someValue = newValue;1021 scope.counter++;1022 },1023 );1024 scope.$digest();1025 expect(scope.counter).toBe(1);1026 expect(someValue).toBe(scope.aValue);1027 scope.aValue = '4202';1028 scope.$digest();1029 expect(scope.counter).toBe(2);1030 scope.$digest();1031 expect(scope.counter).toBe(2);1032 });1033 it('will work with normal non Collection that is NaN', function () {1034 scope.aValue = 0 / 0;1035 scope.counter = 0;1036 scope.$watchCollection(1037 function (scope) {1038 return scope.aValue;1039 },1040 function (newValue, oldValue, scope) {1041 scope.counter++;1042 },1043 );1044 scope.$digest();1045 expect(scope.counter).toBe(1);1046 scope.$digest();1047 expect(scope.counter).toBe(1);1048 });1049 it('will test the previous element was an array or not', function () {1050 scope.counter = 0;1051 scope.arr = null;1052 scope.$watchCollection(1053 function (scope) {1054 return scope.arr;1055 },1056 function (newValue, oldValue, scope) {1057 scope.counter++;1058 },1059 );1060 scope.$digest();1061 expect(scope.counter).toBe(1);1062 scope.arr = [1, 2, 3];1063 scope.$digest();1064 expect(scope.counter).toBe(2);1065 scope.$digest();1066 expect(scope.counter).toBe(2);1067 });1068 it('will notice an array replace in the Array', function () {1069 scope.arr = [1, 2, 3];1070 scope.counter = 0;1071 scope.$watchCollection(1072 function () {1073 return scope.arr;1074 },1075 function (newValue, oldValue, scope) {1076 scope.counter++;1077 },1078 );1079 scope.$digest();1080 expect(scope.counter).toBe(1);1081 scope.arr[1] = 45;1082 scope.$digest();1083 expect(scope.counter).toBe(2);1084 scope.$digest();1085 expect(scope.counter).toBe(2);1086 });1087 it('notices when array is added or removed from it', function () {1088 scope.arr = [1, 2, 3];1089 scope.counter = 0;1090 scope.$watchCollection(1091 function () {1092 return scope.arr;1093 },1094 function (newValue, oldValue, scope) {1095 scope.counter++;1096 },1097 );1098 scope.$digest();1099 expect(scope.counter).toBe(1);1100 scope.arr.push(69);1101 scope.$digest();1102 expect(scope.counter).toBe(2);1103 scope.$digest();1104 expect(scope.counter).toBe(2);1105 scope.arr.shift();1106 scope.$digest();1107 expect(scope.counter).toBe(3);1108 scope.$digest();1109 expect(scope.counter).toBe(3);1110 });1111 it('notice item reorder in the array', function () {1112 scope.arr = [2, 1, 3];1113 scope.counter = 0;1114 scope.$watchCollection(1115 function () {1116 return scope.arr;1117 },1118 function (newValue, oldValue, scope) {1119 scope.counter++;1120 },1121 );1122 scope.$digest();1123 expect(scope.counter).toBe(1);1124 scope.arr.sort();1125 scope.$digest();1126 expect(scope.counter).toBe(2);1127 scope.$digest();1128 expect(scope.counter).toBe(2);1129 });1130 it('does not fail with NaN in Arrays', function () {1131 scope.arr = [2, NaN, 3];1132 scope.counter = 0;1133 scope.$watchCollection(1134 function () {1135 return scope.arr;1136 },1137 function (newValue, oldValue, scope) {1138 scope.counter++;1139 },1140 );1141 scope.$digest();1142 expect(scope.counter).toBe(1);1143 scope.arr.push(1);1144 scope.$digest();1145 expect(scope.counter).toBe(2);1146 scope.$digest();1147 expect(scope.counter).toBe(2);1148 });1149 it('array like objects notices a change in arguments array like object', function () {1150 scope.counter = 0;1151 (function () {1152 scope.functionArgument = arguments;1153 })(1, 2, 3);1154 expect(scope.functionArgument[1]).toBe(2);1155 scope.$watchCollection(1156 function () {1157 return scope.functionArgument;1158 },1159 function (newValue, oldValue, scope) {1160 scope.counter++;1161 },1162 );1163 scope.$digest();1164 expect(scope.counter).toBe(1);1165 scope.functionArgument[1] = 455;1166 scope.$digest();1167 expect(scope.counter).toBe(2);1168 scope.$digest();1169 expect(scope.counter).toBe(2);1170 });1171 /*it('notices the changes in the NodeList which is array object Argument', function () {1172 document.documentElement.appendChild(document.createElement('div'));1173 scope.arrayLike = document.getElementsByTagName('div');1174 scope.counter = 0;1175 scope.$watchCollection(1176 function (scope) {1177 return scope.arrayLike;1178 },1179 function (newValue, oldValue, scope) {1180 scope.counter++;1181 },1182 );1183 scope.$digest();1184 expect(scope.counter).toBe(1);1185 document.documentElement.appendChild(document.createElement('div'));1186 scope.$digest();1187 expect(scope.counter).toBe(2);1188 scope.$digest();1189 expect(scope.counter).toBe(2);1190 });*/1191 it('detecting new objects when a value becomes one', function () {1192 scope.counter = 0;1193 scope.obj = null;1194 scope.$watchCollection(1195 function () {1196 return scope.obj;1197 },1198 function (newValue, oldValue, scope) {1199 scope.counter++;1200 },1201 );1202 scope.$digest();1203 expect(scope.counter).toBe(1);1204 scope.obj = { a: 1 };1205 scope.$digest();1206 expect(scope.counter).toBe(2);1207 scope.$digest();1208 expect(scope.counter).toBe(2);1209 });1210 it('detecting or changing an attribute in an object', function () {1211 scope.counter = 0;1212 scope.obj = { a: 1 };1213 scope.$watchCollection(1214 function () {1215 return scope.obj;1216 },1217 function (newValue, oldValue, scope) {1218 scope.counter++;1219 },1220 );1221 scope.$digest();1222 expect(scope.counter).toBe(1);1223 scope.obj.b = 2;1224 scope.$digest();1225 expect(scope.counter).toBe(2);1226 scope.$digest();1227 expect(scope.counter).toBe(2);1228 });1229 it('detecting the change of the same attribute', function () {1230 scope.counter = 0;1231 scope.obj = { a: 1 };1232 scope.$watchCollection(1233 function () {1234 return scope.obj;1235 },1236 function (newValue, oldValue, scope) {1237 scope.counter++;1238 },1239 );1240 scope.$digest();1241 expect(scope.counter).toBe(1);1242 scope.obj.a = 2;1243 scope.$digest();1244 expect(scope.counter).toBe(2);1245 scope.$digest();1246 expect(scope.counter).toBe(2);1247 });1248 it('detecting the change delete attribute', function () {1249 scope.counter = 0;1250 scope.obj = { a: 1, b: 2 };1251 scope.$watchCollection(1252 function () {1253 return scope.obj;1254 },1255 function (newValue, oldValue, scope) {1256 scope.counter++;1257 },1258 );1259 scope.$digest();1260 expect(scope.counter).toBe(1);1261 delete scope.obj.a;1262 scope.$digest();1263 expect(scope.counter).toBe(2);1264 scope.$digest();1265 expect(scope.counter).toBe(2);1266 });1267 it('does not consider any object with a length property an array', function () {1268 scope.obj = { length: 42, otherKey: 'abc' };1269 scope.counter = 0;1270 scope.$watchCollection(1271 function (scope) {1272 return scope.obj;1273 },1274 function (newValue, oldValue, scope) {1275 scope.counter++;1276 },1277 );1278 scope.$digest();1279 scope.obj.newKey = 'def';1280 scope.$digest();1281 expect(scope.counter).toBe(2);1282 });1283 it('gives the old non collection value to the listener', function () {1284 scope.aValue = 1;1285 let oldGivenValue = null;1286 scope.$watchCollection(1287 function (scope) {1288 return scope.aValue;1289 },1290 function (newValue, oldValue) {1291 oldGivenValue = oldValue;1292 },1293 );1294 scope.$digest();1295 scope.aValue = 2;1296 scope.$digest();1297 expect(oldGivenValue).toBe(1);1298 });1299 it('gives old value array to the listener', function () {1300 scope.arr = [1, 2, 3];1301 let oldGivenValue = null;1302 scope.$watchCollection(1303 function (scope) {1304 return scope.arr;1305 },1306 function (newValue, oldValue) {1307 oldGivenValue = oldValue;1308 },1309 );1310 scope.$digest();1311 scope.arr.push(2);1312 scope.$digest();1313 expect([...oldGivenValue]).toEqual([1, 2, 3]); //check HERE serialize sting issue1314 });1315 it('gives the old object value to the listener', function () {1316 scope.obj = { a: 1 };1317 let oldGivenValue = null;1318 scope.$watchCollection(1319 function (scope) {1320 return scope.obj;1321 },1322 function (newValue, oldValue) {1323 oldGivenValue = oldValue;1324 },1325 );1326 scope.$digest();1327 scope.obj.b = 2;1328 scope.$digest();1329 expect(oldGivenValue).toEqual({ a: 1 });1330 });1331 it('the new Value as the old value on the first digest', function () {1332 scope.obj = { a: 1 };1333 let oldGivenValue = null;1334 scope.$watchCollection(1335 function (scope) {1336 return scope.obj;1337 },1338 function (newValue, oldValue) {1339 oldGivenValue = oldValue;1340 },1341 );1342 scope.$digest();1343 expect(oldGivenValue).toEqual({ a: 1 });1344 });1345 });1346 describe('Events', function () {1347 let scope;1348 let parent;1349 let child;1350 let isolatedChild;1351 beforeEach(function () {1352 parent = new Scope();1353 scope = parent.$new();1354 child = scope.$new();1355 isolatedChild = scope.$new(true);1356 });1357 it('allows registration events', function () {1358 let listener1 = function () {};1359 let listener2 = function () {};1360 let listener3 = function () {};1361 scope.$on('someEvent', listener1);1362 scope.$on('someEvent', listener2);1363 scope.$on('someOtherEvent', listener3);1364 expect(scope.$$listeners).toEqual({1365 someEvent: [listener1, listener2],1366 someOtherEvent: [listener3],1367 });1368 });1369 it('register different events on each scope', function () {1370 let listener1 = function () {};1371 let listener2 = function () {};1372 let listener3 = function () {};1373 scope.$on('someEvent', listener1);1374 child.$on('someEvent', listener2);1375 isolatedChild.$on('someOtherEvent', listener3);1376 expect(scope.$$listeners).toEqual({1377 someEvent: [listener1],1378 });1379 expect(child.$$listeners).toEqual({1380 someEvent: [listener2],1381 });1382 expect(isolatedChild.$$listeners).toEqual({1383 someOtherEvent: [listener3],1384 });1385 });1386 //$emit and $broadcast common code1387 def.Lo.forEach(['$emit', '$broadcast'], function (method) {1388 it(`calls listeners registered for matching events on : ${method}`, function () {1389 let listener1 = jest.fn();1390 let listener2 = jest.fn();1391 scope.$on('someEvent', listener1);1392 scope.$on('someOtherEvent', listener2);1393 scope[method]('someEvent');1394 expect(listener1).toHaveBeenCalled();1395 expect(listener2).not.toHaveBeenCalled();1396 });1397 it(`passes an an event object with the same name : ${method}`, function () {1398 let listener = jest.fn();1399 scope.$on('someEvent', listener);1400 scope[method]('someEvent');1401 expect(listener).toHaveBeenCalled();1402 expect(listener.mock.calls[listener.mock.calls.length - 1][0].name).toEqual('someEvent');1403 });1404 it(`passes the same event object to each listener on : ${method}`, function () {1405 let listener1 = jest.fn();1406 let listener2 = jest.fn();1407 scope.$on('someEvent', listener1);1408 scope.$on('someEvent', listener2);1409 scope[method]('someEvent');1410 let event1 = listener1.mock.calls[listener1.mock.calls.length - 1][0].name;1411 let event2 = listener2.mock.calls[listener2.mock.calls.length - 1][0].name;1412 expect(event1).toBe(event2);1413 });1414 it(`passes additional argument on Emit for $on to receive : ${method}`, function () {1415 let listener = jest.fn();1416 scope.$on('someEvent', listener);1417 scope[method]('someEvent', 'firstArgument', ['secondArgument1', 'secondArgument2'], 3);1418 expect(listener.mock.calls[listener.mock.calls.length - 1][0].name).toEqual('someEvent');1419 expect(listener.mock.calls[listener.mock.calls.length - 1][1]).toEqual('firstArgument');1420 expect(listener.mock.calls[listener.mock.calls.length - 1][2]).toEqual(['secondArgument1', 'secondArgument2']);1421 expect(listener.mock.calls[listener.mock.calls.length - 1][3]).toEqual(3);1422 });1423 it(`returns the event of the object : ${method}`, function () {1424 let returnedObject = scope[method]('someEvent');1425 expect(returnedObject).toBeDefined();1426 expect(returnedObject.name).toBe('someEvent');1427 });1428 it(`deregister the events from the listener : ${method}`, function () {1429 let mock = jest.fn();1430 let deregister = scope.$on('someEvent', mock);1431 deregister();1432 scope[method]('someEvent');1433 expect(mock).not.toHaveBeenCalled();1434 });1435 it(`does not skip next listener when it is removed from a listener: ${method} `, function () {1436 let deregister;1437 let listener = function () {1438 deregister();1439 };1440 let listener2 = jest.fn();1441 deregister = scope.$on('firstEvent', listener);1442 scope.$on('firstEvent', listener2);1443 scope[method]('firstEvent');1444 expect(listener2).toHaveBeenCalled();1445 });1446 });1447 it('propagates up to the scope hierarchy $emit', function () {1448 let parentListener = jest.fn();1449 let childListener = jest.fn();1450 parent.$on('someEvent', parentListener);1451 scope.$on('someEvent', childListener);1452 scope.$emit('someEvent');1453 expect(parentListener).toHaveBeenCalled();1454 expect(childListener).toHaveBeenCalled();1455 });1456 it('propagates the same event up with $emit', function () {1457 let parentListener = jest.fn();1458 let childListener = jest.fn();1459 scope.$on('someEvent', parentListener);1460 scope.$on('someEvent', childListener);1461 scope.$emit('someEvent');1462 let parentArg = parentListener.mock.calls[parentListener.mock.calls.length - 1][0].name;1463 let childArg = childListener.mock.calls[childListener.mock.calls.length - 1][0].name;1464 expect(parentArg).toEqual(childArg);1465 });1466 it('propagates down to the scope hierarchy $broadcast', function () {1467 let parentListener = jest.fn();1468 let childListener = jest.fn();1469 let isolatedListener = jest.fn();1470 parent.$on('someEvent', parentListener);1471 scope.$on('someEvent', childListener);1472 isolatedChild.$on('someEvent', isolatedListener);1473 parent.$broadcast('someEvent');1474 expect(parentListener).toHaveBeenCalled();1475 expect(childListener).toHaveBeenCalled();1476 expect(isolatedListener).toHaveBeenCalled();1477 });1478 it('propagates down same event down with $broadcast', function () {1479 let parentListener = jest.fn();1480 let childListener = jest.fn();1481 parent.$on('someEvent', parentListener);1482 scope.$on('someEvent', childListener);1483 parent.$broadcast('someEvent');1484 let parentArg = parentListener.mock.calls[parentListener.mock.calls.length - 1][0].name;1485 let childArg = childListener.mock.calls[childListener.mock.calls.length - 1][0].name;1486 expect(parentArg).toEqual(childArg);1487 });1488 it('includes the current and targeted scope in the event object emit', function () {1489 let scopeListener = jest.fn();1490 let childListener = jest.fn();1491 scope.$on('someEvent', scopeListener);1492 parent.$on('someEvent', childListener);1493 scope.$emit('someEvent');1494 expect(scopeListener.mock.calls[scopeListener.mock.calls.length - 1][0].targetScope).toEqual(scope);1495 expect(childListener.mock.calls[childListener.mock.calls.length - 1][0].targetScope).toEqual(scope);1496 });1497 it('includes the current and targeted scope in the event object broadcast', function () {1498 let scopeListener = jest.fn();1499 let parentListener = jest.fn();1500 scope.$on('someEvent', scopeListener);1501 child.$on('someEvent', parentListener);1502 scope.$broadcast('someEvent');1503 expect(scopeListener.mock.calls[scopeListener.mock.calls.length - 1][0].targetScope).toEqual(scope);1504 expect(parentListener.mock.calls[parentListener.mock.calls.length - 1][0].targetScope).toEqual(scope);1505 });1506 it('attaches the current scope in propagation in the event emit', function () {1507 let currentScopeOnScope = null;1508 let currentScopeOnParent = null;1509 let scopeListener = function (event) {1510 currentScopeOnScope = event.currentScope;1511 };1512 let parentListener = function (event) {1513 currentScopeOnParent = event.currentScope;1514 };1515 scope.$on('someEvent', scopeListener);1516 parent.$on('someEvent', parentListener);1517 scope.$emit('someEvent');1518 expect(currentScopeOnScope).toBe(scope);1519 expect(currentScopeOnParent).toBe(parent);1520 });1521 it('attaches the current scope in propagation in the event broadcast', function () {1522 let currentScopeOnScope = null;1523 let currentScopeOnChild = null;1524 let scopeListener = function (event) {1525 currentScopeOnScope = event.currentScope;1526 };1527 let childListener = function (event) {1528 currentScopeOnChild = event.currentScope;1529 };1530 scope.$on('someEvent', scopeListener);1531 child.$on('someEvent', childListener);1532 scope.$broadcast('someEvent');1533 expect(currentScopeOnScope).toBe(scope);1534 expect(currentScopeOnChild).toBe(child);1535 });1536 it('sets current Index null after propagation is over', function () {1537 let event = null;1538 let event1 = null;1539 let scopeListener = function (evt) {1540 event = evt;1541 };1542 let scopeListener1 = function (evt) {1543 event1 = evt;1544 };1545 scope.$on('someEvent', scopeListener);1546 scope.$on('someEventForBroadcast', scopeListener1);1547 scope.$emit('someEvent');1548 scope.$broadcast('someEventForBroadcast');1549 expect(event.currentScope).toBe(null);1550 expect(event1.currentScope).toBe(null);1551 });1552 it('does not propagate the event if stopped parent emit', function () {1553 let scopeListener = function (event) {1554 event.stopPropagation();1555 };1556 let parentListener = jest.fn();1557 scope.$on('someEvent', scopeListener);1558 parent.$on('someEvent', parentListener);1559 scope.$emit();1560 expect(parentListener).not.toHaveBeenCalled();1561 });1562 it('does not propagate the event will receive on the same scope', function () {1563 let scopeListener = function (event) {1564 event.stopPropagation();1565 };1566 let sameScopeListener = jest.fn();1567 scope.$on('someEvent', scopeListener);1568 scope.$on('someEvent', sameScopeListener);1569 scope.$emit('someEvent');1570 expect(sameScopeListener).toHaveBeenCalled();1571 });1572 it('does prevent the default', function () {1573 let scopeListener = function (event) {1574 event.preventDefault();1575 };1576 let scopeMock = jest.fn();1577 scope.$on('someEvent', scopeListener);1578 scope.$on('someEvent', scopeMock);1579 let event1 = scope.$emit('someEvent');1580 let event2 = scope.$broadcast('someEvent');1581 expect(event1.defaultPrevented).toBeTruthy();1582 expect(event2.defaultPrevented).toBeTruthy();1583 });1584 it('fires a destroy when it is removed', function () {1585 let listener = jest.fn();1586 scope.$on('$destroy', listener);1587 scope.$destroy();1588 expect(listener).toHaveBeenCalled();1589 });1590 it('fires a destroy children when it is removed', function () {1591 let listener = jest.fn();1592 child.$on('$destroy', listener);1593 scope.$destroy();1594 expect(listener).toHaveBeenCalled();1595 });1596 it('no longer calls listeners after destroyed', function () {1597 let listener = jest.fn();1598 scope.$on('myEvent', listener);1599 scope.$destroy();1600 scope.$emit('myEvent');1601 expect(listener).not.toHaveBeenCalled();1602 });1603 it('does not stop when exception is thrown', function () {1604 let listener1 = function () {1605 throw '$emit throw error';1606 };1607 let listener2 = function () {1608 throw '$broadcast throw error';1609 };1610 let listener3 = jest.fn();1611 let listener4 = jest.fn();1612 scope.$on('someEvent$emit', listener1);1613 scope.$on('someEvent$emit', listener3);1614 scope.$on('someEvent$broadcast', listener2);1615 scope.$on('someEvent$broadcast', listener4);1616 scope.$emit('someEvent$emit');1617 scope.$broadcast('someEvent$broadcast');1618 expect(listener3).toHaveBeenCalled();1619 expect(listener4).toHaveBeenCalled();1620 });1621 });...

Full Screen

Full Screen

events.js

Source:events.js Github

copy

Full Screen

1'use strict';2angular.module('mean.events').controller('EventController', ['$window', '$filter', '$scope', '$http', '$stateParams', 'Global', 'Technologies', 'Events', '$state', function ($window, $filter, $scope, $http, $stateParams, Global, Technologies, Events, $state) {3 $scope.global = Global;4 $scope.addressees=[];5 $scope.comps = [];6 $scope.cntcts = [];7 $scope.emails=[];8 $scope.methods = ["Phone", "Email", "Meeting"]; 9 $scope.names=[]; 10 $scope.selected = ["None"];11 $scope.selectedcompanies =[];12 $scope.selectedcontacts=[];13 $scope.outcomes = ["In review", "Not interested", "No response", "Other"];14 $scope.numberofoutcomes = $scope.outcomes.length;15 $scope.usernames=[];16 $scope.yesno = ["Yes", "No"];17 18 var stringonames;19 $scope.choose = function(comp){20 $scope.chooseforcreate(comp);21 $scope.event.company = comp;22 // $scope.event.CompanyId = comp.id;23 }; 24 $scope.chooseforcreate = function(comp){25 // console.log("stupidchoosefunctionran");26 $scope.company = comp;27 // console.log("$scope.company", $scope.company);28 var company = $scope.company;29 $http({30 method: 'GET',31 url: '/findcompanycontacts',32 params: {Company_name: company}33 }).then(function(company){34 $scope.company = company.data;35 // console.log("COMpanyfound", $scope.company);36 $scope.compcontacts = $scope.company.Contacts;37 // console.log($scope.compcontacts, "$scope.compcontacts");38 39 $scope.compcontactschunked = $scope.chunk($scope.compcontacts, 3);40 // console.log($scope.compcontactschunked, "$scope.compcontactschunked");41 });42 // $scope.event.company = comp;43 // $scope.event.CompanyId = comp.id;44 }; 45 $scope.chooseuser = function(user){46 console.log("USER: ", user);47 $scope.event.newusername=user;48 $scope.event.userchange=true;49 }; 50 $scope.chooseuserforfollowup = function(user){51 $scope.user = user;52 };53 $scope.chunk = function(arr, size){54 var newArr =[];55 for (var i=0; i<arr.length; i+=size) {56 newArr.push(arr.slice(i, i+size));57 }58 return newArr;59 };60 $scope.contacts = function(event){61 // console.log("revisedrevisedevent.Contacts", event.Contacts);62 $scope.names=[];63 //var stringonames;64 for (var x=0; x<event.Contacts.length; x++){ 65 if (event.Contacts[x].length===0){66 // console.log("triggered");67 $scope.names.push(["None"]);68 } else {69 $scope.names.push(event.Contacts[x].Contact_name);70 // console.log("contactname", event.Contacts[x].Contact_name);71 } 72 }73 stringonames = $scope.names.join(", ");74 // console.log ("$scope.names", $scope.names, typeof $scope.names);75 event.names = stringonames;76 $scope.eventcontacts = stringonames;77 //console.log("$scope.eventcontacts", $scope.eventcontacts);78 if ($scope.eventcontacts.length>=3) {79 // console.log("SHORT");80 $scope.eventcontactschunked=$scope.chunk($scope.eventcontacts, 3);81 } else {82 $scope.eventcontactschunked = $scope.eventcontacts;83 }84 };85 $scope.contactids =[];86 $scope.cleanupcontacts = function(){87 //removing contacts that aren't from the event's selected company88 for (var i=0; i<$scope.selectedcontacts.length; i++){89 if ($scope.selectedcontacts[i].CompanyId!==$scope.company.id){90 $scope.selectedcontacts.splice(i, 1);91 }92 }93 //removing duplicate contacts94 for (var j=0; j<$scope.selectedcontacts.length-1; j++){95 for (var k=1; k<$scope.selectedcontacts.length; k++){96 if($scope.selectedcontacts[j]===$scope.selectedcontacts[k]){97 $scope.selectedcontacts.splice(k,1);98 }99 }100 }101 console.log("cleanedupcontacts: ", $scope.selectedcontacts);102 //get an array of contact ids103 for (var m=0; m<$scope.selectedcontacts.length; m++){104 $scope.contactids.push($scope.selectedcontacts[m].id);105 }106 $scope.event.contactids = $scope.contactids;107 console.log("$scope.event.contactids", $scope.event.contactids);108 };109 110 $scope.createEvent = function() {111 // $scope.cleanupcontacts();112 console.log("NEWEVENT", $scope);113 var event = new Events({114 Event_date: this.Event_date,115 Event_notes: this.notes,116 Company: this.company,117 Contacts: this.selectedcontacts,118 Technology: this.technology,119 Event_flag: this.Event_flag,120 Event_followupdate: this.followupdate, 121 Event_method: this.Event_method, 122 Event_outcome: this.Event_outcome,123 FollowedUp: false124 });125 console.log("Event", event);126 //console.log("DATEFORMAT: ", event.Event_date);127 //console.log("DATEtype: ", typeof event.Event_date);128 event.$save(function(response) {129 // console.log("response", response);130 //$state.go('viewCompany',{Company_name : responseid});131 $state.go('viewTech',{id: response.TechnologyId});132 });133 this.Event_date = "";134 this.Event_notes = "";135 this.company = "";136 this.contacts = "";137 this.flag = "";138 this.followupdate = "";139 this.Event_outcome = "";140 this.FollowedUp = "";141 };142 $scope.createFollowUp = function(){143 var event = new Events({144 Event_date: this.Event_date,145 Event_notes: this.notes,146 Company: this.company,147 Contacts: this.selectedcontacts,148 Technology: this.technology,149 Event_flag: this.Event_flag,150 Event_followupdate: this.followupdate, 151 Event_method: this.Event_method, 152 Event_outcome: this.Event_outcome,153 FollowedUp: false154 });155 console.log("Event", event);156 //console.log("DATEFORMAT: ", event.Event_date);157 //console.log("DATEtype: ", typeof event.Event_date);158 event.$save(function(response) {159 160 //update old event 161 $scope.event.FollowedUp=true;162 $scope.event.Event_followupdate=null;163 $scope.event.Event_flag = false;164 165 $scope.event.updated = [];166 $scope.event.updated.push(new Date().getTime());167 168 $scope.event.$update(function() {169 //console.log("response", response.data);170 }).then(function(){171 $scope.Edit=false;172 $scope.FollowUp=false;173 // console.log("response", response);174 //$state.go('viewCompany',{Company_name : responseid});175 $state.go('viewTech',{id: response.TechnologyId});176 });177 178 // console.log("here'swhat'sleftonthescope", $scope);179 // $scope.createEvent();180 181 // $state.go('viewEvent',{id : event.id});182 // $scope.findOneEvent();183 });184 //$scope.createEvent();185 };186 $scope.startFollowUp = function(){187 // $scope.findCompanies();188 $scope.Edit = false;189 $scope.FollowUp = true;190 $scope.findusers();191 $scope.findCompanies();192 console.log("eventinscope: ", $scope.event);193 $scope.chooseforcreate($scope.event.Company.Company_name);194 $scope.newcontactnames=$scope.names;195 $scope.selectedcontacts=$scope.event.Contacts;196 $scope.company=$scope.event.Company;197 $scope.user=$scope.event.User;198 $scope.technology=$scope.event.Technology;199 // $scope.getfollowupflaganswer($scope.event.Event_flag);200 // $scope.getfollowedupanswer($scope.event.FollowedUp);201 };202 $scope.createMultEvent = function() {203 //go through each selected company204 for (var x=0; x<$scope.selectedcompanies.length; x++){205 $scope.compny = $scope.selectedcompanies[x];206 //find all the contacts associated with that company207 for (var y=0; y<$scope.selectedcontacts.length; y++){208 209 if($scope.selectedcontacts[y].CompanyId===$scope.compny.id){210 $scope.cntcts.push($scope.selectedcontacts[y]);211 }212 }213 // console.log("cntctstosave", $scope.cntcts);214 //create an event for that company215 var event = new Events({216 Event_date: this.Event_date,217 Event_notes: this.notes,218 Company: this.compny,219 Contacts: this.cntcts,220 Technology: this.technology,221 Event_flag: this.Event_flag,222 Event_followupdate: this.followupdate, 223 Event_method: this.Event_method, 224 Event_outcome: this.Event_outcome,225 Followedup: false226 });227 // console.log("EVENT ABOUT TO SAVE", event);228 event.$save(function(response) {229 // console.log("response", response);230 }); 231 $scope.cntcts = []; 232 }233 $state.go('techs'); 234 };235 $scope.editoutcome = function (outcome) {236 $scope.event.Event_outcome = outcome;237 console.log("NEWOUTCOME", $scope.event.Event_outcome);238 console.log("revisedevent", $scope.event);239 240 };241 $scope.exists = function (tag, list) {242 // console.log("compcontact.Contact_name", compcontact.Contact_name, "$scope.names", $scope.names);243 return list.indexOf(tag) > -1;244 };245 $scope.findCompanies = function() {246 $http({247 method: 'GET',248 url: '/companiesforevent'249 }).then(function(response){250 $scope.companies = response.data;251 $scope.companynames = [];252 //console.log("$scope.companies", $scope.companies);253 response.data.forEach(function(company){254 $scope.companynames.push(company.Company_name);255 });256 //console.log("companynames", $scope.companynames);257 $scope.chunkedcompanies = $scope.chunk($scope.companynames, 3);258 }); 259 };260 $scope.findCompanies2 = function() {261 $http({262 method: 'GET',263 url: '/companiesforevent'264 }).then(function(response){265 $scope.companies = response.data;266 $scope.companynames = [];267 //console.log("$scope.companies", $scope.companies); 268 $scope.chunkedcompanies = $scope.chunk($scope.companies, 3);269 }); 270 };271 272 $scope.findCompaniesToEditEvent=function(){273 $scope.findCompanies();274 $scope.choose();275 };276 $scope.findEvent = function() {277 Events.query(function(events) {278 //console.log("findeventfindevent");279 $scope.events = events;280 //console.log(events);281 });282 };283 $scope.findOneEvent = function() {284 // console.log("findoneeventran");285 Events.get({286 id: $stateParams.id 287 }, function(response) {288 //console.log("response", response);289 $scope.event = response;290 // console.log("$scope.event", $scope.event);291 $scope.contacts(response);292 // console.log("stupidateformatlookslike: ", $scope.event.Event_date);293 // console.log("typeofstupid: ", typeof $scope.event.Event_date);294 $scope.event.Event_date = new Date($scope.event.Event_date);295 $scope.event.Event_followupdate = new Date($scope.event.Event_followupdate);296 //$scope.event.Event_date=($scope.event.Event_date | date:'MM/dd/yyyy');297 298 if ($scope.event.FollowedUp===true){299 // console.log("saysfollowedup=true");300 $scope.event.Followedupanswer="Yes";301 // console.log("followedupanswerisnow:", $scope.event.Followedupanswer);302 } else if ($scope.event.FollowedUp===false){303 $scope.event.Followedupanswer="No";304 // console.log("saysfollowedup=true");305 }306 if ($scope.event.Event_flag===true){307 $scope.event.flaganswer="Yes";308 } else {309 $scope.event.flaganswer="No";310 }311 $scope.event.CompanyId=$scope.event.Company.id;312 // console.log("$scope.eventonload", $scope.event);313 console.log("EVENTFOUND", $scope.event); 314 });315 $scope.Edit = false;316 $scope.FollowUp = false;317 console.log("EVENTFOUND", $scope.event);318 // console.log("made it to the end of findoneevent");319 };320 $scope.editEvent = function(){321 // console.log("editeventcalled");322 $scope.Edit = true;323 $scope.FollowUp = false;324 $scope.findusers();325 $scope.findCompanies();326 $scope.chooseforcreate($scope.event.Company.Company_name);327 $scope.newcontactnames=$scope.names;328 $scope.getfollowupflaganswer($scope.event.Event_flag);329 $scope.getfollowedupanswer($scope.event.FollowedUp);330 };331 $scope.findusers = function(){332 $scope.usernames = [];333 $scope.chunkedusernames = [];334 // console.log("findusers just called, here are the users before the call", $scope.users);335 $http.get('/showusers')336 .then(function(response){337 // console.log("HEREARETHE USERS: ", response.data);338 $scope.users = response.data;339 // console.log("length", $scope.users.length, "$scope.users", $scope.users);340 for (var x=0; x<$scope.users.length; x++){341 // console.log("$scope.users[x]", $scope.users[x]);342 $scope.usernames.push($scope.users[x].name);343 }344 // console.log("$scope.usernames", $scope.usernames);345 $scope.chunkedusernames=$scope.chunk($scope.usernames,3);346 });347 };348 $scope.getfollowedupanswer = function(truefalse){349 if(truefalse===true){350 $scope.event.followedupanswer = "Yes";351 } else {352 $scope.event.followedupanswer = "No";353 }354 };355 $scope.getfollowupflaganswer = function(truefalse){356 if(truefalse === true){357 $scope.event.flagyes= "Yes";358 } else {359 $scope.event.flagyes = "No";360 }361 console.log("$scope.event.flagyes: ", $scope.event.flagyes);362 };363 $scope.gettech = function(){364 $http({365 method: 'GET', 366 url: 'findtech',367 params: {id: $stateParams.id}368 }).then(function(tec){369 $scope.technology=tec.data;370 // console.log("technoll", $scope.technology);371 });372 };373 $scope.gettechandcomp = function(){374 $http({375 method: 'GET',376 url: 'findteck',377 params: {TechId: $stateParams.TechId}378 }).then(function(teck){379 $scope.technology=teck.data;380 console.log("teck", $scope.technology);381 });382 $http({383 method: 'GET',384 url: 'findkomp',385 params: {CompId: $stateParams.CompId}386 }).then(function(komp){387 $scope.kompany=komp.data;388 console.log("komp", $scope.kompany);389 });390 };391 $scope.removeEvent = function(event) {392 // console.log("removeevent was called");393 // console.log($scope.event);394 if ($window.confirm("Are you sure you want to delete this event?")){395 if (event) {396 // console.log("THERE WAS AN EVENT");397 event.$remove(); 398 for (var i in $scope.events) {399 if ($scope.events[i] === event) {400 // console.log("that thing happened");401 $scope.events.splice(i, 1);402 }403 }404 }405 else {406 // console.log("hello event else");407 $scope.event.$remove();408 $state.go('techs');409 }410 }411 };412 $scope.selectmethod = function (method){413 //selecting method when creating new event414 $scope.Event_method = method;415 if(method==="Email"){416 $scope.email=true;417 } else {418 $scope.email=false;419 }420 }; 421 $scope.selectmethod2 = function (method){422 //selecting method when modifying already existing event423 $scope.event.Event_method = method;424 if(method==="Email"){425 $scope.email=true;426 } else {427 $scope.email=false;428 }429 console.log("newmethod", $scope.event.Event_method, typeof $scope.event.Event_method);430 console.log("revisedevent", $scope.event);431 }; 432 $scope.selectoutcome = function (outcome){433 $scope.Event_outcome = outcome;434 };435 $scope.email;436 $scope.nameofperson;437 $scope.createandsendmanyemails = function(){438 //console.log("hello");439 440 //console.log($scope.selectedcontacts, "$scope.selectedcontacts");441 //$scope.emailbody =;442 //$scope.createEvent();443 for(var x=0; x<$scope.selectedcontacts.length; x++){444 //console.log("$scope.selectedcontacts[x].Contact_email", $scope.selectedcontacts[x].Contact_email);445 $scope.emails.push($scope.selectedcontacts[x].Contact_email);446 //$scope.addressees.push($scope.selectedcontacts[x].Contact_name);447 //console.log("$scope.addressees", $scope.addressees);448 }449 // $scope.emails = $scope.emails.join("; ");450 console.log("$scope.emails", $scope.emails);451 // $scope.addressees=$scope.addressees.join(", ");452 // console.log("$scope.addressees", $scope.addressees);453 454 // for(var y=0; y<$scope.emails.length; y++){455 // console.log("thisran");456 // $scope.email=$scope.emails[y];457 // $scope.nameofperson=$scope.addressees[y];458 //$scope.sendemail(); 459 460 window.open('mailto:' + $scope.global.user.email461 + '?subject=' + $scope.technology.Tech_name 462 +'&bcc='+$scope.emails463 + '&body=Hello,%0D%0A%0D%0AAny interest in ' + $scope.technology.Tech_name + "? It's really good and I think you might like it.%0D%0A%0D%0ABest regards,%0D%0A" + $scope.global.user.name)464 };465 $scope.sendemail = function(){466 window.open('mailto:' + $scope.email 467 468 +'?subject=' + $scope.technology.Tech_name 469 +'&body=Dear ' + $scope.nameofperson 470 + ",%0D%0A%0D%0AAny interest in " + $scope.technology.Tech_name + "? It's really good and I think you might like it.%0D%0A%0D%0ABest regards,%0D%0A" + $scope.global.user.name); 471 }; 472 $scope.sendemailandsubmit=function(){473 $scope.createEvent();474 $scope.sendemail();475 };476 $scope.sendemailandsubmit2=function(){477 //for creating multiple events478 $scope.createMultEvent();479 $scope.createandsendmanyemails();480 };481 $scope.setfollowedup = function(answer){482 if (answer==="Yes"){483 $scope.event.Followedupanswer=true;484 //$scope.event.flagyes = false;485 //$scope.event.Event_flag = false;486 } else if (answer==="No"){487 $scope.event.Followedupanswer=false;488 489 }490 //$scope.event.Followedupanswer = answer;491 console.log("FOLLLOWEDUPANSWEER", $scope.event.Followedupanswer);492 };493 $scope.setfollowupflag = function(answer){494 if(answer==="Yes"){495 //$scope.event.flagyes = true;496 $scope.Event_flag = true;497 } else {498 //$scope.event.flagyes = false;499 $scope.Event_flag = false;500 }501 }; 502 $scope.setfollowupflagtoedit = function(answer){503 if(answer==="Yes"){504 console.log("flagshouldbeyes");505 //$scope.event.flagyes = true;506 $scope.event.Event_flag = true;507 } else {508 //$scope.event.flagyes = false;509 $scope.event.Event_flag = false;510 console.log("$scope.event.Event_flagrevised", $scope.event.Event_flag);511 }512 console.log("$scope.event.Event_flag", $scope.event.Event_flag);513 }; 514 $scope.showFollowUp = function(){515 console.log("SHOWFOLLOWUP");516 $scope.FollowUp = true;517 $scope.Edit = false;518 };519 $scope.toggle = function (contact) {520 var idx = $scope.selectedcontacts.indexOf(contact);521 //var idx2 = $scope.selectedcontacts.indexOf(contact);522 //console.log($scope.selectedcontacts, "$scope.selectedcontacts");523 // console.log("idx", idx);524 if (idx > -1) {525 $scope.selectedcontacts.splice(idx, 1);526 }527 else {528 $scope.selectedcontacts.push(contact);529 }530 531 };532 $scope.toggle2 = function (contact, selected) {533 //$scope.selectedcontacts=[];534 var idx = $scope.selectedcontacts.indexOf(contact);535 // var idx2 = $scope.selectedcontactnames.indexOf(contact);536 // console.log("idx", idx);537 //if (idx > -1) {538 //selected.splice(idx, 1);539 //}540 //else {541 //selected.push(contact);542 //}543 544 if (idx > -1){545 $scope.selectedcontacts.splice(idx,1);546 } else {547 $scope.selectedcontacts.push(contact);548 }549 550 // console.log("$scope.selectedcontacts", $scope.selectedcontacts);551 };552 $scope.toggleCompanies = function (company,selected) {553 $scope.selectedcompanynames=[];554 $scope.contacts = [];555 $scope.contactinfo = [];556 //console.log("$scope.companies", $scope.companies);557 558 var idx = selected.indexOf(company);559 var idx2 = $scope.selectedcompanies.indexOf(company);560 // console.log("idx", idx);561 if (idx > -1) {562 selected.splice(idx, 1);563 $scope.selectedcompanies.splice(idx2,1);564 }565 else {566 selected.push(company);567 $scope.selectedcompanies.push(company);568 }569 // console.log("selected", selected);570 //console.log("$scope.selectedcompanies", $scope.selectedcompanies);571 //get contact objects into a separate array572 for (var x=0; x<$scope.selectedcompanies.length; x++){573 if(typeof $scope.selectedcompanies[x]==="object"){574 $scope.contacts.push($scope.selectedcompanies[x].Contacts);575 $scope.selectedcompanynames.push(selected[x].Company_name);576 }577 }578 // console.log("$scope.contacts", $scope.contacts);579 //console.log("$scope.selectedcompanynames", $scope.selectedcompanynames);580 if($scope.contacts!=="undefined"){581 var temp = [];582 for (var y=0; y<$scope.contacts.length; y++){583 for (var z=0; z<$scope.contacts[y].length; z++){584 temp.push($scope.contacts[y][z]);585 //$scope.contactnames.push($scope.contacts[y][z].Contact_name);586 }587 $scope.contactinfo.push(temp);588 temp=[];589 }590 //$scope.contactnames = $scope.chunk($scope.contactnames, 3);591 }592 };593 $scope.updateEvent = function() {594 // console.log("typeof", typeof $scope.event);595 if($scope.event.Followedupanswer===true){596 $scope.event.flagyes = false;597 $scope.event.Event_flag = false;598 $scope.event.Event_followupdate = null;599 }600 var event = $scope.event;601 $scope.cleanupcontacts();602// console.log("a;skdlf;aslkdjf;lskdjf", $scope.event.selectedcontacts);603 //console.log("whynotworking", $scope.event.Event_outcome);604 //console.log("EVENT", $scope.event);605 console.log("$scope.event.Event_flag", $scope.event.Event_flag);606 if($scope.event.Event_outcome==="Not interested"){607 $scope.event.Event_flag = false;608 //$scope.event.flagyes = "No";609 //console.log("NOTINETERESTED< BUTDIDNchange");610 $scope.event.Event_followupdate=null;611 }612 if($scope.event.Event_flag===false){613 $scope.event.Event_followupdate=null;614 }615 if($scope.event.FollowedUp===true){616 console.log("HELLOTRUE");617 $scope.event.Event_followupdate=null;618 if($scope.event.notes!==null){619 ("Notnull");620 $scope.event.notes=$scope.event.notes + "; Followed up";621 } else {622 $scope.event.notes = "Followed up";623 }624 }625 event.updated = [];626 event.updated.push(new Date().getTime());627 628 event.$update(function() {629 //console.log("response", response.data);630 }).then(function(){631 $scope.Edit=false;632 $state.go('viewEvent',{id : event.id});633 $scope.findOneEvent();634 });635 };636 $scope.checkifnewuser = function(){637 //find user object if a new user has been selected638 if ($scope.event.userchange===true){639 console.log("USERCHANGED!");640// $http({641 // method: 'GET',642 // url: '/findnewuser',643 // params: {name: $scope.event.newusername}644 // }).then(function(user){645 // console.log("What came back: ", user.data);646 // $scope.event.newuser = user.data;647 648 $scope.updateEvent();649 650 // console.log("$scope.event typeof", typeof $scope.event, "$scope.event", $scope.event);651 652 } else {653 //console.log("ELLLLLLLLLLLLLSSSSSSSSSSSSEEEEEEEEEEE");654 $scope.updateEvent();655 //console.log("$scope.event typeof", typeof $scope.event, "$scope.event", $scope.event);656 //$scope.updateEvent();657 658 }659 };660}]);...

Full Screen

Full Screen

inception_v4.py

Source:inception_v4.py Github

copy

Full Screen

...26from nets import inception_utils27def block_inception_a(inputs, scope=None, reuse=None):28 """Builds Inception-A block for Inception v4 network."""29 # By default use stride=1 and SAME padding30 with slim.arg_scope([slim.conv2d, slim.avg_pool2d, slim.max_pool2d],31 stride=1, padding='SAME'):32 with tf.variable_scope(33 scope, 'BlockInceptionA', [inputs], reuse=reuse):34 with tf.variable_scope('Branch_0'):35 branch_0 = slim.conv2d(inputs, 96, [1, 1], scope='Conv2d_0a_1x1')36 with tf.variable_scope('Branch_1'):37 branch_1 = slim.conv2d(inputs, 64, [1, 1], scope='Conv2d_0a_1x1')38 branch_1 = slim.conv2d(branch_1, 96, [3, 3], scope='Conv2d_0b_3x3')39 with tf.variable_scope('Branch_2'):40 branch_2 = slim.conv2d(inputs, 64, [1, 1], scope='Conv2d_0a_1x1')41 branch_2 = slim.conv2d(branch_2, 96, [3, 3], scope='Conv2d_0b_3x3')42 branch_2 = slim.conv2d(branch_2, 96, [3, 3], scope='Conv2d_0c_3x3')43 with tf.variable_scope('Branch_3'):44 branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')45 branch_3 = slim.conv2d(branch_3, 96, [1, 1], scope='Conv2d_0b_1x1')46 return tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])47def block_reduction_a(inputs, scope=None, reuse=None):48 """Builds Reduction-A block for Inception v4 network."""49 # By default use stride=1 and SAME padding50 with slim.arg_scope([slim.conv2d, slim.avg_pool2d, slim.max_pool2d],51 stride=1, padding='SAME'):52 with tf.variable_scope(53 scope, 'BlockReductionA', [inputs], reuse=reuse):54 with tf.variable_scope('Branch_0'):55 branch_0 = slim.conv2d(inputs, 384, [3, 3], stride=2, padding='VALID',56 scope='Conv2d_1a_3x3')57 with tf.variable_scope('Branch_1'):58 branch_1 = slim.conv2d(inputs, 192, [1, 1], scope='Conv2d_0a_1x1')59 branch_1 = slim.conv2d(branch_1, 224, [3, 3], scope='Conv2d_0b_3x3')60 branch_1 = slim.conv2d(branch_1, 256, [3, 3], stride=2,61 padding='VALID', scope='Conv2d_1a_3x3')62 with tf.variable_scope('Branch_2'):63 branch_2 = slim.max_pool2d(inputs, [3, 3], stride=2, padding='VALID',64 scope='MaxPool_1a_3x3')65 return tf.concat(axis=3, values=[branch_0, branch_1, branch_2])66def block_inception_b(inputs, scope=None, reuse=None):67 """Builds Inception-B block for Inception v4 network."""68 # By default use stride=1 and SAME padding69 with slim.arg_scope([slim.conv2d, slim.avg_pool2d, slim.max_pool2d],70 stride=1, padding='SAME'):71 with tf.variable_scope(72 scope, 'BlockInceptionB', [inputs], reuse=reuse):73 with tf.variable_scope('Branch_0'):74 branch_0 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1')75 with tf.variable_scope('Branch_1'):76 branch_1 = slim.conv2d(inputs, 192, [1, 1], scope='Conv2d_0a_1x1')77 branch_1 = slim.conv2d(branch_1, 224, [1, 7], scope='Conv2d_0b_1x7')78 branch_1 = slim.conv2d(branch_1, 256, [7, 1], scope='Conv2d_0c_7x1')79 with tf.variable_scope('Branch_2'):80 branch_2 = slim.conv2d(inputs, 192, [1, 1], scope='Conv2d_0a_1x1')81 branch_2 = slim.conv2d(branch_2, 192, [7, 1], scope='Conv2d_0b_7x1')82 branch_2 = slim.conv2d(branch_2, 224, [1, 7], scope='Conv2d_0c_1x7')83 branch_2 = slim.conv2d(branch_2, 224, [7, 1], scope='Conv2d_0d_7x1')84 branch_2 = slim.conv2d(branch_2, 256, [1, 7], scope='Conv2d_0e_1x7')85 with tf.variable_scope('Branch_3'):86 branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')87 branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')88 return tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])89def block_reduction_b(inputs, scope=None, reuse=None):90 """Builds Reduction-B block for Inception v4 network."""91 # By default use stride=1 and SAME padding92 with slim.arg_scope([slim.conv2d, slim.avg_pool2d, slim.max_pool2d],93 stride=1, padding='SAME'):94 with tf.variable_scope(95 scope, 'BlockReductionB', [inputs], reuse=reuse):96 with tf.variable_scope('Branch_0'):97 branch_0 = slim.conv2d(inputs, 192, [1, 1], scope='Conv2d_0a_1x1')98 branch_0 = slim.conv2d(branch_0, 192, [3, 3], stride=2,99 padding='VALID', scope='Conv2d_1a_3x3')100 with tf.variable_scope('Branch_1'):101 branch_1 = slim.conv2d(inputs, 256, [1, 1], scope='Conv2d_0a_1x1')102 branch_1 = slim.conv2d(branch_1, 256, [1, 7], scope='Conv2d_0b_1x7')103 branch_1 = slim.conv2d(branch_1, 320, [7, 1], scope='Conv2d_0c_7x1')104 branch_1 = slim.conv2d(branch_1, 320, [3, 3], stride=2,105 padding='VALID', scope='Conv2d_1a_3x3')106 with tf.variable_scope('Branch_2'):107 branch_2 = slim.max_pool2d(inputs, [3, 3], stride=2, padding='VALID',108 scope='MaxPool_1a_3x3')109 return tf.concat(axis=3, values=[branch_0, branch_1, branch_2])110def block_inception_c(inputs, scope=None, reuse=None):111 """Builds Inception-C block for Inception v4 network."""112 # By default use stride=1 and SAME padding113 with slim.arg_scope([slim.conv2d, slim.avg_pool2d, slim.max_pool2d],114 stride=1, padding='SAME'):115 with tf.variable_scope(116 scope, 'BlockInceptionC', [inputs], reuse=reuse):117 with tf.variable_scope('Branch_0'):118 branch_0 = slim.conv2d(inputs, 256, [1, 1], scope='Conv2d_0a_1x1')119 with tf.variable_scope('Branch_1'):120 branch_1 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1')121 branch_1 = tf.concat(axis=3, values=[122 slim.conv2d(branch_1, 256, [1, 3], scope='Conv2d_0b_1x3'),123 slim.conv2d(branch_1, 256, [3, 1], scope='Conv2d_0c_3x1')])124 with tf.variable_scope('Branch_2'):125 branch_2 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1')126 branch_2 = slim.conv2d(branch_2, 448, [3, 1], scope='Conv2d_0b_3x1')127 branch_2 = slim.conv2d(branch_2, 512, [1, 3], scope='Conv2d_0c_1x3')128 branch_2 = tf.concat(axis=3, values=[129 slim.conv2d(branch_2, 256, [1, 3], scope='Conv2d_0d_1x3'),130 slim.conv2d(branch_2, 256, [3, 1], scope='Conv2d_0e_3x1')])131 with tf.variable_scope('Branch_3'):132 branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')133 branch_3 = slim.conv2d(branch_3, 256, [1, 1], scope='Conv2d_0b_1x1')134 return tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])135def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None):136 """Creates the Inception V4 network up to the given final endpoint.137 Args:138 inputs: a 4-D tensor of size [batch_size, height, width, 3].139 final_endpoint: specifies the endpoint to construct the network up to.140 It can be one of [ 'Conv2d_1a_3x3', 'Conv2d_2a_3x3', 'Conv2d_2b_3x3',141 'Mixed_3a', 'Mixed_4a', 'Mixed_5a', 'Mixed_5b', 'Mixed_5c', 'Mixed_5d',142 'Mixed_5e', 'Mixed_6a', 'Mixed_6b', 'Mixed_6c', 'Mixed_6d', 'Mixed_6e',143 'Mixed_6f', 'Mixed_6g', 'Mixed_6h', 'Mixed_7a', 'Mixed_7b', 'Mixed_7c',144 'Mixed_7d']145 scope: Optional variable_scope.146 Returns:147 logits: the logits outputs of the model.148 end_points: the set of end_points from the inception model.149 Raises:150 ValueError: if final_endpoint is not set to one of the predefined values,151 """152 end_points = {}153 def add_and_check_final(name, net):154 end_points[name] = net155 return name == final_endpoint156 with tf.variable_scope(scope, 'InceptionV4', [inputs]):157 with slim.arg_scope([slim.conv2d, slim.max_pool2d, slim.avg_pool2d],158 stride=1, padding='SAME'):159 # 299 x 299 x 3160 net = slim.conv2d(inputs, 32, [3, 3], stride=2,161 padding='VALID', scope='Conv2d_1a_3x3')162 if add_and_check_final('Conv2d_1a_3x3', net): return net, end_points163 # 149 x 149 x 32164 net = slim.conv2d(net, 32, [3, 3], padding='VALID',165 scope='Conv2d_2a_3x3')166 if add_and_check_final('Conv2d_2a_3x3', net): return net, end_points167 # 147 x 147 x 32168 net = slim.conv2d(net, 64, [3, 3], scope='Conv2d_2b_3x3')169 if add_and_check_final('Conv2d_2b_3x3', net): return net, end_points170 # 147 x 147 x 64171 with tf.variable_scope('Mixed_3a'):172 with tf.variable_scope('Branch_0'):173 branch_0 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',174 scope='MaxPool_0a_3x3')175 with tf.variable_scope('Branch_1'):176 branch_1 = slim.conv2d(net, 96, [3, 3], stride=2, padding='VALID',177 scope='Conv2d_0a_3x3')178 net = tf.concat(axis=3, values=[branch_0, branch_1])179 if add_and_check_final('Mixed_3a', net): return net, end_points180 # 73 x 73 x 160181 with tf.variable_scope('Mixed_4a'):182 with tf.variable_scope('Branch_0'):183 branch_0 = slim.conv2d(net, 64, [1, 1], scope='Conv2d_0a_1x1')184 branch_0 = slim.conv2d(branch_0, 96, [3, 3], padding='VALID',185 scope='Conv2d_1a_3x3')186 with tf.variable_scope('Branch_1'):187 branch_1 = slim.conv2d(net, 64, [1, 1], scope='Conv2d_0a_1x1')188 branch_1 = slim.conv2d(branch_1, 64, [1, 7], scope='Conv2d_0b_1x7')189 branch_1 = slim.conv2d(branch_1, 64, [7, 1], scope='Conv2d_0c_7x1')190 branch_1 = slim.conv2d(branch_1, 96, [3, 3], padding='VALID',191 scope='Conv2d_1a_3x3')192 net = tf.concat(axis=3, values=[branch_0, branch_1])193 if add_and_check_final('Mixed_4a', net): return net, end_points194 # 71 x 71 x 192195 with tf.variable_scope('Mixed_5a'):196 with tf.variable_scope('Branch_0'):197 branch_0 = slim.conv2d(net, 192, [3, 3], stride=2, padding='VALID',198 scope='Conv2d_1a_3x3')199 with tf.variable_scope('Branch_1'):200 branch_1 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',201 scope='MaxPool_1a_3x3')202 net = tf.concat(axis=3, values=[branch_0, branch_1])203 if add_and_check_final('Mixed_5a', net): return net, end_points204 # 35 x 35 x 384205 # 4 x Inception-A blocks206 for idx in range(4):207 block_scope = 'Mixed_5' + chr(ord('b') + idx)208 net = block_inception_a(net, block_scope)209 if add_and_check_final(block_scope, net): return net, end_points210 # 35 x 35 x 384211 # Reduction-A block212 net = block_reduction_a(net, 'Mixed_6a')213 if add_and_check_final('Mixed_6a', net): return net, end_points214 # 17 x 17 x 1024215 # 7 x Inception-B blocks216 for idx in range(7):217 block_scope = 'Mixed_6' + chr(ord('b') + idx)218 net = block_inception_b(net, block_scope)219 if add_and_check_final(block_scope, net): return net, end_points220 # 17 x 17 x 1024221 # Reduction-B block222 net = block_reduction_b(net, 'Mixed_7a')223 if add_and_check_final('Mixed_7a', net): return net, end_points224 # 8 x 8 x 1536225 # 3 x Inception-C blocks226 for idx in range(3):227 block_scope = 'Mixed_7' + chr(ord('b') + idx)228 net = block_inception_c(net, block_scope)229 if add_and_check_final(block_scope, net): return net, end_points230 raise ValueError('Unknown final endpoint %s' % final_endpoint)231def inception_v4(inputs, num_classes=1001, is_training=True,232 dropout_keep_prob=0.8,233 reuse=None,234 scope='InceptionV4',235 create_aux_logits=True):236 """Creates the Inception V4 model.237 Args:238 inputs: a 4-D tensor of size [batch_size, height, width, 3].239 num_classes: number of predicted classes. If 0 or None, the logits layer240 is omitted and the input features to the logits layer (before dropout)241 are returned instead.242 is_training: whether is training or not.243 dropout_keep_prob: float, the fraction to keep before final layer.244 reuse: whether or not the network and its variables should be reused. To be245 able to reuse 'scope' must be given.246 scope: Optional variable_scope.247 create_aux_logits: Whether to include the auxiliary logits.248 Returns:249 net: a Tensor with the logits (pre-softmax activations) if num_classes250 is a non-zero integer, or the non-dropped input to the logits layer251 if num_classes is 0 or None.252 end_points: the set of end_points from the inception model.253 """254 end_points = {}255 with tf.variable_scope(256 scope, 'InceptionV4', [inputs], reuse=reuse) as scope:257 with slim.arg_scope([slim.batch_norm, slim.dropout],258 is_training=is_training):259 net, end_points = inception_v4_base(inputs, scope=scope)260 with slim.arg_scope([slim.conv2d, slim.max_pool2d, slim.avg_pool2d],261 stride=1, padding='SAME'):262 # Auxiliary Head logits263 if create_aux_logits and num_classes:264 with tf.variable_scope('AuxLogits'):265 # 17 x 17 x 1024266 aux_logits = end_points['Mixed_6h']267 aux_logits = slim.avg_pool2d(aux_logits, [5, 5], stride=3,268 padding='VALID',269 scope='AvgPool_1a_5x5')270 aux_logits = slim.conv2d(aux_logits, 128, [1, 1],271 scope='Conv2d_1b_1x1')272 aux_logits = slim.conv2d(aux_logits, 768,273 aux_logits.get_shape()[1:3],274 padding='VALID', scope='Conv2d_2a')275 aux_logits = slim.flatten(aux_logits)276 aux_logits = slim.fully_connected(aux_logits, num_classes,277 activation_fn=None,278 scope='Aux_logits')279 end_points['AuxLogits'] = aux_logits280 # Final pooling and prediction281 # TODO(sguada,arnoegw): Consider adding a parameter global_pool which282 # can be set to False to disable pooling here (as in resnet_*()).283 with tf.variable_scope('Logits'):284 # 8 x 8 x 1536285 kernel_size = net.get_shape()[1:3]286 if kernel_size.is_fully_defined():287 net = slim.avg_pool2d(net, kernel_size, padding='VALID',288 scope='AvgPool_1a')289 else:290 net = tf.reduce_mean(291 input_tensor=net,292 axis=[1, 2],293 keepdims=True,294 name='global_pool')295 end_points['global_pool'] = net296 if not num_classes:297 return net, end_points...

Full Screen

Full Screen

inception_v1.py

Source:inception_v1.py Github

copy

Full Screen

...42 Raises:43 ValueError: if final_endpoint is not set to one of the predefined values.44 """45 end_points = {}46 with tf.variable_scope(scope, 'InceptionV1', [inputs]):47 with slim.arg_scope(48 [slim.conv2d, slim.fully_connected],49 weights_initializer=trunc_normal(0.01)):50 with slim.arg_scope([slim.conv2d, slim.max_pool2d],51 stride=1, padding='SAME'):52 end_point = 'Conv2d_1a_7x7'53 net = slim.conv2d(inputs, 64, [7, 7], stride=2, scope=end_point)54 end_points[end_point] = net55 if final_endpoint == end_point: return net, end_points56 end_point = 'MaxPool_2a_3x3'57 net = slim.max_pool2d(net, [3, 3], stride=2, scope=end_point)58 end_points[end_point] = net59 if final_endpoint == end_point: return net, end_points60 end_point = 'Conv2d_2b_1x1'61 net = slim.conv2d(net, 64, [1, 1], scope=end_point)62 end_points[end_point] = net63 if final_endpoint == end_point: return net, end_points64 end_point = 'Conv2d_2c_3x3'65 net = slim.conv2d(net, 192, [3, 3], scope=end_point)66 end_points[end_point] = net67 if final_endpoint == end_point: return net, end_points68 end_point = 'MaxPool_3a_3x3'69 net = slim.max_pool2d(net, [3, 3], stride=2, scope=end_point)70 end_points[end_point] = net71 if final_endpoint == end_point: return net, end_points72 end_point = 'Mixed_3b'73 with tf.variable_scope(end_point):74 with tf.variable_scope('Branch_0'):75 branch_0 = slim.conv2d(net, 64, [1, 1], scope='Conv2d_0a_1x1')76 with tf.variable_scope('Branch_1'):77 branch_1 = slim.conv2d(net, 96, [1, 1], scope='Conv2d_0a_1x1')78 branch_1 = slim.conv2d(branch_1, 128, [3, 3], scope='Conv2d_0b_3x3')79 with tf.variable_scope('Branch_2'):80 branch_2 = slim.conv2d(net, 16, [1, 1], scope='Conv2d_0a_1x1')81 branch_2 = slim.conv2d(branch_2, 32, [3, 3], scope='Conv2d_0b_3x3')82 with tf.variable_scope('Branch_3'):83 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')84 branch_3 = slim.conv2d(branch_3, 32, [1, 1], scope='Conv2d_0b_1x1')85 net = tf.concat(86 axis=3, values=[branch_0, branch_1, branch_2, branch_3])87 end_points[end_point] = net88 if final_endpoint == end_point: return net, end_points89 end_point = 'Mixed_3c'90 with tf.variable_scope(end_point):91 with tf.variable_scope('Branch_0'):92 branch_0 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')93 with tf.variable_scope('Branch_1'):94 branch_1 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')95 branch_1 = slim.conv2d(branch_1, 192, [3, 3], scope='Conv2d_0b_3x3')96 with tf.variable_scope('Branch_2'):97 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')98 branch_2 = slim.conv2d(branch_2, 96, [3, 3], scope='Conv2d_0b_3x3')99 with tf.variable_scope('Branch_3'):100 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')101 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')102 net = tf.concat(103 axis=3, values=[branch_0, branch_1, branch_2, branch_3])104 end_points[end_point] = net105 if final_endpoint == end_point: return net, end_points106 end_point = 'MaxPool_4a_3x3'107 net = slim.max_pool2d(net, [3, 3], stride=2, scope=end_point)108 end_points[end_point] = net109 if final_endpoint == end_point: return net, end_points110 end_point = 'Mixed_4b'111 with tf.variable_scope(end_point):112 with tf.variable_scope('Branch_0'):113 branch_0 = slim.conv2d(net, 192, [1, 1], scope='Conv2d_0a_1x1')114 with tf.variable_scope('Branch_1'):115 branch_1 = slim.conv2d(net, 96, [1, 1], scope='Conv2d_0a_1x1')116 branch_1 = slim.conv2d(branch_1, 208, [3, 3], scope='Conv2d_0b_3x3')117 with tf.variable_scope('Branch_2'):118 branch_2 = slim.conv2d(net, 16, [1, 1], scope='Conv2d_0a_1x1')119 branch_2 = slim.conv2d(branch_2, 48, [3, 3], scope='Conv2d_0b_3x3')120 with tf.variable_scope('Branch_3'):121 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')122 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')123 net = tf.concat(124 axis=3, values=[branch_0, branch_1, branch_2, branch_3])125 end_points[end_point] = net126 if final_endpoint == end_point: return net, end_points127 end_point = 'Mixed_4c'128 with tf.variable_scope(end_point):129 with tf.variable_scope('Branch_0'):130 branch_0 = slim.conv2d(net, 160, [1, 1], scope='Conv2d_0a_1x1')131 with tf.variable_scope('Branch_1'):132 branch_1 = slim.conv2d(net, 112, [1, 1], scope='Conv2d_0a_1x1')133 branch_1 = slim.conv2d(branch_1, 224, [3, 3], scope='Conv2d_0b_3x3')134 with tf.variable_scope('Branch_2'):135 branch_2 = slim.conv2d(net, 24, [1, 1], scope='Conv2d_0a_1x1')136 branch_2 = slim.conv2d(branch_2, 64, [3, 3], scope='Conv2d_0b_3x3')137 with tf.variable_scope('Branch_3'):138 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')139 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')140 net = tf.concat(141 axis=3, values=[branch_0, branch_1, branch_2, branch_3])142 end_points[end_point] = net143 if final_endpoint == end_point: return net, end_points144 end_point = 'Mixed_4d'145 with tf.variable_scope(end_point):146 with tf.variable_scope('Branch_0'):147 branch_0 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')148 with tf.variable_scope('Branch_1'):149 branch_1 = slim.conv2d(net, 128, [1, 1], scope='Conv2d_0a_1x1')150 branch_1 = slim.conv2d(branch_1, 256, [3, 3], scope='Conv2d_0b_3x3')151 with tf.variable_scope('Branch_2'):152 branch_2 = slim.conv2d(net, 24, [1, 1], scope='Conv2d_0a_1x1')153 branch_2 = slim.conv2d(branch_2, 64, [3, 3], scope='Conv2d_0b_3x3')154 with tf.variable_scope('Branch_3'):155 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')156 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')157 net = tf.concat(158 axis=3, values=[branch_0, branch_1, branch_2, branch_3])159 end_points[end_point] = net160 if final_endpoint == end_point: return net, end_points161 end_point = 'Mixed_4e'162 with tf.variable_scope(end_point):163 with tf.variable_scope('Branch_0'):164 branch_0 = slim.conv2d(net, 112, [1, 1], scope='Conv2d_0a_1x1')165 with tf.variable_scope('Branch_1'):166 branch_1 = slim.conv2d(net, 144, [1, 1], scope='Conv2d_0a_1x1')167 branch_1 = slim.conv2d(branch_1, 288, [3, 3], scope='Conv2d_0b_3x3')168 with tf.variable_scope('Branch_2'):169 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')170 branch_2 = slim.conv2d(branch_2, 64, [3, 3], scope='Conv2d_0b_3x3')171 with tf.variable_scope('Branch_3'):172 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')173 branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')174 net = tf.concat(175 axis=3, values=[branch_0, branch_1, branch_2, branch_3])176 end_points[end_point] = net177 if final_endpoint == end_point: return net, end_points178 end_point = 'Mixed_4f'179 with tf.variable_scope(end_point):180 with tf.variable_scope('Branch_0'):181 branch_0 = slim.conv2d(net, 256, [1, 1], scope='Conv2d_0a_1x1')182 with tf.variable_scope('Branch_1'):183 branch_1 = slim.conv2d(net, 160, [1, 1], scope='Conv2d_0a_1x1')184 branch_1 = slim.conv2d(branch_1, 320, [3, 3], scope='Conv2d_0b_3x3')185 with tf.variable_scope('Branch_2'):186 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')187 branch_2 = slim.conv2d(branch_2, 128, [3, 3], scope='Conv2d_0b_3x3')188 with tf.variable_scope('Branch_3'):189 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')190 branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')191 net = tf.concat(192 axis=3, values=[branch_0, branch_1, branch_2, branch_3])193 end_points[end_point] = net194 if final_endpoint == end_point: return net, end_points195 end_point = 'MaxPool_5a_2x2'196 net = slim.max_pool2d(net, [2, 2], stride=2, scope=end_point)197 end_points[end_point] = net198 if final_endpoint == end_point: return net, end_points199 end_point = 'Mixed_5b'200 with tf.variable_scope(end_point):201 with tf.variable_scope('Branch_0'):202 branch_0 = slim.conv2d(net, 256, [1, 1], scope='Conv2d_0a_1x1')203 with tf.variable_scope('Branch_1'):204 branch_1 = slim.conv2d(net, 160, [1, 1], scope='Conv2d_0a_1x1')205 branch_1 = slim.conv2d(branch_1, 320, [3, 3], scope='Conv2d_0b_3x3')206 with tf.variable_scope('Branch_2'):207 branch_2 = slim.conv2d(net, 32, [1, 1], scope='Conv2d_0a_1x1')208 branch_2 = slim.conv2d(branch_2, 128, [3, 3], scope='Conv2d_0a_3x3')209 with tf.variable_scope('Branch_3'):210 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')211 branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')212 net = tf.concat(213 axis=3, values=[branch_0, branch_1, branch_2, branch_3])214 end_points[end_point] = net215 if final_endpoint == end_point: return net, end_points216 end_point = 'Mixed_5c'217 with tf.variable_scope(end_point):218 with tf.variable_scope('Branch_0'):219 branch_0 = slim.conv2d(net, 384, [1, 1], scope='Conv2d_0a_1x1')220 with tf.variable_scope('Branch_1'):221 branch_1 = slim.conv2d(net, 192, [1, 1], scope='Conv2d_0a_1x1')222 branch_1 = slim.conv2d(branch_1, 384, [3, 3], scope='Conv2d_0b_3x3')223 with tf.variable_scope('Branch_2'):224 branch_2 = slim.conv2d(net, 48, [1, 1], scope='Conv2d_0a_1x1')225 branch_2 = slim.conv2d(branch_2, 128, [3, 3], scope='Conv2d_0b_3x3')226 with tf.variable_scope('Branch_3'):227 branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')228 branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')229 net = tf.concat(230 axis=3, values=[branch_0, branch_1, branch_2, branch_3])231 end_points[end_point] = net232 if final_endpoint == end_point: return net, end_points233 raise ValueError('Unknown final endpoint %s' % final_endpoint)234def inception_v1(inputs,235 num_classes=1000,236 is_training=True,237 dropout_keep_prob=0.8,238 prediction_fn=slim.softmax,239 spatial_squeeze=True,240 reuse=None,241 scope='InceptionV1',242 global_pool=False):243 """Defines the Inception V1 architecture.244 This architecture is defined in:245 Going deeper with convolutions246 Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed,247 Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, Andrew Rabinovich.248 http://arxiv.org/pdf/1409.4842v1.pdf.249 The default image size used to train this network is 224x224.250 Args:251 inputs: a tensor of size [batch_size, height, width, channels].252 num_classes: number of predicted classes. If 0 or None, the logits layer253 is omitted and the input features to the logits layer (before dropout)254 are returned instead.255 is_training: whether is training or not.256 dropout_keep_prob: the percentage of activation values that are retained.257 prediction_fn: a function to get predictions out of logits.258 spatial_squeeze: if True, logits is of shape [B, C], if false logits is of259 shape [B, 1, 1, C], where B is batch_size and C is number of classes.260 reuse: whether or not the network and its variables should be reused. To be261 able to reuse 'scope' must be given.262 scope: Optional variable_scope.263 global_pool: Optional boolean flag to control the avgpooling before the264 logits layer. If false or unset, pooling is done with a fixed window265 that reduces default-sized inputs to 1x1, while larger inputs lead to266 larger outputs. If true, any input size is pooled down to 1x1.267 Returns:268 net: a Tensor with the logits (pre-softmax activations) if num_classes269 is a non-zero integer, or the non-dropped-out input to the logits layer270 if num_classes is 0 or None.271 end_points: a dictionary from components of the network to the corresponding272 activation.273 """274 # Final pooling and prediction275 with tf.variable_scope(scope, 'InceptionV1', [inputs], reuse=reuse) as scope:276 with slim.arg_scope([slim.batch_norm, slim.dropout],277 is_training=is_training):278 net, end_points = inception_v1_base(inputs, scope=scope)279 with tf.variable_scope('Logits'):280 if global_pool:281 # Global average pooling.282 net = tf.reduce_mean(net, [1, 2], keep_dims=True, name='global_pool')283 end_points['global_pool'] = net284 else:285 # Pooling with a fixed kernel size.286 net = slim.avg_pool2d(net, [7, 7], stride=1, scope='AvgPool_0a_7x7')287 end_points['AvgPool_0a_7x7'] = net288 if not num_classes:289 return net, end_points290 net = slim.dropout(net, dropout_keep_prob, scope='Dropout_0b')291 logits = slim.conv2d(net, num_classes, [1, 1], activation_fn=None,292 normalizer_fn=None, scope='Conv2d_0c_1x1')293 if spatial_squeeze:...

Full Screen

Full Screen

AppUI.js

Source:AppUI.js Github

copy

Full Screen

1/*!2 * remark v1.0.7 (http://getbootstrapadmin.com/remark)3 * Copyright 2015 amazingsurge4 * Licensed under the Themeforest Standard Licenses5 */6(function(window, document, $, angular) {7 'use strict';8 var AppUI = angular.module('AppUI', ['ui.router', 'oc.lazyLoad', 'ui.bootstrap']);9 AppUI.config(["$stateProvider", "$urlRouterProvider", "$ocLazyLoadProvider", function($stateProvider, $urlRouterProvider, $ocLazyLoadProvider) {10 $stateProvider.state("angularui", {11 url: "/angularui/:type",12 controller: "AngularUIController",13 templateUrl: function($stateParams) {14 return "templates/ui/" + $stateParams.type + ".html";15 },16 resolve: {17 resoucre: function($http, $stateParams) {18 return $http.get("../../assets/data/angular/ui/" + $stateParams.type + ".json").success(function() {19 NProgress.done();20 });21 }22 }23 });24 }]);25 AppUI.controller('AsideController', ['$rootScope', '$scope', '$http', '$location', '$window', function($rootScope, $scope, $http, $location, $window) {26 $scope.lists = [];27 $http.get('../../assets/data/angular/aside.json').success(function(data) {28 $scope.lists = data;29 var tag = '',30 url = $location.url(),31 flag = true;32 for (var i = 0; i < $scope.lists.length; i++) {33 tag = $scope.lists[i].url;34 if (flag && url.search(tag) > 0) {35 $scope.lists[i].active = 'active';36 flag = false;37 } else {38 $scope.lists[i].active = '';39 }40 };41 });42 $rootScope.$on('$locationChangeStart', function(e, url) {43 var tag = '',44 flag = true;45 for (var i = 0; i < $scope.lists.length; i++) {46 tag = $scope.lists[i].url;47 if (flag && url.search(tag) > 0) {48 $scope.lists[i].active = 'active';49 flag = false;50 } else {51 $scope.lists[i].active = '';52 }53 };54 NProgress.start();55 });56 }]).controller('AngularUIController', ['$scope', 'resoucre', function($scope, resoucre) {57 $scope.model = resoucre.data;58 }]).controller('AlertDemoController', ['$scope', function($scope) {59 $scope.alerts = $scope.model;60 $scope.addAlert = function() {61 $scope.model.push({62 msg: 'Another alert!'63 });64 };65 $scope.closeAlert = function(index) {66 $scope.model.splice(index, 1);67 };68 }]).controller('ButtonsDemoController', ['$scope', function($scope) {69 $scope.singleModel = $scope.model.singleModel;70 $scope.radioModel = $scope.model.radioModel;71 $scope.checkModel = $scope.model.checkModel;72 }]).controller('ButtonsDemoController', ['$scope', function($scope) {73 $scope.singleModel = $scope.model.singleModel;74 $scope.radioModel = $scope.model.radioModel;75 $scope.checkModel = $scope.model.checkModel;76 }]).controller('CarouselDemoController', ['$scope', function($scope) {77 $scope.myInterval = $scope.model.myInterval;78 var slides = $scope.slides = [];79 $scope.addSlide = function() {80 var newWidth = 600 + slides.length + 1;81 slides.push({82 image: 'http://placekitten.com/' + newWidth + '/300',83 text: ['More', 'Extra', 'Lots of', 'Surplus'][slides.length % 4] + ' ' + ['Cats', 'Kittys', 'Felines', 'Cutes'][slides.length % 4]84 });85 };86 for (var i = 0; i < 4; i++) {87 $scope.addSlide();88 }89 }]).controller('CollapseDemoController', ['$scope', function($scope) {90 $scope.isCollapsed = $scope.model.isCollapsed;91 }]).controller('DatepickerDemoController', ['$scope', function($scope) {92 $scope.today = function() {93 $scope.dt = new Date();94 };95 $scope.today();96 $scope.clear = function() {97 $scope.dt = null;98 };99 // Disable weekend selection100 $scope.disabled = function(date, mode) {101 return (mode === 'day' && (date.getDay() === 0 || date.getDay() === 6));102 };103 $scope.toggleMin = function() {104 $scope.minDate = $scope.minDate ? null : new Date();105 };106 $scope.toggleMin();107 $scope.open = function($event) {108 $event.preventDefault();109 $event.stopPropagation();110 $scope.opened = true;111 };112 $scope.dateOptions = {113 formatYear: 'yy',114 startingDay: 1115 };116 $scope.formats = $scope.model.formats;117 $scope.format = $scope.formats[0];118 }]).controller('DropdownDemoController', ['$scope', '$log', function($scope, $log) {119 $scope.toggled = function(open) {120 $log.log('Dropdown is now: ', open);121 };122 $scope.toggleDropdown = function($event) {123 $event.preventDefault();124 $event.stopPropagation();125 $scope.status.isopen = !$scope.status.isopen;126 };127 }]).controller('ModalDemoController', ['$scope', '$modal', '$log', function($scope, $modal, $log) {128 $scope.items = $scope.model.items;129 $scope.animationsEnabled = true;130 $scope.open = function(size) {131 var modalInstance = $modal.open({132 animation: $scope.animationsEnabled,133 templateUrl: 'myModalContent.html',134 controller: 'ModalInstanceController',135 size: size,136 resolve: {137 items: function() {138 return $scope.items;139 }140 }141 });142 modalInstance.result.then(function(selectedItem) {143 $scope.selected = selectedItem;144 }, function() {145 $log.info('Modal dismissed at: ' + new Date());146 });147 $scope.toggleAnimation = function() {148 $scope.animationsEnabled = !$scope.animationsEnabled;149 };150 };151 }]).controller('ModalInstanceController', ['$scope', '$modalInstance', 'items', function($scope, $modalInstance, items) {152 // Please note that $modalInstance represents a modal window (instance) dependency.153 // It is not the same as the $modal service used above.154 $scope.items = items;155 $scope.selected = {156 item: $scope.items[0]157 };158 $scope.ok = function() {159 $modalInstance.close($scope.selected.item);160 };161 $scope.cancel = function() {162 $modalInstance.dismiss('cancel');163 };164 }]).controller('PaginationDemoController', ['$scope', '$log', function($scope, $log) {165 $scope.totalItems = $scope.model.totalItems;166 $scope.currentPage = $scope.model.currentPage;167 $scope.maxSize = $scope.model.maxSize;168 $scope.bigTotalItems = $scope.model.bigTotalItems;169 $scope.bigCurrentPage = $scope.model.bigCurrentPage;170 $scope.setPage = function(pageNo) {171 $scope.currentPage = pageNo;172 };173 $scope.pageChanged = function() {174 $log.log('Page changed to: ' + $scope.currentPage);175 };176 }]).controller('PopoverDemoController', ['$scope', function($scope) {177 $scope.dynamicPopover = $scope.model.dynamicPopover;178 $scope.dynamicPopoverTitle = $scope.model.dynamicPopoverTitle;179 }]).controller('ProgressbarDemoController', ['$scope', function($scope) {180 $scope.max = $scope.model.max;181 $scope.random = function() {182 var value = Math.floor((Math.random() * 100) + 1);183 var type;184 if (value < 25) {185 type = 'success';186 } else if (value < 50) {187 type = 'info';188 } else if (value < 75) {189 type = 'warning';190 } else {191 type = 'danger';192 }193 $scope.showWarning = (type === 'danger' || type === 'warning');194 $scope.dynamic = value;195 $scope.type = type;196 };197 $scope.random();198 $scope.randomStacked = function() {199 $scope.stacked = [];200 var types = ['success', 'info', 'warning', 'danger'];201 for (var i = 0, n = Math.floor((Math.random() * 4) + 1); i < n; i++) {202 var index = Math.floor((Math.random() * 4));203 $scope.stacked.push({204 value: Math.floor((Math.random() * 30) + 1),205 type: types[index]206 });207 }208 };209 $scope.randomStacked();210 }]).controller('RatingDemoController', function($scope) {211 $scope.rate = $scope.model.rate;212 $scope.max = $scope.model.max;213 $scope.isReadonly = $scope.model.isReadonly;214 $scope.ratingStates = $scope.model.ratingStates;215 $scope.hoveringOver = function(value) {216 $scope.overStar = value;217 $scope.percent = 100 * (value / $scope.max);218 };219 }).controller('TabsDemoController', ['$scope', '$window', function($scope, $window) {220 $scope.tabs = $scope.model;221 $scope.alertMe = function() {222 setTimeout(function() {223 $window.alert('You\'ve selected the alert tab!');224 });225 };226 }]).controller('TimepickerDemoController', ['$scope', '$log', function($scope, $log) {227 $scope.mytime = new Date();228 $scope.hstep = $scope.model.hstep;229 $scope.mstep = $scope.model.mstep;230 $scope.options = $scope.model.options;231 $scope.ismeridian = $scope.model.ismeridian;232 $scope.toggleMode = function() {233 $scope.ismeridian = !$scope.ismeridian;234 };235 $scope.update = function() {236 var d = new Date();237 d.setHours(14);238 d.setMinutes(0);239 $scope.mytime = d;240 };241 $scope.changed = function() {242 $log.log('Time changed to: ' + $scope.mytime);243 };244 $scope.clear = function() {245 $scope.mytime = null;246 };247 }]).controller('TooltipDemoController', ['$scope', function($scope) {248 $scope.dynamicTooltip = $scope.model.dynamicTooltip;249 $scope.dynamicTooltipText = $scope.model.dynamicTooltipText;250 $scope.htmlTooltip = $scope.model.htmlTooltip;251 }]).controller('TypeaheadDemoController', ['$scope', function($scope) {252 $scope.states = $scope.model.states;253 $scope.statesWithFlags = $scope.model.statesWithFlags;254 $scope.selected = undefined;255 // Any function returning a promise object can be used to load values asynchronously256 $scope.getLocation = function(val) {257 return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {258 params: {259 address: val,260 sensor: false261 }262 }).then(function(response) {263 return response.data.results.map(function(item) {264 return item.formatted_address;265 });266 });267 };268 }]);...

Full Screen

Full Screen

filectrl.js

Source:filectrl.js Github

copy

Full Screen

1var app = angular.module('cfApp');2app.controller('FileCtrl', ['$scope', '$http', '$window', '$rootScope', '$filter', function($scope, $http, $window, $rootScope, $filter) {3 $http.get('/public/data.json').then(function(res) {4 console.log('Res', res);5 $rootScope.newfile = res.data;6 $scope.data = $rootScope.newfile;7 // $scope.data = res.data;8 // var splitarr = res.data.ChurchService.split(", ");9 // console.log('Service Array Initial Get Request ', splitarr);10 // for (var i = 0; i < $scope.data.length; i++) {11 // //$scope.data.ChurchService[i] = $scope.data.ChurchService[i].split(",").join("\n");12 // }13 // console.log('ChurchService', $scope.data.ChurchService);14 // $scope.data.ChurchAddress = 15 // console.log($scope.data[0].churchname);16 });17 $scope.order = function() {18 $scope.data = [];19 // $scope.arrlen = $rootScope.newfile.ChurchName.s;20 for (var i = 0; i < $rootScope.newfile.length; i++) {21 if ($rootScope.newfile[i].ChurchName.startsWith('A')) {22 $scope.data.push($rootScope.newfile[i]);23 }24 }25 console.log('Service Array ', $scope.data.ChurchService);26 };27 $scope.border = function() {28 $scope.data = [];29 for (var i = 0; i < $rootScope.newfile.length; i++) {30 if ($rootScope.newfile[i].ChurchName.startsWith('B')) {31 $scope.data.push($rootScope.newfile[i]);32 }33 }34 };35 $scope.corder = function() {36 $scope.data = [];37 for (var i = 0; i < $rootScope.newfile.length; i++) {38 if ($rootScope.newfile[i].ChurchName.startsWith('C')) {39 $scope.data.push($rootScope.newfile[i]);40 }41 }42 };43 $scope.dorder = function() {44 $scope.data = [];45 for (var i = 0; i < $rootScope.newfile.length; i++) {46 if ($rootScope.newfile[i].ChurchName.startsWith('D')) {47 $scope.data.push($rootScope.newfile[i]);48 }49 }50 };51 $scope.eorder = function() {52 $scope.data = [];53 for (var i = 0; i < $rootScope.newfile.length; i++) {54 if ($rootScope.newfile[i].ChurchName.startsWith('E')) {55 $scope.data.push($rootScope.newfile[i]);56 }57 }58 };59 $scope.forder = function() {60 $scope.data = [];61 for (var i = 0; i < $rootScope.newfile.length; i++) {62 if ($rootScope.newfile[i].ChurchName.startsWith('F')) {63 $scope.data.push($rootScope.newfile[i]);64 }65 }66 };67 $scope.gorder = function() {68 $scope.data = [];69 for (var i = 0; i < $rootScope.newfile.length; i++) {70 if ($rootScope.newfile[i].ChurchName.startsWith('G')) {71 $scope.data.push($rootScope.newfile[i]);72 }73 }74 };75 $scope.horder = function() {76 $scope.data = [];77 for (var i = 0; i < $rootScope.newfile.length; i++) {78 if ($rootScope.newfile[i].ChurchName.startsWith('H')) {79 $scope.data.push($rootScope.newfile[i]);80 }81 }82 };83 $scope.iorder = function() {84 $scope.data = [];85 for (var i = 0; i < $rootScope.newfile.length; i++) {86 if ($rootScope.newfile[i].ChurchName.startsWith('I')) {87 $scope.data.push($rootScope.newfile[i]);88 }89 }90 };91 $scope.jorder = function() {92 $scope.data = [];93 for (var i = 0; i < $rootScope.newfile.length; i++) {94 if ($rootScope.newfile[i].ChurchName.startsWith('J')) {95 $scope.data.push($rootScope.newfile[i]);96 }97 }98 };99 $scope.korder = function() {100 $scope.data = [];101 for (var i = 0; i < $rootScope.newfile.length; i++) {102 if ($rootScope.newfile[i].ChurchName.startsWith('K')) {103 $scope.data.push($rootScope.newfile[i]);104 }105 }106 };107 $scope.lorder = function() {108 $scope.data = [];109 for (var i = 0; i < $rootScope.newfile.length; i++) {110 if ($rootScope.newfile[i].ChurchName.startsWith('L')) {111 $scope.data.push($rootScope.newfile[i]);112 }113 }114 };115 $scope.morder = function() {116 $scope.data = [];117 for (var i = 0; i < $rootScope.newfile.length; i++) {118 if ($rootScope.newfile[i].ChurchName.startsWith('M')) {119 $scope.data.push($rootScope.newfile[i]);120 }121 }122 };123 $scope.norder = function() {124 $scope.data = [];125 for (var i = 0; i < $rootScope.newfile.length; i++) {126 if ($rootScope.newfile[i].ChurchName.startsWith('N')) {127 $scope.data.push($rootScope.newfile[i]);128 }129 }130 };131 $scope.oorder = function() {132 $scope.data = [];133 for (var i = 0; i < $rootScope.newfile.length; i++) {134 if ($rootScope.newfile[i].ChurchName.startsWith('O')) {135 $scope.data.push($rootScope.newfile[i]);136 }137 }138 };139 $scope.porder = function() {140 $scope.data = [];141 for (var i = 0; i < $rootScope.newfile.length; i++) {142 if ($rootScope.newfile[i].ChurchName.startsWith('P')) {143 $scope.data.push($rootScope.newfile[i]);144 }145 }146 };147 $scope.qorder = function() {148 $scope.data = [];149 for (var i = 0; i < $rootScope.newfile.length; i++) {150 if ($rootScope.newfile[i].ChurchName.startsWith('Q')) {151 $scope.data.push($rootScope.newfile[i]);152 }153 }154 };155 $scope.rorder = function() {156 $scope.data = [];157 for (var i = 0; i < $rootScope.newfile.length; i++) {158 if ($rootScope.newfile[i].ChurchName.startsWith('R')) {159 $scope.data.push($rootScope.newfile[i]);160 }161 }162 };163 $scope.sorder = function() {164 $scope.data = [];165 for (var i = 0; i < $rootScope.newfile.length; i++) {166 if ($rootScope.newfile[i].ChurchName.startsWith('S')) {167 $scope.data.push($rootScope.newfile[i]);168 }169 }170 };171 $scope.torder = function() {172 $scope.data = [];173 for (var i = 0; i < $rootScope.newfile.length; i++) {174 if ($rootScope.newfile[i].ChurchName.startsWith('T')) {175 $scope.data.push($rootScope.newfile[i]);176 }177 }178 };179 $scope.uorder = function() {180 $scope.data = [];181 for (var i = 0; i < $rootScope.newfile.length; i++) {182 if ($rootScope.newfile[i].ChurchName.startsWith('U')) {183 $scope.data.push($rootScope.newfile[i]);184 }185 }186 };187 $scope.vorder = function() {188 $scope.data = [];189 for (var i = 0; i < $rootScope.newfile.length; i++) {190 if ($rootScope.newfile[i].ChurchName.startsWith('V')) {191 $scope.data.push($rootScope.newfile[i]);192 }193 }194 };195 $scope.worder = function() {196 $scope.data = [];197 for (var i = 0; i < $rootScope.newfile.length; i++) {198 if ($rootScope.newfile[i].ChurchName.startsWith('W')) {199 $scope.data.push($rootScope.newfile[i]);200 }201 }202 };203 $scope.xorder = function() {204 $scope.data = [];205 for (var i = 0; i < $rootScope.newfile.length; i++) {206 if ($rootScope.newfile[i].ChurchName.startsWith('X')) {207 $scope.data.push($rootScope.newfile[i]);208 }209 }210 };211 $scope.yorder = function() {212 $scope.data = [];213 for (var i = 0; i < $rootScope.newfile.length; i++) {214 if ($rootScope.newfile[i].ChurchName.startsWith('Y')) {215 $scope.data.push($rootScope.newfile[i]);216 }217 }218 };219 $scope.zorder = function() {220 $scope.data = [];221 for (var i = 0; i < $rootScope.newfile.length; i++) {222 if ($rootScope.newfile[i].ChurchName.startsWith('Z')) {223 $scope.data.push($rootScope.newfile[i]);224 }225 }226 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2import { Test } from './test';3describe('Test', () => {4 let mock: Test;5 beforeEach(() => {6 mock = createMock<Test>();7 });8 it('should do something', () => {9 });10});11import { createMock } from 'ts-auto-mock';12import { Test } from './test';13describe('Test', () => {14 let mock: Test;15 beforeEach(() => {16 mock = createMock<Test>();17 });18 it('should do something', () => {19 });20});21import { createMock } from 'ts-auto-mock';22import { Test } from './test';23describe('Test', () => {24 let mock: Test;25 beforeEach(() => {26 mock = createMock<Test>();27 });28 it('should do something', () => {29 });30 it('should do something else', () => {31 });32});33import { create

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2import { mockImport } from 'ts-mock-imports';3import { mock, instance, when, anything, anyString, anythingOfClass, deepEqual, verify, anyNumber, anyOfClass, anyFunction, anyBoolean, anyArray, anyString as anyString1, anyObject, anyString as anyString2 } from 'ts-mockito';4import { mock, instance, when, anything, anyString, anythingOfClass, deepEqual, verify, anyNumber, anyOfClass, anyFunction, anyBoolean, anyArray, anyString as anyString1, anyObject, anyString as anyString2 } from 'ts-mockito/lib/ts-mockito-jest';5import { mock, instance, when, anything, anyString, anythingOfClass, deepEqual, verify, anyNumber, anyOfClass, anyFunction, anyBoolean, anyArray, anyString as anyString1, anyObject, anyString as anyString2 } from 'ts-mockito/lib/ts-mockito-sinon';6import { mock, instance, when, anything, anyString, anythingOfClass, deepEqual, verify, anyNumber, anyOfClass, anyFunction, anyBoolean, anyArray, anyString as anyString1, anyObject, anyString as anyString2 } from 'ts-mockito/lib/ts-mockito-jasmine';7import { mock, instance, when, anything, anyString, anythingOfClass, deepEqual, verify, anyNumber, anyOfClass, anyFunction, anyBoolean, anyArray, anyString as anyString1, anyObject, anyString as anyString2 } from 'ts-mockito/lib/ts-mockito-mocha';8import { mock, instance, when, anything, anyString, anythingOfClass, deepEqual, verify, anyNumber, anyOfClass, anyFunction, anyBoolean, anyArray, anyString as anyString1, anyObject, anyString as anyString2 } from 'ts-mockito/lib/ts-mockito-jest-s

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2import { MyInterface } from './MyInterface';3const myMock: MyInterface = createMock<MyInterface>();4import { createMock } from 'ts-auto-mock';5import { MyInterface } from './MyInterface';6const myMock: MyInterface = createMock<MyInterface>();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2let mock = createMock<Interface>();3mock.method();4mock.property;5import { createMock } from 'ts-auto-mock';6let mock = createMock<Interface>();7mock.method();8mock.property;9import { createMock } from 'ts-auto-mock';10let mock = createMock<Interface>();11mock.method();12mock.property;13import { createMock } from 'ts-auto-mock';14let mock = createMock<Interface>();15mock.method();16mock.property;17import { createMock } from 'ts-auto-mock';18let mock = createMock<Interface>();19mock.method();20mock.property;21import { createMock } from 'ts-auto-mock';22let mock = createMock<Interface>();23mock.method();24mock.property;25import { createMock } from 'ts-auto-mock';26let mock = createMock<Interface>();27mock.method();28mock.property;29import { createMock } from 'ts-auto-mock';30let mock = createMock<Interface>();31mock.method();32mock.property;33import { createMock } from 'ts-auto-mock';34let mock = createMock<Interface>();35mock.method();36mock.property;37import { createMock } from 'ts-auto-mock';38let mock = createMock<Interface>();39mock.method();40mock.property;41import { createMock } from 'ts-auto-mock';42let mock = createMock<Interface>();43mock.method();44mock.property;45import { create

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ts-auto-mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful