Skip to content

Instantly share code, notes, and snippets.

@trevershick
Created July 20, 2011 12:00
Show Gist options
  • Save trevershick/1094834 to your computer and use it in GitHub Desktop.
Save trevershick/1094834 to your computer and use it in GitHub Desktop.
EquipmentIdRange = jook.eqp.EquipmentIdRange;
EquipmentParser = jook.eqp.EquipmentParser;
ExampleTest = TestCase("ExampleTest");
ExampleTest.prototype.testAdjacent_T1 = function() {
var r1 = new EquipmentIdRange("BNSF",1,10);
var r2 = new EquipmentIdRange("BNSF",11,12);
var r3 = new EquipmentIdRange("BNSF", 20,21);
assertTrue(r1.isAdjacentTo(r2));
assertTrue(r2.isAdjacentTo(r1));
assertFalse(r3.isAdjacentTo(r1));
assertFalse(r1.isAdjacentTo(r3));
};
jook.eqp.EquipmentIdRange = function(init,from,to) {
this.initial = init.toUpperCase();
this.from = parseInt(from, 10);
this.to = parseInt(to, 10);
if (this.from > this.to) {
var x = this.to;
this.to = this.from;
this.from = x;
}
this.isAdjacentTo = function(rng) {
if (this.initial !== rng.initial) {
return false;
}
return ((this.from-1) === rng.to) || ((this.to+1) === rng.from);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment