Skip to content

Commit

Permalink
A little more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Nov 1, 2022
1 parent 4f32fe4 commit 6669c5b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
12 changes: 6 additions & 6 deletions tests/QuadTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
*/
class QuadTemplateTest extends \PHPUnit\Framework\TestCase {

public function testToString(): void {
$this->assertIsString((string) new QuadTemplate(DF::namedNode('foo')));
}

public function testEquals(): void {
$bn = DF::blankNode();
$nn1 = DF::namedNode('foo');
Expand Down Expand Up @@ -89,8 +85,12 @@ public function testEquals(): void {
$this->assertEquals($expected, $i['qt']->equals($j), "equals() between QuadTemplate $n and Quad $m failed");
}
}

$this->assertEquals('[<foo> ]', (string)(new QuadTemplate($nn1)));

$this->assertFalse((new QuadTemplate($nn1))->equals(DF::namedNode('foo')));
}

public function testToString(): void {
$this->assertEquals('[<foo> <bar> <baz> ]', (string) (new QuadTemplate(DF::namedNode('foo'), DF::namedNode('bar'), DF::namedNode('baz'))));
}

public function testGetters(): void {
Expand Down
62 changes: 61 additions & 1 deletion tests/ValueTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public function testValueTemplate(): void {
DF::literal('foo bar'),
];

// find all terms not equal 'foo bar'
$tmplt = new ValueTemplate('foo bar', ValueTemplate::NOT_EQUALS);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([true, true, false], $result);

// find all terms containing 'ipsum'
$tmplt = new ValueTemplate('ipsum', ValueTemplate::CONTAINS);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
Expand All @@ -97,6 +102,31 @@ public function testValueTemplate(): void {
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([true, false, false], $result);

// find all terms starting with 'Lorem'
$tmplt = new ValueTemplate('Lorem', ValueTemplate::STARTS);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([true, false, false], $result);

// find all terms ending with 'amet'
$tmplt = new ValueTemplate('amet', ValueTemplate::ENDS);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([false, true, false], $result);

// find all terms with string value greater than 'foo bar'
$tmplt = new ValueTemplate('foo bar', ValueTemplate::GREATER);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([false, true, false], $result);

// find all terms with string value greater or equal than 'http'
$tmplt = new ValueTemplate('http', ValueTemplate::GREATER_EQUAL);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([false, true, false], $result);

// find all terms with string value lower or equal than 'foo bar'
$tmplt = new ValueTemplate('foo bar', ValueTemplate::LOWER_EQUAL);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([true, false, true], $result);

// find all named nodes containing 'ipsum'
$tmplt = new NamedNodeTemplate('ipsum', ValueTemplate::CONTAINS);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
Expand All @@ -120,6 +150,21 @@ public function testValueTemplate(): void {
$this->assertEquals([true, false, true], $result);
}

public function testWrongMatchMode(): void {
try {
new ValueTemplate('foo', 'bar');
$this->assertTrue(false);
} catch (TermTemplatesException $e) {
$this->assertEquals("Unknown match mode", $e->getMessage());
}
try {
new NumericTemplate(4, ValueTemplate::REGEX);
$this->assertTrue(false);
} catch (TermTemplatesException $e) {
$this->assertEquals("Unknown match mode", $e->getMessage());
}
}

public function testNumericTemplate(): void {
$literals = [
DF::literal('2'),
Expand All @@ -140,11 +185,26 @@ public function testNumericTemplate(): void {
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([false, false, false, true, false], $result);

// find terms with a value greate or equal than 3
// find terms with a value greater or equal than 3
$tmplt = new NumericTemplate(3, ValueTemplate::GREATER_EQUAL);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([false, true, false, false, false], $result);

// find terms with a value greater or equal than 2
$tmplt = new NumericTemplate(2, ValueTemplate::GREATER);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([false, true, false, false, false], $result);

// find terms with a value lower or equal than 2
$tmplt = new NumericTemplate(2, ValueTemplate::LOWER_EQUAL);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([true, false, false, true, false], $result);

// find terms with a value lower than 3
$tmplt = new NumericTemplate(3, ValueTemplate::LOWER);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
$this->assertEquals([true, false, false, true, false], $result);

// find all terms with numeric values
$tmplt = new NumericTemplate(matchMode: ValueTemplate::ANY);
$result = array_map(fn($x) => $tmplt->equals($x), $literals);
Expand Down

0 comments on commit 6669c5b

Please sign in to comment.