Created
July 20, 2011 12:00
-
-
Save trevershick/1094834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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