How to use two method in ts-auto-mock

Best JavaScript code snippet using ts-auto-mock

array-of-arrays-test.js

Source:array-of-arrays-test.js Github

copy

Full Screen

1import { expect } from "@hapi/code";2import * as Lab from "@hapi/lab";3import getHelper from "lab-testing";4import manyMappings from "./suites/many-mappings-suite";5import createMapper from "../lib";6import flattenDeep from "lodash.flattendeep";7const lab = exports.lab = Lab.script();8const testing = getHelper(lab);9const group = testing.createExperiment("arrays", "array of arrays");10const groups = ["arrays", "array of arrays"];11group("when mapping from a larger to a small array", () => {12 const src = {13 one: [{14 two: [15 { three: [{ value: "A" }, { value: "B" }] },16 { three: [{ value: "C" }, { value: "D" }] }17 ]18 },19 {20 two: [21 { three: [{ value: "A1" }, { value: "B1" }] },22 { three: [{ value: "C1" }, { value: "D1" }] }23 ]24 }]25 };26 const expected = {27 one: [28 { two: [{ value: "A" }, { value: "B" }, { value: "C" }, { value: "D" }] },29 { two: [{ value: "A1" }, { value: "B1" }, { value: "C1" }, { value: "D1" }] }30 ]31 };32 lab.test("or() mode works when the first get fails", () => {33 const mapper = createMapper();34 const actual = mapper35 .map("fish").or("one[].two[].three[].value").to("one[].two[].value")36 .execute(src);37 expect(actual).to.equal(expected);38 });39 lab.test("or() mode works when the second get succeeds", () => {40 const mapper = createMapper();41 const actual = mapper42 .map("one[].two[].three[].value").or("fish").to("one[].two[].value")43 .execute(src);44 expect(actual).to.equal(expected);45 });46 lab.test("missing data works as expected", () => {47 const emptySource = {48 one: [{ two: [{ three: [] }, { three: [] }, { three: null }, undefined, null] }]49 };50 const mapper = createMapper();51 const actual = mapper52 .map("one[].two[].three[]").to("one[].two[]")53 .execute(emptySource);54 expect(actual).to.equal({});55 });56});57group("with the flattenInverted option == true", () => {58 const src = [{59 one: [60 { name: "first", two: [{ value: "A" }, { value: "B" }] },61 { name: "second", two: [{ value: "C" }, { value: "D" }] }62 ]63 }, {64 one: [65 { name: "third", two: [{ value: "E" }, { value: "F" }] },66 { name: "fourth", two: [{ value: "G" }, { value: "H" }] }67 ]68 }];69 lab.test("a single level flatten works correctly", () => {70 const mapper = createMapper();71 const expected = [72 { name: "first", values: ["A", "B"] },73 { name: "second", values: ["C", "D"] },74 { name: "third", values: ["E", "F"] },75 { name: "fourth", values: ["G", "H"] }76 ];77 const options = { flattenInverted: true };78 mapper79 .map("[].one[].name").to("[].name")80 .map("[].one[].two[].value").with(options).to("[].values[]");81 const actual = mapper.execute(src);82 expect(actual).to.equal(expected);83 });84 lab.test("a two level flatting works correctly", () => {85 const mapper = createMapper();86 // The result whether flattened normally or inverted is the same87 const expected = ["A", "B", "C", "D", "E", "F", "G", "H"];88 const options = { flattenInverted: true };89 mapper90 .map("[].one[].two[].value").with(options).to("[]");91 const actual = mapper.execute(src);92 expect(actual).to.equal(expected);93 });94});95group("with the flatten option == false", () => {96 lab.test("a two level flatting works correctly", () => {97 const mapper = createMapper();98 const src = [{99 one: [100 { name: "first", two: [{ value: "A" }, { value: "B" }] },101 { name: "second", two: [{ value: "C" }, { value: "D" }] }102 ]103 }, {104 one: [105 { name: "third", two: [{ value: "E" }, { value: "F" }] },106 { name: "fourth", two: [{ value: "G" }, { value: "H" }] }107 ]108 }];109 // The result whether flattened normally or inverted is the same110 const expected = [[["A", "B"], ["C", "D"]], [["E", "F"], ["G", "H"]]];111 const options = { flatten: false };112 mapper113 .map("[].one[].two[].value").with(options).to("[]");114 const actual = mapper.execute(src);115 expect(actual).to.equal(expected);116 });117});118group("in multi-mode with array of arrays", () => {119 lab.test("array flattening is not applied", () => {120 const src = {121 one: [{122 two: [123 { three: [{ value: "A" }, { value: "B" }] },124 { three: [{ value: "C" }, { value: "D" }] }125 ]126 },127 {128 two: [129 { three: [{ value: "A1" }, { value: "B1" }] },130 { three: [{ value: "C1" }, { value: "D1" }] }131 ]132 }]133 };134 const expected = {135 result: [136 [["A", "B"], ["C", "D"]],137 [["A1", "B1"], ["C1", "D1"]]138 ]139 };140 const mapper = createMapper();141 const actual = mapper142 .map(["one[].two[].three[].value"]).to("result", item => item)143 .execute(src);144 expect(actual).to.equal(expected);145 });146});147const valueToValueTests = [148 {149 NAME: "1 level to 2 levels",150 SOURCE: {151 one: [{ value: "A" }, { value: "B" }]152 },153 EXPECTED: {154 one: [{ two: [{ value: "A" }, { value: "B" }] }]155 },156 MAPPINGS: [157 {158 from: "one[].value",159 to: "one[].two[].value"160 }]161 },162 {163 NAME: "2 levels to 1 level",164 SOURCE: {165 one: [166 { two: [{ value: "A" }, { value: "B" }] },167 { two: [{ value: "C" }, { value: "D" }] }168 ]169 },170 EXPECTED: {171 one: [{ value: "A" }, { value: "B" }, { value: "C" }, { value: "D" }]172 },173 MAPPINGS: [174 {175 from: "one[].two[].value",176 to: "one[].value"177 }]178 },179 {180 NAME: "2 levels to 2 levels",181 SOURCE: {182 one: [183 { two: [{ value: "A" }, { value: "B" }] },184 { two: [{ value: "C" }, { value: "D" }] }185 ]186 },187 EXPECTED: {188 one: [189 { two: [{ value: "A" }, { value: "B" }] },190 { two: [{ value: "C" }, { value: "D" }] }191 ]192 },193 MAPPINGS: [194 {195 from: "one[].two[].value",196 to: "one[].two[].value"197 }]198 },199 {200 NAME: "2 level to 3 levels",201 SOURCE: {202 one: [203 { two: [{ value: "A" }, { value: "B" }] },204 { two: [{ value: "C" }, { value: "D" }] }205 ]206 },207 EXPECTED: {208 one: [{209 two: [{ three: [{ value: "A" }, { value: "B" }] }]210 },211 {212 two: [{ three: [{ value: "C" }, { value: "D" }] }]213 }]214 },215 MAPPINGS: [216 {217 from: "one[].two[].value",218 to: "one[].two[].three[].value"219 }]220 },221 {222 NAME: "3 level to 2 levels",223 SOURCE: {224 one: [{225 two: [226 { three: [{ value: "A" }, { value: "B" }] },227 { three: [{ value: "C" }, { value: "D" }] }228 ]229 },230 {231 two: [232 { three: [{ value: "A1" }, { value: "B1" }] },233 { three: [{ value: "C1" }, { value: "D1" }] }234 ]235 }]236 },237 EXPECTED: {238 one: [239 { two: [{ value: "A" }, { value: "B" }, { value: "C" }, { value: "D" }] },240 { two: [{ value: "A1" }, { value: "B1" }, { value: "C1" }, { value: "D1" }] }241 ]242 },243 MAPPINGS: [244 {245 from: "one[].two[].three[].value",246 to: "one[].two[].value"247 }]248 },249 {250 NAME: "3 level to 1 levels",251 SOURCE: {252 one: [{253 two: [254 { three: [{ value: "A" }, { value: "B" }] },255 { three: [{ value: "C" }, { value: "D" }] }256 ]257 },258 {259 two: [260 { three: [{ value: "A1" }, { value: "B1" }] },261 { three: [{ value: "C1" }, { value: "D1" }] }262 ]263 }]264 },265 EXPECTED: {266 one: [267 { value: "A" },268 { value: "B" },269 { value: "C" },270 { value: "D" },271 { value: "A1" },272 { value: "B1" },273 { value: "C1" },274 { value: "D1" }275 ]276 },277 MAPPINGS: [278 {279 from: "one[].two[].three[].value",280 to: "one[].value"281 }]282 }283];284valueToValueTests.map(({ NAME, SOURCE, EXPECTED, MAPPINGS }) => {285 const labels = flattenDeep([groups, ["with value source and value target", NAME]]);286 manyMappings.run(lab, {287 LABELS: labels, SOURCE, EXPECTED, MAPPINGS, MULTI_MODE: false288 });289});290const valueToArrayTests = [291 {292 NAME: "1 level to 2 levels",293 SOURCE: {294 one: [{ value: "A" }, { value: "B" }]295 },296 EXPECTED: {297 one: [{ two: ["A", "B"] }]298 },299 MAPPINGS: [300 {301 from: "one[].value",302 to: "one[].two[]"303 }]304 },305 {306 NAME: "2 levels to 1 levels",307 SOURCE: {308 one: [309 { two: [{ value: "A" }, { value: "B" }] },310 { two: [{ value: "C" }, { value: "D" }] }311 ]312 },313 EXPECTED: {314 one: ["A", "B", "C", "D"]315 },316 MAPPINGS: [317 {318 from: "one[].two[].value",319 to: "one[]"320 }]321 },322 {323 NAME: "2 levels to 2 levels",324 SOURCE: {325 one: [326 { two: [{ value: "A" }, { value: "B" }] },327 { two: [{ value: "C" }, { value: "D" }] }328 ]329 },330 EXPECTED: {331 one: [{ two: ["A", "B"] }, { two: ["C", "D"] }]332 },333 MAPPINGS: [334 {335 from: "one[].two[].value",336 to: "one[].two[]"337 }]338 },339 {340 NAME: "2 level to 3 levels",341 SOURCE: {342 one: [343 { two: [{ value: "A" }, { value: "B" }] },344 { two: [{ value: "C" }, { value: "D" }] }345 ]346 },347 EXPECTED: {348 one: [{349 two: [{ three: ["A", "B"] }]350 },351 {352 two: [{ three: ["C", "D"] }]353 }]354 },355 MAPPINGS: [356 {357 from: "one[].two[].value",358 to: "one[].two[].three[]"359 }]360 },361 {362 NAME: "3 level to 2 levels",363 SOURCE: {364 one: [{365 two: [366 { three: [{ value: "A" }, { value: "B" }] },367 { three: [{ value: "C" }, { value: "D" }] }368 ]369 },370 {371 two: [372 { three: [{ value: "A1" }, { value: "B1" }] },373 { three: [{ value: "C1" }, { value: "D1" }] }374 ]375 }]376 },377 EXPECTED: {378 one: [{ two: ["A", "B", "C", "D"] }, { two: ["A1", "B1", "C1", "D1"] }]379 },380 MAPPINGS: [381 {382 from: "one[].two[].three[].value",383 to: "one[].two[]"384 }]385 },386 {387 NAME: "3 level to 1 level",388 SOURCE: {389 one: [{390 two: [391 { three: [{ value: "A" }, { value: "B" }] },392 { three: [{ value: "C" }, { value: "D" }] }393 ]394 },395 {396 two: [397 { three: [{ value: "A1" }, { value: "B1" }] },398 { three: [{ value: "C1" }, { value: "D1" }] }399 ]400 }]401 },402 EXPECTED: {403 one: ["A", "B", "C", "D", "A1", "B1", "C1", "D1"]404 },405 MAPPINGS: [406 {407 from: "one[].two[].three[].value",408 to: "one[]"409 }]410 },411 {412 NAME: "3 level to 0 level",413 SOURCE: {414 one: [{415 two: [416 { three: [{ value: "A" }, { value: "B" }] },417 { three: [{ value: "C" }, { value: "D" }] }418 ]419 },420 {421 two: [422 { three: [{ value: "A1" }, { value: "B1" }] },423 { three: [{ value: "C1" }, { value: "D1" }] }424 ]425 }]426 },427 EXPECTED: ["A", "B", "C", "D", "A1", "B1", "C1", "D1"],428 MAPPINGS: [429 {430 from: "one[].two[].three[].value",431 to: "[]"432 }]433 }434];435valueToArrayTests.map(({ NAME, SOURCE, EXPECTED, MAPPINGS }) => {436 const labels = flattenDeep([groups, ["with value source and with array target", NAME]]);437 manyMappings.run(lab, {438 LABELS: labels, SOURCE, EXPECTED, MAPPINGS, MULTI_MODE: false439 });440});441const arrayToValueTests = [442 {443 NAME: "1 level to 2 levels",444 SOURCE: {445 one: ["A", "B"]446 },447 EXPECTED: {448 one: [{ two: [{ value: "A" }, { value: "B" }] }]449 },450 MAPPINGS: [451 {452 from: "one[]",453 to: "one[].two[].value"454 }]455 },456 {457 NAME: "2 levels to 1 level",458 SOURCE: {459 one: [460 { two: ["A", "B"] },461 { two: ["C", "D"] }462 ]463 },464 EXPECTED: {465 one: [{ value: "A" }, { value: "B" }, { value: "C" }, { value: "D" }]466 },467 MAPPINGS: [468 {469 from: "one[].two[]",470 to: "one[].value"471 }]472 },473 {474 NAME: "2 levels to 2 levels",475 SOURCE: {476 one: [477 { two: ["A", "B"] },478 { two: ["C", "D"] }479 ]480 },481 EXPECTED: {482 one: [483 { two: [{ value: "A" }, { value: "B" }] },484 { two: [{ value: "C" }, { value: "D" }] }485 ]486 },487 MAPPINGS: [488 {489 from: "one[].two[]",490 to: "one[].two[].value"491 }]492 },493 {494 NAME: "2 level to 3 levels",495 SOURCE: {496 one: [497 { two: ["A", "B"] },498 { two: ["C", "D"] }499 ]500 },501 EXPECTED: {502 one: [{503 two: [{ three: [{ value: "A" }, { value: "B" }] }]504 },505 {506 two: [{ three: [{ value: "C" }, { value: "D" }] }]507 }]508 },509 MAPPINGS: [510 {511 from: "one[].two[]",512 to: "one[].two[].three[].value"513 }]514 },515 {516 NAME: "3 level to 2 levels",517 SOURCE: {518 one: [{519 two: [520 { three: ["A", "B"] },521 { three: ["C", "D"] }522 ]523 },524 {525 two: [526 { three: ["A1", "B1"] },527 { three: ["C1", "D1"] }528 ]529 }]530 },531 EXPECTED: {532 one: [533 { two: [{ value: "A" }, { value: "B" }, { value: "C" }, { value: "D" }] },534 { two: [{ value: "A1" }, { value: "B1" }, { value: "C1" }, { value: "D1" }] }535 ]536 },537 MAPPINGS: [538 {539 from: "one[].two[].three[]",540 to: "one[].two[].value"541 }]542 },543 {544 NAME: "3 level to 1 levels",545 SOURCE: {546 one: [{547 two: [548 { three: ["A", "B"] },549 { three: ["C", "D"] }550 ]551 },552 {553 two: [554 { three: ["A1", "B1"] },555 { three: ["C1", "D1"] }556 ]557 }]558 },559 EXPECTED: {560 one: [561 { value: "A" },562 { value: "B" },563 { value: "C" },564 { value: "D" },565 { value: "A1" },566 { value: "B1" },567 { value: "C1" },568 { value: "D1" }569 ]570 },571 MAPPINGS: [572 {573 from: "one[].two[].three[]",574 to: "one[].value"575 }]576 }577];578arrayToValueTests.map(({ NAME, SOURCE, EXPECTED, MAPPINGS }) => {579 const labels = flattenDeep([groups, ["with array source and value target", NAME]]);580 manyMappings.run(lab, {581 LABELS: labels, SOURCE, EXPECTED, MAPPINGS, MULTI_MODE: false582 });583});584const arrayToArrayTests = [585 {586 NAME: "1 level to 2 levels",587 SOURCE: {588 one: ["A", "B"]589 },590 EXPECTED: {591 one: [{ two: ["A", "B"] }]592 },593 MAPPINGS: [594 {595 from: "one[]",596 to: "one[].two[]"597 }]598 },599 {600 NAME: "2 levels to 1 levels",601 SOURCE: {602 one: [603 { two: ["A", "B"] },604 { two: ["C", "D"] }605 ]606 },607 EXPECTED: {608 one: ["A", "B", "C", "D"]609 },610 MAPPINGS: [611 {612 from: "one[].two[]",613 to: "one[]"614 }]615 },616 {617 NAME: "2 levels to 2 levels",618 SOURCE: {619 one: [620 { two: ["A", "B"] },621 { two: ["C", "D"] }622 ]623 },624 EXPECTED: {625 one: [{ two: ["A", "B"] }, { two: ["C", "D"] }]626 },627 MAPPINGS: [628 {629 from: "one[].two[]",630 to: "one[].two[]"631 }]632 },633 {634 NAME: "2 level to 3 levels",635 SOURCE: {636 one: [637 { two: ["A", "B"] },638 { two: ["C", "D"] }639 ]640 },641 EXPECTED: {642 one: [{643 two: [{ three: ["A", "B"] }]644 },645 {646 two: [{ three: ["C", "D"] }]647 }]648 },649 MAPPINGS: [650 {651 from: "one[].two[]",652 to: "one[].two[].three[]"653 }]654 },655 {656 NAME: "3 level to 2 levels",657 SOURCE: {658 one: [{659 two: [660 { three: ["A", "B"] },661 { three: ["C", "D"] }662 ]663 },664 {665 two: [666 { three: ["A1", "B1"] },667 { three: ["C1", "D1"] }668 ]669 }]670 },671 EXPECTED: {672 one: [{ two: ["A", "B", "C", "D"] }, { two: ["A1", "B1", "C1", "D1"] }]673 },674 MAPPINGS: [675 {676 from: "one[].two[].three[]",677 to: "one[].two[]"678 }]679 },680 {681 NAME: "3 level to 1 level",682 SOURCE: {683 one: [{684 two: [685 { three: ["A", "B"] },686 { three: ["C", "D"] }687 ]688 },689 {690 two: [691 { three: ["A1", "B1"] },692 { three: ["C1", "D1"] }693 ]694 }]695 },696 EXPECTED: {697 one: ["A", "B", "C", "D", "A1", "B1", "C1", "D1"]698 },699 MAPPINGS: [700 {701 from: "one[].two[].three[]",702 to: "one[]"703 }]704 }705];706arrayToArrayTests.map(({ NAME, SOURCE, EXPECTED, MAPPINGS }) => {707 const labels = flattenDeep([groups, ["with array source and with array target", NAME]]);708 manyMappings.run(lab, {709 LABELS: labels, SOURCE, EXPECTED, MAPPINGS, MULTI_MODE: false710 });711});712// Data for parent and child tests713const source = {714 foo: [715 { "name": "a", "things": ["a1", "a2"] },716 { "name": "b", "things": ["b1", "b2"] }717 ]718};719const expected = {720 bar: [{721 label: "a",722 values: ["a1", "a2"]723 },724 {725 label: "b",726 values: ["b1", "b2"]727 }728 ]729};730manyMappings.run(lab, {731 LABELS: ["arrays", "array of arrays", "parent and child - normal order"],732 MAPPINGS: [733 { from: "foo[].name", to: "bar[].label" },734 { from: "foo[].things[]", to: "bar[].values[]" }735 ],736 SOURCE: source,737 EXPECTED: expected738});739manyMappings.run(lab, {740 LABELS: ["arrays", "array of arrays", "parent and child - inverted order"],741 MAPPINGS: [742 { from: "foo[].things[]", to: "bar[].values[]" },743 { from: "foo[].name", to: "bar[].label" }744 ],745 SOURCE: source,746 EXPECTED: expected...

Full Screen

Full Screen

sorting.t

Source:sorting.t Github

copy

Full Screen

1#!/usr/bin/env python2.72# -*- coding: utf-8 -*-3###############################################################################4#5# Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez.6#7# Permission is hereby granted, free of charge, to any person obtaining a copy8# of this software and associated documentation files (the "Software"), to deal9# in the Software without restriction, including without limitation the rights10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell11# copies of the Software, and to permit persons to whom the Software is12# furnished to do so, subject to the following conditions:13#14# The above copyright notice and this permission notice shall be included15# in all copies or substantial portions of the Software.16#17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE23# SOFTWARE.24#25# http://www.opensource.org/licenses/mit-license.php26#27###############################################################################28import sys29import os30import re31import unittest32import time33# Ensure python finds the local simpletap module34sys.path.append(os.path.dirname(os.path.abspath(__file__)))35from basetest import Task, TestCase36from basetest.meta import MetaTest37class MetaTestSorting(MetaTest):38 """Helper metaclass to simplify test logic below (TestSorting)39 Creates test_methods in the TestCase class dynamically named after the40 filter used.41 """42 @staticmethod43 def make_function(classname, *args, **kwargs):44 _filter, expectations = args45 def test(self):46 # ### Body of the usual test_testcase ### #47 code, out, err = self.t(48 "rc.report.{0}.sort:{1} {0}".format(self._report, _filter)49 )50 for expected in expectations:51 regex = re.compile(expected, re.DOTALL)52 self.assertRegexpMatches(out, regex)53 # Title of test in report54 test.__doc__ = "{0} sort:{1}".format(classname, _filter)55 return test56class TestSorting(TestCase):57 __metaclass__ = MetaTestSorting58 @classmethod59 def setUpClass(cls):60 cls.t = Task()61 # Report to use when running this class's tests62 cls._report = "list"63 cls.t("add zero")64 cls.t("add priority:H project:A due:yesterday one")65 cls.t("add priority:M project:B due:today two")66 cls.t("add priority:L project:C due:tomorrow three")67 cls.t("add priority:H project:C due:today four")68 cls.t("2 start")69 TESTS = (70 # Filter # Expected matches/outputs71 # Single sort column.72 ('priority-', ('(?:one.+four|four.+one).+two.+three.+zero',)),73 ('priority+', ('zero.+three.+two.+(?:one.+four|four.+one)',)),74 ('project-', ('(?:three.+four|four.+three).+two.+one.+zero',)),75 ('project+', ('zero.+one.+two.+(?:three.+four|four.+three)',)),76 ('start-', ('one.+zero', 'one.+two', 'one.+three', 'one.+four',)),77 ('start+', ('one.+zero', 'one.+two', 'one.+three', 'one.+four',)),78 ('due-', ('three.+(?:two.+four|four.+two).+one.+zero',)),79 ('due+', ('one.+(?:two.+four|four.+two).+three.+zero',)),80 ('description-', ('zero.+two.+three.+one.+four',)),81 ('description+', ('four.+one.+three.+two.+zero',)),82 # Two sort columns.83 ('priority-,project-', ('four.+one.+two.+three.+zero',)),84 ('priority-,project+', ('one.+four.+two.+three.+zero',)),85 ('priority+,project-', ('zero.+three.+two.+four.+one',)),86 ('priority+,project+', ('zero.+three.+two.+one.+four',)),87 ('priority-,start-', ('one.+four.+two.+three.+zero',)),88 ('priority-,start+', ('one.+four.+two.+three.+zero',)),89 ('priority+,start-', ('zero.+three.+two.+one.+four',)),90 ('priority+,start+', ('zero.+three.+two.+one.+four',)),91 ('priority-,due-', ('four.+one.+two.+three.+zero',)),92 ('priority-,due+', ('one.+four.+two.+three.+zero',)),93 ('priority+,due-', ('zero.+three.+two.+four.+one',)),94 ('priority+,due+', ('zero.+three.+two.+one.+four',)),95 ('priority-,description-', ('one.+four.+two.+three.+zero',)),96 ('priority-,description+', ('four.+one.+two.+three.+zero',)),97 ('priority+,description-', ('zero.+three.+two.+one.+four',)),98 ('priority+,description+', ('zero.+three.+two.+four.+one',)),99 ('project-,priority-', ('four.+three.+two.+one.+zero',)),100 ('project-,priority+', ('three.+four.+two.+one.+zero',)),101 ('project+,priority-', ('zero.+one.+two.+four.+three',)),102 ('project+,priority+', ('zero.+one.+two.+three.+four',)),103 ('project-,start-', ('three.+four.+two.+one.+zero',)),104 ('project-,start+', ('(?:four.+three|three.+four).+two.+one.+zero',)),105 ('project+,start-', ('zero.+one.+two.+three.+four',)),106 ('project+,start+', ('zero.+one.+two.+(?:four.+three|three.+four)',)),107 ('project-,due-', ('three.+four.+two.+one.+zero',)),108 ('project-,due+', ('four.+three.+two.+one.+zero',)),109 ('project+,due-', ('zero.+one.+two.+three.+four',)),110 ('project+,due+', ('zero.+one.+two.+four.+three',)),111 ('project-,description-', ('three.+four.+two.+one.+zero',)),112 ('project-,description+', ('four.+three.+two.+one.+zero',)),113 ('project+,description-', ('zero.+one.+two.+three.+four',)),114 ('project+,description+', ('zero.+one.+two.+four.+three',)),115 ('start-,priority-', ('one.+four.+two.+three.+zero',)),116 ('start-,priority+', ('one.+zero.+three.+two.+four',)),117 ('start+,priority-', ('one.+four.+two.+three.+zero',)),118 ('start+,priority+', ('one.+zero.+three.+two.+four',)),119 ('start-,project-', ('one.+(?:three.+four|four.+three).+two.+zero',)),120 ('start-,project+', ('one.+zero.+two.+(?:three.+four|four.+three)',)),121 ('start+,project-', ('one.+(?:three.+four|four.+three).+two.+zero',)),122 ('start+,project+', ('one.+zero.+two.+(?:three.+four|four.+three)',)),123 ('start-,due-', ('one.+three.+(?:four.+two|two.+four).+zero',)),124 ('start-,due+', ('one.+(?:four.+two|two.+four).+three.+zero',)),125 ('start+,due-', ('one.+three.+(?:four.+two|two.+four).+zero',)),126 ('start+,due+', ('one.+(?:four.+two|two.+four).+three.+zero',)),127 ('start-,description-', ('one.+zero.+two.+three.+four',)),128 ('start-,description+', ('one.+four.+three.+two.+zero',)),129 ('start+,description-', ('one.+zero.+two.+three.+four',)),130 ('start+,description+', ('one.+four.+three.+two.+zero',)),131 ('due-,priority-', ('three.+four.+two.+one.+zero',)),132 ('due-,priority+', ('three.+two.+four.+one.+zero',)),133 ('due+,priority-', ('one.+four.+two.+three.+zero',)),134 ('due+,priority+', ('one.+two.+four.+three.+zero',)),135 ('due-,project-', ('three.+four.+two.+one.+zero',)),136 ('due-,project+', ('three.+two.+four.+one.+zero',)),137 ('due+,project-', ('one.+four.+two.+three.+zero',)),138 ('due+,project+', ('one.+two.+four.+three.+zero',)),139 ('due-,start-', ('three.+(?:four.+two|two.+four).+one.+zero',)),140 ('due-,start+', ('three.+(?:four.+two|two.+four).+one.+zero',)),141 ('due+,start-', ('one.+(?:four.+two|two.+four).+three.+zero',)),142 ('due+,start+', ('one.+(?:four.+two|two.+four).+three.+zero',)),143 ('due-,description-', ('three.+two.+four.+one.+zero',)),144 ('due-,description+', ('three.+four.+two.+one.+zero',)),145 ('due+,description-', ('one.+two.+four.+three.+zero',)),146 ('due+,description+', ('one.+four.+two.+three.+zero',)),147 ('description-,priority-', ('zero.+two.+three.+one.+four',)),148 ('description-,priority+', ('zero.+two.+three.+one.+four',)),149 ('description+,priority-', ('four.+one.+three.+two.+zero',)),150 ('description+,priority+', ('four.+one.+three.+two.+zero',)),151 ('description-,project-', ('zero.+two.+three.+one.+four',)),152 ('description-,project+', ('zero.+two.+three.+one.+four',)),153 ('description+,project-', ('four.+one.+three.+two.+zero',)),154 ('description+,project+', ('four.+one.+three.+two.+zero',)),155 ('description-,start-', ('zero.+two.+three.+one.+four',)),156 ('description-,start+', ('zero.+two.+three.+one.+four',)),157 ('description+,start-', ('four.+one.+three.+two.+zero',)),158 ('description+,start+', ('four.+one.+three.+two.+zero',)),159 ('description-,due-', ('zero.+two.+three.+one.+four',)),160 ('description-,due+', ('zero.+two.+three.+one.+four',)),161 ('description+,due-', ('four.+one.+three.+two.+zero',)),162 ('description+,due+', ('four.+one.+three.+two.+zero',)),163 # Four sort columns.164 ('start+,project+,due+,priority+', ('one.+zero.+two.+four.+three',)),165 ('project+,due+,priority+,start+', ('zero.+one.+two.+four.+three',)),166 )167class TestBug438(TestCase):168 __metaclass__ = MetaTestSorting169 # Bug #438: Reports sorting by end, start, and entry are ordered170 # incorrectly, if time is included.171 @classmethod172 def setUpClass(cls):173 cls.t = Task()174 # Report to use when running this class's tests175 cls._report = "foo"176 cls.t.config("dateformat", "SNHDMY")177 cls.t.config("report.foo.columns", "entry,start,end,description")178 cls.t.config("report.foo.dateformat", "SNHDMY")179 # Preparing data:180 # 2 tasks created in the past, 1 second apart181 # 2 tasks created in the past, and started 10 seconds later182 # 2 tasks created in the past, and finished 20 seconds later183 stamp = int(time.time())184 cls.t("add one older entry:{0}".format(stamp))185 stamp += 1186 cls.t("add one newer entry:{0}".format(stamp))187 start = stamp + 10188 cls.t("add two older entry:{0} start:{1}".format(stamp, start))189 start += 1190 cls.t("add two newer entry:{0} start:{1}".format(stamp, start))191 end = start + 10192 cls.t("log three older entry:{0} end:{1}".format(stamp, end))193 end += 1194 cls.t("log three newer entry:{0} end:{1}".format(stamp, end))195 TESTS = {196 ("entry+", ("one older.+one newer",)),197 ("entry-", ("one newer.+one older",)),198 ("start+", ("two older.+two newer",)),199 ("start-", ("two newer.+two older",)),200 ("end+", ("three older.+three newer",)),201 ("end-", ("three newer.+three older",)),202 }203class TestSortNone(TestCase):204 def setUp(self):205 self.t = Task()206 def test_sort_none(self):207 """Verify that 'sort:none' removes all sorting"""208 self.t("add one")209 self.t("add two")210 self.t("add three")211 code, out, err = self.t("_get 1.uuid 2.uuid 3.uuid")212 uuid1, uuid2, uuid3 = out.strip().split(' ')213 code, out, err = self.t("%s %s %s list rc.report.list.sort:none rc.report.list.columns:id,description rc.report.list.labels:id,desc" % (uuid2, uuid3, uuid1))214 self.assertRegexpMatches(out, ' 2 two\n 3 three\n 1 one')215if __name__ == "__main__":216 from simpletap import TAPTestRunner217 unittest.main(testRunner=TAPTestRunner())...

Full Screen

Full Screen

challenge-1.py

Source:challenge-1.py Github

copy

Full Screen

1"""2This is a dumb calculator that can add and subtract whole numbers from zero to five.3When you run the code, you are prompted to enter two numbers (in the form of English4word instead of number) and the operator sign (also in the form of English word).5The code will perform the calculation and give the result if your input is what it6expects.7The code is very long and messy. Refactor it according to what you have learned about8code simplicity and efficiency.9"""10print('Welcome to this calculator!')11print('It can add and subtract whole numbers from zero to five')12a = input('Please choose your first number (zero to five): ')13b = input('What do you want to do? plus or minus: ')14c = input('Please choose your second number (zero to five): ')15if a == 'zero' and b == 'plus' and c == 'zero':16 print("zero plus zero equals zero")17if a == 'zero' and b == 'plus' and c == 'one':18 print("zero plus one equals one")19if a == 'zero' and b == 'plus' and c == 'two':20 print("zero plus two equals two")21if a == 'zero' and b == 'plus' and c == 'three':22 print("zero plus three equals three")23if a == 'zero' and b == 'plus' and c == 'four':24 print("zero plus four equals four")25if a == 'zero' and b == 'plus' and c == 'five':26 print("zero plus five equals five")27if a == 'one' and b == 'plus' and c == 'zero':28 print("one plus zero equals one")29if a == 'one' and b == 'plus' and c == 'one':30 print("one plus one equals two")31if a == 'one' and b == 'plus' and c == 'two':32 print("one plus two equals three")33if a == 'one' and b == 'plus' and c == 'three':34 print("one plus three equals four")35if a == 'one' and b == 'plus' and c == 'four':36 print("one plus four equals five")37if a == 'one' and b == 'plus' and c == 'five':38 print("one plus five equals six")39if a == 'two' and b == 'plus' and c == 'zero':40 print("two plus zero equals two")41if a == 'two' and b == 'plus' and c == 'one':42 print("two plus one equals three")43if a == 'two' and b == 'plus' and c == 'two':44 print("two plus two equals four")45if a == 'two' and b == 'plus' and c == 'three':46 print("two plus three equals five")47if a == 'two' and b == 'plus' and c == 'four':48 print("two plus four equals six")49if a == 'two' and b == 'plus' and c == 'five':50 print("two plus five equals seven")51if a == 'three' and b == 'plus' and c == 'zero':52 print("three plus zero equals three")53if a == 'three' and b == 'plus' and c == 'one':54 print("three plus one equals four")55if a == 'three' and b == 'plus' and c == 'two':56 print("three plus two equals five")57if a == 'three' and b == 'plus' and c == 'three':58 print("three plus three equals six")59if a == 'three' and b == 'plus' and c == 'four':60 print("three plus four equals seven")61if a == 'three' and b == 'plus' and c == 'five':62 print("three plus five equals eight")63if a == 'four' and b == 'plus' and c == 'zero':64 print("four plus zero equals four")65if a == 'four' and b == 'plus' and c == 'one':66 print("four plus one equals five")67if a == 'four' and b == 'plus' and c == 'two':68 print("four plus two equals six")69if a == 'four' and b == 'plus' and c == 'three':70 print("four plus three equals seven")71if a == 'four' and b == 'plus' and c == 'four':72 print("four plus four equals eight")73if a == 'four' and b == 'plus' and c == 'five':74 print("four plus five equals nine")75if a == 'five' and b == 'plus' and c == 'zero':76 print("five plus zero equals five")77if a == 'five' and b == 'plus' and c == 'one':78 print("five plus one equals six")79if a == 'five' and b == 'plus' and c == 'two':80 print("five plus two equals seven")81if a == 'five' and b == 'plus' and c == 'three':82 print("five plus three equals eight")83if a == 'five' and b == 'plus' and c == 'four':84 print("five plus four equals nine")85if a == 'five' and b == 'plus' and c == 'five':86 print("five plus five equals ten")87if a == 'zero' and b == 'minus' and c == 'zero':88 print("zero minus zero equals zero")89if a == 'zero' and b == 'minus' and c == 'one':90 print("zero minus one equals negative one")91if a == 'zero' and b == 'minus' and c == 'two':92 print("zero minus two equals negative two")93if a == 'zero' and b == 'minus' and c == 'three':94 print("zero minus three equals negative three")95if a == 'zero' and b == 'minus' and c == 'four':96 print("zero minus four equals negative four")97if a == 'zero' and b == 'minus' and c == 'five':98 print("zero minus five equals negative five")99if a == 'one' and b == 'minus' and c == 'zero':100 print("one minus zero equals one")101if a == 'one' and b == 'minus' and c == 'one':102 print("one minus one equals zero")103if a == 'one' and b == 'minus' and c == 'two':104 print("one minus two equals negative one")105if a == 'one' and b == 'minus' and c == 'three':106 print("one minus three equals negative three")107if a == 'one' and b == 'minus' and c == 'four':108 print("one minus four equals negative three")109if a == 'one' and b == 'minus' and c == 'five':110 print("one minus five equals negative four")111if a == 'two' and b == 'minus' and c == 'zero':112 print("two minus zero equals two")113if a == 'two' and b == 'minus' and c == 'one':114 print("two minus one equals one")115if a == 'two' and b == 'minus' and c == 'two':116 print("two minus two equals zero")117if a == 'two' and b == 'minus' and c == 'three':118 print("two minus three equals negative one")119if a == 'two' and b == 'minus' and c == 'four':120 print("two minus four equals negative two")121if a == 'two' and b == 'minus' and c == 'five':122 print("two minus five equals negative three")123if a == 'three' and b == 'minus' and c == 'zero':124 print("three minus zero equals three")125if a == 'three' and b == 'minus' and c == 'one':126 print("three minus one equals two")127if a == 'three' and b == 'minus' and c == 'two':128 print("three minus two equals one")129if a == 'three' and b == 'minus' and c == 'three':130 print("three minus three equals zero")131if a == 'three' and b == 'minus' and c == 'four':132 print("three minus four equals negative one")133if a == 'three' and b == 'minus' and c == 'five':134 print("three minus five equals negative two")135if a == 'four' and b == 'minus' and c == 'zero':136 print("four minus zero equals four")137if a == 'four' and b == 'minus' and c == 'one':138 print("four minus one equals three")139if a == 'four' and b == 'minus' and c == 'two':140 print("four minus two equals two")141if a == 'four' and b == 'minus' and c == 'three':142 print("four minus three equals one")143if a == 'four' and b == 'minus' and c == 'four':144 print("four minus four equals zero")145if a == 'four' and b == 'minus' and c == 'five':146 print("four minus five equals negative one")147if a == 'five' and b == 'minus' and c == 'zero':148 print("five minus zero equals five")149if a == 'five' and b == 'minus' and c == 'one':150 print("five minus one equals four")151if a == 'five' and b == 'minus' and c == 'two':152 print("five minus two equals three")153if a == 'five' and b == 'minus' and c == 'three':154 print("five minus three equals two")155if a == 'five' and b == 'minus' and c == 'four':156 print("five minus four equals one")157if a == 'five' and b == 'minus' and c == 'five':158 print("five minus five equals zero")159if (not a == 'zero' and not a == 'one' and not a == 'two' and not a == 'three' and not a == 'four' and not a == 'five') or (not c == 'zero' and not c == 'one' and not c == 'two' and not c == 'three' and not c == 'four' and not c == 'five') or (not b == 'plus' and not b == 'minus'):160 print("I am not able to answer this question. Check your input.")...

Full Screen

Full Screen

math-floor-local.js

Source:math-floor-local.js Github

copy

Full Screen

1// Copyright 2012 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above9// copyright notice, this list of conditions and the following10// disclaimer in the documentation and/or other materials provided11// with the distribution.12// * Neither the name of Google Inc. nor the names of its13// contributors may be used to endorse or promote products derived14// from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27// Flags: --max-semi-space-size=1 --allow-natives-syntax28// Test inlining of Math.floor when assigned to a local.29var test_id = 0;30function testFloor(expect, input) {31 var test = new Function('n',32 '"' + (test_id++) +33 '";var f = Math.floor; return f(n)');34 assertEquals(expect, test(input));35 assertEquals(expect, test(input));36 assertEquals(expect, test(input));37 %OptimizeFunctionOnNextCall(test);38 assertEquals(expect, test(input));39}40function zero() {41 var x = 0.5;42 return (function() { return x - 0.5; })();43}44function test() {45 testFloor(0, 0);46 testFloor(0, zero());47 testFloor(-0, -0);48 testFloor(Infinity, Infinity);49 testFloor(-Infinity, -Infinity);50 testFloor(NaN, NaN);51 // Ensure that a negative zero coming from Math.floor is properly handled52 // by other operations.53 function ifloor(x) {54 return 1 / Math.floor(x);55 }56 assertEquals(-Infinity, ifloor(-0));57 assertEquals(-Infinity, ifloor(-0));58 assertEquals(-Infinity, ifloor(-0));59 %OptimizeFunctionOnNextCall(ifloor);60 assertEquals(-Infinity, ifloor(-0));61 testFloor(0, 0.1);62 testFloor(0, 0.49999999999999994);63 testFloor(0, 0.5);64 testFloor(0, 0.7);65 testFloor(-1, -0.1);66 testFloor(-1, -0.49999999999999994);67 testFloor(-1, -0.5);68 testFloor(-1, -0.7);69 testFloor(1, 1);70 testFloor(1, 1.1);71 testFloor(1, 1.5);72 testFloor(1, 1.7);73 testFloor(-1, -1);74 testFloor(-2, -1.1);75 testFloor(-2, -1.5);76 testFloor(-2, -1.7);77 testFloor(0, Number.MIN_VALUE);78 testFloor(-1, -Number.MIN_VALUE);79 testFloor(Number.MAX_VALUE, Number.MAX_VALUE);80 testFloor(-Number.MAX_VALUE, -Number.MAX_VALUE);81 testFloor(Infinity, Infinity);82 testFloor(-Infinity, -Infinity);83 // 2^30 is a smi boundary.84 var two_30 = 1 << 30;85 testFloor(two_30, two_30);86 testFloor(two_30, two_30 + 0.1);87 testFloor(two_30, two_30 + 0.5);88 testFloor(two_30, two_30 + 0.7);89 testFloor(two_30 - 1, two_30 - 1);90 testFloor(two_30 - 1, two_30 - 1 + 0.1);91 testFloor(two_30 - 1, two_30 - 1 + 0.5);92 testFloor(two_30 - 1, two_30 - 1 + 0.7);93 testFloor(-two_30, -two_30);94 testFloor(-two_30, -two_30 + 0.1);95 testFloor(-two_30, -two_30 + 0.5);96 testFloor(-two_30, -two_30 + 0.7);97 testFloor(-two_30 + 1, -two_30 + 1);98 testFloor(-two_30 + 1, -two_30 + 1 + 0.1);99 testFloor(-two_30 + 1, -two_30 + 1 + 0.5);100 testFloor(-two_30 + 1, -two_30 + 1 + 0.7);101 // 2^52 is a precision boundary.102 var two_52 = (1 << 30) * (1 << 22);103 testFloor(two_52, two_52);104 testFloor(two_52, two_52 + 0.1);105 assertEquals(two_52, two_52 + 0.5);106 testFloor(two_52, two_52 + 0.5);107 assertEquals(two_52 + 1, two_52 + 0.7);108 testFloor(two_52 + 1, two_52 + 0.7);109 testFloor(two_52 - 1, two_52 - 1);110 testFloor(two_52 - 1, two_52 - 1 + 0.1);111 testFloor(two_52 - 1, two_52 - 1 + 0.5);112 testFloor(two_52 - 1, two_52 - 1 + 0.7);113 testFloor(-two_52, -two_52);114 testFloor(-two_52, -two_52 + 0.1);115 testFloor(-two_52, -two_52 + 0.5);116 testFloor(-two_52, -two_52 + 0.7);117 testFloor(-two_52 + 1, -two_52 + 1);118 testFloor(-two_52 + 1, -two_52 + 1 + 0.1);119 testFloor(-two_52 + 1, -two_52 + 1 + 0.5);120 testFloor(-two_52 + 1, -two_52 + 1 + 0.7);121}122// Test in a loop to cover the custom IC and GC-related issues.123for (var i = 0; i < 10; i++) {124 test();125 new Array(i * 10000);126}127// Regression test for a bug where a negative zero coming from Math.floor128// was not properly handled by other operations.129function floorsum(i, n) {130 var ret = Math.floor(n);131 while (--i > 0) {132 ret += Math.floor(n);133 }134 return ret;135}136assertEquals(-0, floorsum(1, -0));137%OptimizeFunctionOnNextCall(floorsum);138// The optimized function will deopt. Run it with enough iterations to try139// to optimize via OSR (triggering the bug)....

Full Screen

Full Screen

math-floor-global.js

Source:math-floor-global.js Github

copy

Full Screen

1// Copyright 2012 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above9// copyright notice, this list of conditions and the following10// disclaimer in the documentation and/or other materials provided11// with the distribution.12// * Neither the name of Google Inc. nor the names of its13// contributors may be used to endorse or promote products derived14// from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27// Flags: --max-semi-space-size=1 --allow-natives-syntax28// Test inlining of Math.floor when assigned to a global.29var flo = Math.floor;30var test_id = 0;31function testFloor(expect, input) {32 var test = new Function('n',33 '"' + (test_id++) + '";return flo(n)');34 assertEquals(expect, test(input));35 assertEquals(expect, test(input));36 assertEquals(expect, test(input));37 %OptimizeFunctionOnNextCall(test);38 assertEquals(expect, test(input));39}40function zero() {41 var x = 0.5;42 return (function() { return x - 0.5; })();43}44function test() {45 testFloor(0, 0);46 testFloor(0, zero());47 testFloor(-0, -0);48 testFloor(Infinity, Infinity);49 testFloor(-Infinity, -Infinity);50 testFloor(NaN, NaN);51 // Ensure that a negative zero coming from Math.floor is properly handled52 // by other operations.53 function ifloor(x) {54 return 1 / Math.floor(x);55 }56 assertEquals(-Infinity, ifloor(-0));57 assertEquals(-Infinity, ifloor(-0));58 assertEquals(-Infinity, ifloor(-0));59 %OptimizeFunctionOnNextCall(ifloor);60 assertEquals(-Infinity, ifloor(-0));61 testFloor(0, 0.1);62 testFloor(0, 0.49999999999999994);63 testFloor(0, 0.5);64 testFloor(0, 0.7);65 testFloor(-1, -0.1);66 testFloor(-1, -0.49999999999999994);67 testFloor(-1, -0.5);68 testFloor(-1, -0.7);69 testFloor(1, 1);70 testFloor(1, 1.1);71 testFloor(1, 1.5);72 testFloor(1, 1.7);73 testFloor(-1, -1);74 testFloor(-2, -1.1);75 testFloor(-2, -1.5);76 testFloor(-2, -1.7);77 testFloor(0, Number.MIN_VALUE);78 testFloor(-1, -Number.MIN_VALUE);79 testFloor(Number.MAX_VALUE, Number.MAX_VALUE);80 testFloor(-Number.MAX_VALUE, -Number.MAX_VALUE);81 testFloor(Infinity, Infinity);82 testFloor(-Infinity, -Infinity);83 // 2^30 is a smi boundary.84 var two_30 = 1 << 30;85 testFloor(two_30, two_30);86 testFloor(two_30, two_30 + 0.1);87 testFloor(two_30, two_30 + 0.5);88 testFloor(two_30, two_30 + 0.7);89 testFloor(two_30 - 1, two_30 - 1);90 testFloor(two_30 - 1, two_30 - 1 + 0.1);91 testFloor(two_30 - 1, two_30 - 1 + 0.5);92 testFloor(two_30 - 1, two_30 - 1 + 0.7);93 testFloor(-two_30, -two_30);94 testFloor(-two_30, -two_30 + 0.1);95 testFloor(-two_30, -two_30 + 0.5);96 testFloor(-two_30, -two_30 + 0.7);97 testFloor(-two_30 + 1, -two_30 + 1);98 testFloor(-two_30 + 1, -two_30 + 1 + 0.1);99 testFloor(-two_30 + 1, -two_30 + 1 + 0.5);100 testFloor(-two_30 + 1, -two_30 + 1 + 0.7);101 // 2^52 is a precision boundary.102 var two_52 = (1 << 30) * (1 << 22);103 testFloor(two_52, two_52);104 testFloor(two_52, two_52 + 0.1);105 assertEquals(two_52, two_52 + 0.5);106 testFloor(two_52, two_52 + 0.5);107 assertEquals(two_52 + 1, two_52 + 0.7);108 testFloor(two_52 + 1, two_52 + 0.7);109 testFloor(two_52 - 1, two_52 - 1);110 testFloor(two_52 - 1, two_52 - 1 + 0.1);111 testFloor(two_52 - 1, two_52 - 1 + 0.5);112 testFloor(two_52 - 1, two_52 - 1 + 0.7);113 testFloor(-two_52, -two_52);114 testFloor(-two_52, -two_52 + 0.1);115 testFloor(-two_52, -two_52 + 0.5);116 testFloor(-two_52, -two_52 + 0.7);117 testFloor(-two_52 + 1, -two_52 + 1);118 testFloor(-two_52 + 1, -two_52 + 1 + 0.1);119 testFloor(-two_52 + 1, -two_52 + 1 + 0.5);120 testFloor(-two_52 + 1, -two_52 + 1 + 0.7);121}122// Test in a loop to cover the custom IC and GC-related issues.123for (var i = 0; i < 10; i++) {124 test();125 new Array(i * 10000);126}127// Regression test for a bug where a negative zero coming from Math.floor128// was not properly handled by other operations.129function floorsum(i, n) {130 var ret = Math.floor(n);131 while (--i > 0) {132 ret += Math.floor(n);133 }134 return ret;135}136assertEquals(-0, floorsum(1, -0));137%OptimizeFunctionOnNextCall(floorsum);138// The optimized function will deopt. Run it with enough iterations to try139// to optimize via OSR (triggering the bug)....

Full Screen

Full Screen

pb2server.py

Source:pb2server.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright (c) Twisted Matrix Laboratories.3# See LICENSE for details.4from __future__ import print_function5from twisted.spread import pb6from twisted.internet import reactor7class Two(pb.Referenceable):8 def remote_print(self, arg):9 print("two.print was given", arg)10 11class One(pb.Root):12 def __init__(self, two):13 #pb.Root.__init__(self) # pb.Root doesn't implement __init__14 self.two = two15 def remote_getTwo(self):16 print("One.getTwo(), returning my two called", self.two)17 return self.two18 def remote_checkTwo(self, newtwo):19 print("One.checkTwo(): comparing my two", self.two)20 print("One.checkTwo(): against your two", newtwo)21 if self.two == newtwo:22 print("One.checkTwo(): our twos are the same")23 24two = Two()25root_obj = One(two)26reactor.listenTCP(8800, pb.PBServerFactory(root_obj))...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mock } from 'ts-auto-mock';2import { mock2 } from 'ts-auto-mock';3import { mock } from 'ts-auto-mock';4import { mock2 } from 'ts-auto-mock';5This is the issue I am facing. I have 3 test files and all of them are using ts-auto-mock library. But I am not able to import both the methods of ts-auto-mock in a single test file. I have to import the methods in different test files. Is there any way I can import both the methods in a single test file?6I have tried importing it into a file

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2import { createMock } from 'ts-auto-mock/extension';3import { createMock } from 'ts-auto-mock/extension';4import { createMock } from 'ts-auto-mock';5import { createMock } from 'ts-auto-mock/extension';6import { createMock } from 'ts-auto-mock';7import { createMock } from 'ts-auto-mock/extension';8import { createMock } from 'ts-auto-mock';9import { createMock } from 'ts-auto-mock/extension';10import { createMock } from 'ts-auto-mock';11import { createMock } from 'ts-auto-mock/extension';12import { createMock } from 'ts-auto-mock';13import { createMock } from 'ts-auto-mock/extension';14import { createMock } from 'ts-auto-mock';15import { createMock } from 'ts-auto-mock/extension';16import { createMock } from 'ts-auto-mock';17import { createMock } from 'ts-auto-mock/extension';18import { createMock } from 'ts-auto-mock';19import { createMock } from 'ts-auto-mock/extension';20import { createMock } from 'ts-auto-mock';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2const mock = createMock<Interface1>();3const mock2 = createMock<Interface2>();4import { createMock } from 'ts-auto-mock';5const mock = createMock<Interface1>();6const mock2 = createMock<Interface2>();7import { createMock } from 'ts-auto-mock';8const mock = createMock<Interface1>();9const mock2 = createMock<Interface2>();10import { createMock } from 'ts-auto-mock';11const mock = createMock<Interface1>();12const mock2 = createMock<Interface2>();13import { createMock } from 'ts-auto-mock';14const mock = createMock<Interface1>();15const mock2 = createMock<Interface2>();16import { createMock } from 'ts-auto-mock';17const mock = createMock<Interface1>();18const mock2 = createMock<Interface2>();19import { createMock } from 'ts-auto-mock';20const mock = createMock<Interface1>();21const mock2 = createMock<Interface2>();22import { createMock } from 'ts-auto-mock';23const mock = createMock<Interface1>();24const mock2 = createMock<Interface2>();25import { createMock } from 'ts-auto-mock';26const mock = createMock<Interface1>();27const mock2 = createMock<Interface2>();28import { createMock } from 'ts-auto-mock';29const mock = createMock<Interface1>();30const mock2 = createMock<Interface2>();

Full Screen

Using AI Code Generation

copy

Full Screen

1import * as autoMock from 'ts-auto-mock';2import {Test2} from './test2';3export class Test1 {4 public test2: Test2;5 constructor() {6 this.test2 = autoMock.create<Test2>();7 }8}9export class Test2 {10 public test1: Test1;11 constructor() {12 this.test1 = autoMock.create<Test1>();13 }14}15import {Test1} from './test1';16import {Test2} from './test2';17describe('test', () => {18 it('should work', () => {19 const test1 = new Test1();20 const test2 = new Test2();21 expect(test1.test2).toEqual(test2);22 expect(test2.test1).toEqual(test1);23 });24});25 at Object.create (node_modules/ts-auto-mock/dist/lib/create.js:21:17)26 at Test1.constructor (test1.ts:10:22)27 at Object.create (node_modules/ts-auto-mock/dist/lib/create.js:18:26)28 at Test2.constructor (test2.ts:7:22)29 at Object.create (node_modules/ts-auto-mock/dist/lib/create.js:18:26)30 at Test1.constructor (test1.ts:10:22)31 at Object.create (node_modules/ts-auto-mock/dist/lib/create.js:18:26)32 at Test2.constructor (test2.ts:7:22)33 at Object.create (node_modules/ts-auto-mock/dist/lib/create.js:18:26)34 at Test1.constructor (test1.ts:10:22)

Full Screen

Using AI Code Generation

copy

Full Screen

1import {Mock} from 'ts-auto-mock';2import {Foo} from './foo';3describe('test1', () => {4 it('should work', () => {5 const mock = Mock.ofType<Foo>();6 const mock2 = new Mock<Foo>();7 });8});9export class Foo {10 public bar() {11 return 'bar';12 }13}14import {Foo} from './foo';15describe('foo', () => {16 it('should work', () => {17 const foo = new Foo();18 expect(foo.bar()).toBe('bar');19 });20});21 14 | }22 15 | function Mock() {23 > 16 | var _this = _super !== null && _super.apply(this, arguments) || this;24 17 | _this._name = 'Mock';25 18 | return _this;26 19 | }27 at Object.Mock (node_modules/ts-auto-mock/dist/mock.js:16:17)28 at Object.<anonymous> (test1.js:6:16)29"compilerOptions": {30}31import {Foo} from './foo';32describe('foo', () => {33 it('should work', () => {34 const foo = new Foo();35 expect(foo.bar()).toBe('bar');36 });37});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2import { test2 } from './test2';3export const test1 = createMock<test2>();4export interface test2 {5 test: string;6}7export class test3 {8 test: string;9}10export class test4 {11 test: string;12}13export class test5 {14 test: string;15}16export class test6 {17 test: string;18}19export class test7 {20 test: string;21}22export class test8 {23 test: string;24}25export class test9 {26 test: string;27}28export class test10 {29 test: string;30}31export class test11 {32 test: string;33}34export class test12 {35 test: string;36}37export class test13 {38 test: string;39}40export class test14 {41 test: string;42}43export class test15 {44 test: string;45}46export class test16 {47 test: string;48}49export class test17 {50 test: string;51}52export class test18 {53 test: string;54}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2import { A, B } from './test2';3const a: A = createMock<A>();4console.log(a);5const b: B = createMock<B>();6console.log(b);7export class A {8 a: string;9 b: string;10 c: string;11}12export class B {13 a: string;14 b: string;15 c: string;16}17{ a: 'string', b: 'string', c: 'string' } { a: 'string', b: 'string', c: 'string' }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createMock } from 'ts-auto-mock';2import { test2 } from './test2';3const mock = createMock<test2>();4mock.method1('test');5describe('test', () => {6 it('test', () => {7 const mock = createMock<test2>();8 mock.method1('test');9 });10});11export class test2 {12 method1(input: string) {13 console.log(input);14 }15}16{17 "compilerOptions": {18 "paths": {19 },20 },21}22{23 "compilerOptions": {24 }25}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

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

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

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful