<commit_before>let expect = require('chai').expect;
let KnapsackSolver = require('../app/knapsacksolver');

describe('KnapsackSolver', function() {
	let _1chips = [ {color:'white',amount:100,denomination:.05} ];
	let _2chips = _1chips.concat([{color:'red',amount:150,denomination:.1}]);
	let _3chips = _2chips.concat([{color:'blue',amount:100,denomination:.25}]);
	let _4chips = _3chips.concat([{color:'green',amount:100,denomination:.5}]);
	let _5chips = _4chips.concat([{color:'black',amount:50,denomination:1}]);
	describe('applyValues', function() {
		it('with 1 item => value is 1', function() {
			let assignedChips = _1chips;
			let items = KnapsackSolver.applyValues(assignedChips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:1}
			]);
		});
		it('with 2 items => values are equal', function() {
			let assignedChips = _2chips;
			let items = KnapsackSolver.applyValues(assignedChips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:1},
				{color:'red',	value:1}
			]);
		});
		it('with 3 items => second item has highest value, last item lowest', function() {
			let assignedChips = _3chips;
			let items = KnapsackSolver.applyValues(assignedChips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:2},
				{color:'red',	value:3},
				{color:'blue',	value:1}
			]);
		});
		it('with 4 items => second item has highest value, 3rd item second highest, rest descend in values along position in item list', function() {
			let assignedChips = _4chips;
			let items = KnapsackSolver.applyValues(assignedChips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:2},
				{color:'red',	value:4},
				{color:'blue',	value:3},
				{color:'green',	value:1}
			]);
		});
		it('with 5 items => same as with 4', function() {
			let assignedChips = _5chips;
			let items = KnapsackSolver.applyValues(assignedChips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:3},
				{color:'red',	value:5},
				{color:'blue',	value:4},
				{color:'green',	value:2},
				{color:'black',	value:1}
			]);
		});
	});

	describe.skip('applyWeights', function() {
		it('1 player => weights == total amount of chips', function() {

		});
	});
});

function toValueColorPairs(items){
	return items.map(({value,wrapped:{color}}) => {return {color,value};});
}<commit_msg>more refactoring<commit_after>let expect = require('chai').expect;
let KnapsackSolver = require('../app/knapsacksolver');

describe('KnapsackSolver', function() {
	let _1chips = [{color:'white',amount:100,denomination:.05}];
	let _2chips = _1chips.concat([{color:'red',amount:150,denomination:.1}]);
	let _3chips = _2chips.concat([{color:'blue',amount:100,denomination:.25}]);
	let _4chips = _3chips.concat([{color:'green',amount:100,denomination:.5}]);
	let _5chips = _4chips.concat([{color:'black',amount:50,denomination:1}]);
	
	describe('applyValues', function() {
		it('with 1 item => value is 1', function() {
			let items = KnapsackSolver.applyValues(_1chips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:1}
			]);
		});
		it('with 2 items => values are equal', function() {
			let items = KnapsackSolver.applyValues(_2chips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:1},
				{color:'red',	value:1}
			]);
		});
		it('with 3 items => second item has highest value, last item lowest', function() {
			let items = KnapsackSolver.applyValues(_3chips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:2},
				{color:'red',	value:3},
				{color:'blue',	value:1}
			]);
		});
		it('with 4 items => second item has highest value, 3rd item second highest, rest descend in values along position in item list', function() {
			let items = KnapsackSolver.applyValues(_4chips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:2},
				{color:'red',	value:4},
				{color:'blue',	value:3},
				{color:'green',	value:1}
			]);
		});
		it('with 5 items => same as with 4', function() {
			let items = KnapsackSolver.applyValues(_5chips);
			let itemValues = toValueColorPairs(items);
			expect(itemValues).to.deep.equal([
				{color:'white',	value:3},
				{color:'red',	value:5},
				{color:'blue',	value:4},
				{color:'green',	value:2},
				{color:'black',	value:1}
			]);
		});
	});

	describe.only('applyWeights', function() {
		it('1 player => weights == total amount of chips', function() {

		});
	});
});

function toValueColorPairs(items){
	return items.map(({value,wrapped:{color}}) => {return {color,value};});
}

function toWeightColorPairs(items){
	return items.map(({weight,wrapped:{color}}) => {return {color,weight};});
}
{'fraction_non_alphanumeric': 0.1823587710604559, 'fraction_numerical': 0.023389494549058473, 'mean_word_length': 4.881118881118881, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '6409667', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1735, 'n_words': 346}