Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
992 lines (892 sloc) 30 KB
<html>
<head>
<title>Neural.js</title>
<!--<link rel="stylesheet" href="/css/style.css">-->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<div id="result"></div>
<script type="text/javascript">
var test = test || {};
test.synapses = test.synapses || {};
test.synapses.cursor = test.synapses.cursor || {};
test.neurons = test.neurons || {};
test.neurons.cursor = test.neurons.cursor || {};
test.synapses.data = test.synapses.data || {};
test.neurons.data = test.neurons.data || {};
var test_id = 77;
var inc_amount = 1;
test.synapses.data.add = function ( count, on_success, on_error ) {
var map = [];
for( var i = 0; i < count; i++ ) {
var node1 = Math.floor( Math.random()*100 );
var node2 = Math.floor( Math.random()*100 );
Neural.synapses.add( { 'data': { 'type': 'connection', 'from': node1, 'to': node2, 'strength': Math.random() }, 'on_success': function( result_value ) {
if( !!Neural.debug ) {
console.log( 'Added synapse', result_value );
}
if( 'undefined' !== typeof on_success ) {
on_success( result_value );
}
}, 'on_error': function( context ) {
if( !!Neural.debug ) {
console.log( 'Failed to add synapses', context );
}
if( 'undefined' !== typeof on_error ) {
on_error( context );
}
} } );
}
}
test.synapses.getAttr = function( test_callback ) {
var on_error = function( test_callback ) {
console.log( 'test.synapses.getAttr(): failed' );
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
};
Neural.synapses.getAttr( {
'key': test_id
, 'index': 'id'
, 'on_success': function( value ) {
if( 'undefined' !== value ) {
console.log( 'test.synapses.getAttr(): passed' );
} else {
console.log( 'test.synapses.getAttr(): failed' );
}
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
test.synapses.setAttr = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.synapses.setAttr(): failed' );
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
};
Neural.synapses.getAttr( {
'key': test_id
, 'index': 'id'
, 'on_success': function( context ) {
var value = InDB.row.value( context.event );
var expected = {};
var key = Neural.synapses.shorthand( 'strength' );
expected[ key ] = value[ key ];
Neural.synapses.setAttr( {
'key': test_id
, 'index': 'id'
, 'expecting': expected
, 'strength': function( current ) {
var replacement = current / 2;
replacement = ( !!replacement && replacement > .001 ) ? replacement : 1;
return replacement;
}, 'on_success': function( context ) {
Neural.synapses.getAttr( {
'key': test_id
, 'index': 'id'
, 'on_success': function( value ) {
if( 'undefined' !== typeof value ) {
console.log( 'test.synapses.setAttr(): passed' );
} else {
console.log( 'test.synapses.setAttr(): failed' );
}
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.synapses.get = function( test_callback ) {
var on_error = function( get_context ) {
console.log( 'test.synapses.get(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
Neural.synapses.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( value ) {
console.log( 'test.synapses.get(): passed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
test.synapses.put = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.synapses.put(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
Neural.synapses.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( new_value ) {
new_value[ 'from' ] = ( isNaN( new_value[ 'from' ] ) ) ? 1 : new_value[ 'from' ];
new_value[ 'from' ] = parseInt( new_value[ 'from' ], 10 ) + inc_amount;
new_value[ 'to' ] = ( isNaN( new_value[ 'to' ] ) ) ? 1 : new_value[ 'to' ];
new_value[ 'to' ] = parseInt( new_value[ 'to' ], 10 ) + inc_amount;
Neural.synapses.put( {
'key': test_id
, 'data': new_value
, 'on_success': function( result_id ) {
Neural.synapses.get( {
'key': result_id
//, 'index': 'id'
, 'on_success': function( return_value ) {
if( 'undefined' !== typeof return_value[ 'from' ] && new_value[ 'from' ] == return_value[ 'from' ] && 'undefined' !== typeof return_value[ 'to' ] && new_value[ 'to' ] == return_value[ 'to' ] ) {
console.log( 'test.synapses.put(): passed' );
} else {
console.log( 'test.synapses.put(): failed', new_value, return_value );
}
if( 'function' == typeof test_callback ) {
test_callback( return_value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.synapses.add = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.synapses.add(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
var new_value = {
'to': 1
, 'from': 1
, 'type': 'connection'
, 'strength': Math.random()
};
Neural.synapses.add( {
'data': new_value
, 'on_success': function( add_value ) {
Neural.synapses.get( {
'key': add_value
//, 'index': 'id'
, 'on_success': function( return_value ) {
if( 'undefined' !== typeof return_value && null !== return_value && add_value == return_value.id ) {
test_id = return_value;
console.log( 'test.synapses.add(): passed' );
} else {
console.log( 'test.synapses.add(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( return_value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.synapses.update = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.synapses.update(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
Neural.synapses.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( value ) {
var expected = {};
expected[ 'to' ] = value[ 'to' ];
Neural.synapses.update( {
'key': test_id
//, 'index': 'id'
, 'expecting': expected
, 'data': function( current ) {
var val = {};
val[ 'to' ] = parseInt( current[ 'to' ], 10 ) + inc_amount;
return val;
}, 'on_success': function( context ) {
Neural.synapses.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( returned_value ) {
if( 'undefined' !== typeof returned_value && null !== returned_value && ( returned_value[ 'to' ] - inc_amount ) == expected[ 'to' ] ) {
console.log( 'test.synapses.update(): passed' );
} else {
console.log( 'test.synapses.update(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( returned_value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.synapses.delete = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.synapses.delete(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
var new_value = {
'to': 1
, 'from': 1
, 'type': 'connection'
, 'strength': Math.random()
};
Neural.synapses.add( {
'data': new_value
, 'on_success': function( add_value ) {
Neural.synapses.get( {
'key': add_value
//, 'index': 'id'
, 'on_success': function( get_value_1 ) {
Neural.synapses.delete( {
'key': add_value
, 'on_success': function( delete_value ) {
Neural.synapses.get( {
'key': add_value
//, 'index': 'id'
, 'on_error': on_error
, 'on_success': function( context ) {
var get_value_2 = InDB.row.value( context );
if( 'undefined' !== typeof get_value_2 && null == get_value_2 ) {
console.log( 'test.synapses.delete(): passed' );
} else {
console.log( 'test.synapses.delete(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( get_value_2 );
}
}
} );
}, 'on_error': on_error } );
}, 'on_error': on_error } );
}, 'on_error': on_error } );
};
/* Clear */
test.synapses.clear = function( test_callback ) {
var on_error = function( get_context ) {
console.log( 'test.synapses.clear(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
Neural.synapses.clear( {
'on_success': function( value ) {
console.log( 'test.synapses.cursor.clear(): passed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
/* Cursor */
test.synapses.cursor.get = function( test_callback ) {
var on_error = function( get_context ) {
console.log( 'test.synapses.get(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
Neural.synapses.cursor.get( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
, 'limit': 20
, 'direction': InDB.cursor.direction.previous()
, 'on_success': function( value ) {
item_count++;
}, 'on_complete': function( value ) {
console.log( 'test.synapses.cursor.get(): passed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
test.synapses.cursor.delete = function( test_callback ) {
test.synapses.data.add( 5 );
var on_error = function( get_context ) {
console.log( 'test.synapses.delete(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
var limit = 20;
Neural.synapses.cursor.get( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
//, 'limit': limit
, 'direction': InDB.cursor.direction.previous()
, 'on_success': function( value ) {
item_count++;
}, 'on_complete': function( value ) {
console.log("TOTAL", item_count );
var delete_count = 0;
Neural.synapses.cursor.delete( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
//, 'limit': limit
, 'direction': InDB.cursor.direction.next()
, 'on_success': function( value ) {
delete_count++;
}, 'on_complete': function( value ) {
var final_count = 0;
Neural.synapses.cursor.get( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
//, 'limit': limit
, 'direction': InDB.cursor.direction.previous()
, 'on_success': function( value ) {
if( 'undefined' !== typeof value && null !== value ) {
final_count++;
}
}, 'on_complete': function( value ) {
if( 0 == final_count ) {
console.log( 'test.synapses.cursor.delete(): passed' );
} else {
console.log( 'test.synapses.cursor.delete(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.synapses.cursor.update = function( test_callback ) {
test.synapses.data.add( 5 );
var on_error = function( get_context ) {
console.log( 'test.synapses.update(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
var limit = 20;
var update_map = {};
Neural.synapses.cursor.update( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id' //xxx
, 'data': function( current_value ) {
if( 'undefined' !== typeof current_value && null !== current_value && 'undefined' !== typeof current_value.strength ) {
//var new_strength = ( 'undefined' !== typeof current_value.strength ) ? current_value.strength / 2 : 1;
var new_strength = "123456";
update_map[ current_value.id ] = new_strength;
console.log("UPDATED FROM/TO",current_value.strength,new_strength);
current_value.strength = new_strength;
}
return current_value;
}//, 'limit': limit
, 'direction': InDB.cursor.direction.next()
, 'on_success': function( value ) {
item_count++;
console.log('updated');
}, 'on_complete': function( value ) {
console.log("UPPITY",value);
if( limit > 0 && item_count <= limit ) {
console.log( 'test.synapses.cursor.update(): passed', update_map );
} else {
console.log( 'test.synapses.cursor.update(): failed. Counted ' + item_count + ' successes, expected ' + limit );
}
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
/* Neurons */
test.neurons.data.add = function ( count, on_success, on_error ) {
var map = [];
for( var i = 0; i < count; i++ ) {
var node1 = Math.floor( Math.random()*100 );
var node2 = Math.floor( Math.random()*100 );
Neural.neurons.add( { 'data': { 'type': 'hidden', 'slug': InDB.utilities.random( 12, 'string' ) }, 'on_success': function( result_value ) {
if( !!Neural.debug ) {
console.log( 'Added neuron', result_value );
}
if( 'undefined' !== typeof on_success ) {
on_success( result_value );
}
}, 'on_error': function( context ) {
if( !!Neural.debug ) {
console.log( 'Failed to add neurons', context );
}
if( 'undefined' !== typeof on_error ) {
on_error( context );
}
} } );
}
}
test.neurons.getAttr = function( attribute, key, index, test_callback ) {
var on_error = function( test_callback ) {
console.log( 'test.neurons.getAttr(): failed' );
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
};
Neural.neurons.getAttr( {
'key': key
, 'attribute': attribute
, 'index': index
, 'on_success': function( value ) {
if( 'undefined' !== value ) {
console.log( 'test.neurons.getAttr(): passed' );
} else {
console.log( 'test.neurons.getAttr(): failed' );
}
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
test.neurons.setAttr = function( attribute, key, index, test_callback ) {
var on_error = function( value ) {
console.log( 'test.neurons.setAttr(): failed' );
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
};
Neural.neurons.getAttr( {
'key': key
, 'attribute': attribute
, 'index': index
, 'on_success': function( context ) {
var value = InDB.row.value( context.event );
var expected = {};
var key = Neural.neurons.shorthand( 'strength' );
expected[ key ] = value[ key ];
Neural.neurons.setAttr( {
'key': test_id
, 'index': 'id'
, 'expecting': expected
, 'strength': function( current ) {
var replacement = current / 2;
replacement = ( !!replacement && replacement > .001 ) ? replacement : 1;
return replacement;
}, 'on_success': function( context ) {
Neural.neurons.getAttr( {
'key': test_id
, 'index': 'id'
, 'on_success': function( value ) {
if( 'undefined' !== typeof value ) {
console.log( 'test.neurons.setAttr(): passed' );
} else {
console.log( 'test.neurons.setAttr(): failed' );
}
if( 'function' !== typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.neurons.get = function( test_callback ) {
var on_error = function( get_context ) {
console.log( 'test.neurons.get(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
Neural.neurons.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( value ) {
console.log( 'test.neurons.get(): passed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
test.neurons.put = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.neurons.put(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
Neural.neurons.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( new_value ) {
new_value[ 'from' ] = ( isNaN( new_value[ 'from' ] ) ) ? 1 : new_value[ 'from' ];
new_value[ 'from' ] = parseInt( new_value[ 'from' ], 10 ) + inc_amount;
new_value[ 'to' ] = ( isNaN( new_value[ 'to' ] ) ) ? 1 : new_value[ 'to' ];
new_value[ 'to' ] = parseInt( new_value[ 'to' ], 10 ) + inc_amount;
Neural.neurons.put( {
'key': test_id
, 'data': new_value
, 'on_success': function( result_id ) {
Neural.neurons.get( {
'key': result_id
//, 'index': 'id'
, 'on_success': function( return_value ) {
if( 'undefined' !== typeof return_value[ 'from' ] && new_value[ 'from' ] == return_value[ 'from' ] && 'undefined' !== typeof return_value[ 'to' ] && new_value[ 'to' ] == return_value[ 'to' ] ) {
console.log( 'test.neurons.put(): passed' );
} else {
console.log( 'test.neurons.put(): failed', new_value, return_value );
}
if( 'function' == typeof test_callback ) {
test_callback( return_value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.neurons.add = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.neurons.add(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
var new_value = {
'to': 1
, 'from': 1
, 'type': 'connection'
, 'strength': Math.random()
};
Neural.neurons.add( {
'data': new_value
, 'on_success': function( add_value ) {
Neural.neurons.get( {
'key': add_value
//, 'index': 'id'
, 'on_success': function( return_value ) {
if( 'undefined' !== typeof return_value && null !== return_value && add_value == return_value.id ) {
test_id = return_value;
console.log( 'test.neurons.add(): passed' );
} else {
console.log( 'test.neurons.add(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( return_value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.neurons.update = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.neurons.update(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
Neural.neurons.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( value ) {
var expected = {};
expected[ 'to' ] = value[ 'to' ];
Neural.neurons.update( {
'key': test_id
//, 'index': 'id'
, 'expecting': expected
, 'data': function( current ) {
var val = {};
val[ 'to' ] = parseInt( current[ 'to' ], 10 ) + inc_amount;
return val;
}, 'on_success': function( context ) {
Neural.neurons.get( {
'key': test_id
//, 'index': 'id'
, 'on_success': function( returned_value ) {
if( 'undefined' !== typeof returned_value && null !== returned_value && ( returned_value[ 'to' ] - inc_amount ) == expected[ 'to' ] ) {
console.log( 'test.neurons.update(): passed' );
} else {
console.log( 'test.neurons.update(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( returned_value );
}
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.neurons.delete = function( test_callback ) {
var on_error = function( value ) {
console.log( 'test.neurons.delete(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
};
var new_value = {
'to': 1
, 'from': 1
, 'type': 'connection'
, 'strength': Math.random()
};
Neural.neurons.add( {
'data': new_value
, 'on_success': function( add_value ) {
Neural.neurons.get( {
'key': add_value
//, 'index': 'id'
, 'on_success': function( get_value_1 ) {
Neural.neurons.delete( {
'key': add_value
, 'on_success': function( delete_value ) {
Neural.neurons.get( {
'key': add_value
//, 'index': 'id'
, 'on_error': on_error
, 'on_success': function( context ) {
var get_value_2 = InDB.row.value( context );
if( 'undefined' !== typeof get_value_2 && null == get_value_2 ) {
console.log( 'test.neurons.delete(): passed' );
} else {
console.log( 'test.neurons.delete(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( get_value_2 );
}
}
} );
}, 'on_error': on_error } );
}, 'on_error': on_error } );
}, 'on_error': on_error } );
};
/* Clear */
test.neurons.clear = function( test_callback ) {
var on_error = function( get_context ) {
console.log( 'test.neurons.clear(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
Neural.neurons.clear( {
'on_success': function( value ) {
console.log( 'test.neurons.cursor.clear(): passed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
/* Cursor */
test.neurons.cursor.get = function( test_callback ) {
var on_error = function( get_context ) {
console.log( 'test.neurons.get(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
Neural.neurons.cursor.get( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
, 'limit': 20
, 'direction': InDB.cursor.direction.previous()
, 'on_success': function( value ) {
item_count++;
}, 'on_complete': function( value ) {
console.log( 'test.neurons.cursor.get(): passed' );
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
test.neurons.cursor.delete = function( test_callback ) {
test.neurons.data.add( 5 );
var on_error = function( get_context ) {
console.log( 'test.neurons.delete(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
var limit = 20;
Neural.neurons.cursor.get( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
//, 'limit': limit
, 'direction': InDB.cursor.direction.previous()
, 'on_success': function( value ) {
item_count++;
}, 'on_complete': function( value ) {
console.log("TOTAL", item_count );
var delete_count = 0;
Neural.neurons.cursor.delete( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
//, 'limit': limit
, 'direction': InDB.cursor.direction.next()
, 'on_success': function( value ) {
delete_count++;
}, 'on_complete': function( value ) {
var final_count = 0;
Neural.neurons.cursor.get( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id'
//, 'limit': limit
, 'direction': InDB.cursor.direction.previous()
, 'on_success': function( value ) {
if( 'undefined' !== typeof value && null !== value ) {
final_count++;
}
}, 'on_complete': function( value ) {
if( 0 == final_count ) {
console.log( 'test.neurons.cursor.delete(): passed' );
} else {
console.log( 'test.neurons.cursor.delete(): failed' );
}
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}
} );
}, 'on_error': on_error
} );
}, 'on_error': on_error
} );
};
test.neurons.cursor.update = function( test_callback ) {
test.neurons.data.add( 5 );
var on_error = function( get_context ) {
console.log( 'test.neurons.update(): failed' );
if( 'function' == typeof test_callback ) {
test_callback( get_context );
}
};
var item_count = 0;
var limit = 20;
var update_map = {};
Neural.neurons.cursor.update( {
'begin': 0
, 'left_inclusive': true
//, 'index': 'id' //xxx
, 'data': function( current_value ) {
if( 'undefined' !== typeof current_value && null !== current_value && 'undefined' !== typeof current_value.strength ) {
//var new_strength = ( 'undefined' !== typeof current_value.strength ) ? current_value.strength / 2 : 1;
var new_strength = "123456";
update_map[ current_value.id ] = new_strength;
console.log("UPDATED FROM/TO",current_value.strength,new_strength);
current_value.strength = new_strength;
}
return current_value;
}//, 'limit': limit
, 'direction': InDB.cursor.direction.next()
, 'on_success': function( value ) {
item_count++;
console.log('updated');
}, 'on_complete': function( value ) {
console.log("UPPITY",value);
if( limit > 0 && item_count <= limit ) {
console.log( 'test.neurons.cursor.update(): passed', update_map );
} else {
console.log( 'test.neurons.cursor.update(): failed. Counted ' + item_count + ' successes, expected ' + limit );
}
if( 'function' == typeof test_callback ) {
test_callback( value );
}
}, 'on_error': on_error
} );
};
$(document).ready(function() {
var Neural = Neural || {};
Neural.database_name = "Neural-017";
Neural.database_description = "Basic MLP neural network."
var browser_check = InDB.checkBrowser();
InDB.assert( -1 !== browser_check, 'incompatible browser' );
if ( 0 === browser_check ) {
InDB.fixBrowser();
}
var debug = false;
InDB.debug = debug;
Neural.debug = debug;
var on_loaded = function( context ) {
jQuery( document ).trigger( 'neuron_database_loaded', context );
}
InDB.trigger( 'InDB_do_database_load', { 'name': Neural.database_name, 'description': Neural.database_description, 'on_success': on_loaded } ) ;
});
jQuery( document ).bind( 'neuron_database_loaded', function( context ) {
console.log( "Neuron InDB is loaded", context );
var done = function( context ) {
console.log( "Tests complete." );
};
var get_test = function( context ) {
test.synapses.get( put_test );
};
var put_test = function( context ) {
test.synapses.put( update_test );
};
var update_test = function( context ) {
test.synapses.update( add_test );
};
var add_test = function( context ) {
test.synapses.add( delete_test );
};
var delete_test = function( context ) {
test.synapses.delete( cursor_delete_test );
};
var cursor_get_test = function( context ) {
test.synapses.cursor.get( cursor_update_test );
};
var cursor_delete_test = function( context ) {
test.synapses.cursor.delete( cursor_get_test );
};
var cursor_update_test = function( context ) {
test.synapses.cursor.update( clear_test );
};
var clear_test = function( context ) {
test.synapses.clear( cursor_get_test );
};
var node1 = Math.floor( Math.random()*100 );
var node2 = Math.floor( Math.random()*100 );
Neural.synapses.add( { 'data': { 'type': 'connection', 'from': node1, 'to': node2, 'strength': Math.random() }, 'on_success': function( result_value ) {
test_id = result_value;
get_test();
}, 'on_error': function( context ) {
console.log( 'FAILED to add synapses', context );
} } );
//test.synapses.getAttr();
//test.synapses.setAttr();
} );
</script>
<script type="text/javascript" src="http://github.com/editor/InDB/raw/master/indb.dev.js"></script>
<script type="text/javascript" src="https://github.com/editor/Neural/raw/master/neural.dev.js"></script>
</body>
</html>