How to use test_attributes method in Testify

Best Python code snippet using Testify_python

test.CUI.Slider.js

Source:test.CUI.Slider.js Github

copy

Full Screen

1/*2 * ADOBE CONFIDENTIAL3 *4 * Copyright 2014 Adobe Systems Incorporated5 * All Rights Reserved.6 *7 * NOTICE: All information contained herein is, and remains8 * the property of Adobe Systems Incorporated and its suppliers,9 * if any. The intellectual and technical concepts contained10 * herein are proprietary to Adobe Systems Incorporated and its11 * suppliers and may be covered by U.S. and Foreign Patents,12 * patents in process, and are protected by trade secret or copyright law.13 * Dissemination of this information or reproduction of this material14 * is strictly forbidden unless prior written permission is obtained15 * from Adobe Systems Incorporated.16 */17;(function () {18 var $sliderSingle, $sliderRange, $sliderFromOptions,19 origIsTouch = CUI.util.isTouch;20 var SLIDER_OPTIONS_MINIMAL = {21 min: 0,22 max: 100,23 step: 10,24 value: 5025 };26 var SLIDER_BARE = {27 "name" : 'slider bare',28 "html" : '' +29 '<div class="coral-Slider" data-init="slider">' +30 '<label>' +31 'Basic Horizontal Slider, no minimal options<br>' +32 '<input type="range">' +33 '</label>' +34 '</div>'35 };36 var SLIDER_SINGLE = {37 "name" : 'slider single',38 "html" : '' +39 '<div class="coral-Slider" data-init="slider">' +40 '<label>' +41 'Basic Horizontal Slider<br>' +42 '<input type="range" min="' + SLIDER_OPTIONS_MINIMAL.min + '" max="' + SLIDER_OPTIONS_MINIMAL.max +43 '" step="' + SLIDER_OPTIONS_MINIMAL.step + '" value="' + SLIDER_OPTIONS_MINIMAL.value + '">' +44 '</label>' +45 '</div>'46 };47 var SLIDER_RANGE = {48 "name" : 'slider range',49 "html" : '' +50 '<div class="coral-Slider" data-init="slider">' +51 '<fieldset>' +52 '<!-- Note if you remove the legend, rendering errors occur. It can be empty, apparently. -->' +53 '<legend>Range Slider</legend>' +54 '<label>Minimum <input type="range" min="' + SLIDER_OPTIONS_MINIMAL.min + '" max="' + SLIDER_OPTIONS_MINIMAL.max +55 '" step="' + SLIDER_OPTIONS_MINIMAL.step + '" value="' + SLIDER_OPTIONS_MINIMAL.value + '"></label>' +56 '<label>Maximum <input type="range" min="' + SLIDER_OPTIONS_MINIMAL.min + '" max="' + SLIDER_OPTIONS_MINIMAL.max +57 '" step="' + SLIDER_OPTIONS_MINIMAL.step + '" value="' + SLIDER_OPTIONS_MINIMAL.value + '"></label>' +58 '</fieldset>' +59 '</div>'60 };61 var SLIDER_LABELED = {62 "name" : 'slider labeled',63 "html" : '' +64 '<div class="coral-Slider coral-Slider--ticked" data-init="labeled-slider" data-alternating="true">' +65 '<label>' +66 'Basic Horizontal Slider<br>' +67 '<input type="range" min="' + SLIDER_OPTIONS_MINIMAL.min + '" max="' + SLIDER_OPTIONS_MINIMAL.max +68 '" step="' + SLIDER_OPTIONS_MINIMAL.step + '" value="' + SLIDER_OPTIONS_MINIMAL.value + '">' +69 '</label>' +70 '<ul class="coral-Slider-tickLabels">' +71 '<li>First label</li>' +72 '<li>Second label</li>' +73 '<li>Third label</li>' +74 '<li>Fourth label</li>' +75 '<li>Fifth label</li>' +76 '</ul>' +77 '</div>'78 };79 var TEST_ATTRIBUTES = {80 "classes" : {81 "modifiers" : {82 "bound" : "coral-Slider--bound",83 "filled" : "coral-Slider--filled",84 "ticked" : "coral-Slider--ticked",85 "tooltips" : "coral-Slider--tooltips",86 "vertical" : "coral-Slider--vertical",87 "labeled" : "coral-Slider--labeled",88 "alternatinglabels" : "coral-Slider--alternatingLabels",89 "tick_covered" : "coral-Slider-tick--covered",90 "tooltip_info" : "coral-Tooltip--inspect"91 },92 "components" : {93 "clickarea" : "coral-Slider-clickarea",94 "fill" : "coral-Slider-fill",95 "handle" : "coral-Slider-handle",96 "ticks" : "coral-Slider-ticks",97 "tick" : "coral-Slider-tick",98 "ticklabels" : "coral-Slider-tickLabels",99 "ticklabel" : "coral-Slider-tickLabel",100 "value" : "coral-Slider-value",101 "tooltip" : "coral-Tooltip"102 }103 }104 };105 describe('CUI.Slider', function() {106 beforeEach(function () {107 $sliderSingle = $(SLIDER_SINGLE.html).slider().appendTo(document.body);108 $sliderRange = $(SLIDER_RANGE.html).slider().appendTo(document.body);109 $sliderFromOptions = $("<div>").slider(SLIDER_OPTIONS_MINIMAL).appendTo(document.body);110 });111 afterEach(function () {112 $sliderSingle113 .add($sliderRange)114 .add($sliderFromOptions)115 .remove();116 $sliderSingle = $sliderRange = $sliderFromOptions = null;117 CUI.util.isTouch = origIsTouch;118 });119 it('should be defined in CUI namespace', function() {120 expect(CUI).to.have.property('Slider');121 });122 it('should be defined on jQuery object', function() {123 var div = $('<div/>');124 expect(div).to.have.property('slider');125 });126 describe("from markup", function() {127 it ('should be a slider', function() {128 expect($sliderSingle).to.have.class("coral-Slider");129 });130 it('should have attributes set for min, max, step and value if any are missing', function() {131 var $sliderBare = $(SLIDER_BARE.html).slider().appendTo(document.body),132 $input = $sliderBare.find('input');133 expect($input.is("[min]")).to.be.true;134 expect($input.is("[max]")).to.be.true;135 expect($input.is("[step]")).to.be.true;136 expect($input.is("[value]")).to.be.true;137 $sliderBare.remove();138 });139 });140 describe("from options", function() {141 it('should create an input field', function() {142 expect($sliderFromOptions.find("input").length).to.equal(1);143 });144 it('should correctly set the initial input value', function() {145 expect(parseFloat($sliderFromOptions.find("input").val())).to.equal(SLIDER_OPTIONS_MINIMAL.value);146 });147 });148 describe('with option tooltips="true"', function() {149 var $sliderSingleTooltips, $sliderRangeTooltips, $handlesSingle, $handlesRange, $tooltipsSingle, $tooltipsRange;150 beforeEach(function () {151 $sliderSingleTooltips = $(SLIDER_SINGLE.html).slider($.extend(SLIDER_OPTIONS_MINIMAL, {"tooltips":true})).appendTo(document.body);152 $sliderRangeTooltips = $(SLIDER_RANGE.html).slider($.extend(SLIDER_OPTIONS_MINIMAL, {"tooltips":true})).appendTo(document.body);153 $tooltipsSingle = $sliderSingleTooltips.find('.'+TEST_ATTRIBUTES.classes.components.tooltip);154 $tooltipsRange = $sliderRangeTooltips.find('.'+TEST_ATTRIBUTES.classes.components.tooltip);155 $handlesSingle = $sliderSingleTooltips.find('.'+TEST_ATTRIBUTES.classes.components.handle);156 $handlesRange = $sliderRangeTooltips.find('.'+TEST_ATTRIBUTES.classes.components.handle);157 });158 afterEach(function () {159 $sliderSingleTooltips160 .add($sliderRangeTooltips)161 .add($handlesSingle)162 .add($handlesRange)163 .add($tooltipsSingle)164 .add($tooltipsRange)165 .remove();166 $sliderSingleTooltips = $sliderRangeTooltips = $handlesSingle = $handlesRange = $tooltipsSingle = $tooltipsRange = null;167 });168 it('should be modified as having tooltips', function() {169 expect($sliderSingleTooltips).to.have.class(TEST_ATTRIBUTES.classes.modifiers.tooltips);170 });171 it('should add a tooltip element for the handle (single)', function() {172 expect($tooltipsSingle.length).to.equal($handlesSingle.length);173 });174 it('should add a tooltip element for each handle (range)', function() {175 expect($tooltipsRange.length).to.equal($handlesRange.length);176 });177 it('should modify tooltips as type "info"', function() {178 expect($tooltipsRange).to.have.class(TEST_ATTRIBUTES.classes.modifiers.tooltip_info);179 });180 it('should match the tooltip text to the input value on value change (default tooltip formatter)', function() {181 var $input = $sliderSingleTooltips.find('input').first(),182 $tooltip = $tooltipsSingle.first(),183 newVal = 60;184 $sliderSingleTooltips.data('slider').setValue(newVal, 0);185 expect($input.val() == $tooltip.text()).to.be.true;186 });187 });188 describe('with option filled="true"', function() {189 var $sliderFilled, $fill;190 beforeEach(function () {191 $sliderFilled = $("<div>").slider($.extend(SLIDER_OPTIONS_MINIMAL, {"filled":true})).appendTo(document.body);192 $fill = $sliderFilled.find('.' + TEST_ATTRIBUTES.classes.components.fill);193 });194 afterEach(function () {195 $sliderFilled.remove();196 $sliderFilled = $fill = null;197 });198 it('should be modified to filled', function() {199 expect($sliderFilled).to.have.class(TEST_ATTRIBUTES.classes.modifiers.filled);200 });201 it('should add a single fill element', function() {202 expect($fill.length).to.equal(1);203 });204 });205 describe('with option orientation="vertical"', function() {206 var $sliderVertical = $("<div>").slider($.extend(SLIDER_OPTIONS_MINIMAL, {"orientation":"vertical"})).appendTo(document.body);207 it('should mark the slider as vertical', function() {208 expect($sliderVertical).to.have.class(TEST_ATTRIBUTES.classes.modifiers.vertical);209 });210 $sliderVertical.remove();211 });212 describe('with option ticks="true"', function() {213 var $sliderTicked, $tickContainer, $ticks;214 beforeEach(function () {215 $sliderTicked = $("<div>").slider($.extend(SLIDER_OPTIONS_MINIMAL, {"ticks":true})).appendTo(document.body);216 $tickContainer = $sliderTicked.find('.' + TEST_ATTRIBUTES.classes.components.ticks);217 $ticks = $sliderTicked.find('.' + TEST_ATTRIBUTES.classes.components.tick);218 });219 afterEach(function () {220 $sliderTicked.remove();221 $sliderTicked = $tickContainer = $ticks = null;222 });223 it('should be modified to ticked', function() {224 expect($sliderTicked).to.have.class(TEST_ATTRIBUTES.classes.modifiers.ticked);225 });226 it('should add tick related DOM elements', function() {227 expect($tickContainer.length).to.equal(1);228 expect($ticks.length <= 0).to.be.false;229 });230 });231 describe('with option bound="true"', function() {232 var $sliderBound;233 beforeEach(function () {234 $sliderBound = $(SLIDER_RANGE.html).slider($.extend(SLIDER_OPTIONS_MINIMAL, {"bound":true})).appendTo(document.body);235 });236 afterEach(function () {237 $sliderBound.remove();238 });239 it('should not be able to "slide" handles past one another when using setValue() api', function() {240 var $inputs = $sliderBound.find('input');241 $sliderBound.data('slider').setValue(40,0);242 $sliderBound.data('slider').setValue(60,0); // try handle0 > handle1 (handle0 = 60, handle1 = 50)243 expect(parseInt($inputs.eq(0).val(), 10)).to.equal(SLIDER_OPTIONS_MINIMAL.value);244 $sliderBound.data('slider').setValue(40,1); // try handle1 < handle0 (handle0 = 50, handle1 = 40)245 expect(parseInt($inputs.eq(1).val(), 10)).to.equal(SLIDER_OPTIONS_MINIMAL.value);246 });247 });248 describe('api', function() {249 describe('setValue(value)', function() {250 it('should correctly set the input value', function() {251 var value = 20; // Choose step point, otherwise it would be adjusted252 $sliderSingle.data('slider').setValue(value);253 expect(parseInt($sliderSingle.find('input').val(), 10)).to.equal(value);254 });255 it('should correctly snap input values to the nearest step', function() {256 var setValue = 27, expectedSnap = 30;257 $sliderSingle.data('slider').setValue(setValue);258 expect(parseInt($sliderSingle.find('input').eq(0).val(), 10)).to.equal(expectedSnap);259 });260 it('should not trigger a change event on the input field', function(done) {261 var $input = $sliderSingle.find('input'), changeFired = false;262 $input.on('change', function() {263 changeFired = true;264 });265 setTimeout(function() {266 expect(changeFired).to.equal(false);267 done();268 }, 200);269 $sliderSingle.data('slider').setValue(20);270 });271 });272 describe('setValue(value, handleNumber)', function() {273 it('should correctly set declared input value of a range input', function() {274 var firstValue = 30, secondValue = 80; // Choose step points, otherwise they would be adjusted275 $sliderRange.data('slider').setValue(firstValue, 0);276 $sliderRange.data('slider').setValue(secondValue, 1);277 expect(parseInt($sliderRange.find('input').eq(0).val(), 10)).to.equal(firstValue);278 expect(parseInt($sliderRange.find('input').eq(1).val(), 10)).to.equal(secondValue);279 });280 });281 });282 describe('accessibility', function() {283 var $sliderAccessibility,284 cached_supportsRangeInput,285 keysNext = [286 38, // up287 39 // right288 ],289 keysPrev = [290 37, // down291 40 // left292 ],293 keyPageUp = 33,294 keyPageDown = 34,295 keyEnd = 35,296 keyHome = 36;297 describe('in browsers that support input[type=range]', function() {298 beforeEach(function() {299 $sliderAccessibility = $("<div>").slider(SLIDER_OPTIONS_MINIMAL).appendTo(document.body);300 });301 afterEach(function() {302 $sliderAccessibility.remove();303 $sliderAccessibility = null;304 });305 it('moves the value to the next step using the native input.stepUp method', function() {306 var prevVal, currVal, step = 10,307 input = $sliderAccessibility.find('input')[0];308 prevVal = input.valueAsNumber;309 input.stepUp();310 currVal = input.valueAsNumber;311 expect(currVal === (prevVal + step)).to.be.true;312 });313 it('moves the value to the previous step using the native input.stepDown method', function() {314 var prevVal, currVal, step = 10,315 input = $sliderAccessibility.find('input')[0];316 prevVal = input.valueAsNumber;317 input.stepDown();318 currVal = input.valueAsNumber;319 expect(currVal === (prevVal - step)).to.be.true;320 });321 });322 describe('in browsers that do not support input[type=range]', function() {323 beforeEach(function() {324 cached_supportsRangeInput = CUI.Slider.prototype._supportsRangeInput;325 CUI.Slider.prototype._supportsRangeInput = false;326 $sliderAccessibility = $("<div>").slider(SLIDER_OPTIONS_MINIMAL).appendTo(document.body);327 });328 afterEach(function() {329 $sliderAccessibility.remove();330 $sliderAccessibility = null;331 CUI.Slider.prototype._supportsRangeInput = cached_supportsRangeInput;332 });333 it('expects the handle to have role=slider', function() {334 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle);335 expect($handle.attr('role')).to.equal('slider');336 });337 it('expects the handle to have tabindex=0', function() {338 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle);339 expect($handle.attr('tabindex')).to.equal('0');340 });341 describe('expects the handle to have correct', function() {342 it('aria-valuemin', function() {343 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle);344 expect(Number($handle.attr('aria-valuemin'))).to.equal(SLIDER_OPTIONS_MINIMAL.min);345 });346 it('aria-valuemax', function() {347 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle);348 expect(Number($handle.attr('aria-valuemax'))).to.equal(SLIDER_OPTIONS_MINIMAL.max);349 });350 it('aria-valuestep', function() {351 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle);352 expect(Number($handle.attr('aria-valuestep'))).to.equal(SLIDER_OPTIONS_MINIMAL.step);353 });354 it('aria-valuenow', function() {355 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle);356 expect(Number($handle.attr('aria-valuenow'))).to.equal(SLIDER_OPTIONS_MINIMAL.value);357 });358 it('aria-valuetext', function() {359 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle);360 expect(Number($handle.attr('aria-valuetext'))).to.equal(SLIDER_OPTIONS_MINIMAL.value);361 });362 });363 describe('setValue(value)', function() {364 it('should set aria-valuenow and aria-valuetext', function() {365 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),366 value = 20; // Choose step point, otherwise it would be adjusted367 $sliderAccessibility.data('slider').setValue(value);368 expect(Number($handle.attr('aria-valuenow'))).to.equal(value);369 });370 it('should correctly snap aria-valuenow to the nearest step', function() {371 var $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),372 setValue = 27, expectedSnap = 30;373 $sliderAccessibility.data('slider').setValue(setValue);374 expect(Number($handle.attr('aria-valuenow'))).to.equal(expectedSnap);375 });376 });377 it('expects the input to have aria-hidden=true', function() {378 var $input = $sliderAccessibility.find('input');379 expect($input.attr('aria-hidden')).to.equal('true');380 });381 it('moves the value to the next step using keys', function() {382 var prevVal, currVal, step = 10, e = $.Event('keydown'),383 $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),384 $input = $sliderAccessibility.find('input');385 $.each(keysNext, function(i, keycode) {386 prevVal = parseInt($input.val(), 10);387 e.which = e.keyCode = keycode;388 $handle.trigger(e);389 currVal = parseInt($input.val(), 10);390 expect(currVal === (prevVal + step)).to.be.true;391 });392 });393 it('move the value to the previous step using keys', function() {394 var prevVal, currVal, step = 10,395 e = $.Event('keydown'),396 $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),397 $input = $sliderAccessibility.find('input');398 $.each(keysPrev, function(i, keycode) {399 prevVal = parseInt($input.val(), 10);400 e.which = e.keyCode = keycode;401 $handle.trigger(e);402 currVal = parseInt($input.val(), 10);403 expect(currVal === (prevVal - step)).to.be.true;404 });405 });406 it('pages up on "page up" keypress', function() {407 var prevVal, currVal, page = 10,408 e = $.Event('keydown'),409 $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),410 $input = $sliderAccessibility.find('input');411 prevVal = parseInt($input.val(), 10);412 e.which = e.keyCode = keyPageUp;413 $handle.trigger(e);414 currVal = parseInt($input.val(), 10);415 expect(currVal === (prevVal + page)).to.be.true;416 });417 it('page down on "page down" keypress', function() {418 var prevVal, currVal, page = 10,419 e = $.Event('keydown'),420 $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),421 $input = $sliderAccessibility.find('input');422 prevVal = parseInt($input.val(), 10);423 e.which = e.keyCode = keyPageDown;424 $handle.trigger(e);425 currVal = parseInt($input.val(), 10);426 expect(currVal === (prevVal - page)).to.be.true;427 });428 it('moves to min on "home" keypress', function() {429 var e = $.Event('keydown'),430 $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),431 $input = $sliderAccessibility.find('input');432 e.which = e.keyCode = keyHome;433 $handle.trigger(e);434 expect(parseInt($input.val(), 10)).to.equal(SLIDER_OPTIONS_MINIMAL.min);435 });436 it('moves to max on "end" keypress', function() {437 var e = $.Event('keydown'),438 $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),439 $input = $sliderAccessibility.find('input');440 e.which = e.keyCode = keyEnd;441 $handle.trigger(e);442 expect(parseInt($input.val(), 10)).to.equal(SLIDER_OPTIONS_MINIMAL.max);443 });444 it('does not precede or exceed min/max limits when moving to prev/next step via keys', function() {445 var min = 0, max = 100,446 e = $.Event('keydown'),447 $handle = $sliderAccessibility.find('.' + TEST_ATTRIBUTES.classes.components.handle),448 $input = $sliderAccessibility.find('input');449 $sliderAccessibility.data('slider').setValue(min);450 e.which = e.keyCode = keysPrev[0];451 $handle.trigger(e);452 expect(parseInt($input.val(), 10)).to.equal(min);453 $sliderAccessibility.data('slider').setValue(max);454 e.which = e.keyCode = keysNext[0];455 $handle.trigger(e);456 expect(parseInt($input.val(), 10)).to.equal(max);457 });458 });459 });460 });461 describe('CUI.LabeledSlider', function() {462 var $sliderLabeled;463 beforeEach(function() {464 $sliderLabeled = $(SLIDER_LABELED.html).labeledSlider().appendTo(document.body);465 });466 afterEach(function() {467 $sliderLabeled.remove();468 $sliderLabeled = null;469 });470 it('should be defined in CUI namespace', function() {471 expect(CUI).to.have.property('LabeledSlider');472 });473 it('should be defined on jQuery object', function() {474 var div = $('<div/>');475 expect(div).to.have.property('labeledSlider');476 });477 it('should be modified as labeled', function() {478 expect($sliderLabeled).to.have.class(TEST_ATTRIBUTES.classes.modifiers.labeled);479 });480 it('should build ticks and tick labels', function() {481 var $ticks = $sliderLabeled.find('.' + TEST_ATTRIBUTES.classes.components.tick),482 $tickLabels = $sliderLabeled.find('.' + TEST_ATTRIBUTES.classes.components.ticklabel);483 expect($ticks.length === $tickLabels.length).to.be.true;484 });485 describe('with class modifier alternatingLabels="true"', function() {486 it('should have an "alternating" property set', function() {487 var $sliderLabeledAlternatingLabels = $(SLIDER_LABELED.html).addClass(TEST_ATTRIBUTES.classes.modifiers.alternatinglabels).labeledSlider().appendTo(document.body);488 expect($sliderLabeledAlternatingLabels.data('labeledSlider').get('alternating')).to.be.true;489 $sliderLabeledAlternatingLabels.remove();490 });491 });492 });...

Full Screen

Full Screen

test.CUI.FlexWizard.js

Source:test.CUI.FlexWizard.js Github

copy

Full Screen

1/*2 ADOBE CONFIDENTIAL3 Copyright 2014 Adobe Systems Incorporated4 All Rights Reserved.5 NOTICE: All information contained herein is, and remains6 the property of Adobe Systems Incorporated and its suppliers,7 if any. The intellectual and technical concepts contained8 herein are proprietary to Adobe Systems Incorporated and its9 suppliers and may be covered by U.S. and Foreign Patents,10 patents in process, and are protected by trade secret or copyright law.11 Dissemination of this information or reproduction of this material12 is strictly forbidden unless prior written permission is obtained13 from Adobe Systems Incorporated.14 */15describe('CUI.FlexWizard', function() {16 var $wizardMultistep, $wizardMultistepSteplistitems, $wizardMultistepSteps,17 wizardMultistep;18 var WIZARD_MULTISTEP = '' +19 '<form action="test" method="post" class="coral-Wizard" data-init="flexwizard">' +20 '<nav class="js-coral-Wizard-nav coral-Wizard-nav coral--dark">' +21 '<ol class="coral-Wizard-steplist">' +22 '<li class="js-coral-Wizard-steplist-item coral-Wizard-steplist-item">Step 1</li>' +23 '<li class="js-coral-Wizard-steplist-item coral-Wizard-steplist-item">Step 2</li>' +24 '<li class="js-coral-Wizard-steplist-item coral-Wizard-steplist-item">Step 3</li>' +25 '</ol>' +26 '</nav>' +27 '<div class="js-coral-Wizard-step coral-Wizard-step"><p>Step 1 Content.</p></div>' +28 '<div class="js-coral-Wizard-step coral-Wizard-step"><p>Step 2 Content.</p></div>' +29 '<div class="js-coral-Wizard-step coral-Wizard-step"><p>Step 3 Content.</p></div>' +30 '</form>';31 var TEST_ATTRIBUTES = {32 "classes" : {33 "components" : {34 "step" : "coral-Wizard-step"35 },36 "js" : {37 "step" : "js-coral-Wizard-step",38 "steplistitem" : "js-coral-Wizard-steplist-item"39 },40 "states" : {41 "active" : "is-active",42 "stepped" : "is-stepped"43 },44 "utils" : {45 "hidden" : "u-coral-hidden"46 }47 }48 };49 var TEST_EVENTS = {50 "stepchange" : "flexwizard-stepchange"51 };52 beforeEach(function() {53 $wizardMultistep = $(WIZARD_MULTISTEP).flexWizard().appendTo(document.body);54 $wizardMultistepSteplistitems = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.js.steplistitem);55 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);56 wizardMultistep = $wizardMultistep.data('flexWizard');57 });58 afterEach(function() {59 $wizardMultistep.remove();60 $wizardMultistep = $wizardMultistepSteplistitems = wizardMultistep = null;61 });62 it('should be defined in CUI namespace', function() {63 expect(CUI).to.have.property('FlexWizard');64 });65 it('should be defined on jQuery object', function() {66 var form = $('form');67 expect(form).to.have.property('flexWizard');68 });69 describe('api', function() {70 it('initial step should be active', function() {71 expect($wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.js.steplistitem + ':first')).to.have.class(TEST_ATTRIBUTES.classes.states.active);72 });73 describe('nextStep()', function() {74 it('should mark the correct steplist item as active', function() {75 for (var s = 0; s < $wizardMultistepSteps.length-1; s++) {76 wizardMultistep.nextStep();77 expect($wizardMultistepSteplistitems.eq(s + 1)).to.have.class(TEST_ATTRIBUTES.classes.states.active);78 }79 });80 it('should not display inactive steps', function() {81 for (var s = 0; s < $wizardMultistepSteps.length-1; s++) {82 wizardMultistep.nextStep();83 expect($wizardMultistepSteps.eq(s + 1)).not.to.have.class(TEST_ATTRIBUTES.classes.utils.hidden);84 expect($wizardMultistepSteps.not($wizardMultistepSteps.eq(s + 1))).to.have.class(TEST_ATTRIBUTES.classes.utils.hidden);85 }86 });87 it('should mark the previous steplist item as stepped', function() {88 for (var s = 0; s < $wizardMultistepSteps.length-1; s++) {89 wizardMultistep.nextStep();90 expect($wizardMultistepSteplistitems.eq(s)).to.have.class(TEST_ATTRIBUTES.classes.states.stepped);91 }92 });93 it('should continue to display same step when called on last step', function() {94 for (var s = 0; s < $wizardMultistepSteps.length; s++) {95 wizardMultistep.nextStep();96 }97 expect($wizardMultistepSteplistitems.eq($wizardMultistepSteps.length-1)).to.have.class(TEST_ATTRIBUTES.classes.states.active);98 });99 });100 describe('prevStep()', function() {101 beforeEach(function() {102 for (var s = 0; s < $wizardMultistepSteps.length-1; s++) {103 wizardMultistep.nextStep();104 }105 });106 it('should mark the correct steplist item as active', function() {107 for (var s = $wizardMultistepSteps.length-1; s > 0; s--) {108 wizardMultistep.prevStep();109 expect($wizardMultistepSteplistitems.eq(s - 1)).to.have.class(TEST_ATTRIBUTES.classes.states.active);110 }111 });112 it('should not display inactive steps', function() {113 for (var s = $wizardMultistepSteps.length-1; s > 0; s--) {114 wizardMultistep.prevStep();115 expect($wizardMultistepSteps.eq(s - 1)).not.to.have.class(TEST_ATTRIBUTES.classes.utils.hidden);116 expect($wizardMultistepSteps.not($wizardMultistepSteps.eq(s - 1))).to.have.class(TEST_ATTRIBUTES.classes.utils.hidden);117 }118 });119 it('should mark the previous steplist item as stepped', function() {120 for (var s = $wizardMultistepSteps.length-1; s > 1; s--) {121 wizardMultistep.prevStep();122 expect($wizardMultistepSteplistitems.eq(s - 2)).to.have.class(TEST_ATTRIBUTES.classes.states.stepped);123 }124 });125 it('should continue to display same step when called on first step', function() {126 for (var s = 0; s < $wizardMultistepSteps.length; s++) {127 wizardMultistep.prevStep();128 }129 expect($wizardMultistepSteplistitems.eq(0)).to.have.class(TEST_ATTRIBUTES.classes.states.active);130 });131 });132 describe('add(step, index)', function(){133 var newStepHtml, oldStepCount;134 beforeEach(function() {135 newStepHtml = "<div class='"+ TEST_ATTRIBUTES.classes.components.step + "'>new step</div>";136 oldStepCount = $wizardMultistepSteps.length;137 });138 it('should add an additional step using add(HTMLElement)', function() {139 var wrap = document.createElement('div');140 wrap.innerHTML = newStepHtml;141 wizardMultistep.add(wrap.firstChild);142 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);143 expect($wizardMultistepSteps.length).to.equal(oldStepCount + 1);144 });145 it('should add an additional step using add(jQuery)', function() {146 wizardMultistep.add($(newStepHtml));147 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);148 expect($wizardMultistepSteps.length).to.equal(oldStepCount + 1);149 });150 it('should add an additional step using add(String)', function() {151 wizardMultistep.add(newStepHtml);152 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);153 expect($wizardMultistepSteps.length).to.equal(oldStepCount + 1);154 });155 it('should add the additional step as the last step if no index supplied', function() {156 var $newStep = $(newStepHtml);157 wizardMultistep.add($newStep);158 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);159 expect($wizardMultistepSteps.last().is($newStep)).to.be.true;160 });161 it('should add the additional step after the supplied index', function() {162 var index = 0, $newStep = $(newStepHtml);163 wizardMultistep.add($newStep, index);164 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);165 expect($wizardMultistepSteps.eq(index + 1).is($newStep)).to.be.true;166 });167 it('should add the additional step list item and not mark it as active or stepped', function () {168 var index = 0; var $newStep = $(newStepHtml);169 wizardMultistep.add($newStep, index);170 $wizardMultistepSteplistitems = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.js.steplistitem);171 expect($wizardMultistepSteplistitems.eq(index + 1)).not.to.have.class(TEST_ATTRIBUTES.classes.states.active);172 expect($wizardMultistepSteplistitems.eq(index + 1)).not.to.have.class(TEST_ATTRIBUTES.classes.states.stepped);173 });174 });175 describe('addAfter(step, refStep)', function() {176 var newStepHtml, oldStepCount;177 beforeEach(function() {178 newStepHtml = "<div class='"+ TEST_ATTRIBUTES.classes.components.step + "'>New step content.</div>";179 oldStepCount = $wizardMultistepSteps.length;180 });181 it('should add an additional step', function() {182 wizardMultistep.addAfter($(newStepHtml), $wizardMultistepSteps.first());183 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);184 expect($wizardMultistepSteps.length).to.equal(oldStepCount + 1);185 });186 it('should add the additional step after the refStep', function() {187 var $newStep = $(newStepHtml);188 wizardMultistep.addAfter($newStep, $wizardMultistepSteps.first());189 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);190 expect($wizardMultistepSteps.eq(1).is($newStep)).to.be.true;191 });192 });193 describe('remove(step)', function() {194 var $stepToRemove, oldStepCount;195 beforeEach(function() {196 $stepToRemove = $wizardMultistepSteps.eq(1);197 oldStepCount = $wizardMultistepSteps.length;198 });199 it('should remove a step', function() {200 wizardMultistep.remove($stepToRemove);201 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);202 expect($wizardMultistepSteps.length).to.equal(oldStepCount - 1);203 });204 it('should remove the correct step', function() {205 wizardMultistep.remove($stepToRemove);206 $wizardMultistepSteps = $wizardMultistep.find('.' + TEST_ATTRIBUTES.classes.components.step);207 expect($wizardMultistepSteps.eq(1).is($stepToRemove)).to.be.false;208 });209 });210 });211 describe('events', function() {212 it('should fire a ' + TEST_EVENTS.stepchange + ' event when step has changed and provide the correct to/from data', function(done) {213 var $expectedFrom = $wizardMultistepSteps.eq(0),214 $expectedTo = $wizardMultistepSteps.eq(1);215 wizardMultistep.on(TEST_EVENTS.stepchange, function(e, to, from) {216 expect($(from).is($expectedFrom)).to.be.true;217 expect($(to).is($expectedTo)).to.be.true;218 done();219 });220 wizardMultistep.nextStep();221 });222 });...

Full Screen

Full Screen

kNN.py

Source:kNN.py Github

copy

Full Screen

1#####################################################################2# kNN and its variants3# Alex Gillies4# LLLL765# Python version: 36#####################################################################7import csv8import cv29import os10import numpy as np11import math12import random13import matplotlib.pyplot as plt14import itertools15import IO16#####################################################################17def kNN(training_labels, training_attributes, test_labels, test_attributes, K):18 ############ Perform Training -- k-NN19 # define kNN object20 knn = cv2.ml.KNearest_create()21 # set to use BRUTE_FORCE neighbour search as KNEAREST_KDTREE seems to break22 # on this data set (may not for others - http://code.opencv.org/issues/2661)23 knn.setAlgorithmType(cv2.ml.KNEAREST_BRUTE_FORCE)24 # set default 3, can be changed at query time in predict() call25 knn.setDefaultK(K)26 # set up classification, turning off regression27 knn.setIsClassifier(True)28 # perform training of k-NN29 knn.train(training_attributes, cv2.ml.ROW_SAMPLE, training_labels)30 ############ Perform Testing -- k-NN31 correct = 032 incorrect = 033 actual_labels = []34 predicted_labels = []35 for i in range(len(test_attributes)):36 # iterate though every index of the test data37 sample = np.vstack((test_attributes[i,:], np.zeros(len(test_attributes[i,:])).astype(np.float32)))38 # formatting before running39 _, results, neigh_respones, distances = knn.findNearest(sample, k = K)40 # run the test on the current thing41 predicted_labels.append(int(results[0][0]))42 actual_labels.append(int(test_labels[i]))43 if(results[0] == test_labels[i]):44 correct += 145 else:46 incorrect += 147 print("Correct: " + str(correct/len(test_attributes) * 100))48 print("Incorrext: " + str(incorrect/len(test_attributes) * 100))49 return (correct/len(test_attributes) * 100), predicted_labels, actual_labels50 # show or use results51#####################################################################52def kNN_weighted(training_labels, training_attributes, test_labels, test_attributes, K, inverse_square, similarity):53 54 ############ Perform Training -- k-NN55 # define kNN object56 knn = cv2.ml.KNearest_create()57 # set to use BRUTE_FORCE neighbour search as KNEAREST_KDTREE seems to break58 # on this data set (may not for others - http://code.opencv.org/issues/2661)59 knn.setAlgorithmType(cv2.ml.KNEAREST_BRUTE_FORCE)60 # use the parameter for K as default61 knn.setDefaultK(K)62 # set up classification, turning off regression63 knn.setIsClassifier(True)64 # perform training of k-NN65 knn.train(training_attributes, cv2.ml.ROW_SAMPLE, training_labels)66 ############ Perform Testing -- k-NN67 correct = 068 incorrect = 069 actual_labels = []70 predicted_labels = []71 for i in range(len(test_attributes)):72 # iterate though every index of the test data73 sample = np.vstack((test_attributes[i,:], np.zeros(len(test_attributes[i,:])).astype(np.float32)))74 # formatting before running75 _, results, neigh_respones, distances = knn.findNearest(sample, k = K)76 # run the test on the current thing77 ################### The weighting bit78 # Inverse Square Distance79 if(inverse_square):80 # use a parameter as a switch81 prediction = 082 # set a default prediction83 weighted_labels = np.array([0,0,0,0,0,0,0,0,0,0,0,0]).astype(np.float32)84 # an array to store the probability of each of the classes85 for x in range(len(neigh_respones[0])):86 # iterate through each of the neghbors and their decisions and distances87 current_inverse_square = 1/(distances[0][x] * distances[0][x])88 # work out the inverse square distance for the current neighbour89 index = int(neigh_respones[0][x] - 1)90 # get the index of the class that the current nearest neighbour thinks is correct 91 weighted_labels[index] += current_inverse_square92 # incremenet the probability of that class with the weight that the current neighbour has93 prediction = np.argmax(weighted_labels, axis=0) + 194 # get the overall prediction95 # Similarity96 if(similarity):97 prediction = 098 # set a default prediction99 weighted_labels = np.array([0,0,0,0,0,0,0,0,0,0,0,0]).astype(np.float32)100 # an array to store the probability of each of the classes101 for x in range(len(neigh_respones[0])):102 # iterate through each of the neghbors and their decisions and distances103 current_similarity = 1 - distances[0][x]104 # work out the similarity of the nearest neighbour105 index = int(neigh_respones[0][x] - 1)106 # get the index of the class that the current nearest neighbour thinks is correct 107 weighted_labels[index] += current_similarity108 # increment the index of the class that the current neighbiour thinks is correct109 prediction = np.argmin(weighted_labels, axis=0) + 1110 # get the overall prediction111 ################### End of the weighting bit112 predicted_labels.append(int(results[0][0]))113 actual_labels.append(int(test_labels[i]))114 if(prediction == test_labels[i]):115 # if the prediction is correct116 correct += 1117 # increment the number of correct 118 else:119 incorrect += 1120 # increment the number of incorrect121 print("Correct: " + str(correct/len(test_attributes) * 100))122 print("Incorrext: " + str(incorrect/len(test_attributes) * 100))123 return (correct/len(test_attributes) * 100), predicted_labels, actual_labels124 # show or use results125#####################################################################126# Run Code Here127# this will run to show the best results for each of the functions128"""129print("-----")130total = 0131for y in range(0,10):132 # do each one 10 times133 test_labels, test_attributes, training_labels, training_attributes = IO.read_in_everything_10()134 # with different test values135 to_add, _, _ = kNN(training_labels, training_attributes, test_labels, test_attributes, 1)136 # accumulate the percentage of each137 total += to_add138print("the total percentage: " + str(total / 10))139# get the average140print("-----")141total = 0142for y in range(0,10):143 # do each one 10 times144 test_labels, test_attributes, training_labels, training_attributes = IO.read_in_everything_10()145 # with different test values146 to_add, _, _ = kNN_weighted(training_labels, training_attributes, test_labels, test_attributes, 8, True, False)147 # accumulate the percentage of each148 total += to_add149print("the total percentage: " + str(total / 10))150# get the average151print("-----")152total = 0153for y in range(0,10):154 # do each one 10 times155 test_labels, test_attributes, training_labels, training_attributes = IO.read_in_everything_10()156 # with different test values157 to_add, _, _ = kNN_weighted(training_labels, training_attributes, test_labels, test_attributes, 1, False, True)158 # accumulate the percentage of each159 total += to_add160print("the total percentage: " + str(total / 10))161# get the average162"""...

Full Screen

Full Screen

interface.any.js

Source:interface.any.js Github

copy

Full Screen

...17 assert_function_length(object[name], length, `${object_name}.${name}`);18 }, `${object_name}.${name}: length`);19 }20}21function test_attributes(object, object_name, attributes) {22 for (const [name, mutable] of attributes) {23 test(() => {24 const propdesc = Object.getOwnPropertyDescriptor(object, name);25 assert_equals(typeof propdesc, "object");26 assert_true(propdesc.enumerable, "enumerable");27 assert_true(propdesc.configurable, "configurable");28 }, `${object_name}.${name}`);29 test(() => {30 const propdesc = Object.getOwnPropertyDescriptor(object, name);31 assert_equals(typeof propdesc, "object");32 assert_equals(typeof propdesc.get, "function");33 assert_function_name(propdesc.get, "get " + name, `getter for "${name}"`);34 assert_function_length(propdesc.get, 0, `getter for "${name}"`);35 }, `${object_name}.${name}: getter`);36 test(() => {37 const propdesc = Object.getOwnPropertyDescriptor(object, name);38 assert_equals(typeof propdesc, "object");39 if (mutable) {40 assert_equals(typeof propdesc.set, "function");41 assert_function_name(propdesc.set, "set " + name, `setter for "${name}"`);42 assert_function_length(propdesc.set, 1, `setter for "${name}"`);43 } else {44 assert_equals(typeof propdesc.set, "undefined");45 }46 }, `${object_name}.${name}: setter`);47 }48}49test(() => {50 const propdesc = Object.getOwnPropertyDescriptor(this, "WebAssembly");51 assert_equals(typeof propdesc, "object");52 assert_true(propdesc.writable, "writable");53 assert_false(propdesc.enumerable, "enumerable");54 assert_true(propdesc.configurable, "configurable");55 assert_equals(propdesc.value, this.WebAssembly);56}, "WebAssembly: property descriptor");57test(() => {58 assert_throws_js(TypeError, () => WebAssembly());59}, "WebAssembly: calling");60test(() => {61 assert_throws_js(TypeError, () => new WebAssembly());62}, "WebAssembly: constructing");63const interfaces = [64 "Module",65 "Instance",66 "Memory",67 "Table",68 "Global",69 "CompileError",70 "LinkError",71 "RuntimeError",72];73for (const name of interfaces) {74 test(() => {75 const propdesc = Object.getOwnPropertyDescriptor(WebAssembly, name);76 assert_equals(typeof propdesc, "object");77 assert_true(propdesc.writable, "writable");78 assert_false(propdesc.enumerable, "enumerable");79 assert_true(propdesc.configurable, "configurable");80 assert_equals(propdesc.value, WebAssembly[name]);81 }, `WebAssembly.${name}: property descriptor`);82 test(() => {83 const interface_object = WebAssembly[name];84 const propdesc = Object.getOwnPropertyDescriptor(interface_object, "prototype");85 assert_equals(typeof propdesc, "object");86 assert_false(propdesc.writable, "writable");87 assert_false(propdesc.enumerable, "enumerable");88 assert_false(propdesc.configurable, "configurable");89 }, `WebAssembly.${name}: prototype`);90 test(() => {91 const interface_object = WebAssembly[name];92 const interface_prototype_object = interface_object.prototype;93 const propdesc = Object.getOwnPropertyDescriptor(interface_prototype_object, "constructor");94 assert_equals(typeof propdesc, "object");95 assert_true(propdesc.writable, "writable");96 assert_false(propdesc.enumerable, "enumerable");97 assert_true(propdesc.configurable, "configurable");98 assert_equals(propdesc.value, interface_object);99 }, `WebAssembly.${name}: prototype.constructor`);100}101test_operations(WebAssembly, "WebAssembly", [102 ["validate", 1],103 ["compile", 1],104 ["instantiate", 1],105]);106test_operations(WebAssembly.Module, "WebAssembly.Module", [107 ["exports", 1],108 ["imports", 1],109 ["customSections", 2],110]);111test_attributes(WebAssembly.Instance.prototype, "WebAssembly.Instance", [112 ["exports", false],113]);114test_operations(WebAssembly.Memory.prototype, "WebAssembly.Memory", [115 ["grow", 1],116]);117test_attributes(WebAssembly.Memory.prototype, "WebAssembly.Memory", [118 ["buffer", false],119]);120test_operations(WebAssembly.Table.prototype, "WebAssembly.Table", [121 ["grow", 1],122 ["get", 1],123 ["set", 2],124]);125test_attributes(WebAssembly.Table.prototype, "WebAssembly.Table", [126 ["length", false],127]);128test_operations(WebAssembly.Global.prototype, "WebAssembly.Global", [129 ["valueOf", 0],130]);131test_attributes(WebAssembly.Global.prototype, "WebAssembly.Global", [132 ["value", true],...

Full Screen

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