<commit_before><commit_msg>create test for Maps that are configured with equal comparison (not identity as default)<commit_after><?php namespace GenericCollections\Tests;

use GenericCollections\Map;
use GenericCollections\Tests\Samples\Foo;

/*
 *
 * The map is fully tested, what we have to check here is
 * the methods that depends on this behavior, wich are:
 * - containsValue: in_array, isComparisonIdentical
 * - removeExact: isComparisonIdentical
 * - replaceExact: isComparisonIdentical
 *
 */
class MapEqualTest extends \PHPUnit_Framework_TestCase
{
    protected function newFooMapWithEqualComparisons()
    {
        return new Map('string', Foo::class, [], false);
    }

    public function testConstruct()
    {
        $map = $this->newFooMapWithEqualComparisons();

        $this->assertFalse($map->isComparisonIdentical(), 'The map non-identical says the opposite');
    }

    public function testContainsValue()
    {
        // the two objects are not the same but are equals
        $bar = new Foo('foobar');
        $foo = new Foo('foobar');
        $non = new Foo('non existent');
        $this->assertEquals($bar, $foo);
        $this->assertNotSame($bar, $foo);

        $map = $this->newFooMapWithEqualComparisons();
        $map->put('', $bar);
        $this->assertTrue($map->containsValue($bar));
        $this->assertTrue($map->containsValue($foo));
        $this->assertFalse($map->containsValue($non));
    }

    public function testRemoveExact()
    {
        $bar = new Foo('foobar');
        $foo = new Foo('foobar');
        $new = new Foo('New value');
        $map = $this->newFooMapWithEqualComparisons();

        // insert foobar => $bar
        $map->put('foobar', $bar);

        // replaceExact with a not-found value
        $this->assertFalse($map->replaceExact('foobar', new Foo('not found'), $new));

        // replaceExact <foobar, $foo> with $new
        // $bar and $foo are equals but not the same
        $this->assertTrue($map->replaceExact('foobar', $foo, $new));

        // the last operation must return $bar
        $inserted = $map->get('foobar');
        $this->assertSame($inserted, $new);
    }
}
{'fraction_non_alphanumeric': 0.1410730804810361, 'fraction_numerical': 0.0, 'mean_word_length': 3.0055555555555555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '2754299', 'n_tokens_mistral': 641, 'n_tokens_neox': 608, 'n_words': 163}