Пример #1
0
  const checkWriting = (text: string, width: number, height: number, shouldHaveTitle = false) => {
    svg.attr("width", width);
    svg.attr("height", height);
    writer.write(text, width, height, writeOptions);
    const bbox = SvgUtils.getDimensions(svg.select(".text-area").node() as SVGGraphicsElement);
    const dimensions = measurer.measure(
                      wrapper.wrap(
                        text,
                        measurer,
                        isHorizontal ? width : height,
                        isHorizontal ? height : width,
                      ).wrappedText);

    assert.closeTo(bbox.width, dimensions.width, 1,
      "width of the text should be almost the same as measurer width");
    assert.closeTo(bbox.height, dimensions.height, 1,
      "height of the text should be almost the same as measurer height");

    assertBBoxInclusion(svg, svg.select(".text-area"));
    assert.equal(svg.select(".text-container").select("title").empty(),
                 !shouldHaveTitle,
                 "title element was created according to writer options");

    svg.remove();
  };
Пример #2
0
			it(`should map to ${testCase.expected}`, () => {
				assert.closeTo(
					NumberUtil.map(...testCase.args),
					testCase.expected,
					DELTA,
				);
			});
Пример #3
0
 it('adds geocoding columns to CSV', async () => {
   const bin = path.join(__dirname, '..', 'lib', 'program.js')
   const fixture = path.join(__dirname, 'fixtures', 'landmarks.csv')
   let out = await execP(`${bin} --input ${fixture} --output -`)
   const geocoded: { [key: string]: string }[] = []
   await new Promise<void>((resolve, reject) => {
     csv.fromString(out.stdout, { headers: true })
       .on('data', (data) => { geocoded.push(data) })
       .on('end', () => { resolve() })
       .on('error', () => { reject() })
   })
   assert.strictEqual(geocoded[0].landmark, "White House")
   assert.strictEqual(geocoded[0].ss_zipcode, "20500")
   assert.closeTo(Number(geocoded[0].ss_latitude), 38.8987, 0.1)
   assert.closeTo(Number(geocoded[0].ss_longitude), -77.0352, 0.1)
 })
 it('should equal the correct values that were written above', () => {
   assert.strictEqual(reader.readUInt8(), 0xc8);
   assert.strictEqual(reader.readUInt8(), 0xff);
   assert.strictEqual(reader.readInt16BE(), 0x6699);
   assert.strictEqual(reader.readInt16LE(), 0xc8);
   assert.strictEqual(reader.readInt16LE(), 0x6699);
   assert.strictEqual(reader.readUInt16BE(), 0xffdd);
   assert.strictEqual(reader.readUInt16LE(), 0xffdd);
   assert.strictEqual(reader.readInt32BE(), 0x77889900);
   assert.strictEqual(reader.readInt32LE(), 0x77889900);
   assert.strictEqual(reader.readUInt32BE(), 0xffddccbb);
   assert.strictEqual(reader.readUInt32LE(), 0xffddccbb);
   assert.closeTo(reader.readFloatBE(), 1.234, 0.001);
   assert.closeTo(reader.readFloatLE(), 1.234, 0.001);
   assert.closeTo(reader.readDoubleBE(), 1.23456789, 0.001);
   assert.closeTo(reader.readDoubleLE(), 1.23456789, 0.001);
   assert.equal(reader.readUInt8(0), 0xc8);
 });
Пример #5
0
 it("multi time wrapping", () => {
   const availableWidth = measurer.measure("hell").width;
   const result = wrapper.wrap(line, measurer, availableWidth);
   assert.deepEqual(result.originalText, line, "original text has been set");
   assert.lengthOf(result.wrappedText.split("\n"), 5, "wrapping occured");
   assert.deepEqual(result.truncatedText, "", "non of the text has been truncated");
   assert.closeTo(result.noBrokeWords, 3, 1, "wrapping with breaking two words about three times");
   assert.equal(result.noLines, 5, "wrapping was needed");
   assert.operator(measurer.measure(result.wrappedText).width, "<=", availableWidth, "wrapped text fits in");
 });
Пример #6
0
	it('should constrain value with step', () => {
		const c = new StepConstraint({
			step: 1,
		});
		assert.closeTo(c.constrain(-0.51), -1, DELTA);
		assert.closeTo(c.constrain(-0.5), -1, DELTA);
		assert.closeTo(c.constrain(-0.49), 0, DELTA);
		assert.closeTo(c.constrain(0), 0, DELTA);
		assert.closeTo(c.constrain(1.49), 1, DELTA);
		assert.closeTo(c.constrain(1.5), 2, DELTA);
		assert.closeTo(c.constrain(1.51), 2, DELTA);
	});
Пример #7
0
	it('should constrain value with decimal step', () => {
		const c = new StepConstraint({
			step: 0.2,
		});
		assert.closeTo(c.constrain(-1.51), -1.6, DELTA);
		assert.closeTo(c.constrain(-1.5), -1.6, DELTA);
		assert.closeTo(c.constrain(-1.49), -1.4, DELTA);
		assert.closeTo(c.constrain(0), 0, DELTA);
		assert.closeTo(c.constrain(1.49), 1.4, DELTA);
		assert.closeTo(c.constrain(1.5), 1.6, DELTA);
		assert.closeTo(c.constrain(1.51), 1.6, DELTA);
	});
 it('should use existing identifier for control flow storage with expected chance', () => {
     assert.closeTo(usingExistingIdentifierChance, expectedChance, delta);
 });
 it('should add two `control flow storage` nodes (root and inner) to the obfuscated code in different scopes', () => {
     assert.closeTo(appendToScopeThreshold, expectedAppendToScopeThreshold, delta);
 });
Пример #10
0
			it(`it should convert to ${JSON.stringify(rgb)}`, () => {
				const actual = ColorModel.hsvToRgb(hsv.h, hsv.s, hsv.v);
				assert.closeTo(actual[0], rgb.r, DELTA);
				assert.closeTo(actual[1], rgb.g, DELTA);
				assert.closeTo(actual[2], rgb.b, DELTA);
			});