<commit_before>
const assert = require('assert');
const computation = require('../computation');


describe('computation', () => {
	describe('derivative', () => {
		it('y=const', () => {
			function func(x) {
				return 10;
			}
			assert.equal(computation.derivative(func, 1), 0);
			assert.equal(computation.derivative(func, 10), 0);
			assert.equal(computation.derivative(func, -1), 0);
		});
		
		it('y = x', () => {
			function func(x) {
				return x;
			}
			equalFloat(computation.derivative(func, 1), 1);
			equalFloat(computation.derivative(func, 10), 1);
			equalFloat(computation.derivative(func, -1), 1);
		});
		
		it('y = 3 * x', () => {
			function func(x) {
				return 3 * x;
			}
			equalFloat(computation.derivative(func, 1), 3);
			equalFloat(computation.derivative(func, 10), 3);
			equalFloat(computation.derivative(func, -1), 3);
		});
		
		it('y = 3 * x * x', () => {
			function func(x) {
				return 3 * x * x;
			}
			equalFloat(computation.derivative(func, 1), 3 * 2 * 1);
			equalFloat(computation.derivative(func, 10), 3 * 2  * 10);
			equalFloat(computation.derivative(func, -5), 3 * 2 * -5);
		});
		
		it('y = exp(x)', () => {
			function func(x) {
				return Math.exp(x);
			}
			equalFloat(computation.derivative(func, 1), Math.exp(1));
			equalFloat(computation.derivative(func, 5), Math.exp(5));
			equalFloat(computation.derivative(func, 3), Math.exp(3));
			equalFloat(computation.derivative(func, -3), Math.exp(-3));
		});
		
		it('c = a + b', () => {
			function func(x) {
				return x[0] + x[1];
			}
			equalFloat(computation.derivative(func, [1, 2], 0), 1);
			equalFloat(computation.derivative(func, [10, 20], 1), 1);
			equalFloat(computation.derivative(func, [-1, 3], 0), 1);
		});<commit_msg>Derivative of function with parameters<commit_after>
const assert = require('assert');
const computation = require('../computation');


describe('computation', () => {
	describe('derivative', () => {
		it('y=const', () => {
			function func(x) {
				return 10;
			}
			assert.equal(computation.derivative(func, 1), 0);
			assert.equal(computation.derivative(func, 10), 0);
			assert.equal(computation.derivative(func, -1), 0);
		});
		
		it('y = x', () => {
			function func(x) {
				return x;
			}
			equalFloat(computation.derivative(func, 1), 1);
			equalFloat(computation.derivative(func, 10), 1);
			equalFloat(computation.derivative(func, -1), 1);
		});
		
		it('y = 3 * x', () => {
			function func(x) {
				return 3 * x;
			}
			equalFloat(computation.derivative(func, 1), 3);
			equalFloat(computation.derivative(func, 10), 3);
			equalFloat(computation.derivative(func, -1), 3);
		});
		
		it('y = 3 * x * x', () => {
			function func(x) {
				return 3 * x * x;
			}
			equalFloat(computation.derivative(func, 1), 3 * 2 * 1);
			equalFloat(computation.derivative(func, 10), 3 * 2  * 10);
			equalFloat(computation.derivative(func, -5), 3 * 2 * -5);
		});
		
		it('y = exp(x)', () => {
			function func(x) {
				return Math.exp(x);
			}
			equalFloat(computation.derivative(func, 1), Math.exp(1));
			equalFloat(computation.derivative(func, 5), Math.exp(5));
			equalFloat(computation.derivative(func, 3), Math.exp(3));
			equalFloat(computation.derivative(func, -3), Math.exp(-3));
		});
		
		it('c = a + b', () => {
			function func(x) {
				return x[0] + x[1];
			}
			equalFloat(computation.derivative(func, [1, 2], 0), 1);
			equalFloat(computation.derivative(func, [10, 20], 1), 1);
			equalFloat(computation.derivative(func, [-1, 3], 0), 1);
		});
		
		it('c = x * x * a + b', () => {
			function func(args) {
				return Math.pow(args[0], 2) * args[1] + args[2];
			}
			equalFloat(computation.derivative(func, [3, 2, 5], 0), 2 * 3 * 2);
			equalFloat(computation.derivative(func, [3, 2, 5], 1), 3 * 3);
			equalFloat(computation.derivative(func, [3, 2, 5], 2), 1);
		});
{'fraction_non_alphanumeric': 0.20470588235294118, 'fraction_numerical': 0.03973856209150327, 'mean_word_length': 3.527810650887574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '2959067', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1396, 'n_words': 279}