Support for raw chinese_whispers
This commit introduces chinese_whispers method without any "helpers" on PHP side. Users needs to take care of everything (building edges from 128D face chip vector, for example), but this is exposed for people that need low-level call and want to calculate distances and build edges in PHP directly.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
Basic tests for chinese_whispers
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(dlib_chinese_whispers([[0,0]])); // Case with only one node
|
||||
var_dump(dlib_chinese_whispers([[0,0], [1,1]])); // Case with two separate nodes
|
||||
var_dump(dlib_chinese_whispers([[0,0], [0,1], [1,0], [1,1]])); // Case with two connected nodes
|
||||
?>
|
||||
--EXPECT--
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(1)
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(0)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
Edge given in edges array for chinese_whispers functions is associative array
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
dlib_chinese_whispers([[0,0], ["foo"=>0, "bar"=>1]]);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
--EXPECT--
|
||||
string(46) "Edge should be numeric array with integer keys"
|
||||
@@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
Edge elements given in edges array for chinese_whispers functions are not of long type
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
dlib_chinese_whispers([[0,0], [1, "foo"]]);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
try {
|
||||
dlib_chinese_whispers([[0,0], [1, 1.1]]);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
--EXPECT--
|
||||
string(47) "Both elements in each edge must be of long type"
|
||||
string(47) "Both elements in each edge must be of long type"
|
||||
@@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
Edge given in edges array for chinese_whispers functions is not having all values to be arrays with 2 elements
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
dlib_chinese_whispers([[0,0], [1]]);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
try {
|
||||
dlib_chinese_whispers([[0,0], [1,1,1]]);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
string(42) "Edges need to contain exactly two elements"
|
||||
string(42) "Edges need to contain exactly two elements"
|
||||
@@ -0,0 +1,21 @@
|
||||
--TEST--
|
||||
Edge given in edges array is not array for chinese_whispers functions
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
dlib_chinese_whispers([[0,0], "foo"]);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
dlib_chinese_whispers([[0,0], 1]);
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
string(67) "Each edge provided in array needs to be numeric array of 2 elements"
|
||||
string(67) "Each edge provided in array needs to be numeric array of 2 elements"
|
||||
@@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
Args given to chinese_whispers functions is not correct
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("pdlib")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
try {
|
||||
dlib_chinese_whispers("foo");
|
||||
} catch (Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Warning: dlib_chinese_whispers() expects parameter 1 to be array, string given in /home/branko/pdlib/tests/chinese_whispers_wrong_arg_type_error.php on line 3
|
||||
string(46) "Unable to parse edges in dlib_chinese_whispers"
|
||||
Reference in New Issue
Block a user