"use strict";

var assert = require('assert');

var calculateScore = function(guess, secret) {
    var cows = 0;
    var bulls = 0;

    for (var i=0;i<secret.length;++i) {
	var found = guess.indexOf(secret[i]);
	if (found === i) 
	    bulls++
	else if (found !== -1)
	    cows++;
    }

    return { cows: cows, bulls: bulls };
};

var Player = function() {

    this.guesses = ['5678'];

    this.guess = function() {
	return this.guesses.pop();
    };
    
    this.update = function(guess, score) {
    };

    return this;
};

describe('cows and bulls', function() {
    describe('scoring', function() {
	var assertCowsAndBulls = function(expected, actual) {
	    assert.equal(actual.cows, expected.cows);
	    assert.equal(actual.bulls, expected.bulls);
	};

	it('no matches scores zero cows and bulls', function() {
	    var score = calculateScore('1234','5678');
	    assertCowsAndBulls({cows: 0, bulls: 0}, score);
	});
	
	it('single match in wrong place scores one cows', function() {
	    var score = calculateScore('1234', '5671');
	    assertCowsAndBulls({cows: 1, bulls: 0}, score);
	});

	it('single match in right place scores one bull', function() {
	    var score = calculateScore('1234', '1567');
	    assertCowsAndBulls({cows: 0, bulls: 1}, score);
	});
    });

    describe('strategy', function() {
	it('initially has all possibilities', function() {
	    var player = new Player();
	    assert.equal(4, player.guess().length);
	});

	it('eliminates possibilities', function() {
	    var player = new Player();
	    player.update('1234', {cows: 0, bulls: 0});

	    var guess = player.guess();
	    for (var i=1;i<=4;++i) {
		assert(guess.indexOf('' + i) === -1);
	    }
	});
    });
});

@@ -457,59 +457,8 @@
    %0A
-    this.update = function(guess, score) %7B%0A    %7D;%0A%0A
     
@@ -1272,38 +1272,35 @@
 it('
-initially has all possibilitie
+guesses have four character
 s', 
@@ -1397,251 +1397,8 @@
 %09%7D);
-%0A%0A%09it('eliminates possibilities', function() %7B%0A%09    var player = new Player();%0A%09    player.update('1234', %7Bcows: 0, bulls: 0%7D);%0A%0A%09    var guess = player.guess();%0A%09    for (var i=1;i%3C=4;++i) %7B%0A%09%09assert(guess.indexOf('' + i) === -1);%0A%09    %7D%0A%09%7D);
 %0A   

pare back to something way more sensible