var expect = require('chai').expect;
var Foswig = require('../lib/index');
var dictionary = require('./dictionary');

describe('Foswig',function() {
	describe('generateWord',function() {
		it('should generate words of the correct length',function() {
			var markov = new Foswig(2);
			markov.addWordsToChain(dictionary);

			for (var i = 0;i < 100; ++i) {
                while (true) {
                    try {
                        var word = markov.generateWord(2,5,true);
                        break;
                    } catch (err) {
                        // sometimes the word generator cannot satisfy the 
                        // length constraints in the default number of attempts.
                        // This is expected, so we'll just try again
                    }
                }
				expect(word.length).to.be.at.least(2);
				expect(word.length).to.be.at.most(5);
				//console.log(word);
			}
		});

		it('should not generate duplicate words from the input dictionary',function() {
			var markov = new Foswig(2);
			markov.addWordsToChain(dictionary);

			for (var i = 0;i < 100; ++i) {
                try {
                    var word = markov.generateWord(2,5,false);
                    break;
                } catch (err) {
                    // sometimes the word generator cannot satisfy the 
                    // length constraints in the default number of attempts.
                    // This is expected, so we'll just try again
                }
				expect([word]).to.not.have.members(dictionary);
				//console.log(word);
			}
		});
	});
});


@@ -1621,16 +1621,763 @@
 %0D%0A%09%09%7D);%0D
+%0A%0D%0A%09%09it('should generate words of the correct length when maxLength is -1',function() %7B%0D%0A%09%09%09var markov = new Foswig(2);%0D%0A%09%09%09markov.addWordsToChain(dictionary);%0D%0A%0D%0A%09%09%09for (var i = 0;i %3C 100; ++i) %7B%0D%0A                while (true) %7B%0D%0A                    try %7B%0D%0A                        var word = markov.generateWord(2,-1,true);%0D%0A                        break;%0D%0A                    %7D catch (err) %7B%0D%0A                        // sometimes the word generator cannot satisfy the %0D%0A                        // length constraints in the default number of attempts.%0D%0A                        // This is expected, so we'll just try again%0D%0A                    %7D%0D%0A                %7D%0D%0A%09%09%09%09expect(word.length).to.be.at.least(2);%0D%0A%09%09%09%09//console.log(word);%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D
 %0A%09%7D);%0D%0A%7D

add test for maxLength=-1, currently hangs (infinite loop)