<commit_before>import { expect } from 'chai';

describe('calculator', () => {
  it('compute: should return null if any attrubutes depended on is not ready yet', () => {
    const geometry = require('../geometry');
    geometry.addGeometry('calender', {
      x: 100,
      y: 200,
      width: 400,
      height: 700,
    });

    const calculator = require('../calculator');
    calculator.addCalculators('content', {
      height: [{ identifier: 'calender', attr: 'y' }, '+', { identifier: 'header', attr: 'height' }]
    });

    expect(calculator.compute('content', 'height')).to.equal(null);
  });

  it('compute: should return appropriate attr value', () => {
    const geometry = require('../geometry');
    geometry.addGeometry('calender', {
      x: 100,
      y: 200,
      width: 400,
      height: 700,
    });

    geometry.addGeometry('header', {
      x: 50,
      y: 100,
      width: 200,
      height: 300,
    });

    const calculator = require('../calculator');<commit_msg>refactor test to mock with sinon<commit_after>import { expect } from 'chai';
import sinon from 'sinon';
import * as geometry from '../geometry';

describe('calculator', () => {
  let getValue;

  beforeEach(() => {
    getValue = sinon.stub(geometry, 'getValue');
  });

  afterEach(() => {
    getValue.restore();
  });

  it('compute: should return null if any attrubutes depended on is not ready yet', () => {
    getValue.withArgs('calender', 'y').returns(200);
    getValue.withArgs('header', 'height').returns(undefined);

    const calculator = require('../calculator');
    calculator.addCalculators('content', {
      height: [{ identifier: 'calender', attr: 'y' }, '+', { identifier: 'header', attr: 'height' }]
    });

    expect(calculator.compute('content', 'height')).to.equal(null);
  });

  it('compute: should return appropriate attr value', () => {
    getValue.withArgs('calender', 'y').returns(200);
    getValue.withArgs('header', 'height').returns(300);

    const calculator = require('../calculator');
{'fraction_non_alphanumeric': 0.18514851485148515, 'fraction_numerical': 0.02178217821782178, 'mean_word_length': 3.3744588744588744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6952882', 'n_tokens_mistral': 666, 'n_tokens_neox': 591, 'n_words': 146}