Skip to content

Instantly share code, notes, and snippets.

@chrisdew
Last active December 19, 2015 15:09
Show Gist options
  • Save chrisdew/5974199 to your computer and use it in GitHub Desktop.
Save chrisdew/5974199 to your computer and use it in GitHub Desktop.
it('should provide a many to one relation', function() {
var ic = util.ManyToOne('imei', 'callsign');
ic.add('345123123123', 'ROMEO1');
ic.add('345456456456', 'DELTA2');
ic.add('345678678678', 'ROMEO1');
assert.equal(ic.imei_to_callsign['345123123123'], 'ROMEO1');
assert.equal(ic.imei_to_callsign['345456456456'], 'DELTA2');
assert.equal(ic.imei_to_callsign['345678678678'], 'ROMEO1');
assert.equal(ic.callsign_to_imeis['ROMEO1'], ['345123123123', '345678678678']);
assert.equal(ic.callsign_to_imeis['DELTA2'], ['345678678678']);
ic.remove_by_imei('345678678678');
ic.remove_by_callsign('DELTA1');
});
it('should provide a many to one relation', function() {
var imei_to_callsign = util.ManyToOne();
var callsign_to_imeis = imei_to_callsign.reverse();
imei_to_callsign.add('345123123123', 'ROMEO1');
imei_to_callsign.add('345456456456', 'DELTA2');
imei_to_callsign.add('345678678678', 'ROMEO1');
assert.equal(imei_to_callsign('345123123123'), 'ROMEO1');
assert.equal(imei_to_callsign('345456456456'), 'DELTA2');
assert.equal(imei_to_callsign('345678678678'), 'ROMEO1');
assert.equal(callsign_to_imeis('ROMEO1'), ['345123123123', '345678678678']);
assert.equal(callsign_to_imeis('DELTA2'), ['345678678678']);
imei_to_callsign.remove_one('345678678678');
imei_to_callsign.remove_many('DELTA1');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment