<commit_before><?php
/*
 * This file is part of PHPASN1 written by <NAME>.
 * 
 * Copyright © <NAME>, Berlin 2012
 * 
 * PHPASN1 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PHPASN1 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHPASN1.  If not, see <http://www.gnu.org/licenses/>.
 */
 
namespace PHPASN1;

require_once(dirname(__FILE__) . '/../../PHPASN1TestCase.class.php');

class ASN_IntegerTest extends PHPASN1TestCase {
    
    public function testGetType() {
        $object = new ASN_Integer(123);
        $this->assertEquals(Identifier::INTEGER, $object->getType());
    }
    
    public function testContent() {
        $object = new ASN_Integer(1234);
        $this->assertEquals(1234, $object->getContent());
        
        $object = new ASN_Integer(-1234);
        $this->assertEquals(-1234, $object->getContent());
        
        $object = new ASN_Integer(0);
        $this->assertEquals(0, $object->getContent());
        
        // test with maximum integer value
        $object = new ASN_Integer(PHP_INT_MAX);
        $this->assertEquals(PHP_INT_MAX, $object->getContent());
        
        // test with minimum integer value by negating the max value
        $object = new ASN_Integer(~PHP_INT_MAX);
        $this->assertEquals(~PHP_INT_MAX, $object->getContent());
    }    
    
    
    public function testGetObjectLength() {
        $positiveObj = new ASN_Integer(0);
        $expectedSize = 2 + 1;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());

        $positiveObj = new ASN_Integer( 127);
        $negativeObj = new ASN_Integer(-127);
        $expectedSize = 2 + 1;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 128);
        $negativeObj = new ASN_Integer(-128);
        $expectedSize = 2 + 2;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x7FFF);
        $negativeObj = new ASN_Integer(-0x7FFF);
        $expectedSize = 2 + 2;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x8000);
        $negativeObj = new ASN_Integer(-0x8000);
        $expectedSize = 2 + 3;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x7FFFFF);
        $negativeObj = new ASN_Integer(-0x7FFFFF);
        $expectedSize = 2 + 3;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x800000);
        $negativeObj = new ASN_Integer(-0x800000);
        $expectedSize = 2 + 4;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x7FFFFFFF);
        $negativeObj = new ASN_Integer(-0x7FFFFFFF);
        $expectedSize = 2 + 4;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
    }
        
    public function testGetBinary() {
        $expectedType = chr(Identifier::INTEGER);
        $expectedLength = chr(0x01);
       
        $object = new ASN_Integer(0);
        $expectedContent = chr(0x00);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(127);
        $expectedContent = chr(0x7F);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(-127);
        $expectedContent = chr(0x81);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(200);
        $expectedLength = chr(0x02);
        $expectedContent = chr(0x00);
        $expectedContent .= chr(0xC8);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(7420);
        $expectedLength   = chr(0x02);
        $expectedContent  = chr(0x1C);
        $expectedContent .= chr(0xFC);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(-1891004);
        $expectedLength   = chr(0x03);
        $expectedContent  = chr(0xE3);
        $expectedContent .= chr(0x25);
        $expectedContent .= chr(0x44);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
    }<commit_msg>Just another test for a negative integer<commit_after><?php
/*
 * This file is part of PHPASN1 written by <NAME>.
 * 
 * Copyright © <NAME>, Berlin 2012
 * 
 * PHPASN1 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PHPASN1 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHPASN1.  If not, see <http://www.gnu.org/licenses/>.
 */
 
namespace PHPASN1;

require_once(dirname(__FILE__) . '/../../PHPASN1TestCase.class.php');

class ASN_IntegerTest extends PHPASN1TestCase {
    
    public function testGetType() {
        $object = new ASN_Integer(123);
        $this->assertEquals(Identifier::INTEGER, $object->getType());
    }
    
    public function testContent() {
        $object = new ASN_Integer(1234);
        $this->assertEquals(1234, $object->getContent());
        
        $object = new ASN_Integer(-1234);
        $this->assertEquals(-1234, $object->getContent());
        
        $object = new ASN_Integer(0);
        $this->assertEquals(0, $object->getContent());
        
        // test with maximum integer value
        $object = new ASN_Integer(PHP_INT_MAX);
        $this->assertEquals(PHP_INT_MAX, $object->getContent());
        
        // test with minimum integer value by negating the max value
        $object = new ASN_Integer(~PHP_INT_MAX);
        $this->assertEquals(~PHP_INT_MAX, $object->getContent());
    }    
    
    
    public function testGetObjectLength() {
        $positiveObj = new ASN_Integer(0);
        $expectedSize = 2 + 1;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());

        $positiveObj = new ASN_Integer( 127);
        $negativeObj = new ASN_Integer(-127);
        $expectedSize = 2 + 1;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 128);
        $negativeObj = new ASN_Integer(-128);
        $expectedSize = 2 + 2;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x7FFF);
        $negativeObj = new ASN_Integer(-0x7FFF);
        $expectedSize = 2 + 2;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x8000);
        $negativeObj = new ASN_Integer(-0x8000);
        $expectedSize = 2 + 3;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x7FFFFF);
        $negativeObj = new ASN_Integer(-0x7FFFFF);
        $expectedSize = 2 + 3;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x800000);
        $negativeObj = new ASN_Integer(-0x800000);
        $expectedSize = 2 + 4;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
        
        $positiveObj = new ASN_Integer( 0x7FFFFFFF);
        $negativeObj = new ASN_Integer(-0x7FFFFFFF);
        $expectedSize = 2 + 4;
        $this->assertEquals($expectedSize, $positiveObj->getObjectLength());
        $this->assertEquals($expectedSize, $negativeObj->getObjectLength());
    }
        
    public function testGetBinary() {
        $expectedType = chr(Identifier::INTEGER);
        $expectedLength = chr(0x01);
       
        $object = new ASN_Integer(0);
        $expectedContent = chr(0x00);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(127);
        $expectedContent = chr(0x7F);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(-127);
        $expectedContent = chr(0x81);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(200);
        $expectedLength = chr(0x02);
        $expectedContent = chr(0x00);
        $expectedContent .= chr(0xC8);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(-546);
        $expectedLength = chr(0x02);
        $expectedContent = chr(0xFD);
        $expectedContent .= chr(0xDE);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(7420);
        $expectedLength   = chr(0x02);
        $expectedContent  = chr(0x1C);
        $expectedContent .= chr(0xFC);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
        
        $object = new ASN_Integer(-1891004);
        $expectedLength   = chr(0x03);
        $expectedContent  = chr(0xE3);
        $expectedContent .= chr(0x25);
        $expectedContent .= chr(0x44);
        $this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
    }
{'fraction_non_alphanumeric': 0.1305375590964805, 'fraction_numerical': 0.027841008579933463, 'mean_word_length': 2.9403242497412903, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '963698', 'n_tokens_mistral': 3373, 'n_tokens_neox': 3152, 'n_words': 701}