mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-16 20:08:41 +00:00
test fixes
This commit is contained in:
parent
65264e33ae
commit
9d2b2e2e06
|
|
@ -49,15 +49,29 @@ final class ModelCF
|
|||
* the multiplication gives a score of how much the user may like that movie.
|
||||
* A segnificant amount of attributes are required to calculate a good match
|
||||
*
|
||||
* @param Matrix $users A mxa matrix where each "m" defines how much the user likes a certain attribute type and "a" defines different users
|
||||
* @param Matrix $items A bxm matrix where each "b" defines a item and "m" defines how much it belongs to a certain attribute type
|
||||
* @param array<int|string, array<int|float>> $users A mxa matrix where each "m" defines how much the user likes a certain attribute type and "a" defines different users
|
||||
* @param array<int|string, array<int|float>> $items A bxm matrix where each "b" defines a item and "m" defines how much it belongs to a certain attribute type
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function score(Matrix $users, Matrix $items) : array
|
||||
public static function score(array $users, array $items) : array
|
||||
{
|
||||
return $users->mult($items)->getMatrix();
|
||||
$matrix = [];
|
||||
|
||||
foreach ($users as $uid => $userrow) {
|
||||
foreach ($items as $iid => $itemrow) {
|
||||
$matrix[$uid][$iid] = 0.0;
|
||||
|
||||
foreach ($userrow as $user) {
|
||||
foreach ($itemrow as $item) {
|
||||
$matrix[$uid][$iid] += $user * $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $matrix;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
48
tests/Business/Recommendation/ModelCFTest.php
Normal file
48
tests/Business/Recommendation/ModelCFTest.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* Jingga
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\tests\Business\Recommendation;
|
||||
|
||||
use phpOMS\Business\Recommendation\ModelCF;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Business\Recommendation\ModelCFTest: Article affinity/correlation
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class ModelCFTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testScore() : void
|
||||
{
|
||||
self::assertEquals(
|
||||
[
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
],
|
||||
ModelCF::score(
|
||||
[
|
||||
[2, 3],
|
||||
[1, 4],
|
||||
[3, 3],
|
||||
],
|
||||
[
|
||||
[1, 4],
|
||||
[3, 2],
|
||||
[2, 2],
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -169,6 +169,12 @@ final class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_direct')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relations')->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_directp')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_relp')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relationsp')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_belongs_to_onep')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_owns_onep')->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user