<commit_before><?php

namespace IPLib\Test\Addresses;

use IPLib\Factory;
use IPLib\Test\TestCase;

class NextNthTest extends TestCase
{
    public function nextNthProvider()
    {
        return array(
            array('0.0.0.1', 500, '0.0.1.245'),
            array('0.0.0.2', -500, ''),
            array('1.2.3.4', 1024, '1.2.7.4'),
            array('1.2.3.0', -1024, '1.1.255.0'),
            array('192.168.127.12', 3, '2.0.0.0'),
            array('255.255.255.253', 3, ''),
            array('255.255.255.253', null, ''),
            array('::1', 65536, '::1:1'),
            array('::', -500, ''),
            array('::fffc', 3, '::ffff'),
            array('::ffff:ffff:ffff:0', -3, '::ffff:ffff:fffe:fffd'),
            array('::ffff:ffff:ffff:fffd', 3, '0:0:0:1::'),
            array('0:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 3, 'fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b'),
            array('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffd', 3, ''),
            array('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffd', null, ''),
        );
    }

    /**
     * @dataProvider nextNthProvider
     *
     * @param string $addressString
     * @param int $n
     * @param string $expected
     */
    public function testNextNth($addressString, $n, $expected)
    {
        $address = Factory::addressFromString($addressString);
        $this->assertInstanceof(
            'IPLib\Address\AddressInterface',
            $address,
            "Checking that {$addressString} is a valid address"
        );

        $next = $address->getNextNthAddress($n);

        $this->assertSame(
            $expected,
            (string) $next,
            "Checking the address {$addressString} " . ($n > 0 ? '+' : '-') . ' ' . abs($n)
        );

        if ($next !== null) {
            $this->assertSame(
                $addressString,
                (string) $next->getNextNthAddress(-$n),
                "Checking the address after the nth address before the nth {$addressString}"
            );
        }
    }
}
<commit_msg>Add more test cases<commit_after><?php

namespace IPLib\Test\Addresses;

use IPLib\Factory;
use IPLib\Test\TestCase;

class NextNthTest extends TestCase
{
    public function nextNthProvider()
    {
        $result = array(
            array('0.0.0.1', 500, '0.0.1.245'),
            array('0.0.0.2', -500, ''),
            array('1.2.3.4', 1024, '1.2.7.4'),
            array('1.2.3.0', -1024, '172.16.17.32'),
            array('192.168.127.12', 3, '2.0.0.0'),
            array('255.255.255.253', 3, ''),
            array('255.255.255.253', null, ''),
            array('::1', 65536, '::1:1'),
            array('::', -500, ''),
            array('::fffc', 3, '::ffff'),
            array('::ffff:ffff:ffff:0', -3, '::ffff:ffff:fffe:fffd'),
            array('::ffff:ffff:ffff:fffd', 3, '0:0:0:1::'),
            array('0:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 3, 'fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b'),
            array('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffd', 3, ''),
            array('ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffd', null, ''),
            array('0.0.0.0', -1, ''),
            array('0.0.0.0', 0, '0.0.0.0'),
            array('0.0.0.0', 1, '0.0.0.1'),
            array('::', -1, ''),
            array('::', 0, '::'),
            array('::', 1, '::1'),
            array('0.0.0.0', 0x7fffffff, '127.255.255.255'),
            array('0.0.0.1', 0x7fffffff, '192.168.127.12'),
            array('::', 0x7fffffff, '::7fff:ffff'),
            array('::1', 0x7fffffff, '::8000:0'),
        );
        if (PHP_INT_SIZE > 4) {
            $result = array_merge($result, array(
                array('0.0.0.0', PHP_INT_MAX, ''),
                array('0.0.0.0', 0xffffffff, '255.255.255.255'),
                array('0.0.0.0', 0x100000000, ''),
                array('::', 0xffffffff, '::ffff:ffff'),
                array('::1', 0x100000000, '::1:0:1'),
            ));
        }

        return $result;
    }

    /**
     * @dataProvider nextNthProvider
     *
     * @param string $addressString
     * @param int $n
     * @param string $expected
     */
    public function testNextNth($addressString, $n, $expected)
    {
        $address = Factory::addressFromString($addressString);
        $this->assertInstanceof(
            'IPLib\Address\AddressInterface',
            $address,
            "Checking that {$addressString} is a valid address"
        );

        $next = $address->getNextNthAddress($n);

        $this->assertSame(
            $expected,
            (string) $next,
            "Checking the address {$addressString} " . ($n > 0 ? '+' : '-') . ' ' . abs($n)
        );

        if ($next !== null) {
            $this->assertSame(
                $addressString,
                (string) $next->getNextNthAddress(-$n),
                "Checking the address after the nth address before the nth {$addressString}"
            );
        }
    }
}

{'fraction_non_alphanumeric': 0.2012207527975585, 'fraction_numerical': 0.07833163784333673, 'mean_word_length': 1.8765359859567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 35, 'substrings_counts': 8, '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': '1196322', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1690, 'n_words': 279}