<commit_before>
const { expect } = require('chai');
const BoundlessCache = require('../cache/boundless');
const MetricsCache = require('../cache/metrics');

const newCache = () => {
	let Impl = MetricsCache(BoundlessCache);
	return new Impl({})
};

describe('MetricsCache', function() {
	it('Can create', function() {
		expect(newCache()).to.not.be.null;
	});

	it('Set and get value in cache', function() {
		const cache = newCache();
		cache.set('key', 'value');

		expect(cache.has('key')).to.equal(true);
		expect(cache.getIfPresent('key')).to.equal('value');

		expect(cache.metrics.hits).to.equal(1);
		expect(cache.metrics.misses).to.equal(0);
		expect(cache.metrics.hitRate).to.equal(1.0);
	});

	it('Get non-existent value in cache', function() {
		const cache = newCache();

		expect(cache.getIfPresent('key')).to.equal(null);

		expect(cache.metrics.hits).to.equal(0);
		expect(cache.metrics.misses).to.equal(1);
		expect(cache.metrics.hitRate).to.equal(0);
	});
});
<commit_msg>Adding new test for get without stats<commit_after>
const { expect } = require('chai');
const BoundlessCache = require('../cache/boundless');
const MetricsCache = require('../cache/metrics');

const newCache = () => {
	let Impl = MetricsCache(BoundlessCache);
	return new Impl({})
};

describe('MetricsCache', function() {
	it('Can create', function() {
		expect(newCache()).to.not.be.null;
	});

	it('Set and get value in cache', function() {
		const cache = newCache();
		cache.set('key', 'value');

		expect(cache.has('key')).to.equal(true);
		expect(cache.getIfPresent('key')).to.equal('value');

		expect(cache.metrics.hits).to.equal(1);
		expect(cache.metrics.misses).to.equal(0);
		expect(cache.metrics.hitRate).to.equal(1.0);
	});

	it('Get non-existent value in cache', function() {
		const cache = newCache();

		expect(cache.getIfPresent('key')).to.equal(null);

		expect(cache.metrics.hits).to.equal(0);
		expect(cache.metrics.misses).to.equal(1);
		expect(cache.metrics.hitRate).to.equal(0);
	});

	it('Get without recording stats', function() {
		const cache = newCache();

		expect(cache.getIfPresent('key', false)).to.equal(null);

		expect(cache.metrics.hits).to.equal(0);
		expect(cache.metrics.misses).to.equal(0);
		expect(cache.metrics.hitRate).to.equal(1);
	});
});

{'fraction_non_alphanumeric': 0.2054433713784021, 'fraction_numerical': 0.007462686567164179, 'mean_word_length': 4.950391644908616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6919606', 'n_tokens_mistral': 830, 'n_tokens_neox': 782, 'n_words': 127}