Best JavaScript code snippet using root
es3fRasterizerDiscardTests.js
Source:es3fRasterizerDiscardTests.js
1/*-------------------------------------------------------------------------2 * drawElements Quality Program OpenGL ES 3.0 Module3 * -------------------------------------------------4 *5 * Copyright 2014 The Android Open Source Project6 *7 * Licensed under the Apache License, Version 2.0 (the "License");8 * you may not use this file except in compliance with the License.9 * You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * distributed under the License is distributed on an "AS IS" BASIS,15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16 * See the License for the specific language governing permissions and17 * limitations under the License.18 *19 *//*!20 * \file21 * \brief Rasterizer discard tests.22 *//*--------------------------------------------------------------------*/23goog.provide('functional.gles3.es3fRasterizerDiscardTests');24goog.require('framework.common.tcuLogImage');25goog.require('framework.common.tcuSurface');26goog.require('framework.common.tcuTestCase');27goog.require('framework.delibs.debase.deRandom');28goog.require('framework.delibs.debase.deString');29goog.require('framework.opengl.gluDrawUtil');30goog.require('framework.opengl.gluShaderProgram');31goog.scope(function() {32var es3fRasterizerDiscardTests = functional.gles3.es3fRasterizerDiscardTests;33var deString = framework.delibs.debase.deString;34var tcuTestCase = framework.common.tcuTestCase;35var deRandom = framework.delibs.debase.deRandom;36var gluShaderProgram = framework.opengl.gluShaderProgram;37var tcuSurface = framework.common.tcuSurface;38var gluDrawUtil = framework.opengl.gluDrawUtil;39var tcuLogImage = framework.common.tcuLogImage;40/** @const */ var NUM_CASE_ITERATIONS = 1;41/** @const */ var FAIL_COLOR_RED = [1, 0, 0.0, 1];42/** @const */ var PASS_COLOR_BLUE = [0, 0, 0.5, 1];43/** @const */ var BLACK_COLOR = [0, 0, 0.0, 1];44/** @const */ var FAIL_DEPTH = 0;45/** @const */ var FAIL_STENCIL = 1;46/** @const */ var UNIT_SQUARE = [47 1, 1, 0.05, 1,48 1, -1, 0.05, 1,49 -1, 1, 0.05, 1,50 -1, -1, 0.05, 151];52/** @type {WebGL2RenderingContext} */ var gl;53/**54 * @enum55 */56es3fRasterizerDiscardTests.CaseType = {57 WRITE_DEPTH: 0,58 WRITE_STENCIL: 1,59 CLEAR_COLOR: 2,60 CLEAR_DEPTH: 3,61 CLEAR_STENCIL: 462};63/**64 * @enum {{useFBO: boolean, useScissor: boolean}}65 */66es3fRasterizerDiscardTests.CaseOptions = {67 FBO: {useFBO: true, useScissor: false},68 SCISSOR: {useFBO: false, useScissor: true}69};70/**71 * @constructor72 * @extends {tcuTestCase.DeqpTest}73 * @param {string} name74 * @param {string} description75 * @param {number} numPrimitives76 * @param {es3fRasterizerDiscardTests.CaseType} caseType77 * @param {?es3fRasterizerDiscardTests.CaseOptions} caseOptions78 * @param {gluDrawUtil.primitiveType=} drawMode79 */80es3fRasterizerDiscardTests.RasterizerDiscardCase = function(name, description, numPrimitives, caseType, caseOptions, drawMode) {81 tcuTestCase.DeqpTest.call(this, name, description);82 this.m_numPrimitives = numPrimitives;83 this.m_caseType = caseType;84 this.m_caseOptions = caseOptions || {useFBO: false, useScissor: false};85 this.m_drawMode = drawMode || gluDrawUtil.primitiveType.TRIANGLES;86 this.m_program = null;87 this.m_fbo = null;88 this.m_colorBuf = null;89 this.m_depthStencilBuf = null;90 this.m_iterNdx = 0;91 this.m_rnd = new deRandom.Random(deString.deStringHash(name));92};93es3fRasterizerDiscardTests.RasterizerDiscardCase.prototype = Object.create(tcuTestCase.DeqpTest.prototype);94es3fRasterizerDiscardTests.RasterizerDiscardCase.prototype.constructor = es3fRasterizerDiscardTests.RasterizerDiscardCase;95/**96 * @param {number} numPrimitives97 * @param {deRandom.Random} rnd98 * @param {gluDrawUtil.primitiveType} drawMode99 * @return {Array<number>}100 */101es3fRasterizerDiscardTests.generateVertices = function(numPrimitives, rnd, drawMode) {102 var dst = [];103 var numVertices;104 switch (drawMode) {105 case gl.POINTS: numVertices = numPrimitives; break;106 case gl.LINES: numVertices = 2 * numPrimitives; break;107 case gl.LINE_STRIP: numVertices = numPrimitives + 1; break;108 case gl.LINE_LOOP: numVertices = numPrimitives + 2; break;109 case gl.TRIANGLES: numVertices = 3 * numPrimitives; break;110 case gl.TRIANGLE_STRIP: numVertices = numPrimitives + 2; break;111 case gl.TRIANGLE_FAN: numVertices = numPrimitives + 2; break;112 default:113 throw new Error('Invalid drawMode: ' + drawMode);114 }115 for (var i = 0; i < numVertices; i++) {116 dst[i * 4] = rnd.getFloat(-1.0, 1.0); // x117 dst[i * 4 + 1] = rnd.getFloat(-1.0, 1.0); // y118 dst[i * 4 + 2] = rnd.getFloat(0.1, 0.9); // z119 dst[i * 4 + 3] = 1.0; // w120 }121 return dst;122};123es3fRasterizerDiscardTests.RasterizerDiscardCase.prototype.setupFramebufferObject = function() {124 var width = gl.drawingBufferWidth;125 var height = gl.drawingBufferHeight;126 // Create framebuffer object127 this.m_fbo = gl.createFramebuffer();128 this.m_colorBuf = gl.createTexture();129 this.m_depthStencilBuf = gl.createRenderbuffer();130 // Create color texture131 gl.bindTexture(gl.TEXTURE_2D, this.m_colorBuf);132 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);133 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);134 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);135 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);136 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);137 // Create depth and stencil buffers138 gl.bindRenderbuffer(gl.RENDERBUFFER, this.m_depthStencilBuf);139 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH24_STENCIL8, width, height);140 // Attach texture and buffers to FBO141 gl.bindFramebuffer(gl.FRAMEBUFFER, this.m_fbo);142 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.m_colorBuf, 0);143 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this.m_depthStencilBuf);144 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.m_depthStencilBuf);145 var fboStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER);146 if (fboStatus == gl.FRAMEBUFFER_UNSUPPORTED)147 throw new Error('Framebuffer unsupported');148 else if (fboStatus != gl.FRAMEBUFFER_COMPLETE)149 throw new Error('Failed to create framebuffer object: ' + deString.enumToString(gl, fboStatus));150};151es3fRasterizerDiscardTests.RasterizerDiscardCase.prototype.deleteFramebufferObject = function() {152 gl.deleteTexture(this.m_colorBuf);153 gl.deleteRenderbuffer(this.m_depthStencilBuf);154 gl.deleteFramebuffer(this.m_fbo);155};156es3fRasterizerDiscardTests.RasterizerDiscardCase.prototype.init = function() {157 var vertShaderSource =158 '#version 300 es\n' +159 'layout(location = 0) in mediump vec4 a_position;\n' +160 '\n' +161 'void main (void)\n' +162 '{\n' +163 ' gl_Position = a_position;\n' +164 '}\n';165 var fragShaderSource =166 '#version 300 es\n' +167 'layout(location = 0) out mediump vec4 dEQP_FragColor;\n' +168 'uniform mediump vec4 u_color;\n' +169 '\n' +170 'void main (void)\n' +171 '{\n' +172 ' mediump float depth_gradient = gl_FragCoord.z;\n' +173 ' mediump float bias = 0.1;\n' +174 ' dEQP_FragColor = vec4(u_color.xyz * (depth_gradient + bias), 1.0);\n' +175 '}\n';176 this.m_program = new gluShaderProgram.ShaderProgram(gl, gluShaderProgram.makeVtxFragSources(vertShaderSource, fragShaderSource));177 if (!this.m_program.isOk()) {178 bufferedLogToConsole(this.m_program);179 testFailedOptions('Failed to compile shader program', true);180 }181};182es3fRasterizerDiscardTests.RasterizerDiscardCase.prototype.deinit = function() {183 this.deleteFramebufferObject();184 this.m_program = null;185};186es3fRasterizerDiscardTests.RasterizerDiscardCase.prototype.iterate = function() {187 var program = this.m_program.getProgram();188 var colorUnif = gl.getUniformLocation(program, 'u_color');189 var failColorFound = false;190 var passColorFound = false;191 var vertices;192 bufferedLogToConsole('Case iteration ' + (this.m_iterNdx + 1) + ' / ' + NUM_CASE_ITERATIONS);193 // Create and bind FBO if needed194 if (this.m_caseOptions.useFBO) {195 this.setupFramebufferObject();196 }197 if (this.m_caseOptions.useScissor) {198 gl.enable(gl.SCISSOR_TEST);199 gl.scissor(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);200 bufferedLogToConsole('Scissor test enabled: glScissor(0, 0, ' + gl.drawingBufferWidth + ', ' + gl.drawingBufferHeight + ')');201 }202 gl.useProgram(this.m_program.getProgram());203 gl.enable(gl.DEPTH_TEST);204 gl.depthRange(0, 1);205 gl.depthFunc(gl.LEQUAL);206 gl.enable(gl.STENCIL_TEST);207 gl.stencilFunc(gl.NOTEQUAL, 1, 0xFF);208 gl.stencilOp(gl.REPLACE, gl.KEEP, gl.KEEP);209 gl.clearColor(PASS_COLOR_BLUE[0], PASS_COLOR_BLUE[1], PASS_COLOR_BLUE[2], PASS_COLOR_BLUE[3]);210 gl.clearDepth(1);211 gl.clearStencil(0);212 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);213 // Generate vertices214 vertices = es3fRasterizerDiscardTests.generateVertices(this.m_numPrimitives, this.m_rnd, this.m_drawMode);215 var posLoc = gl.getAttribLocation(program, 'a_position');216 var vertexArrays = [];217 vertexArrays.push(new gluDrawUtil.VertexArrayBinding(gl.FLOAT, posLoc, 4, vertices.length / 4, vertices));218 // Clear color to black for depth and stencil clear cases219 if (this.m_caseType == es3fRasterizerDiscardTests.CaseType.CLEAR_DEPTH || this.m_caseType == es3fRasterizerDiscardTests.CaseType.CLEAR_STENCIL) {220 gl.clearColor(BLACK_COLOR[0], BLACK_COLOR[1], BLACK_COLOR[2], BLACK_COLOR[3]);221 gl.clear(gl.COLOR_BUFFER_BIT);222 }223 // Set fail values for color, depth and stencil224 gl.uniform4fv(colorUnif, FAIL_COLOR_RED);225 gl.clearColor(FAIL_COLOR_RED[0], FAIL_COLOR_RED[1], FAIL_COLOR_RED[2], FAIL_COLOR_RED[3]);226 gl.clearDepth(FAIL_DEPTH);227 gl.clearStencil(FAIL_STENCIL);228 // Enable rasterizer discard229 gl.enable(gl.RASTERIZER_DISCARD);230 bufferedLogToConsole('Rasterizer discard enabled');231 // Do to-be-discarded primitive draws and buffer clears232 switch (this.m_caseType) {233 case es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH:234 gluDrawUtil.draw(gl, program, vertexArrays, new gluDrawUtil.PrimitiveList(this.m_drawMode, vertices.length / 4));235 break;236 case es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL:237 gluDrawUtil.draw(gl, program, vertexArrays, new gluDrawUtil.PrimitiveList(this.m_drawMode, vertices.length / 4));238 break;239 case es3fRasterizerDiscardTests.CaseType.CLEAR_COLOR:240 if (this.m_caseOptions.useFBO)241 gl.clearBufferfv(gl.COLOR, 0, FAIL_COLOR_RED);242 else243 gl.clear(gl.COLOR_BUFFER_BIT);244 break;245 case es3fRasterizerDiscardTests.CaseType.CLEAR_DEPTH:246 if (this.m_caseOptions.useFBO)247 gl.clearBufferfv(gl.DEPTH, 0, [FAIL_DEPTH]);248 else249 gl.clear(gl.DEPTH_BUFFER_BIT);250 break;251 case es3fRasterizerDiscardTests.CaseType.CLEAR_STENCIL:252 if (this.m_caseOptions.useFBO)253 gl.clearBufferiv(gl.STENCIL, 0, [FAIL_STENCIL]);254 else255 gl.clear(gl.STENCIL_BUFFER_BIT);256 break;257 default:258 throw new Error('Invalid case type ' + this.m_caseType);259 }260 // Disable rasterizer discard261 gl.disable(gl.RASTERIZER_DISCARD);262 bufferedLogToConsole('Rasterizer discard disabled');263 if (this.m_caseType == es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL) {264 if (this.m_caseOptions.useFBO || gl.getContextAttributes().stencil) {265 // Draw a full-screen square that colors all pixels red if they have stencil value 1.266 var square = [new gluDrawUtil.VertexArrayBinding(gl.FLOAT, posLoc, 4, UNIT_SQUARE.length / 4, UNIT_SQUARE)];267 gl.stencilFunc(gl.EQUAL, 1, 0xFF);268 gluDrawUtil.draw(gl, program, square,269 new gluDrawUtil.PrimitiveList(gluDrawUtil.primitiveType.TRIANGLE_STRIP, UNIT_SQUARE.length / 4));270 }271 // \note If no stencil buffers are present and test is rendering to default framebuffer, test will always pass.272 } else if (this.m_caseType == es3fRasterizerDiscardTests.CaseType.CLEAR_DEPTH || this.m_caseType == es3fRasterizerDiscardTests.CaseType.CLEAR_STENCIL) {273 // Draw pass-indicating primitives for depth and stencil clear cases274 gl.uniform4fv(colorUnif, PASS_COLOR_BLUE);275 gluDrawUtil.draw(gl, program, vertexArrays, new gluDrawUtil.PrimitiveList(this.m_drawMode, vertices.length / 4));276 }277 gl.finish();278 gl.disable(gl.STENCIL_TEST);279 gl.disable(gl.DEPTH_TEST);280 gl.disable(gl.SCISSOR_TEST);281 // Read and check pixel data282 var pixels = new tcuSurface.Surface();283 pixels.readViewport(gl);284 var width = pixels.getWidth();285 var height = pixels.getHeight();286 for (var y = 0; y < height; y++) {287 for (var x = 0; x < width; x++) {288 var pixel = pixels.getPixel(x, y);289 if (pixel[2] != 0)290 passColorFound = true;291 if (pixel[0] != 0) {292 failColorFound = true;293 break;294 }295 }296 if (failColorFound) break;297 }298 // Delete FBO if created299 if (this.m_caseOptions.useFBO)300 this.deleteFramebufferObject();301 // Evaluate test result302 var testOk = passColorFound && !failColorFound;303 if (!testOk) {304 tcuLogImage.logImage('Result image', '', pixels.getAccess());305 testFailed('Primitive or buffer clear was not discarded.');306 return tcuTestCase.IterateResult.STOP;307 }308 bufferedLogToConsole('Primitive or buffer clear was discarded correctly.');309 if (++this.m_iterNdx < NUM_CASE_ITERATIONS)310 return tcuTestCase.IterateResult.CONTINUE;311 testPassed();312 return tcuTestCase.IterateResult.STOP;313};314es3fRasterizerDiscardTests.init = function() {315 var state = tcuTestCase.runner;316 var testGroup = state.testCases;317 var basic = tcuTestCase.newTest('basic', 'Rasterizer discard test for default framebuffer');318 var scissor = tcuTestCase.newTest('scissor', 'Rasterizer discard test for default framebuffer with scissor test enabled');319 var fbo = tcuTestCase.newTest('fbo', 'Rasterizer discard test for framebuffer object');320 testGroup.addChild(basic);321 testGroup.addChild(scissor);322 testGroup.addChild(fbo);323 // Default framebuffer cases324 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_points', 'points', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, null, gluDrawUtil.primitiveType.POINTS));325 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_lines', 'lines', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, null, gluDrawUtil.primitiveType.LINES));326 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_line_strip', 'line_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, null, gluDrawUtil.primitiveType.LINE_STRIP));327 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_line_loop', 'line_loop', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, null, gluDrawUtil.primitiveType.LINE_LOOP));328 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangles', 'triangles', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, null, gluDrawUtil.primitiveType.TRIANGLES));329 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangle_strip', 'triangle_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, null, gluDrawUtil.primitiveType.TRIANGLE_STRIP));330 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangle_fan', 'triangle_fan', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, null, gluDrawUtil.primitiveType.TRIANGLE_FAN));331 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_points', 'points', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, null, gluDrawUtil.primitiveType.POINTS));332 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_lines', 'lines', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, null, gluDrawUtil.primitiveType.LINES));333 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_line_strip', 'line_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, null, gluDrawUtil.primitiveType.LINE_STRIP));334 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_line_loop', 'line_loop', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, null, gluDrawUtil.primitiveType.LINE_LOOP));335 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangles', 'triangles', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, null, gluDrawUtil.primitiveType.TRIANGLES));336 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangle_strip', 'triangle_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, null, gluDrawUtil.primitiveType.TRIANGLE_STRIP));337 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangle_fan', 'triangle_fan', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, null, gluDrawUtil.primitiveType.TRIANGLE_FAN));338 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_color', 'clear_color', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_COLOR, null));339 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_depth', 'clear_depth', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_DEPTH, null));340 basic.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_stencil', 'clear_stencil', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_STENCIL, null));341 // Default framebuffer cases with scissor test enabled342 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_points', 'points', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.POINTS));343 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_lines', 'lines', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.LINES));344 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_line_strip', 'line_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.LINE_STRIP));345 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_line_loop', 'line_loop', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.LINE_LOOP));346 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangles', 'triangles', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.TRIANGLES));347 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangle_strip', 'triangle_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.TRIANGLE_STRIP));348 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangle_fan', 'triangle_fan', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.TRIANGLE_FAN));349 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_points', 'points', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.POINTS));350 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_lines', 'lines', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.LINES));351 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_line_strip', 'line_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.LINE_STRIP));352 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_line_loop', 'line_loop', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.LINE_LOOP));353 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangles', 'triangles', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.TRIANGLES));354 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangle_strip', 'triangle_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.TRIANGLE_STRIP));355 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangle_fan', 'triangle_fan', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR, gluDrawUtil.primitiveType.TRIANGLE_FAN));356 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_color', 'clear_color', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_COLOR, es3fRasterizerDiscardTests.CaseOptions.SCISSOR));357 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_depth', 'clear_depth', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_DEPTH, es3fRasterizerDiscardTests.CaseOptions.SCISSOR));358 scissor.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_stencil', 'clear_stencil', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_STENCIL, es3fRasterizerDiscardTests.CaseOptions.SCISSOR));359 // FBO cases360 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_points', 'points', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.POINTS));361 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_lines', 'lines', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.LINES));362 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_line_strip', 'line_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.LINE_STRIP));363 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_line_loop', 'line_loop', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.LINE_LOOP));364 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangles', 'triangles', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.TRIANGLES));365 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangle_strip', 'triangle_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.TRIANGLE_STRIP));366 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_depth_triangle_fan', 'triangle_fan', 4, es3fRasterizerDiscardTests.CaseType.WRITE_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.TRIANGLE_FAN));367 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_points', 'points', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.POINTS));368 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_lines', 'lines', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.LINES));369 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_line_strip', 'line_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.LINE_STRIP));370 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_line_loop', 'line_loop', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.LINE_LOOP));371 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangles', 'triangles', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.TRIANGLES));372 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangle_strip', 'triangle_strip', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.TRIANGLE_STRIP));373 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('write_stencil_triangle_fan', 'triangle_fan', 4, es3fRasterizerDiscardTests.CaseType.WRITE_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO, gluDrawUtil.primitiveType.TRIANGLE_FAN));374 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_color', 'clear_color', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_COLOR, es3fRasterizerDiscardTests.CaseOptions.FBO));375 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_depth', 'clear_depth', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_DEPTH, es3fRasterizerDiscardTests.CaseOptions.FBO));376 fbo.addChild(new es3fRasterizerDiscardTests.RasterizerDiscardCase('clear_stencil', 'clear_stencil', 4, es3fRasterizerDiscardTests.CaseType.CLEAR_STENCIL, es3fRasterizerDiscardTests.CaseOptions.FBO));377};378/**379 * Create and execute the test cases380 */381es3fRasterizerDiscardTests.run = function(context) {382 gl = context;383 //Set up Test Root parameters384 var testName = 'rasterizer_discard';385 var testDescription = 'Rasterizer Discard Tests';386 var state = tcuTestCase.runner;387 state.testName = testName;388 state.testCases = tcuTestCase.newTest(testName, testDescription, null);389 //Set up name and description of this test series.390 setCurrentTestName(testName);391 description(testDescription);392 try {393 es3fRasterizerDiscardTests.init();394 tcuTestCase.runTestCases();395 } catch (err) {396 testFailedOptions('Failed to run tests', false);397 bufferedLogToConsole(err);398 tcuTestCase.runner.terminate();399 }400};...
test_vp_analyzer.py
Source:test_vp_analyzer.py
1from collections import Counter2from scipy.misc import comb3import unittest4from vp_analyzer import HandAnalyzer, DiscardValue5class Test_vp_analyzer(unittest.TestCase):6 def setUp(self):7 self.h1 = HandAnalyzer('ahjcts7s4h')8 self.h2 = HandAnalyzer('qd9c8d5c2c')9 self.h3 = HandAnalyzer('qd9c8dacad')10 self.junk = HandAnalyzer('ts9c8d5c2h')11 self.aces8s_d = {'pair_jqka': 1, 'two_pair': 2, 'three_kind': 3,12 'straight': 4, 'flush': 5, 'full_house': 8,13 'four_kind': 25, 'four_kind7':50, 'four_kindA8':80,14 'straight_flush': 50, 'royal_flush': 800}15 self.tripbonusplus_d = {'pair_jqka': 1, 'two_pair': 1, 'three_kind': 3,16 'straight': 4, 'flush': 5, 'full_house': 9,17 'four_kind': 50, 'four_kind234':120, 'four_kindA':240,18 'straight_flush': 100, 'royal_flush': 800}19 #TODO: test count_wins (currently tested indirectly via HandAnalyzer.analyze)20 def test_hold(self):21 h1 = HandAnalyzer('ahjcts7s4h')22 hold_d_h1AJ = {'d': [('T', 's'), ('7', 's'), ('4', 'h')],23 'h': [('A', 'h'), ('J', 'c')]}24 hold_d = h1.hold([True]*2 + [False]*3)25 self.assertEqual(hold_d, hold_d_h1AJ)26 def test_analyze(self):27 #based on results from: https://www.videopokertrainer.org/calculator/28 junk_plays = self.junk.analyze()29 disc_all = 'X'*1030 exp_val_discardjunk = junk_plays[disc_all]['expected_val']31 self.assertEqual(round(exp_val_discardjunk, 5), round(0.35843407071, 5))32 exp_val_holdt = junk_plays['TsXXXXXXXX']['expected_val']33 self.assertEqual(round(exp_val_holdt, 5), round(0.32971715302, 5))34 h2_plays = self.h2.analyze()35 exp_val_holdq = h2_plays['QdXXXXXXXX']['expected_val']36 self.assertEqual(round(exp_val_holdq, 5), round(0.4741961707734, 5))37 h2_plays_bdc = self.h2.analyze(return_full_analysis = False,38 return_bestdisc_cnts = True)39 h2_bdc_out = {'QdXXXXXXXX': {'full_house': 288.0, 'three_kind': 4102.0,40 'four_kind': 52.0, 'straight': 590, 'straight_flush': 1, 'royal_flush': 1,41 'expected_val': 0.47419617077341408, 'flush': 328.0, 'pair_jqka': 45456.0,42 'two_pair': 8874.0}}43 self.assertEqual(h2_plays_bdc, h2_bdc_out)44 exp_val_holdq8 = h2_plays['QdXX8dXXXX']['expected_val']45 self.assertEqual(round(exp_val_holdq8, 5), round(0.41036077705827, 5))46 h3_plays = self.h3.analyze()47 exp_val_holdaa = h3_plays['XXXXXXAcAd']['expected_val']48 self.assertEqual(round(exp_val_holdaa, 5), round(1.536540240518, 5))49 exp_val_holdaa8 = h3_plays['XXXX8dAcAd']['expected_val']50 self.assertEqual(round(exp_val_holdaa8, 5), round(1.4162812210915, 5))51 lowp = HandAnalyzer('qcjckdtdth').analyze()52 exp_val_qjkt = lowp['QcJcKdTdXX']['expected_val']53 self.assertEqual(round(exp_val_qjkt, 5), round(0.8723404255319, 5))54 h2A8 = HandAnalyzer(''.join(self.h2.hand), payouts = self.aces8s_d)55 h2A8_plays = h2A8.analyze()56 exp_val_h2A8 = h2A8_plays['QdXXXXXXXX']['expected_val']57 self.assertEqual(round(exp_val_h2A8, 5), round(0.47119109690802569, 5))58 junk6 = HandAnalyzer('tc9d6h5s2c', payouts = self.aces8s_d)59 j6_plays = junk6.analyze()60 exp_val_j6 = j6_plays[disc_all]['expected_val']61 j6_disc_ev = 0.358844126135393962 self.assertEqual(round(exp_val_j6, 5), round(j6_disc_ev, 5))63 j6_best = junk6.analyze(return_full_analysis = False,64 return_bestdisc_cnts = False)65 self.assertEqual(j6_best[0], ''.join(disc_all))66 self.assertEqual(round(j6_best[1], 5), round(j6_disc_ev, 5))67 aaa = HandAnalyzer('ACADAH9CQH',payouts = self.aces8s_d)68 aaa_best = aaa.analyze(return_full_analysis = False,69 return_bestdisc_cnts = False)70 self.assertEqual(aaa_best[0], ''.join(('Ac', 'Ad', 'Ah', 'XX', 'XX')))71 self.assertEqual(round(aaa_best[1], 5), round(6.5818686401480111, 5))72 def test_pay_current_hand(self):73 for handobj in [self.h1, self.h2, self.junk]:74 self.assertEqual(handobj.pay_current_hand(), 0)75 fours_str = ['7c7h7d8s7s', '8c8d7h8h8s', 'As7sAhAdAc', 'QcQdQhQs2c']76 for fks, pay in zip(fours_str, [50, 80, 80, 25]):77 self.assertEqual(HandAnalyzer(fks).pay_current_hand(), 25)78 foursA8 = HandAnalyzer(fks, payouts = self.aces8s_d)79 self.assertEqual(foursA8.pay_current_hand(), pay)80 normal_wins = [('ackcqcjctc', 800), ('ac5c3c2c4c', 50),81 ('jc2cjd2djs', 9), ('7hKh9h4h2h', 6), ('Ac2d5d4d3d', 4),82 ('AcKdTdQdJd', 4), ('9h7c8sTcJc', 4), ('7c8h7h3s7s', 3),83 ('2c5d2h5s9c', 2), ('AcJc8s4dJd', 1), ('TsTdAs7c4h', 0)]84 for hand, pay in normal_wins:85 self.assertEqual(HandAnalyzer(hand).pay_current_hand(), pay)86 def test_pivot_held_d(self):87 test_pivot = [('A', 'J'), ('h', 'c'), ('T', '7', '4'), ('s', 's', 'h')]88 dv = DiscardValue(held_d = {'d': [('T', 's'), ('7', 's'), ('4', 'h')],89 'h': [('A', 'h'), ('J', 'c')]})90 self.assertEqual(dv.pivot_held_d(), test_pivot)91 dv2 = DiscardValue(hand_str = 'ahjcts7s4h', hold_str = 'ahjcxxXXxx')92 self.assertEqual(dv2.pivot_held_d(), test_pivot)93 def test_royal_flush(self):94 h1aj = DiscardValue(held_d = self.h1.hold([True]*2 + [False]*3))95 self.assertEqual(h1aj.royal_flush(), 0)96 holda = DiscardValue(held_d = self.h1.hold([True] + [False]*4))97 self.assertEqual(holda.royal_flush(), 1)98 discard_all = DiscardValue(held_d = self.h1.hold([False]*5))99 self.assertEqual(discard_all.royal_flush(), 1)100 discard_h2 = DiscardValue(held_d = self.h2.hold([False]*5))101 self.assertEqual(discard_h2.royal_flush(), 3)102 def test_three_kind(self):103 discard_h2 = DiscardValue(held_d = self.h2.hold([False]*5))104 self.assertEqual(discard_h2.three_kind(), 31502)105 h3holdaa = DiscardValue(held_d = self.h3.hold([False]*3 + [True]*2))106 self.assertEqual(h3holdaa.three_kind(), 1854)107 h3hold8aa = DiscardValue(held_d = self.h3.hold([False]*2 + [True]*3))108 self.assertEqual(h3hold8aa.three_kind(), 84)109 # fh = HandAnalyzer('qdqcqh2s2d')110 # self.assertEqual(fh.three_kind(fh.hold([True]*5)), 0)111 # self.assertEqual(fh.three_kind(fh.hold([True]*3+[False]*2)), 968)112 holdfh = DiscardValue(hand_str = 'qdqcqh2s2d', hold_str = 'qdqcqh2s2d')113 self.assertEqual(holdfh.three_kind(), 0)114 qqq = DiscardValue(held_d=HandAnalyzer('qdqcqh2s2d').hold([True]*3+[False]*2))115 self.assertEqual(qqq.three_kind(), 968)116 def test_draw_for_ranks(self):117 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))118 h2d4r = holdq._draw_for_ranks(gsize = 3, cnt_held_only = False)119 self.assertEqual(h2d4r, 4102)120 h3d4r = DiscardValue(held_d = self.h3.hold([False]*3 + [True]*2))121 self.assertEqual(h3d4r._draw_for_ranks(gsize = 3), 1893)122 def test_pair_jqka(self):123 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))124 self.assertEqual(holdq.pair_jqka(), 45456)125 holdaa = DiscardValue(held_d = self.h3.hold([False]*3 + [True]*2))126 self.assertEqual(holdaa.pair_jqka(), 11559)127 twop = DiscardValue(held_d=HandAnalyzer('acad8h8s2c').hold([True]*2 + [False]*3))128 self.assertEqual(twop.pair_jqka(), 11520)129 nohi = DiscardValue(held_d=HandAnalyzer('td9c8d5c2c').hold([False]*5))130 self.assertEqual(nohi.pair_jqka(), 241680)131 lowp = DiscardValue(held_d=HandAnalyzer('qcjckdtdth').hold([True]*4+[False]))132 self.assertEqual(lowp.pair_jqka(), 9)133 threek = DiscardValue(held_d=HandAnalyzer('4h4c5h3h4s').hold([True]*5))134 self.assertEqual(threek.pair_jqka(), 0)135 def test_four_kind(self):136 holdaa = DiscardValue(held_d = self.h3.hold([False]*3 + [True]*2))137 self.assertEqual(holdaa.four_kind(), 45)138 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))139 self.assertEqual(holdq.four_kind(), 52)140 h3hold8aa = DiscardValue(held_d = self.h3.hold([False]*2 + [True]*3))141 self.assertEqual(h3hold8aa.four_kind(), 1)142 discard_h2 = DiscardValue(held_d = self.h2.hold([False]*5))143 self.assertEqual(discard_h2.four_kind(), 344)144 fh = DiscardValue(held_d=HandAnalyzer('qdqcqh2s2d').hold([True]*3 + [False]*2))145 self.assertEqual(fh.four_kind(), 46)146 fourk = DiscardValue(held_d=HandAnalyzer('qcqdqhqs2c').hold([True]*4 + [False]))147 self.assertEqual(fourk.four_kind(), 47)148 h2A8 = HandAnalyzer(''.join(self.h2.hand), payouts = self.aces8s_d)149 h2A8holdq = DiscardValue(held_d=h2A8.hold([True]+[False]*4))150 h2A8holdq8 = DiscardValue(held_d=h2A8.hold([True,False,True]+[False]*2))151 spec = ['A', '7', '8']152 self.assertEqual(h2A8holdq.four_kind(specials=spec), 50)153 self.assertEqual(h2A8holdq8.four_kind(specials=spec), 1)154 junk6 = HandAnalyzer('tc9d6h5s2c', payouts = self.aces8s_d)155 j6disc = DiscardValue(held_d=junk6.hold([False]*5))156 self.assertEqual(j6disc.four_kind(specials=spec), 215)157 h2tbp = HandAnalyzer(''.join(self.h2.hand), payouts = self.tripbonusplus_d)158 h2tbpholdq = DiscardValue(held_d=h2tbp.hold([True]+[False]*4))159 h2tbpholdq8 = DiscardValue(held_d=h2tbp.hold([True,False,True]+[False]*2))160 spec_tbp = 'A234'161 self.assertEqual(h2tbpholdq.four_kind(specials=spec_tbp), 49)162 self.assertEqual(h2tbpholdq8.four_kind(specials=spec_tbp), 2)163 junk6tbp = HandAnalyzer('tc9d6h5s2c', payouts = self.tripbonusplus_d)164 j6disctbp = DiscardValue(held_d=junk6tbp.hold([False]*5))165 self.assertEqual(j6disctbp.four_kind(specials=spec_tbp), 215)166 def test_two_pair(self):167 twop = HandAnalyzer('acad8h8s2c')168 twopdv1 = DiscardValue(held_d=twop.hold([True]*4 + [False]))169 twopdv2 = DiscardValue(held_d=twop.hold([True]*5))170 twopdv3 = DiscardValue(held_d=twop.hold([True]*3 + [False]*2))171 self.assertEqual(twopdv1.two_pair(), 43)172 self.assertEqual(twopdv2.two_pair(), 1)173 self.assertEqual(twopdv3.two_pair(), 149)174 discard_h2 = DiscardValue(held_d = self.h2.hold([False]*5))175 self.assertEqual(discard_h2.two_pair(), 71802)176 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))177 self.assertEqual(holdq.two_pair(), 8874)178 holdq9 = DiscardValue(held_d = self.h2.hold([True]*2 + [False]*3))179 self.assertEqual(holdq9.two_pair(), 711)180 holdq98 = DiscardValue(held_d = self.h2.hold([True]*3 + [False]*2))181 self.assertEqual(holdq98.two_pair(), 27)182 hold98a = DiscardValue(held_d = self.h3.hold([False, True, True, True, False]))183 self.assertEqual(hold98a.two_pair(), 21)184 holdq985 = DiscardValue(held_d = self.h2.hold([True]*4 + [False]*1))185 self.assertEqual(holdq985.two_pair(), 0)186 h3hold8aa = DiscardValue(held_d = self.h3.hold([False]*2 + [True]*3))187 self.assertEqual(h3hold8aa.two_pair(), 186)188 holdaa = DiscardValue(held_d = self.h3.hold([False]*3 + [True]*2))189 self.assertEqual(holdaa.two_pair(), 2592)190 discaa = DiscardValue(held_d = self.h3.hold([True]*3 + [False]*2))191 self.assertEqual(discaa.two_pair(), 27)192 fourk = DiscardValue(held_d=HandAnalyzer('qcqdqhqs2c').hold([True]*4 + [False]))193 self.assertEqual(fourk.two_pair(), 0)194 fh = DiscardValue(held_d=HandAnalyzer('qdqcqh2s2d').hold([True]*5))195 self.assertEqual(fh.two_pair(), 0)196 def test_full_house(self):197 discard_h2 = DiscardValue(held_d = self.h2.hold([False]*5))198 self.assertEqual(discard_h2.full_house(), 2124)199 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))200 self.assertEqual(holdq.full_house(), 288)201 holdq9 = DiscardValue(held_d = self.h2.hold([True]*2 + [False]*3))202 self.assertEqual(holdq9.full_house(), 18)203 holdq98 = DiscardValue(held_d = self.h2.hold([True]*3 + [False]*2))204 self.assertEqual(holdq98.full_house(), 0)205 holdaa = DiscardValue(held_d = self.h3.hold([False]*3 + [True]*2))206 self.assertEqual(holdaa.full_house(), 165)207 h3hold8aa = DiscardValue(held_d = self.h3.hold([False]*2 + [True]*3))208 self.assertEqual(h3hold8aa.full_house(), 9)209 trips = HandAnalyzer('qcqdqh7c2d')210 tripsonly = DiscardValue(held_d=trips.hold([True]*3+[False]*2))211 self.assertEqual(tripsonly.full_house(), 66)212 tripsp1 = DiscardValue(held_d=trips.hold([True]*4+[False]))213 self.assertEqual(tripsp1.full_house(), 3)214 twop = DiscardValue(held_d=HandAnalyzer('acad8h8s2c').hold([True]*4 + [False]))215 self.assertEqual(twop.full_house(), 4)216 fh1 = DiscardValue(held_d=HandAnalyzer('qdqcqh2s2d').hold([True]*5))217 self.assertEqual(fh1.full_house(), 1)218 fh2 = DiscardValue(held_d=HandAnalyzer('qdqcqh2s2d').hold([True]*4 + [False]))219 self.assertEqual(fh2.full_house(), 2)220 def test_straight(self):221 discard_h2 = DiscardValue(held_d = self.h2.hold([False]*5))222 self.assertEqual(discard_h2.straight(), 5832)223 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))224 self.assertEqual(holdq.straight(), 590)225 holdq9 = DiscardValue(held_d = self.h2.hold([True]*2 + [False]*3))226 self.assertEqual(holdq9.straight(), 112)227 holdq98 = DiscardValue(held_d = self.h2.hold([True]*3 + [False]*2))228 self.assertEqual(holdq98.straight(), 16)229 def test_straight_flush(self):230 discard_h2 = DiscardValue(held_d = self.h2.hold([False]*5))231 self.assertEqual(discard_h2.straight_flush(), 21)232 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))233 self.assertEqual(holdq.straight_flush(), 1)234 h1aj = DiscardValue(held_d = self.h1.hold([True]*2+[False]*3))235 self.assertEqual(h1aj.straight_flush(), 0)236 junkd = DiscardValue(held_d = self.junk.hold([False]*5))237 self.assertEqual(junkd.straight_flush(), 16)238 junkt = DiscardValue(held_d = self.junk.hold([True]+[False]*4))239 self.assertEqual(junkt.straight_flush(), 4)240 junk8 = DiscardValue(held_d = self.junk.hold([False, False, True, False, False]))241 self.assertEqual(junk8.straight_flush(), 5)242 def test_flush(self):243 holdq = DiscardValue(held_d = self.h2.hold([True] + [False]*4))244 self.assertEqual(holdq.flush(), 328)245 holdq9 = DiscardValue(held_d = self.h2.hold([True]*2 + [False]*3))246 self.assertEqual(holdq9.flush(), 0)247 holdq8 = DiscardValue(held_d = self.h2.hold([True, False, True, False, False]))248 self.assertEqual(holdq8.flush(), 164)249 junkd = DiscardValue(held_d = self.junk.hold([False]*5))250 self.assertEqual(junkd.flush(), 2819)251 junkt = DiscardValue(held_d = self.junk.hold([True]+[False]*4))252 self.assertEqual(junkt.flush(), 490)253 def test_four_kindA8(self):254 h2A8 = HandAnalyzer(''.join(self.h2.hand), payouts = self.aces8s_d)255 h2A8dv = DiscardValue(held_d=h2A8.hold([True]+[False]*4))256 self.assertEqual(h2A8dv.four_kindA8(), 1)257 junk6 = HandAnalyzer('tc9d6h5s2c', payouts = self.aces8s_d)258 junk6dv = DiscardValue(held_d=junk6.hold([False]*5))259 self.assertEqual(junk6dv.four_kindA8(), 86)260 aaa = HandAnalyzer('ACADAH9CQH',payouts = self.aces8s_d)261 aaadv = DiscardValue(held_d=aaa.hold([True]*3+[False]*2))262 self.assertEqual(aaadv.four_kindA8(), 46)263 def test_four_kind7(self):264 h2A8 = HandAnalyzer(''.join(self.h2.hand), payouts = self.aces8s_d)265 h2A8dv = DiscardValue(held_d=h2A8.hold([True]+[False]*4))266 self.assertEqual(h2A8dv.four_kind7(), 1)267 h2A8dv2 = DiscardValue(held_d=h2A8.hold([True,False,True]+[False]*2))268 self.assertEqual(h2A8dv2.four_kind7(), 0)269 junk6 = HandAnalyzer('tc9d6h5s2c', payouts = self.aces8s_d)270 junk6dv = DiscardValue(held_d=junk6.hold([False]*5))271 self.assertEqual(junk6dv.four_kind7(), 43)272 def test_four_kindA(self):273 h2tbp = HandAnalyzer(''.join(self.h2.hand), payouts = self.tripbonusplus_d)274 h2tbpdv = DiscardValue(held_d=h2tbp.hold([True]+[False]*4))275 self.assertEqual(h2tbpdv.four_kindA(), 1)276 h2tbpdv2 = DiscardValue(held_d=h2tbp.hold([True,False,True]+[False]*2))277 self.assertEqual(h2tbpdv2.four_kindA(), 0)278 junk6 = HandAnalyzer('tc9d6h5s2c', payouts = self.tripbonusplus_d)279 junk6dv = DiscardValue(held_d=junk6.hold([False]*5))280 self.assertEqual(junk6dv.four_kindA(), 43)281 def test_four_kind234(self):282 h2tbp = HandAnalyzer(''.join(self.h2.hand), payouts = self.tripbonusplus_d)283 h2tbpdv = DiscardValue(held_d=h2tbp.hold([True]+[False]*4))284 self.assertEqual(h2tbpdv.four_kind234(), 2)285 h2tbpdv2 = DiscardValue(held_d=h2tbp.hold([True,False,True]+[False]*2))286 self.assertEqual(h2tbpdv2.four_kind234(), 0)287 junk6 = HandAnalyzer('tc9d6h5s2c', payouts = self.tripbonusplus_d)288 junk6dv = DiscardValue(held_d=junk6.hold([False]*5))...
Jaccard.py
Source:Jaccard.py
...52 # remove stop words from string 53 X_set = {w for w in X_list if not w in sw} 54 Y_set = {w for w in Y_list if not w in sw} 5556 X_set.discard('.')57 X_set.discard('(')58 X_set.discard(')')59 X_set.discard('"')60 X_set.discard(',')61 X_set.discard('-')62 X_set.discard('\'')63 64 Y_set.discard('.')65 Y_set.discard('(')66 Y_set.discard(')')67 Y_set.discard('"')68 Y_set.discard(',')69 Y_set.discard('-')70 Y_set.discard('\'')7172 print("\nX_set ", X_set, "\nY_set", Y_set,"\n")73 74 # form a set containing keywords of both strings 75 rvector = X_set.union(Y_set) 76 for w in rvector: 77 if w in X_set: l1.append(1) # create a vector 78 else: l1.append(0) 79 if w in Y_set: l2.append(1) 80 else: l2.append(0)8182 c = 083 vect_len = len(rvector)8485 #print("\n",l1,"\n",l2,"\n")8687 intersection = 088 union = vect_len89 #calculating average of each sentence90 for i in range(vect_len) :91 intersection += l1[i]*l2[i]9293 # jaccard coefficient formula9495 jaccard = intersection/union 96 average += jaccard/no_of_sen97 print("\nsimilarity: ", jaccard) 9899 print("\nfinal average jaccard coefficient=",average,"\n")100101 elif(language==2) : #English document102103 tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')104105 with open("output.txt") as f:106 output = f.readlines()107 with open("actual.txt") as g:108 actual = g.readlines()109110 # tokenization 111112 output_lines = DutchtoEnglish.sentence_tokenizer(output)113 actual_lines = DutchtoEnglish.sentence_tokenizer(actual)114115 output_sentences = list()116 actual_sentences = list()117118 for line in output_lines :119 l = tokenizer.tokenize(line)120 for sen in l :121 output_sentences.append(sen)122 for line in actual_lines :123 l = tokenizer.tokenize(line)124 for sen in l :125 actual_sentences.append(sen)126127 no_of_sen = len(actual_sentences)128 average = 0.0129130 # sw contains the list of stopwords 131 sw = stopwords.words('english')132133 for index in range(no_of_sen) :134 135 l1 =[]136 l2 =[] 137 138 X_list = word_tokenize(output_sentences[index].lower())139 Y_list = word_tokenize(actual_sentences[index].lower())140141 # remove stop words from string 142 X_set = {w for w in X_list if not w in sw} 143 Y_set = {w for w in Y_list if not w in sw} 144145 X_set.discard('.')146 X_set.discard('(')147 X_set.discard(')')148 X_set.discard('"')149 X_set.discard(',')150 X_set.discard('-')151 X_set.discard('\'')152 153 Y_set.discard('.')154 Y_set.discard('(')155 Y_set.discard(')')156 Y_set.discard('"')157 Y_set.discard(',')158 Y_set.discard('-')159 Y_set.discard('\'')160161 print("\nX_set ", X_set, "\nY_set", Y_set,"\n")162 163 # form a set containing keywords of both strings 164 rvector = X_set.union(Y_set) 165 for w in rvector: 166 if w in X_set: l1.append(1) # create a vector 167 else: l1.append(0) 168 if w in Y_set: l2.append(1) 169 else: l2.append(0) 170171 c = 0172 vect_len = len(rvector)173 print("vec_len=", vect_len, "\n")
...
CosineSimilarity.py
Source:CosineSimilarity.py
...52 # remove stop words from string 53 X_set = {w for w in X_list if not w in sw} 54 Y_set = {w for w in Y_list if not w in sw} 5556 X_set.discard('.')57 X_set.discard('(')58 X_set.discard(')')59 X_set.discard('"')60 X_set.discard(',')61 X_set.discard('-')62 X_set.discard('\'')63 64 Y_set.discard('.')65 Y_set.discard('(')66 Y_set.discard(')')67 Y_set.discard('"')68 Y_set.discard(',')69 Y_set.discard('-')70 Y_set.discard('\'')71 72 73 # form a set containing keywords of both strings 74 rvector = X_set.union(Y_set) 75 for w in rvector: 76 if w in X_set: l1.append(1) # create a vector 77 else: l1.append(0) 78 if w in Y_set: l2.append(1) 79 else: l2.append(0) 80 c = 081 82 # cosine formula 83 for i in range(len(rvector)): 84 c+= l1[i]*l2[i] 85 cosine = c / float((sum(l1)*sum(l2))**0.5) 8687 average += cosine/no_of_sen88 print("\ncosine =",cosine)8990 print("\nfinal cosine similarity: ",average) 9192 elif(language==2) :93 94 tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')9596 with open("output.txt") as f:97 output = f.readlines()98 with open("actual.txt") as g:99 actual = g.readlines()100101 # tokenization 102103 output_lines = DutchtoEnglish.sentence_tokenizer(output)104 actual_lines = DutchtoEnglish.sentence_tokenizer(actual)105106 output_sentences = list()107 actual_sentences = list()108109 for line in output_lines :110 l = tokenizer.tokenize(line)111 for sen in l :112 output_sentences.append(sen)113 for line in actual_lines :114 l = tokenizer.tokenize(line)115 for sen in l :116 actual_sentences.append(sen)117118 no_of_sen = len(actual_sentences)119 average = 0.0120121 # sw contains the list of stopwords 122 sw = stopwords.words('english')123124 for index in range(no_of_sen) :125 126 l1 =[];l2 =[] 127 128 X_list = word_tokenize(output_sentences[index].lower())129 Y_list = word_tokenize(actual_sentences[index].lower())130131 # remove stop words from string 132 X_set = {w for w in X_list if not w in sw} 133 Y_set = {w for w in Y_list if not w in sw} 134135 X_set.discard('.')136 X_set.discard('(')137 X_set.discard(')')138 X_set.discard('"')139 X_set.discard(',')140 X_set.discard('-')141 X_set.discard('\'')142143 Y_set.discard('.')144 Y_set.discard('(')145 Y_set.discard(')')146 Y_set.discard('"')147 Y_set.discard(',')148 Y_set.discard('-')149 Y_set.discard('\'')150 151 # form a set containing keywords of both strings 152 rvector = X_set.union(Y_set) 153 for w in rvector: 154 if w in X_set: l1.append(1) # create a vector 155 else: l1.append(0) 156 if w in Y_set: l2.append(1) 157 else: l2.append(0) 158 c = 0159 160 # cosine formula 161 for i in range(len(rvector)): 162 c+= l1[i]*l2[i] 163 cosine = c / float((sum(l1)*sum(l2))**0.5)
...
discardReasons.js
Source:discardReasons.js
1'use strict';2angular.module('bsis')3 .controller('DiscardReasonsCtrl', function($scope, $location, DiscardReasonsService, ngTableParams, $timeout, $filter, ICONS) {4 $scope.icons = ICONS;5 var data = [{}];6 $scope.data = data;7 $scope.discardReasons = {};8 $scope.clear = function() {9 };10 $scope.clearForm = function(form) {11 form.$setPristine();12 $scope.submitted = '';13 };14 $scope.getDiscards = function() {15 DiscardReasonsService.getDiscards(function(response) {16 if (response !== false) {17 data = response;18 $scope.data = data;19 $scope.discardReasons = data;20 $scope.discardReasonsCount = $scope.discardReasons.length;21 }22 });23 };24 $scope.discardsTableParams = new ngTableParams({25 page: 1, // show first page26 count: 6, // count per page27 filter: {},28 sorting: {}29 },30 {31 defaultSort: 'asc',32 counts: [], // hide page counts control33 total: data.length, // length of data34 getData: function($defer, params) {35 var filteredData = params.filter() ?36 $filter('filter')(data, params.filter()) : data;37 var orderedData = params.sorting() ?38 $filter('orderBy')(filteredData, params.orderBy()) : data;39 params.total(orderedData.length); // set total for pagination40 $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));41 }42 });43 $scope.$watch('data', function() {44 $timeout(function() {45 $scope.discardsTableParams.reload();46 });47 });48 $scope.addNewDiscardReason = function() {49 DiscardReasonsService.setDiscardReason('');50 $location.path('/manageDiscardReason');51 };52 $scope.manageDiscardReason = function(discard) {53 $scope.discard = discard;54 DiscardReasonsService.setDiscardReason(discard);55 $location.path('/manageDiscardReason/' + discard.id);56 };57 $scope.getDiscards();58 })59 .controller('ManageDiscardReasonsCtrl', function($scope, $location, DiscardReasonsService, ICONS, DATATYPES, $routeParams) {60 $scope.icons = ICONS;61 $scope.selection = '/manageDiscardReason';62 $scope.getDiscardReason = function() {63 DiscardReasonsService.getDiscardReasonById($routeParams.id, function(discardReason) {64 $scope.discard = discardReason;65 }, function(err) {66 $scope.err = err;67 });68 };69 if (!$routeParams.id) {70 $scope.discard = {71 isDeleted: false72 };73 } else {74 $scope.getDiscardReason();75 $scope.disableDiscardname = true;76 }77 $scope.dataTypes = DATATYPES.options;78 $scope.saveDiscardReason = function(discard, discardForm) {79 if (discardForm.$valid) {80 if (angular.isDefined(discard)) {81 if (angular.isDefined(discard.id)) {82 $scope.updateDiscardReason(discard, discardForm);83 } else {84 $scope.addDiscardReason(discard, discardForm);85 }86 }87 } else {88 $scope.submitted = true;89 }90 };91 $scope.serverError = {};92 $scope.updateDiscardReason = function(discard, discardForm) {93 if (discardForm.$valid) {94 $scope.savingDiscardReason = true;95 DiscardReasonsService.updateDiscardReason(discard, function(response, err) {96 if (response !== false) {97 $scope.go('/discardReasons');98 } else {99 if (err.reason) {100 $scope.discardReasonInvalid = 'ng-invalid';101 $scope.serverError.reason = err.reason;102 }103 }104 $scope.savingDiscardReason = false;105 });106 } else {107 $scope.submitted = true;108 }109 };110 $scope.addDiscardReason = function(discard, discardForm) {111 if (discardForm.$valid) {112 discard.isDeleted = false;113 $scope.savingDiscardReason = true;114 DiscardReasonsService.addDiscardReason(discard, function(response, err) {115 if (response !== false) {116 $scope.discard = {117 reason: '',118 isDeleted: false119 };120 discardForm.$setPristine();121 $scope.submitted = '';122 $scope.go('/discardReasons');123 } else {124 if (err.reason) {125 $scope.discardReasonInvalid = 'ng-invalid';126 $scope.serverError.reason = err.reason;127 }128 }129 $scope.savingDiscardReason = false;130 });131 } else {132 $scope.submitted = true;133 }134 };135 $scope.clearForm = function(form) {136 form.$setPristine();137 $scope.submitted = '';138 };139 $scope.cancel = function(form) {140 $scope.clearForm(form);141 $location.path('/discardReasons');142 };143 $scope.go = function(path) {144 $location.path(path);145 };...
deck of cards.py
Source:deck of cards.py
...4950 def drawcard(self):51 return self.cards.pop()5253 def discard(self):54 return self.hand.pop()55 5657class Player:58 def __init__(self, u_name_l):59 self.hand = []60 self.pile = []61 self.name = u_name_l6263 def draw(self, deck, x):64 for i in range(x):65 self.hand.append(deck.drawcard())66 #return self #allows player draw multiple cards67 68 69 def showhand(self):70 print("\nYour hand is")71 for card in self.hand:72 card.showcard()7374 def showpile (self):75 print("'\nCards on the pile are")76 for card in self.pile:77 card.showcard()78 7980 def discard(self): #remove random card - could be used in 'AI'81 discard_card = input("What card do you want to discard? ").split(' ')82 suit = discard_card[0]83 if discard_card[1] == 'Reverse':84 discard_card[1] = 1085 number = int(discard_card[1])86 discard_card = Card(suit, number)87 elif discard_card[1] == 'Skip':88 discard_card[1] = 1189 number = int(discard_card[1])90 discard_card = Card(suit, number)91 elif discard_card[1] == '+2':92 discard_card[1] = 1293 number = int(discard_card[1])94 discard_card = Card(suit , number)95 elif discard_card[1] == '9':96 number = int(discard_card[1])97 discard_card = Card(suit, number)98 elif discard_card[1] == '8':99 number = int(discard_card[1])100 discard_card = Card(suit, number)101 elif discard_card[1] == '7':102 number = int(discard_card[1])103 discard_card = Card(suit, number)104 elif discard_card[1] == '6':105 number = int(discard_card[1])106 discard_card = Card(suit, number)107 elif discard_card[1] == '5':108 number = int(discard_card[1])109 discard_card = Card(suit, number)110 elif discard_card[1] == '4':111 number = int(discard_card[1])112 discard_card = Card(suit, number)113 elif discard_card[1] == '3':114 number = int(discard_card[1])115 discard_card = Card(suit, number)116 elif discard_card[1] == '2':117 number = int(discard_card[1])118 discard_card = Card(suit, number)119 elif discard_card[1] == '1':120 number = int(discard_card[1])121 discard_card = Card(suit, number)122 elif discard_card[1] == '0':123 number = int(discard_card[1])124 discard_card = Card(suit, number)125 126 if discard_card in self.hand:127 self.hand.remove(discard_card)128 self.pile.append(discard_card)129 130131deck = Deck()132deck.shuffle()133Player1 = Player('David')134Player1.draw(deck, 5)135Player1.showhand()136Player1.discard()137Player1.showhand()138Player1.showpile()139
...
test_samples.py
Source:test_samples.py
1SAMPLE_INITIAL_HANDS = {2 'Lil': ['+8H', '+9H', '+JS', '+6H'],3 'Shady': ['+??', '+??', '+??', '+??'],4 'Danny': ['+??', '+??', '+??', '+??'],5 'Rocky': ['+QH', '+KD', '+8S', '+9C']6}7SAMPLE_ROUND_DICT = {1: [8 ['Shady', '+??', '+??', '+??', '+??'],9 ['Rocky', '+QH', '+KD', '+8S', '+9C'],10 ['Danny', '+??', '+??', '+??', '+??'],11 ['Lil', '+8H', '+9H', '+JS', '+6H'],12 ['Shady', '-QD:discard', '-2S:discard'],13 ['Rocky', '-KD:Shady', '+7H'],14 ['Danny', '-QC:Rocky', '+??', '+??'],15 ['Lil', '-6H:Rocky', '-??:Shady', '-8H:discard',16 '+??', '-10S:discard', '+??'],17 ['*', '-JS:Shady', '+10S', '+QS']18], 2: [19 ['Shady', '+KD:Rocky', '+??:Lil', '-KD:discard', '-??:Lil'],20 ['Rocky', '+QC:Danny', '+6H:Lil', '-9C:Danny',21 '-6H:discard', '-7H:discard', '+3D', '+3H'],22 ['Danny', '+9C:Rocky', '-AD:discard', '+??'],23 ['Lil', '+??:Shady', '+??', '-??:Danny', '-??:Shady', '+??'],24 ['*', '+AH:Shady', '+8D', '-8D:Danny', '-QS:Shady', '+8C']25], 3: [26 ['Shady', '+??:Lil', '-7S:discard', '+??', '-10H:discard'],27 ['Rocky', '-QH:Lil', '+5D', '-8S:Shady', '-3H:discard', '-QC:discard'],28 ['Danny', '+??:Lil', '+??', '+??', '-??:Lil', '-3S:Rocky', '-??:Shady'],29 ['Lil', '+QH:Rocky', '+??:Danny', '-AH:Rocky', '-QH:discard'],30 ['*', '+4D:Danny']31], 4: [32 ['Shady', '+8S:Rocky', '+??:Danny', '-JS:discard',33 '+??', '+??', '+??', '+??'],34 ['Rocky', '+3S:Danny', '+AH:Lil', '+AS', '+4H'],35 ['Danny', '-10D:discard', '+??', '-6S:discard',36 '-JC:discard', '-8D:discard'],37 ['Lil', '-8C:discard', '-??:Shady', '+??', '-??:Danny'],38 ['*', '-4D:Shady', '+KH', '-KH:Danny']39], 5: [40 ['Shady', '+??:Lil', '-??:Danny', '+??', '-2H:discard'],41 ['Rocky', '+5C', '-5D:discard', '+3C', '-3D:discard',42 '-5C:discard', '+KS'],43 ['Danny', '+??:Lil', '+??:Shady', '-??:Lil', '-6D:discard', '+??'],44 ['Lil', '+??:Danny', '-??:Shady', '-??:Danny'],45 ['*', '+KH:Danny', '-9H:Shady', '-KH:Danny']46]}47# I am using this, because the individual functions are reliant on each48# other whilst processing the data - as I am using pop to remove49# items as I work through the round dict.50SAMPLE_SIGNAL_ONLY_ROUND_DICT = {51 1: [ ['*', '-JS:Shady', '+10S', '+QS'] ],52 2: [ ['*', '+AH:Shady', '+8D', '-8D:Danny', '-QS:Shady', '+8C'] ],53 3: [ ['*', '+4D:Danny'] ],54 4: [ ['*', '-4D:Shady', '+KH', '-KH:Danny'] ],55 5: [ ['*', '+KH:Danny', '-9H:Shady', '-KH:Danny'] ]56}57SAMPLE_ROUND_2_SIGNALS = {58 1: ['+AH:Shady', '+8D', '-8D:Danny', '-QS:Shady', '+8C']...
Using AI Code Generation
1root.discard();2child.discard();3grandChild.discard();4grandGrandChild.discard();5grandGrandGrandChild.discard();6grandGrandGrandGrandChild.discard();7grandGrandGrandGrandGrandChild.discard();8grandGrandGrandGrandGrandGrandChild.discard();9grandGrandGrandGrandGrandGrandGrandChild.discard();10grandGrandGrandGrandGrandGrandGrandGrandChild.discard();11grandGrandGrandGrandGrandGrandGrandGrandGrandChild.discard();12grandGrandGrandGrandGrandGrandGrandGrandGrandGrandChild.discard();
Using AI Code Generation
1$scope.$on('$locationChangeStart', function(event, next, current) {2 event.preventDefault();3 $scope.$apply(function() {4 $location.path("/login");5 });6});
Using AI Code Generation
1var root = require('./root.js');2root.discard('test.js');3root.discard('test2.js');4root.discard('test3.js');5root.discard('test4.js');6root.discard('test5.js');7root.discard('test6.js');8root.discard('test7.js');9root.discard('test8.js');10root.discard('test9.js');11root.discard('test10.js');12root.discard('test11.js');13root.discard('test12.js');14root.discard('test13.js');15root.discard('test14.js');16root.discard('test15.js');17root.discard('test16.js');18root.discard('test17.js');19root.discard('test18.js');20root.discard('test19.js');21root.discard('test20.js');22root.discard('test21.js');23root.discard('test22.js');24root.discard('test23.js');25root.discard('test24.js');26root.discard('test25.js');27root.discard('test26.js');28root.discard('test27.js');29root.discard('test28.js');30root.discard('test29.js');31root.discard('test30.js');32root.discard('test31.js');33root.discard('test32.js');34root.discard('test33.js');35root.discard('test34.js');36root.discard('test35.js');37root.discard('test36.js');38root.discard('test37.js');39root.discard('test38.js');40root.discard('test39.js');41root.discard('test40.js');42root.discard('test41.js');43root.discard('test42.js');44root.discard('test43.js');45root.discard('test44.js');46root.discard('test45.js');47root.discard('test46.js');48root.discard('test47.js');49root.discard('test48.js');50root.discard('test49.js');51root.discard('test50.js');52root.discard('test51.js');53root.discard('test52.js');54root.discard('test53.js');55root.discard('test54.js');56root.discard('test55.js');57root.discard('test56.js');58root.discard('test57.js');59root.discard('test58.js');60root.discard('test59.js');61root.discard('test60.js');62root.discard('test61.js');
Using AI Code Generation
1var root = document.getElementById("root");2root.discard();3var child = document.getElementById("child");4child.discard();5var root = document.getElementById("root");6root.discard();7var child = document.getElementById("child");8child.discard();9var root = document.getElementById("root");10root.discard();11var child = document.getElementById("child");12child.discard();13var root = document.getElementById("root");14root.discard();15var child = document.getElementById("child");16child.discard();17var root = document.getElementById("root");18root.discard();19var child = document.getElementById("child");20child.discard();21var root = document.getElementById("root");22root.discard();23var child = document.getElementById("child");24child.discard();25var root = document.getElementById("root");26root.discard();27var child = document.getElementById("child");28child.discard();
Using AI Code Generation
1var root = require('./root');2var child = require('./child');3root.discard(child);4var discard = function(child) {5 console.log("discarding child");6};7module.exports = {8};9var root = require('./root');10root.discard();11var discard = function() {12 console.log("discarding child");13};14module.exports = {15};16var root = require('./root');17root.discard();18var discard = function() {19 console.log("discarding child");20};21module.exports = {22};23var root = require('./root');24root.discard();25var discard = function() {26 console.log("discarding child");27};28module.exports = {29};30var root = require('./root');31root.discard();32var discard = function() {33 console.log("discarding child");34};35module.exports = {36};37var root = require('./root');38root.discard();39var discard = function() {40 console.log("discarding child");41};42module.exports = {43};44var root = require('./root');45root.discard();46var discard = function() {47 console.log("discarding child");48};49module.exports = {50};51var root = require('./root');52root.discard();
Using AI Code Generation
1var root = require('Root');2root.discard();3### `root.get(key)`4var root = require('Root');5var value = root.get('key');6### `root.set(key, value)`7var root = require('Root');8root.set('key', 'value');9### `root.has(key)`10var root = require('Root');11var isKeyPresent = root.has('key');12### `root.keys()`13var root = require('Root');14var keys = root.keys();15### `root.values()`16var root = require('Root');17var values = root.values();18### `root.entries()`19var root = require('Root');20var keyValues = root.entries();21### `root.forEach(callback)`22var root = require('Root');23root.forEach(function (value, key) {24 console.log(key + ': ' + value);25});26### `root.clear()`27var root = require('Root');28root.clear();29### `root.size()`30var root = require('Root');31var size = root.size();32### `root.toJSON()`
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!