<commit_before>YAHOO.namespace('GEIESMONADS.test');

var Assert = YAHOO.util.Assert;

YAHOO.GEIESMONADS.test.oTestMMAO = new YAHOO.tool.TestCase({
	name : "TestMaybeAsObject",
	testMaybeMonadAsObject : function() {
	
		// builds a famb from a fab
		var famb = function(fab) { 
			return function(x) {
				return Monad.maybe.unit(fab(x));};};
		
		var fabStringToIntAndReverse = function(value){
			return (typeof value === 'string') ? value.length : 'str'+value;
		};
		
		var more = function(value){
			return 'more ' + value;
		};
		
		var mMore = famb(more);
		
		// Maybe.unit(new Person(marco, 123)).bind(new LookupPersonId())
		//	.bind(new LookupAccount()).bind(new LookupBalance()).bind(new CheckOverdraft());
		
		//var maybeString = Monad.maybe.unit(3).bind(maybeStringToIntAndReverse);
		
		var coffee = Monad.maybe.create('coffee');
		Assert.areEqual('coffee', coffee());
		//var flattened = coffee.flatten('qwe');
		//Assert.areEqual('coffee', coffee());
		
		var moreCoffee = coffee.bind(mMore);		
		Assert.areEqual('more coffee',moreCoffee());
		
		var moreMoreCoffee = coffee.bind(mMore).bind(mMore).bind(mMore).bind(mMore).bind(mMore);
		Assert.areEqual('more more more more more coffee',moreMoreCoffee());
		
	}
});

YAHOO.GEIESMONADS.test.oTestIdentityMonad = new YAHOO.tool.TestCase({
	name : "TestIdentityMonad",
	testMonadicLawsForIdentityMonad : function() {
	
		var monad = myIdentityMonad;

		var a = 'aaa';
		var b = 3;
		var ma = monad.unit(a);
		var mb = monad.unit(b);
		
		var fab = function(value){
			return (typeof value === 'string')?value.length:'zz'+value;
		};

		//var famb = monad.unit(fab); // cazzata! unit opera su valori, non su funzioni!!!!!	
		var famb = function(x){return monad.unit(fab(x));};
		var fbma = function(value){
			return monad.unit((typeof value === 'string')?value.length:'zz'+value);
		}
		
		Assert.areEqual(3,fab(a));
		Assert.areEqual('zz3',fab(3));
		
		var unitFab = monad.unit(fab); // cazzata! unit opera su monadi, non su funzioni!!!!!		
		var unitFabA = unitFab(a);
		// Assert.areEqual('', monad.flatten(unitFabA));
		
		// zeroeth law --> m map f = m bind unit(f(x))
		var zeroethLawLeft = monad.map(ma,fab);
		var zeroethLawRight = monad.bind(ma,function(x){return monad.unit(fab(x))});
		Assert.areEqual(monad.flatten(zeroethLawLeft),monad.flatten(zeroethLawRight));
		
		// first law --> m bind unit = m
		var firstLawLeft = monad.bind(ma,monad.unit);
		Assert.areEqual(monad.flatten(firstLawLeft),monad.flatten(ma));
		
		// second law --> unit(x) bind famb = famb(x)
		var secondLawLeft = monad.bind(monad.unit(a),famb);
		Assert.areEqual(monad.flatten(secondLawLeft),monad.flatten(famb(a)));
		
		// third law --> (m bind g) bind f = m bind (g(x) bind f)
		var mBindFbma = monad.bind(mb,fbma);
		var fbmaXBindFamb = monad.bind(fbma(mb),famb)

		var m = mb;
		var g = fbma;
		var f = famb
		var thirdLawLeft = monad.bind(monad.bind(m,g),f);
		var thirdLawRight = monad.bind(m,function(x){return monad.bind(g(x),f)})
		Assert.areEqual(monad.flatten(thirdLawLeft),monad.flatten(thirdLawRight));
		
		
	}
});

YAHOO.GEIESMONADS.test.oTestMaybeMonad = new YAHOO.tool.TestCase({
	name : "TestMaybeMonad",
	testMonadicLawsForMaybeMonad : function() {
	
		var monad = myMaybeMonad;

		var a = 'aaa';
		var b = null;
		var ma = monad.unit(a);
		var mb = monad.unit(b);
		
		var fab = function(value){
			return (typeof value === 'string')?value.length:'zz'+value;
		};
		
		//var famb = monad.unit(fab); // cazzata! unit opera su valori, non su funzioni!!!!!		
		var famb = function(x){return monad.unit(fab(x));};
		var fbma = function(value){
			return monad.unit((typeof value === 'string')?value.length:'zz'+value);
		}
		
		Assert.areEqual(3,fab(a));
		Assert.areEqual('zz3',fab(3));
		
		var unitFab = monad.unit(fab); // cazzata! unit opera su valori, non su funzioni!!!!!		
		var unitFabA = unitFab(a);
		// Assert.areEqual('', monad.flatten(unitFabA));
		
		// zeroeth law --> m map f = m bind unit(f(x))
		var zeroethLawLeft = monad.map(ma,fab);
		var zeroethLawRight = monad.bind(ma,function(x){return monad.unit(fab(x))});
		Assert.areEqual(monad.flatten(zeroethLawLeft),monad.flatten(zeroethLawRight));
		
		// first law --> m bind unit = m
		var firstLawLeft = monad.bind(ma,monad.unit);
		Assert.areEqual(monad.flatten(firstLawLeft),monad.flatten(ma));
		
		// second law --> unit(x) bind famb = famb(x)
		var secondLawLeft = monad.bind(monad.unit(a),famb);
		Assert.areEqual(monad.flatten(secondLawLeft),monad.flatten(famb(a)));
		
		// third law --> (m bind g) bind f = m bind (g(x) bind f)
		var mBindFbma = monad.bind(mb,fbma);
		var fbmaXBindFamb = monad.bind(fbma(mb),famb)

		var m = mb;
		var g = fbma;
		var f = famb
		var thirdLawLeft = monad.bind(monad.bind(m,g),f);
		var thirdLawRight = monad.bind(m,function(x){return monad.bind(g(x),f)})
		Assert.areEqual(monad.flatten(thirdLawLeft),monad.flatten(thirdLawRight));
		
		
	}
});

YAHOO.GEIESMONADS.test.oTestStateMonadLooseMethods = new YAHOO.tool.TestCase({
	name : "TestStateMonadLooseMethods",
	testStateMonadLooseMethods : function() {
	
		var ma = identityUnit('aaa');
		// here is a famb!!!!
		var more = function (a){
			return identityUnit('more ' + a);
		}
		var mb = identityBind(ma, more);
		Assert.areEqual('more aaa', identityFlatten(mb));
		
		// chaining
		var mMore = function(ma){
			return identityBind(ma, more);
		};
		Assert.areEqual('more aaa', identityFlatten(mMore(ma)));
		
		var more0 = identityLift(more)(ma);
		Assert.areEqual('more aaa', identityFlatten(more0));
		
		var more_more1 = identityBind(identityBind(ma,more),more);
		var more_more2 = identityBind(identityLift(more)(ma),more);
		
		var more_more3 = identityLift(more)(identityLift(more)(ma));
		//var more_more4 = identityLift(more)(more)(ma);
		
		Assert.areEqual('more more aaa',identityFlatten(more_more1));		
		Assert.areEqual('more more aaa',identityFlatten(more_more2));
		Assert.areEqual('more more aaa',identityFlatten(more_more3));
		//Assert.areEqual('more more aaa',identityFlatten(more_more4));

	}
});

YAHOO.GEIESMONADS.test.oTestStateMonad = new YAHOO.tool.TestCase({
	name : "TestStateMonad",
	testMonadicLawsForStateMonad : function() {<commit_msg>first implementation of state monad<commit_after>YAHOO.namespace('GEIESMONADS.test');

var Assert = YAHOO.util.Assert;

YAHOO.GEIESMONADS.test.oTestMMAO = new YAHOO.tool.TestCase({
	name : "TestMaybeAsObject",
	testMaybeMonadAsObject : function() {
	
		// builds a famb from a fab
		var famb = function(fab) { 
			return function(x) {
				return Monad.maybe.unit(fab(x));};};
		
		var fabStringToIntAndReverse = function(value){
			return (typeof value === 'string') ? value.length : 'str'+value;
		};
		
		var more = function(value){
			return 'more ' + value;
		};
		
		var mMore = famb(more);
		
		// Maybe.unit(new Person(marco, 123)).bind(new LookupPersonId())
		//	.bind(new LookupAccount()).bind(new LookupBalance()).bind(new CheckOverdraft());
		
		//var maybeString = Monad.maybe.unit(3).bind(maybeStringToIntAndReverse);
		
		var coffee = Monad.maybe.create('coffee');
		Assert.areEqual('coffee', coffee());
		//var flattened = coffee.flatten('qwe');
		//Assert.areEqual('coffee', coffee());
		
		var moreCoffee = coffee.bind(mMore);		
		Assert.areEqual('more coffee',moreCoffee());
		
		var moreMoreCoffee = coffee.bind(mMore).bind(mMore).bind(mMore).bind(mMore).bind(mMore);
		Assert.areEqual('more more more more more coffee',moreMoreCoffee());
		
	}
});

YAHOO.GEIESMONADS.test.oTestIdentityMonad = new YAHOO.tool.TestCase({
	name : "TestIdentityMonad",
	testMonadicLawsForIdentityMonad : function() {
	
		var monad = myIdentityMonad;

		var a = 'aaa';
		var b = 3;
		var ma = monad.unit(a);
		var mb = monad.unit(b);
		
		var fab = function(value){
			return (typeof value === 'string')?value.length:'zz'+value;
		};

		//var famb = monad.unit(fab); // cazzata! unit opera su valori, non su funzioni!!!!!	
		var famb = function(x){return monad.unit(fab(x));};
		var fbma = function(value){
			return monad.unit((typeof value === 'string')?value.length:'zz'+value);
		}
		
		Assert.areEqual(3,fab(a));
		Assert.areEqual('zz3',fab(3));
		
		var unitFab = monad.unit(fab); // cazzata! unit opera su monadi, non su funzioni!!!!!		
		var unitFabA = unitFab(a);
		// Assert.areEqual('', monad.flatten(unitFabA));
		
		// zeroeth law --> m map f = m bind unit(f(x))
		var zeroethLawLeft = monad.map(ma,fab);
		var zeroethLawRight = monad.bind(ma,function(x){return monad.unit(fab(x))});
		Assert.areEqual(monad.flatten(zeroethLawLeft),monad.flatten(zeroethLawRight));
		
		// first law --> m bind unit = m
		var firstLawLeft = monad.bind(ma,monad.unit);
		Assert.areEqual(monad.flatten(firstLawLeft),monad.flatten(ma));
		
		// second law --> unit(x) bind famb = famb(x)
		var secondLawLeft = monad.bind(monad.unit(a),famb);
		Assert.areEqual(monad.flatten(secondLawLeft),monad.flatten(famb(a)));
		
		// third law --> (m bind g) bind f = m bind (g(x) bind f)
		var mBindFbma = monad.bind(mb,fbma);
		var fbmaXBindFamb = monad.bind(fbma(mb),famb)

		var m = mb;
		var g = fbma;
		var f = famb
		var thirdLawLeft = monad.bind(monad.bind(m,g),f);
		var thirdLawRight = monad.bind(m,function(x){return monad.bind(g(x),f)})
		Assert.areEqual(monad.flatten(thirdLawLeft),monad.flatten(thirdLawRight));
		
		
	}
});

YAHOO.GEIESMONADS.test.oTestMaybeMonad = new YAHOO.tool.TestCase({
	name : "TestMaybeMonad",
	testMonadicLawsForMaybeMonad : function() {
	
		var monad = myMaybeMonad;

		var a = 'aaa';
		var b = null;
		var ma = monad.unit(a);
		var mb = monad.unit(b);
		
		var fab = function(value){
			return (typeof value === 'string')?value.length:'zz'+value;
		};
		
		//var famb = monad.unit(fab); // cazzata! unit opera su valori, non su funzioni!!!!!		
		var famb = function(x){return monad.unit(fab(x));};
		var fbma = function(value){
			return monad.unit((typeof value === 'string')?value.length:'zz'+value);
		}
		
		Assert.areEqual(3,fab(a));
		Assert.areEqual('zz3',fab(3));
		
		var unitFab = monad.unit(fab); // cazzata! unit opera su valori, non su funzioni!!!!!		
		var unitFabA = unitFab(a);
		// Assert.areEqual('', monad.flatten(unitFabA));
		
		// zeroeth law --> m map f = m bind unit(f(x))
		var zeroethLawLeft = monad.map(ma,fab);
		var zeroethLawRight = monad.bind(ma,function(x){return monad.unit(fab(x))});
		Assert.areEqual(monad.flatten(zeroethLawLeft),monad.flatten(zeroethLawRight));
		
		// first law --> m bind unit = m
		var firstLawLeft = monad.bind(ma,monad.unit);
		Assert.areEqual(monad.flatten(firstLawLeft),monad.flatten(ma));
		
		// second law --> unit(x) bind famb = famb(x)
		var secondLawLeft = monad.bind(monad.unit(a),famb);
		Assert.areEqual(monad.flatten(secondLawLeft),monad.flatten(famb(a)));
		
		// third law --> (m bind g) bind f = m bind (g(x) bind f)
		var mBindFbma = monad.bind(mb,fbma);
		var fbmaXBindFamb = monad.bind(fbma(mb),famb)

		var m = mb;
		var g = fbma;
		var f = famb
		var thirdLawLeft = monad.bind(monad.bind(m,g),f);
		var thirdLawRight = monad.bind(m,function(x){return monad.bind(g(x),f)})
		Assert.areEqual(monad.flatten(thirdLawLeft),monad.flatten(thirdLawRight));
		
		
	}
});

YAHOO.GEIESMONADS.test.oTestStateMonadLooseMethods = new YAHOO.tool.TestCase({
	name : "TestStateMonadLooseMethods",
	testStateMonadLooseMethods : function() {
	
		var monad = myStateMonad;
		
		// already a famb - no need for lifting
		var more = function(value){
			return function(state){
				return {value:'more '+ value,state:state};
			};
		}

		// already a famb - no need for lifting
		var addSugar = function(value){
			return function(state){
				return {value:value,state:state+1};
			};
		}

		var ma = monad.unit('coffee');

		var mb = monad.bind(ma, more);
		Assert.areEqual('more coffee', mb(0).value);
		
		var mc = monad.bind(mb, addSugar);
		Assert.areEqual(1, mc(0).state);
	}
});

YAHOO.GEIESMONADS.test.oTestStateMonad = new YAHOO.tool.TestCase({
	name : "TestStateMonad",
	testMonadicLawsForStateMonad : function() {
{'fraction_non_alphanumeric': 0.1656671664167916, 'fraction_numerical': 0.0029985007496251873, 'mean_word_length': 4.16874730951356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5863263', 'n_tokens_mistral': 5045, 'n_tokens_neox': 4413, 'n_words': 855}