Skip to content

Commit ac09cc0

Browse files
committed
Expand classmark range for new library
1 parent b5d3a94 commit ac09cc0

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PHP library for helping developers with classmarks
1111
Add this to your composer require:
1212
* "unikent/lib-php-classmark": "dev-master"
1313

14-
Then get lists like so:
14+
Then compare classmarks like so:
1515
```
1616
$parser = new \unikent\Classmark\Classmark();
1717

src/Classmark.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function parse($classmark)
8282
}
8383

8484
// Strip off the first set of uppercase alpha characters.
85-
if (preg_match('/(^[A-Z]{1,2})/', $classmark, $matches)) {
85+
if (preg_match('/(^[A-Z]{1,3})/', $classmark, $matches)) {
8686
$subject = $matches[1];
8787
$classmark = trim(substr($classmark, strlen($subject)));
8888
}
@@ -127,7 +127,7 @@ public function get_subdivision()
127127

128128
/**
129129
* Comparison.
130-
* Returns 0 if we match, 1 is we are greater than $classmark or -1 if we are less than $classmark.
130+
* Returns 0 if we match, 1 if we are greater than $classmark or -1 if we are less than $classmark.
131131
*/
132132
public function compareTo($classmark)
133133
{
@@ -143,7 +143,7 @@ public function compareTo($classmark)
143143
$otherpieces = explode('.', trim($classmark->subdivision, '.\t\n\r'));
144144

145145
foreach ($pieces as $i => $piece) {
146-
if ($piece == $otherpieces[$i] || !isset($otherpieces[$i])) {
146+
if (!isset($otherpieces[$i]) || $piece == $otherpieces[$i]) {
147147
continue;
148148
}
149149

tests/RangeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,30 @@ public function testAdvancedDottedSubdivision() {
9494
$classmarka = new \unikent\Classmark\Classmark("K", "600.Z9");
9595
$classmarkb = new \unikent\Classmark\Classmark("K", "3240.4");
9696
$range = new \unikent\Classmark\Range($classmarka, $classmarkb);
97+
$this->assertTrue($range->contains(new \unikent\Classmark\Classmark("K", "601")));
98+
$this->assertFalse($range->contains(new \unikent\Classmark\Classmark("K", "600")));
9799

98100
$classmarka = new \unikent\Classmark\Classmark("BS", "476.R45");
99101
$classmarkb = new \unikent\Classmark\Classmark("BS", "2560");
100102
$range = new \unikent\Classmark\Range($classmarka, $classmarkb);
103+
$this->assertTrue($range->contains(new \unikent\Classmark\Classmark("BS", "479")));
104+
$this->assertFalse($range->contains(new \unikent\Classmark\Classmark("BS", "475")));
101105

102106
$classmarka = new \unikent\Classmark\Classmark("BR", "1.S3");
103107
$classmarkb = new \unikent\Classmark\Classmark("BR", ".481.R3");
104108
$range = new \unikent\Classmark\Range($classmarka, $classmarkb);
109+
$this->assertTrue($range->contains(new \unikent\Classmark\Classmark("BR", "2")));
110+
$this->assertFalse($range->contains(new \unikent\Classmark\Classmark("BR", "3987")));
105111

106112
$classmarka = new \unikent\Classmark\Classmark("PN", "513");
107113
$classmarkb = new \unikent\Classmark\Classmark("PN", "1993.5.G7.H552");
108114
$range = new \unikent\Classmark\Range($classmarka, $classmarkb);
115+
$this->assertTrue($range->contains(new \unikent\Classmark\Classmark("PN", "514")));
116+
$this->assertTrue($range->contains(new \unikent\Classmark\Classmark("PN", "1993")));
117+
$this->assertFalse($range->contains(new \unikent\Classmark\Classmark("PN", "512")));
118+
$this->assertFalse($range->contains(new \unikent\Classmark\Classmark("PN", "1994")));
119+
120+
$range = new \unikent\Classmark\Range(\unikent\Classmark\Classmark::parse("KJE 6467"), \unikent\Classmark\Classmark::parse("KN 112.6"));
121+
$this->assertFalse($range->contains(\unikent\Classmark\Classmark::parse('KJE946')));
109122
}
110123
}

0 commit comments

Comments
 (0)