<commit_before><?php declare(strict_types=1);

namespace Symplify\Statie\Tests\Metrics;

use PHPUnit\Framework\TestCase;
use Symplify\Statie\Configuration\Configuration;
use Symplify\Statie\Configuration\Parser\NeonParser;
use Symplify\Statie\Metrics\PostSimilarityAnalyzer;
use Symplify\Statie\Metrics\SimilarPostsResolver;
use Symplify\Statie\Renderable\File\PostFile;
use Symplify\Statie\Tests\Helper\PostFactory;
use TextAnalysis\Comparisons\CosineSimilarityComparison;
use Tracy\Debugger;

final class SimilarPostsResolverTest extends TestCase
{
    /**
     * @var PostFile
     */
    private $mainPost;

    /**
     * @var PostFactory
     */
    private $postFactory;

    /**
     * @var SimilarPostsResolver
     */
    private $similarPostsResolver;

    protected function setUp(): void
    {
        $this->postFactory = new PostFactory;

        $this->similarPostsResolver = $this->createSimilarPostsResolver();

        $this->mainPost = $this->postFactory->createPostFromFilePath(
            __DIR__ . '/../PostsSource/2017-01-05-another-related-post.md'
        );
    }

    public function testOrder(): void
    {
        $similarPosts = $this->similarPostsResolver->resolveForPostWithLimit($this->mainPost, 3);

        $mostSimilarPost = $similarPosts[0];
        $this->assertSame('Statie 4: How to Create The Simplest Blog', $mostSimilarPost['title']);
        $this->assertNotSame($this->mainPost['title'], $mostSimilarPost['title']);
    }

    public function testPerformance(): void
    {
        Debugger::timer();
        $this->similarPostsResolver->resolveForPostWithLimit($this->mainPost, 3);
        $durationInMs = 1000 * Debugger::timer();

        $this->assertLessThan(2, $durationInMs);
    }

    public function testLimit(): void
    {
        $this->assertCount(3, $this->similarPostsResolver->resolveForPostWithLimit($this->mainPost, 3));
        $this->assertCount(1, $this->similarPostsResolver->resolveForPostWithLimit($this->mainPost, 1));
    }

    private function createSimilarPostsResolver(): SimilarPostsResolver
    {
        $configuration = new Configuration(new NeonParser);
        $configuration->addGlobalVarialbe('posts', $this->getAllPosts());
<commit_msg>[Statie] drop performance test, relative<commit_after><?php declare(strict_types=1);

namespace Symplify\Statie\Tests\Metrics;

use PHPUnit\Framework\TestCase;
use Symplify\Statie\Configuration\Configuration;
use Symplify\Statie\Configuration\Parser\NeonParser;
use Symplify\Statie\Metrics\PostSimilarityAnalyzer;
use Symplify\Statie\Metrics\SimilarPostsResolver;
use Symplify\Statie\Renderable\File\PostFile;
use Symplify\Statie\Tests\Helper\PostFactory;
use TextAnalysis\Comparisons\CosineSimilarityComparison;
use Tracy\Debugger;

final class SimilarPostsResolverTest extends TestCase
{
    /**
     * @var PostFile
     */
    private $mainPost;

    /**
     * @var PostFactory
     */
    private $postFactory;

    /**
     * @var SimilarPostsResolver
     */
    private $similarPostsResolver;

    protected function setUp(): void
    {
        $this->postFactory = new PostFactory;

        $this->similarPostsResolver = $this->createSimilarPostsResolver();

        $this->mainPost = $this->postFactory->createPostFromFilePath(
            __DIR__ . '/../PostsSource/2017-01-05-another-related-post.md'
        );
    }

    public function testOrder(): void
    {
        $similarPosts = $this->similarPostsResolver->resolveForPostWithLimit($this->mainPost, 3);

        $mostSimilarPost = $similarPosts[0];
        $this->assertSame('Statie 4: How to Create The Simplest Blog', $mostSimilarPost['title']);
        $this->assertNotSame($this->mainPost['title'], $mostSimilarPost['title']);
    }

    public function testLimit(): void
    {
        $this->assertCount(3, $this->similarPostsResolver->resolveForPostWithLimit($this->mainPost, 3));
        $this->assertCount(1, $this->similarPostsResolver->resolveForPostWithLimit($this->mainPost, 1));
    }

    private function createSimilarPostsResolver(): SimilarPostsResolver
    {
        $configuration = new Configuration(new NeonParser);
        $configuration->addGlobalVarialbe('posts', $this->getAllPosts());

{'fraction_non_alphanumeric': 0.12633832976445397, 'fraction_numerical': 0.009041161075422317, 'mean_word_length': 3.782707622298066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1215291', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1166, 'n_words': 200}