How to use objType.is method in unexpected

Best JavaScript code snippet using unexpected

runtime.js

Source:runtime.js Github

copy

Full Screen

1// ECMAScript 5 strict mode2"use strict";3assert2(cr, "cr namespace not created");4assert2(cr.plugins_, "cr.plugins_ not created");5/////////////////////////////////////6// Plugin class7cr.plugins_.Rex_gInstGroup = function (runtime) {8 this.runtime = runtime;9};10(function () {11 var pluginProto = cr.plugins_.Rex_gInstGroup.prototype;12 /////////////////////////////////////13 // Object type class14 pluginProto.Type = function (plugin) {15 this.plugin = plugin;16 this.runtime = plugin.runtime;17 };18 var typeProto = pluginProto.Type.prototype;19 typeProto.onCreate = function () {};20 /////////////////////////////////////21 // Instance class22 pluginProto.Instance = function (type) {23 this.type = type;24 this.runtime = type.runtime;25 };26 var instanceProto = pluginProto.Instance.prototype;27 var _uids = []; // private global object 28 instanceProto.onCreate = function () {29 this.check_name = "INSTGROUP";30 this.groups = {};31 this.randomGen = null;32 this.randomGenUid = -1; // for loading33 this.mapUID = 0;34 this.cmpUIDA = 0;35 this.cmpUIDB = 0;36 this.mapFnName = "";37 this.sortFnName = "";38 this.mappingResult = 0;39 this.cmpResult = 0;40 this.foreachItem = {};41 this.foreachIndex = {};42 this.privateGroupName = {};43 // Need to know if pinned object gets destroyed44 if (!this.recycled) {45 this.myDestroyCallback = (function (self) {46 return function (inst) {47 self.onInstanceDestroyed(inst);48 };49 })(this);50 }51 this.runtime.addDestroyCallback(this.myDestroyCallback);52 };53 instanceProto.onDestroy = function () {54 this.runtime.removeDestroyCallback(this.myDestroyCallback);55 };56 instanceProto.onInstanceDestroyed = function (inst) {57 // auto remove uid from groups58 var uid = inst.uid;59 var name;60 var groups = this.groups;61 for (name in groups)62 groups[name].RemoveUID(uid);63 this.removePrivateGroup(uid);64 };65 var PGPrefix = "@";66 var PGPostfix = "$";67 var getUIDOfPrivateGroup = function (name) {68 if (name.charAt(0) != PGPrefix)69 return (-1);70 var index = name.indexOf(PGPostfix);71 if (index == (-1))72 return (-1);73 var uid = parseInt(name.substring(1, index));74 return uid;75 };76 instanceProto.appendPrivateGroup = function (name) {77 var uid = getUIDOfPrivateGroup(name);78 if (uid == (-1))79 return;80 var nameList = this.privateGroupName[uid];81 if (nameList == null) {82 nameList = [name];83 this.privateGroupName[uid] = nameList;84 } else85 nameList.push(name);86 };87 instanceProto.removePrivateGroup = function (uid) {88 var nameList = this.privateGroupName[uid];89 if (nameList == null)90 return;91 var listLen = nameList.length;92 var i;93 for (i = 0; i < listLen; i++)94 this.DestroyGroup(nameList[i]);95 delete this.privateGroupName[uid];96 };97 instanceProto.GetGroup = function (name) {98 var group = this.groups[name];99 if (group == null) {100 group = new window.RexC2GroupKlass();101 this.groups[name] = group;102 this.appendPrivateGroup(name);103 }104 return group;105 };106 instanceProto.HasGroup = function (name) {107 return this.groups.hasOwnProperty(name);108 };109 instanceProto.DestroyGroup = function (name) {110 if (this.HasGroup(name))111 delete this.groups[name];112 };113 instanceProto.all2string = function () {114 var strings = {};115 var name;116 var groups = this.groups;117 for (name in groups)118 strings[name] = groups[name].ToString();119 return JSON.stringify(strings);120 };121 instanceProto.getGroupAB = function (groupA, groupB, groupResult) {122 if ((groupA != groupResult) && (groupB != groupResult)) {123 this.GetGroup(groupResult).Copy(this.GetGroup(groupA));124 groupA = groupResult;125 } else if (groupResult == groupB) {126 groupB = groupA;127 groupA = groupResult;128 }129 return {130 "a": groupA,131 "b": groupB132 };133 };134 instanceProto.uid2Inst = function (uid, objtype) {135 var inst = this.runtime.getObjectByUID(uid);136 if (inst == null)137 return null;138 if ((objtype == null) || (inst.type == objtype))139 return inst;140 else if (objtype.is_family) {141 var families = inst.type.families;142 var cnt = families.length,143 i;144 for (i = 0; i < cnt; i++) {145 if (objtype == families[i])146 return inst;147 }148 }149 // objtype mismatch150 return null;151 };152 instanceProto.PickUIDs = function (uids, objType) {153 if (!objType)154 return false;155 return window.RexC2PickUIDs.call(this, uids, objType);156 };157 instanceProto.callMapFunction = function (fnName, uid) {158 this.mapFnName = fnName;159 this.mappingResult = 0;160 this.mapUID = uid;161 this.runtime.trigger(cr.plugins_.Rex_gInstGroup.prototype.cnds.OnMappingFn, this, fnName);162 return this.mappingResult;163 };164 instanceProto.group2insts = function (name, objtype, isPop) {165 var group = this.GetGroup(name);166 var uidList = group.GetList();167 var i, cnt = uidList.length;168 for (i = 0; i < cnt; i++) {169 _uids.push(uidList[i]);170 }171 var hasInst = this.PickUIDs(_uids, objtype);172 if (isPop == 1) {173 for (i = 0; i < cnt; i++)174 group.RemoveUID(_uids[i]);175 }176 _uids.length = 0;177 return hasInst;178 };179 instanceProto.popInstance = function (name, index, objtype, isPop) {180 var group = this.GetGroup(name);181 var uidList = group.GetList();182 var uid = uidList[index];183 _uids.push(uid);184 // output 185 var hasInst = this.PickUIDs(_uids, objtype);186 if (isPop == 1) {187 group.RemoveUID(uid);188 }189 _uids.length = 0;190 return hasInst;191 };192 instanceProto.popInstanceByMapFn = function (name, objtype, isPop, mapFnName, resultType) {193 var group = this.GetGroup(name);194 var uidList = group.GetList();195 var i, cnt = uidList.length;196 var result = null,197 val;198 var isMax = (resultType === 1);199 var uid = -1,200 isUpdated;201 for (i = 0; i < cnt; i++) {202 val = this.callMapFunction(mapFnName, uidList[i]);203 isUpdated = (result === null) ||204 (!isMax && (result > val)) ||205 (isMax && (result < val));206 if (isUpdated) {207 result = val;208 uid = uidList[i];209 }210 }211 _uids.push(uid);212 // output 213 var hasInst = this.PickUIDs(_uids, objtype);214 if (isPop == 1) {215 group.RemoveUID(uid);216 }217 _uids.length = 0;218 return hasInst;219 };220 instanceProto.saveToJSON = function () {221 var info = {};222 var name;223 var groups = this.groups;224 for (name in groups)225 info[name] = groups[name].GetList();226 var randomGenUid = (this.randomGen != null) ? this.randomGen.uid : (-1);227 return {228 "d": info,229 "randomuid": randomGenUid230 };231 };232 instanceProto.loadFromJSON = function (o) {233 var info = o["d"];234 var name, group;235 for (name in info)236 this.GetGroup(name).SetByUIDList(info[name]);237 this.randomGenUid = o["randomuid"];238 };239 instanceProto.afterLoad = function () {240 if (this.randomGenUid === -1)241 this.randomGen = null;242 else {243 this.randomGen = this.runtime.getObjectByUID(this.randomGenUid);244 assert2(this.randomGen, "Instance group: Failed to find random gen object by UID");245 }246 this.randomGenUid = -1;247 };248 /**BEGIN-PREVIEWONLY**/249 instanceProto.getDebuggerValues = function (propsections) {250 var prop = [];251 var groups = this.groups,252 groupName;253 var uid, uids, inst;254 var types = {},255 typeName, s;256 for (groupName in groups) {257 // clean types258 for (typeName in types) {259 delete types[typeName];260 }261 uids = groups[groupName].GetSet();262 for (uid in uids) {263 inst = this.runtime.getObjectByUID(uid);264 if (inst == null)265 continue;266 typeName = inst.type.name;267 if (typeName in types)268 types[typeName] += 1;269 else270 types[typeName] = 1;271 }272 s = "";273 for (typeName in types)274 s += typeName.toString() + ":" + types[typeName].toString() + " ";275 prop.push({276 "name": groupName,277 "value": s278 });279 }280 propsections.push({281 "title": this.type.name,282 "properties": prop283 });284 };285 /**END-PREVIEWONLY**/286 //////////////////////////////////////287 // Conditions288 function Cnds() {};289 pluginProto.cnds = new Cnds();290 Cnds.prototype.OnMappingFn = function (name) {291 return (this.mapFnName === name);292 };293 Cnds.prototype.OnSortingFn = function (name) {294 return (this.sortFnName === name);295 };296 Cnds.prototype.ForEachUID = function (var_name, name) {297 var uids = this.GetGroup(name).GetList();298 var uids_len = uids.length;299 var i;300 var current_event = this.runtime.getCurrentEventStack().current_event;301 for (i = 0; i < uids_len; i++) {302 this.foreachItem[var_name] = uids[i];303 this.foreachIndex[var_name] = i;304 this.runtime.pushCopySol(current_event.solModifiers);305 current_event.retrigger();306 this.runtime.popSol(current_event.solModifiers);307 }308 return false;309 };310 Cnds.prototype.Group2Insts = function (name, objtype, isPop) {311 if (!objtype)312 return;313 return this.group2insts(name, objtype, isPop);314 };315 Cnds.prototype.IsInGroup = function (uid, name) {316 return this.GetGroup(name).IsInGroup(uid);317 };318 Cnds.prototype.IsEmpty = function (name) {319 return (this.GetGroup(name).GetList().length == 0);320 };321 Cnds.prototype.PopInst = function (name, index, objtype, isPop) {322 if (!objtype)323 return;324 return this.popInstance(name, index, objtype, isPop);325 };326 Cnds.prototype.IsSubset = function (subset_name, main_name) {327 var main_group = this.GetGroup(main_name);328 var subsetGroup = this.GetGroup(subset_name);329 return main_group.IsSubset(subsetGroup);330 };331 Cnds.prototype.RandomPopInstance = function (name, objtype, isPop) {332 if (!objtype)333 return;334 var index = Math.floor(Math.random() * this.GetGroup(name).GetList().length);335 return this.popInstance(name, index, objtype, isPop);336 };337 Cnds.prototype.PopInstByMappingFunction = function (name, objtype, isPop, mapFnName, resultType) {338 if (!objtype)339 return;340 return this.popInstanceByMapFn(name, objtype, isPop, mapFnName, resultType);341 };342 //////////////////////////////////////343 // Actions344 function Acts() {};345 pluginProto.acts = new Acts();346 Acts.prototype.DestroyAll = function () {347 var name;348 for (name in this.groups)349 delete this.groups[name];350 };351 Acts.prototype.Clean = function (name) {352 this.GetGroup(name).Clean();353 };354 Acts.prototype.DestroyGroup = function (name) {355 this.DestroyGroup(name);356 };357 Acts.prototype.Copy = function (source, target) {358 if (source == target)359 return;360 this.GetGroup(target).Copy(this.GetGroup(source));361 };362 Acts.prototype.String2Group = function (JSONString, name) {363 this.GetGroup(name).JSONString2Group(JSONString);364 };365 Acts.prototype.String2All = function (JSONString) {366 var groups = JSON.parse(JSONString);367 var name;368 for (name in groups)369 this.GetGroup(name).JSONString2Group(groups[name]);370 };371 Acts.prototype.AddInsts = function (objtype, name) {372 if (!objtype)373 return;374 var insts = objtype.getCurrentSol().getObjects();375 var cnt = insts.length;376 if (cnt == 1)377 this.GetGroup(name).AddUID(insts[0].uid);378 else {379 var i, uids = [];380 uids.length = insts.length;381 for (i = 0; i < cnt; i++)382 uids[i] = insts[i].uid;383 this.GetGroup(name).AddUID(uids);384 }385 };386 Acts.prototype.AddInstByUID = function (uid, name) {387 this.GetGroup(name).AddUID(uid);388 };389 Acts.prototype.RemoveInsts = function (objtype, name) {390 if (!objtype)391 return;392 var insts = objtype.getCurrentSol().getObjects();393 var cnt = insts.length;394 if (cnt == 1)395 this.GetGroup(name).RemoveUID(insts[0].uid);396 else {397 var i, uids = [];398 uids.length = insts.length;399 for (i = 0; i < cnt; i++)400 uids[i] = insts[i].uid;401 this.GetGroup(name).RemoveUID(uids);402 }403 };404 Acts.prototype.RemoveInst = function (uid, name) {405 this.GetGroup(name).RemoveUID(uid);406 };407 Acts.prototype.Union = function (groupA, groupB, groupResult) {408 var groups = this.getGroupAB(groupA, groupB, groupResult);409 this.GetGroup(groups["a"]).Union(this.GetGroup(groups["b"]));410 };411 Acts.prototype.Complement = function (groupA, groupB, groupResult) {412 var groups = this.getGroupAB(groupA, groupB, groupResult);413 this.GetGroup(groups["a"]).Complement(this.GetGroup(groups["b"]));414 };415 Acts.prototype.Intersection = function (groupA, groupB, groupResult) {416 var groups = this.getGroupAB(groupA, groupB, groupResult);417 this.GetGroup(groups["a"]).Intersection(this.GetGroup(groups["b"]));418 };419 Acts.prototype.Shuffle = function (name) {420 this.GetGroup(name).Shuffle(this.randomGen);421 };422 Acts.prototype.SortByFn = function (name, fnName) {423 var uidList = this.GetGroup(name).GetList();424 var self = this;425 uidList.sort(function (uidA, uidB) {426 self.cmpUIDA = uidA;427 self.cmpUIDB = uidB;428 self.cmpResult = 0;429 self.runtime.trigger(cr.plugins_.Rex_gInstGroup.prototype.cnds.OnSortingFn, self, fnName);430 return self.cmpResult;431 });432 };433 Acts.prototype.SetCmpResultDirectly = function (result) {434 this.cmpResult = result;435 };436 Acts.prototype.SetCmpResultCombo = function (result) {437 this.cmpResult = result - 1;438 };439 Acts.prototype.Group2Insts = function (name, objtype, isPop) {440 if (!objtype)441 return;442 this.group2insts(name, objtype, isPop);443 };444 Acts.prototype.SortByUID = function (name, method) {445 var uidList = this.GetGroup(name).GetList();446 uidList.sort();447 if (method === 0)448 uidList.reverse();449 };450 // deprecated451 Acts.prototype.SortByUIDDec = function (name) {452 this.GetGroup(name).GetList().sort().reverse();453 };454 Acts.prototype.Reverse = function (name) {455 this.GetGroup(name).GetList().reverse();456 };457 Acts.prototype.Slice = function (source, start, end, target, isPop) {458 var sourceGroup = this.GetGroup(source);459 var targetGroup = this.GetGroup(target);460 var _list = sourceGroup.GetList().slice(start, end);461 targetGroup.SetByUIDList(_list);462 if (isPop == 1)463 sourceGroup.Complement(targetGroup);464 };465 Acts.prototype.PopInst = function (name, index, objtype, isPop) {466 if (!objtype)467 return;468 this.popInstance(name, index, objtype, isPop);469 };470 Acts.prototype.SetRandomGenerator = function (objType) {471 var randomGen = objType.getFirstPicked();472 if (randomGen.check_name == "RANDOM")473 this.randomGen = randomGen;474 else475 alert("[Instance group] This object is not a random generator object.");476 };477 Acts.prototype.PushInsts = function (isFront, objtype, name) {478 if (!objtype)479 return;480 var insts = objtype.getCurrentSol().getObjects();481 var cnt = insts.length;482 if (cnt == 1)483 this.GetGroup(name).PushUID(isFront, insts[0].uid);484 else {485 var i, uids = [];486 uids.length = insts.length;487 for (i = 0; i < cnt; i++)488 uids[i] = insts[i].uid;489 this.GetGroup(name).PushUID(uids, isFront);490 }491 };492 Acts.prototype.PushInstByUID = function (isFront, uid, name) {493 this.GetGroup(name).PushUID(uid, isFront);494 };495 Acts.prototype.InsertInsts = function (objtype, name, index) {496 if (!objtype)497 return;498 var insts = objtype.getCurrentSol().getObjects();499 var cnt = insts.length;500 if (cnt == 1)501 this.GetGroup(name).InsertUID(insts[0].uid, index);502 else {503 var i, uids = [];504 uids.length = insts.length;505 for (i = 0; i < cnt; i++)506 uids[i] = insts[i].uid;507 this.GetGroup(name).InsertUID(uids, index);508 }509 };510 Acts.prototype.InsertInstByUID = function (uid, name, index) {511 this.GetGroup(name).InsertUID(uid, index);512 };513 Acts.prototype.CleanAdddInsts = function (objtype, name) {514 cr.plugins_.Rex_gInstGroup.prototype.acts.Clean.call(this, name);515 cr.plugins_.Rex_gInstGroup.prototype.acts.AddInsts.call(this, objtype, name);516 };517 Acts.prototype.CleanAdddInstByUID = function (uid, name) {518 cr.plugins_.Rex_gInstGroup.prototype.acts.Clean.call(this, name);519 cr.plugins_.Rex_gInstGroup.prototype.acts.AddInstByUID.call(this, uid, name);520 };521 Acts.prototype.RandomPopInstance = function (name, objtype, isPop) {522 if (!objtype)523 return;524 var index = Math.floor(Math.random() * this.GetGroup(name).GetList().length);525 return this.popInstance(name, index, objtype, isPop);526 };527 Acts.prototype.SetMappingResult = function (val) {528 this.mappingResult = val;529 };530 Acts.prototype.PopInstByMappingFunction = function (name, objtype, isPop, mapFnName, resultType) {531 if (!objtype)532 return;533 return this.popInstanceByMapFn(name, objtype, isPop, mapFnName, resultType);534 };535 Acts.prototype.SortByMappingFunction = function (name, fnName, method_) {536 var uidList = this.GetGroup(name).GetList();537 var self = this;538 var uid2result = {};539 uidList.sort(function (uidA, uidB) {540 if (!uid2result.hasOwnProperty(uidA))541 uid2result[uidA] = self.callMapFunction(fnName, uidA);542 if (!uid2result.hasOwnProperty(uidB))543 uid2result[uidB] = self.callMapFunction(fnName, uidB);544 var method = method_;545 var valA = uid2result[uidA];546 var valB = uid2result[uidB];547 if (method >= 2) {548 valA = parseFloat(valA);549 valB = parseFloat(valB);550 method -= 2;551 }552 if (valA === valB)553 return 0;554 else if (valA > valB) {555 if (method === 1)556 return 1;557 else558 return -1;559 } else {560 if (method === 1)561 return -1;562 else563 return 1;564 }565 });566 };567 Acts.prototype.DestroyInstanceInGroup = function (name) {568 if (!this.HasGroup(name))569 return;570 var uids = this.GetGroup(name).GetList();571 var i, cnt = uids.length,572 inst;573 for (i = 0; i < cnt; i++) {574 inst = this.uid2Inst(uids[i]);575 if (inst)576 this.runtime.DestroyInstance(inst);577 }578 };579 //////////////////////////////////////580 // Expressions581 function Exps() {};582 pluginProto.exps = new Exps();583 Exps.prototype.MapUID = function (ret) {584 ret.set_any(this.mapUID);585 };586 Exps.prototype.CmpUIDA = function (ret) {587 ret.set_any(this.cmpUIDA);588 };589 Exps.prototype.CmpUIDB = function (ret) {590 ret.set_any(this.cmpUIDB);591 };592 Exps.prototype.InstCnt = function (ret, name) {593 ret.set_int(this.GetGroup(name).GetList().length);594 };595 Exps.prototype.UID2Index = function (ret, name, uid) {596 ret.set_int(this.GetGroup(name).UID2Index(uid));597 };598 Exps.prototype.Index2UID = function (ret, name, index) {599 ret.set_any(this.GetGroup(name).Index2UID(index));600 };601 Exps.prototype.Item = function (ret, var_name) {602 var item = this.foreachItem[var_name];603 if (item == null)604 item = (-1);605 ret.set_any(item);606 };607 Exps.prototype.Index = function (ret, var_name) {608 var index = this.foreachIndex[var_name];609 if (index == null)610 index = (-1);611 ret.set_int(index);612 };613 Exps.prototype.GroupToString = function (ret, name) {614 ret.set_string(this.GetGroup(name).ToString());615 };616 Exps.prototype.AllToString = function (ret) {617 ret.set_string(this.all2string());618 };619 Exps.prototype.PrivateGroup = function (ret, uid, name) {620 ret.set_string(PGPrefix + uid.toString() + PGPostfix + name);621 };622 Exps.prototype.Pop = function (ret, name, index) {623 ret.set_any(this.GetGroup(name).Pop(index));624 };625 Exps.prototype.FirstUID = function (ret, name) {626 ret.set_any(this.GetGroup(name).Index2UID(0));627 };628 Exps.prototype.LastUID = function (ret, name) {629 var uidList = this.GetGroup(name).GetList();630 var index = uidList.length - 1;631 var uid = uidList[index];632 if (uid == null) {633 uid = -1;634 }635 ret.set_any(uid);636 };637 Exps.prototype.RandomIndex = function (ret, name) {638 var index = Math.floor(Math.random() * this.GetGroup(name).GetList().length);639 ret.set_int(index);640 };641 Exps.prototype.RandomIndex2UID = function (ret, name) {642 var group = this.GetGroup(name);643 var index = Math.floor(Math.random() * group.GetList().length);644 ret.set_any(group.Index2UID(index));645 };646 Exps.prototype.RandomPop = function (ret, name) {647 var index = Math.floor(Math.random() * this.GetGroup(name).GetList().length);648 ret.set_any(this.GetGroup(name).Pop(index));649 };650}());651(function () {652 // general pick instances function653 if (window.RexC2PickUIDs != null)654 return;655 var _uidmap = {};656 var PickUIDs = function (uids, objtype, checkCb) {657 var sol = objtype.getCurrentSol();658 sol.instances.length = 0;659 sol.select_all = false;660 var isFamily = objtype.is_family;661 var members, memberCnt, i;662 if (isFamily) {663 members = objtype.members;664 memberCnt = members.length;665 }666 var i, j, uid_cnt = uids.length;667 for (i = 0; i < uid_cnt; i++) {668 var uid = uids[i];669 if (uid == null)670 continue;671 if (_uidmap.hasOwnProperty(uid))672 continue;673 _uidmap[uid] = true;674 var inst = this.runtime.getObjectByUID(uid);675 if (inst == null)676 continue;677 if ((checkCb != null) && (!checkCb(uid)))678 continue;679 var typeName = inst.type.name;680 if (isFamily) {681 for (j = 0; j < memberCnt; j++) {682 if (typeName == members[j].name) {683 sol.instances.push(inst);684 break;685 }686 }687 } else {688 if (typeName == objtype.name) {689 sol.instances.push(inst);690 }691 }692 }693 objtype.applySolToContainer();694 for (var k in _uidmap)695 delete _uidmap[k];696 return (sol.instances.length > 0);697 };698 window.RexC2PickUIDs = PickUIDs;699}());700(function () {701 // general group class702 if (window.RexC2GroupKlass != null)703 return;704 var GroupKlass = function () {705 this._set = {};706 this._list = [];707 };708 var GroupKlassProto = GroupKlass.prototype;709 GroupKlassProto.Clean = function () {710 var key;711 for (key in this._set)712 delete this._set[key];713 this._list.length = 0;714 return this;715 };716 GroupKlassProto.Copy = function (group) {717 var key, table;718 table = this._set;719 for (key in table)720 delete this._set[key];721 table = group._set;722 for (key in table)723 this._set[key] = table[key];724 cr.shallowAssignArray(this._list, group._list);725 return this;726 };727 GroupKlassProto.SetByUIDList = function (uidList, can_repeat) {728 if (can_repeat) // special case729 {730 cr.shallowAssignArray(this._list, uidList);731 var listLen = uidList.length;732 var i, key, table;733 table = this._set;734 for (key in table)735 delete this._set[key];736 for (i = 0; i < listLen; i++)737 this._set[uidList[i]] = true;738 } else {739 this.Clean();740 this.AddUID(uidList);741 }742 return this;743 };744 GroupKlassProto.AddUID = function (_uid) // single number, number list745 {746 if (typeof (_uid) === "object") // uid list 747 {748 var i, uid, cnt = _uid.length;749 for (i = 0; i < cnt; i++) {750 uid = _uid[i];751 if (this._set[uid] == null) // not in group752 {753 this._set[uid] = true;754 this._list.push(uid); // push back755 }756 // else ingored 757 }758 } else // single number759 {760 if (this._set[_uid] == null) // not in group761 {762 this._set[_uid] = true;763 this._list.push(_uid); // push back764 }765 // else ingored 766 }767 return this;768 };769 GroupKlassProto.PushUID = function (_uid, isFront) // single number, number list770 {771 if (typeof (_uid) === "object") // uid list 772 {773 var i, uid, cnt = _uid.length;774 for (i = 0; i < cnt; i++) {775 uid = _uid[i];776 if (this._set[uid] == null)777 this._set[uid] = true;778 else // remove existed item in this._list779 cr.arrayRemove(this._list, this._list.indexOf(uid));780 }781 // add uid ( no repeating check )782 if (isFront)783 this._list.unshift.apply(this._list, _uid); // push front784 else785 this._list.push.apply(this._list, _uid); // push back 786 } else // single number787 {788 if (this._set[_uid] == null)789 this._set[_uid] = true;790 else // remove existed item in this._list791 cr.arrayRemove(this._list, this._list.indexOf(_uid));792 // add uid793 if (isFront)794 this._list.unshift(_uid); // push front795 else796 this._list.push(_uid); // push back 797 }798 return this;799 };800 GroupKlassProto.InsertUID = function (_uid, index) // single number, number list801 {802 if (typeof (_uid) === "object") // uid list 803 {804 var i, uid, cnt = _uid.length;805 for (i = 0; i < cnt; i++) {806 uid = _uid[i];807 if (this._set[uid] == null)808 this._set[uid] = true;809 else // remove existed item in this._list810 cr.arrayRemove(this._list, this._list.indexOf(uid));811 }812 // add uid ( no repeating check )813 arrayInsert(this._list, _uid, index)814 } else // single number815 {816 if (this._set[_uid] == null)817 this._set[_uid] = true;818 else // remove existed item in this._list819 cr.arrayRemove(this._list, this._list.indexOf(_uid));820 arrayInsert(this._list, _uid, index)821 }822 return this;823 };824 GroupKlassProto.RemoveUID = function (_uid) // single number, number list825 {826 if (typeof (_uid) === "object") // uid list 827 {828 var i, uid, cnt = _uid.length;829 for (i = 0; i < cnt; i++) {830 uid = _uid[i];831 if (this._set[uid] != null) {832 delete this._set[uid];833 cr.arrayRemove(this._list, this._list.indexOf(uid));834 }835 // else ingored 836 }837 } else // single number838 {839 if (this._set[_uid] != null) {840 delete this._set[_uid];841 cr.arrayRemove(this._list, this._list.indexOf(_uid));842 }843 }844 return this;845 };846 GroupKlassProto.UID2Index = function (uid) {847 return this._list.indexOf(uid);848 };849 GroupKlassProto.Index2UID = function (index) {850 var _list = this._list;851 var uid = _list[index];852 if (uid == null)853 uid = -1;854 return uid;855 };856 GroupKlassProto.Pop = function (index) {857 var _list = this._list;858 if (index < 0)859 index = _list.length + index;860 var uid = _list[index];861 if (uid == null)862 uid = -1;863 else864 this.RemoveUID(uid);865 return uid;866 };867 GroupKlassProto.Union = function (group) {868 var uids = group._set;869 var uid;870 for (uid in uids)871 this.AddUID(parseInt(uid));872 return this;873 };874 GroupKlassProto.Complement = function (group) {875 this.RemoveUID(group._list);876 return this;877 };878 GroupKlassProto.Intersection = function (group) {879 // copy this._set880 var uid, uids = this._set;881 var flags = {};882 for (uid in uids)883 flags[uid] = true;884 // clean all885 this.Clean();886 // add intersection itme887 uids = group._set;888 for (uid in uids) {889 if (flags[uid] != null)890 this.AddUID(parseInt(uid));891 }892 return this;893 };894 GroupKlassProto.IsSubset = function (subsetGroup) {895 var subsetUIDs = subsetGroup._set;896 var uid;897 var isSubset = true;898 for (uid in subsetUIDs) {899 if (!(uid in this._set)) {900 isSubset = false;901 break;902 }903 }904 return isSubset;905 };906 GroupKlassProto.GetSet = function () {907 return this._set;908 };909 GroupKlassProto.GetList = function () {910 return this._list;911 };912 GroupKlassProto.IsInGroup = function (uid) {913 return (this._set[uid] != null);914 };915 GroupKlassProto.ToString = function () {916 return JSON.stringify(this._list);917 };918 GroupKlassProto.JSONString2Group = function (JSONString) {919 this.SetByUIDList(JSON.parse(JSONString));920 };921 GroupKlassProto.Shuffle = function (randomGen) {922 _shuffle(this._list, randomGen);923 };924 var _shuffle = function (arr, randomGen) {925 if (randomGen == null)926 randomGen = Math;927 var i = arr.length, j, temp;928 if (i == 0) return;929 while (--i) {930 j = Math.floor(randomGen.random() * (i + 1));931 temp = arr[i];932 arr[i] = arr[j];933 arr[j] = temp;934 }935 };936 var arrayInsert = function (arr, _value, index) {937 var arrLen = arr.length;938 if (index > arrLen)939 index = arrLen;940 if (typeof (_value) != "object") {941 if (index == 0)942 arr.unshift(_value);943 else if (index == arrLen)944 arr.push(_value);945 else {946 var i, last_index = arr.length;947 arr.length += 1;948 for (i = last_index; i > index; i--)949 arr[i] = arr[i - 1];950 arr[index] = _value;951 }952 } else {953 if (index == 0)954 arr.unshift.apply(arr, _value);955 else if (index == arrLen)956 arr.push.apply(arr, _value);957 else {958 var start_index = arr.length - 1;959 var end_index = index;960 var cnt = _value.length;961 arr.length += cnt;962 var i;963 for (i = start_index; i >= end_index; i--)964 arr[i + cnt] = arr[i];965 for (i = 0; i < cnt; i++)966 arr[i + index] = _value[i];967 }968 }969 };970 window.RexC2GroupKlass = GroupKlass;...

Full Screen

Full Screen

actions.js

Source:actions.js Github

copy

Full Screen

1"use strict";2{3 C3.Plugins.Rex_gInstGroup.Acts =4 {5 DestroyAll() 6 {7 var name;8 for (name in this.groups)9 delete this.groups[name];10 },11 Clean(name) 12 {13 this.GetGroup(name).Clean();14 },15 DestroyGroup(name) 16 {17 this.DestroyGroup(name);18 },19 Copy(source, target) 20 {21 if (source == target)22 return;23 this.GetGroup(target).Copy(this.GetGroup(source));24 },25 String2Group(JSONString, name) 26 {27 this.GetGroup(name).JSONString2Group(JSONString);28 },29 String2All(JSONString) 30 {31 var groups = JSON.parse(JSONString);32 var name;33 for (name in groups)34 this.GetGroup(name).JSONString2Group(groups[name]);35 },36 AddInsts(objtype, name) 37 {38 if (!objtype)39 return;40 var insts = objtype.GetCurrentSol().GetInstances();41 var cnt = insts.length;42 if (cnt == 1)43 this.GetGroup(name).AddUID(insts[0].GetUID());44 else {45 var i, uids = [];46 uids.length = insts.length;47 for (i = 0; i < cnt; i++)48 uids[i] = insts[i].GetUID();49 this.GetGroup(name).AddUID(uids);50 }51 },52 AddInstByUID(uid, name) 53 {54 this.GetGroup(name).AddUID(uid);55 },56 RemoveInsts(objtype, name) 57 {58 if (!objtype)59 return;60 var insts = objtype.GetCurrentSol().GetInstances();61 var cnt = insts.length;62 if (cnt == 1)63 this.GetGroup(name).RemoveUID(insts[0].GetUID());64 else {65 var i, uids = [];66 uids.length = insts.length;67 for (i = 0; i < cnt; i++)68 uids[i] = insts[i].GetUID();69 this.GetGroup(name).RemoveUID(uids);70 }71 },72 RemoveInst(uid, name) 73 {74 this.GetGroup(name).RemoveUID(uid);75 },76 Union(groupA, groupB, groupResult) 77 {78 var groups = this.getGroupAB(groupA, groupB, groupResult);79 this.GetGroup(groups["a"]).Union(this.GetGroup(groups["b"]));80 },81 Complement(groupA, groupB, groupResult) 82 {83 var groups = this.getGroupAB(groupA, groupB, groupResult);84 this.GetGroup(groups["a"]).Complement(this.GetGroup(groups["b"]));85 },86 Intersection(groupA, groupB, groupResult) 87 {88 var groups = this.getGroupAB(groupA, groupB, groupResult);89 this.GetGroup(groups["a"]).Intersection(this.GetGroup(groups["b"]));90 },91 Shuffle(name) 92 {93 this.GetGroup(name).Shuffle(this.randomGen);94 },95 SortByFn(name, fnName) 96 {97 var uidList = this.GetGroup(name).GetList();98 var self = this;99 uidList.sort(function (uidA, uidB) {100 self.cmpUIDA = uidA;101 self.cmpUIDB = uidB;102 self.cmpResult = 0;103 self.Trigger(C3.Plugins.Rex_gInstGroup.Cnds.OnSortingFn); // dikkat self, fnName)104 return self.cmpResult;105 });106 },107 SetCmpResultDirectly(result) 108 {109 this.cmpResult = result;110 },111 SetCmpResultCombo(result) 112 {113 this.cmpResult = result - 1;114 },115 Group2Insts(name, objtype, isPop) 116 {117 if (!objtype)118 return;119 this.group2insts(name, objtype, isPop);120 },121 SortByUID(name, method) 122 {123 var uidList = this.GetGroup(name).GetList();124 uidList.sort();125 if (method === 0)126 uidList.reverse();127 },128 // deprecated129 SortByUIDDec(name) 130 {131 this.GetGroup(name).GetList().sort().reverse();132 },133 Reverse(name) 134 {135 this.GetGroup(name).GetList().reverse();136 },137 Slice(source, start, end, target, isPop) 138 {139 var sourceGroup = this.GetGroup(source);140 var targetGroup = this.GetGroup(target);141 var _list = sourceGroup.GetList().slice(start, end);142 targetGroup.SetByUIDList(_list);143 if (isPop == 1)144 sourceGroup.Complement(targetGroup);145 },146 PopInst(name, index, objtype, isPop) 147 {148 if (!objtype)149 return;150 this.popInstance(name, index, objtype, isPop);151 },152 SetRandomGenerator(objType) 153 {154 var randomGen = objType.GetFirstPicked();155 if (randomGen.check_name == "RANDOM")156 this.randomGen = randomGen;157 },158 PushInsts(isFront, objtype, name) 159 {160 if (!objtype)161 return;162 var insts = objtype.GetCurrentSol().GetInstances();163 var cnt = insts.length;164 if (cnt == 1)165 this.GetGroup(name).PushUID(isFront, insts[0].GetUID());166 else {167 var i, uids = [];168 uids.length = insts.length;169 for (i = 0; i < cnt; i++)170 uids[i] = insts[i].GetUID();171 this.GetGroup(name).PushUID(uids, isFront);172 }173 },174 PushInstByUID(isFront, uid, name) 175 {176 this.GetGroup(name).PushUID(uid, isFront);177 },178 InsertInsts(objtype, name, index) 179 {180 if (!objtype)181 return;182 var insts = objtype.GetCurrentSol().GetInstances();183 var cnt = insts.length;184 if (cnt == 1)185 this.GetGroup(name).InsertUID(insts[0].GetUID(), index);186 else {187 var i, uids = [];188 uids.length = insts.length;189 for (i = 0; i < cnt; i++)190 uids[i] = insts[i].GetUID();191 this.GetGroup(name).InsertUID(uids, index);192 }193 },194 InsertInstByUID(uid, name, index) 195 {196 this.GetGroup(name).InsertUID(uid, index);197 },198 CleanAdddInsts(objtype, name) 199 {200 C3.Plugins.Rex_gInstGroup.Acts.Clean.call(this, name);201 C3.Plugins.Rex_gInstGroup.Acts.AddInsts.call(this, objtype, name);202 },203 CleanAdddInstByUID(uid, name) 204 {205 C3.Plugins.Rex_gInstGroup.Acts.Clean.call(this, name);206 C3.Plugins.Rex_gInstGroup.Acts.AddInstByUID.call(this, uid, name);207 },208 RandomPopInstance(name, objtype, isPop) 209 {210 if (!objtype)211 return;212 var index = Math.floor(Math.random() * this.GetGroup(name).GetList().length);213 return this.popInstance(name, index, objtype, isPop);214 },215 SetMappingResult(val) 216 {217 this.mappingResult = val;218 },219 PopInstByMappingFunction(name, objtype, isPop, mapFnName, resultType) 220 {221 if (!objtype)222 return;223 return this.popInstanceByMapFn(name, objtype, isPop, mapFnName, resultType);224 },225 SortByMappingFunction(name, fnName, method_) 226 {227 var uidList = this.GetGroup(name).GetList();228 var self = this;229 var uid2result = {};230 uidList.sort(function (uidA, uidB) {231 if (!uid2result.hasOwnProperty(uidA))232 uid2result[uidA] = self.callMapFunction(fnName, uidA);233 if (!uid2result.hasOwnProperty(uidB))234 uid2result[uidB] = self.callMapFunction(fnName, uidB);235 var method = method_;236 var valA = uid2result[uidA];237 var valB = uid2result[uidB];238 if (method >= 2) {239 valA = parseFloat(valA);240 valB = parseFloat(valB);241 method -= 2;242 }243 if (valA === valB)244 return 0;245 else if (valA > valB) {246 if (method === 1)247 return 1;248 else249 return -1;250 } else {251 if (method === 1)252 return -1;253 else254 return 1;255 }256 });257 },258 DestroyInstanceInGroup(name) 259 {260 if (!this.HasGroup(name))261 return;262 var uids = this.GetGroup(name).GetList();263 var i, cnt = uids.length,264 inst;265 for (i = 0; i < cnt; i++) {266 inst = this.uid2Inst(uids[i]);267 if (inst)268 this._runtime.DestroyInstance(inst);269 }270 }271 };...

Full Screen

Full Screen

conditions.js

Source:conditions.js Github

copy

Full Screen

1"use strict";2{3 C3.Plugins.Rex_gInstGroup.Cnds =4 {5 OnMappingFn(name) 6 {7 return (this.mapFnName === name);8 },9 OnSortingFn(name) 10 {11 return (this.sortFnName === name);12 },13 ForEachUID(var_name, name) 14 {15 var uids = this.GetGroup(name).GetList();16 var uids_len = uids.length;17 var i;18 var current_frame = this._runtime.GetEventSheetManager().GetCurrentEventStackFrame();19 var current_event = current_frame.GetCurrentEvent();20 var solmod = current_event.GetSolModifiers();21 var c = this._runtime.GetEventSheetManager().GetEventStack();22 var p = this._runtime.GetEventStack(); 23 var h = c.Push(current_event);24 for (i = 0; i < uids_len; i++) 25 {26 this.foreachItem[var_name] = uids[i];27 this.foreachIndex[var_name] = i;28 this._runtime.GetEventSheetManager().PushCopySol(solmod);29 current_event.Retrigger(current_frame,h);30 this._runtime.GetEventSheetManager().PopSol(solmod);31 }32 return false;33 },34 Group2Insts(name, objtype, isPop) 35 {36 if (!objtype)37 return;38 return this.group2insts(name, objtype, isPop);39 },40 IsInGroup(uid, name) 41 {42 return this.GetGroup(name).IsInGroup(uid);43 },44 IsEmpty(name) 45 {46 return (this.GetGroup(name).GetList().length == 0);47 },48 PopInst(name, index, objtype, isPop) 49 {50 if (!objtype)51 return;52 return this.popInstance(name, index, objtype, isPop);53 },54 IsSubset(subset_name, main_name) 55 {56 var main_group = this.GetGroup(main_name);57 var subsetGroup = this.GetGroup(subset_name);58 return main_group.IsSubset(subsetGroup);59 },60 RandomPopInstance(name, objtype, isPop) 61 {62 if (!objtype)63 return;64 var index = Math.floor(Math.random() * this.GetGroup(name).GetList().length);65 return this.popInstance(name, index, objtype, isPop);66 },67 PopInstByMappingFunction(name, objtype, isPop, mapFnName, resultType) 68 {69 if (!objtype)70 return;71 return this.popInstanceByMapFn(name, objtype, isPop, mapFnName, resultType);72 }73 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const unexpected = require('unexpected');2const unexpectedObjType = require('unexpected-obj-type');3const unexpectedSinon = require('unexpected-sinon');4const expect = unexpected.clone().use(unexpectedObjType).use(unexpectedSinon);5const objType = require('obj-type');6const obj = {};7expect(obj, 'is', objType.is('object'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var objType = require('unexpected').clone().addAssertion(2 function (expect, subject, value) {3 expect(subject.constructor.name, 'to equal', value);4 }5);6var objType = require('unexpected').clone().addAssertion(7 function (expect, subject, value) {8 expect(subject.constructor.name, 'to equal', value);9 }10);11var objType = require('unexpected').clone().addAssertion(12 function (expect, subject, value) {13 expect(subject.constructor.name, 'to equal', value);14 }15);

Full Screen

Using AI Code Generation

copy

Full Screen

1var unexpected = require('unexpected');2var unexpectedObjType = require('unexpected-objtype');3var expect = unexpected.clone().use(unexpectedObjType);4describe('test', function () {5 it('test', function () {6 var obj = {a:1, b:2};7 expect(obj, 'to be an object');8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var unexpected = require('unexpected');2var objType = require('unexpected-obj-type');3var expect = unexpected.clone().use(objType);4expect('foo', 'to be a string');5expect(1, 'to be a number');6expect(true, 'to be a boolean');7expect(undefined, 'to be undefined');8expect(null, 'to be null');9expect({}, 'to be an object');10expect([], 'to be an array');11expect(new Date(), 'to be a date');12expect(/foo/, 'to be a regexp');13expect(function () {}, 'to be a function');14expect(new Error(), 'to be an error');15expect(new Buffer('foo'), 'to be a buffer');16expect(new String('foo'), 'to be a string object');17expect(new Number(1), 'to be a number object');18expect(new Boolean(true), 'to be a boolean object');19expect(new Map(), 'to be a map');20expect(new Set(), 'to be a set');21expect(new WeakMap(), 'to be a weak map');22expect(new WeakSet(), 'to be a weak set');23expect(new Promise(function () {}), 'to be a promise');24var unexpected = require('unexpected');25var objType = require('unexpected-obj-type');26var expect = unexpected.clone().use(objType);27expect('foo', 'to be a string');28expect(1, 'to be a number');29expect(true, 'to be a boolean');30expect(undefined, 'to be undefined');31expect(null, 'to be null');32expect({}, 'to be an object');33expect([], 'to be an array');34expect(new Date(), 'to be a date');35expect(/foo/, 'to be a regexp');36expect(function () {}, 'to be a function');37expect(new Error(), 'to be an error');38expect(new Buffer('foo'), 'to be a buffer');39expect(new String('foo'), 'to be a string object');40expect(new Number(1), 'to be a number object');41expect(new Boolean(true), 'to be a boolean object');42expect(new Map(), 'to be a map');43expect(new Set(), 'to be a set');44expect(new WeakMap(), 'to be a weak map');45expect(new WeakSet(), 'to be a weak set');46expect(new Promise(function () {}), 'to be a promise');

Full Screen

Using AI Code Generation

copy

Full Screen

1var objType = require('unexpected').clone().installPlugin(require('unexpected-obj-type'));2var expect = require('unexpected');3var objType = require('unexpected').clone().installPlugin(require('unexpected-obj-type'));4var expect = require('unexpected');5var testObj = {6};7expect(testObj, objType.is('object'));8expect(testObj, objType.is('object', {name: 'test'}));9expect(testObj, objType.is('object', {age: 20}));10expect(testObj, objType.is('object', {age: 20, name: 'test'}));11expect(testObj, objType.is('object', {age: 21}));12expect(testObj, objType.is('object', {name: 'test', age: 21}));13expect(testObj, objType.is('object', {name: 'test1', age: 21}));14expect(testObj, objType.is('object', {name: 'test1'}));15#### objType.is([type], [props])16MIT © [Vijay Menon](

Full Screen

Using AI Code Generation

copy

Full Screen

1const objType = require('unexpected/lib/types/object');2const expect = require('unexpected')3 .clone()4 .use(objType);5expect(6 {7 },8 {9 }10);11const objType = require('unexpected-object-type/lib/types/object');12const expect = require('unexpected-object-type')13 .clone()14 .use(objType);15expect(16 {17 },18 {19 }20);21### `objType.is(value, [options])`22MIT © [Kevin Mårtensson](

Full Screen

Using AI Code Generation

copy

Full Screen

1var objType = require('unexpected').clone().addAssertion('is', function (expect, subject, type) {2 expect(subject, 'to be a', type);3});4objType.is(obj, 'object');5var objType = require('unexpected').clone().addAssertion('is', function (expect, subject, type) {6 expect(subject, 'to be a', type);7});8objType.is(obj, Object);

Full Screen

Using AI Code Generation

copy

Full Screen

1const objType = require('unexpected/lib/types/ObjectType');2const expect = require('unexpected');3const test = require('ava');4test('test', t => {5 const actual = { a: 1 };6 const expected = { b: 1 };7 t.throws(() => {8 expect(actual, 'to satisfy', expected);9 }, (err) => {10 console.log(err);11 return true;12 });13});14AssertionError: expected { a: 1 } to satisfy { b: 1 }15 expected { a: 1 } to be an object satisfying { b: 1 }16 {17 }18 at Object.<anonymous> (/Users/ashish/Desktop/unexpected-test/test.js:14:13)19 at Generator.next (<anonymous>)20 at new Promise (<anonymous>)21 at Object.<anonymous> (/Users/ashish/Desktop/unexpected-test/test.js:2:1)22 at Module._compile (module.js:653:30)23 at Object.Module._extensions..js (module.js:664:10)24 at Module.load (module.js:566:32)25 at tryModuleLoad (module.js:506:12)26 at Function.Module._load (module.js:498:3)27 at Module.require (module.js:597:17)28 at require (internal/module.js:11:18)29 at Object.<anonymous> (/Users/ashish/Desktop/unexpected-test/node_modules/ava/lib/worker/subprocess.js:5:1)30 at Module._compile (module.js:653:30)31 at Object.Module._extensions..js (module.js:664:10)

Full Screen

Using AI Code Generation

copy

Full Screen

1const unexpected = require('unexpected');2const objType = require('unexpected-obj-type');3const expect = unexpected.clone().use(objType);4const MyType = function MyType() {};5const instance = new MyType();6expect(instance, 'to be a', MyType);7To use with [unexpected-react](

Full Screen

Using AI Code Generation

copy

Full Screen

1var unexpected = require('unexpected');2var objType = unexpected.clone();3var array = [1,2,3];4var notArray = 1;5console.log(objType.is(array, 'array'));6console.log(objType.is(notArray, 'array'));7var unexpected = require('unexpected');8var objType = unexpected.clone();9var str = 'string';10var notStr = 1;11console.log(objType.is(str, 'string'));12console.log(objType.is(notStr, 'string'));13var unexpected = require('unexpected');14var objType = unexpected.clone();15var num = 1;16var notNum = 'string';17console.log(objType.is(num, 'number'));18console.log(objType.is(notNum, 'number'));

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 unexpected 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