<commit_before><?php

/*
 * This file is part of HotSpots.
 *
 * (c) 2012 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace HotSpots\Colors;

/**
 * Test the grayscale colorer.
 *
 * @package HotSpots
 * @author  <NAME> <<EMAIL>>
 */
class ImageTest extends \HotSpots\AbtractColorsTest {
    
    public function setUp() {
        $this->Colors = new \HotSpots\Colors\Image('Classic');
    }
    
    public function tearDown() {
        unset($this->Colors);
    }

    public function testGetColor() {
        $this->image = imagecreatefrompng(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Images' . DIRECTORY_SEPARATOR . 'Classic.png');
        
        for ($channel = 0; $channel < 256; $channel++) {
            $color = $this->Colors->getColor($channel);
            
            $rgb = imagecolorat($this->image, 255 - $channel, 0);
            $colors = imagecolorsforindex($this->image, $rgb);
            
            $this->assertSame($colors['red'], $color->getRed());
            $this->assertSame($colors['green'], $color->getGreen());
            $this->assertSame($colors['blue'], $color->getBlue());
            $this->assertSame(0, $color->getAlpha());
        }
        
        imagedestroy($this->image);
    }

    public function testGetColorAlpha() {
        // Overwriting default image used
        unset($this->Colors);
        $this->Colors = new \HotSpots\Colors\Image('ClassicAlpha');
        $this->image = imagecreatefrompng(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Images' . DIRECTORY_SEPARATOR . 'ClassicAlpha.png');
        
        for ($channel = 0; $channel < 256; $channel++) {
            $color = $this->Colors->getColor($channel);
            
            $rgb = imagecolorat($this->image, 255 - $channel, 0);
            $colors = imagecolorsforindex($this->image, $rgb);
            
            $this->assertSame($colors['red'], $color->getRed());
            $this->assertSame($colors['green'], $color->getGreen());
            $this->assertSame($colors['blue'], $color->getBlue());
            $this->assertSame($colors['alpha'], $color->getAlpha());
        }
        
        imagedestroy($this->image);
    }

}<commit_msg>- Added test for nonexisting image file<commit_after><?php

/*
 * This file is part of HotSpots.
 *
 * (c) 2012 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace HotSpots\Colors;

/**
 * Test the grayscale colorer.
 *
 * @package HotSpots
 * @author  <NAME> <<EMAIL>>
 */
class ImageTest extends \HotSpots\AbtractColorsTest {
    
    public function setUp() {
        $this->Colors = new \HotSpots\Colors\Image('Classic');
    }
    
    public function tearDown() {
        unset($this->Colors);
    }

    public function testGetColor() {
        $this->image = imagecreatefrompng(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Images' . DIRECTORY_SEPARATOR . 'Classic.png');
        
        for ($channel = 0; $channel < 256; $channel++) {
            $color = $this->Colors->getColor($channel);
            
            $rgb = imagecolorat($this->image, 255 - $channel, 0);
            $colors = imagecolorsforindex($this->image, $rgb);
            
            $this->assertSame($colors['red'], $color->getRed());
            $this->assertSame($colors['green'], $color->getGreen());
            $this->assertSame($colors['blue'], $color->getBlue());
            $this->assertSame(0, $color->getAlpha());
        }
        
        imagedestroy($this->image);
    }

    public function testGetColorAlpha() {
        // Overwriting default image used
        unset($this->Colors);
        $this->Colors = new \HotSpots\Colors\Image('ClassicAlpha');
        $this->image = imagecreatefrompng(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Images' . DIRECTORY_SEPARATOR . 'ClassicAlpha.png');
        
        for ($channel = 0; $channel < 256; $channel++) {
            $color = $this->Colors->getColor($channel);
            
            $rgb = imagecolorat($this->image, 255 - $channel, 0);
            $colors = imagecolorsforindex($this->image, $rgb);
            
            $this->assertSame($colors['red'], $color->getRed());
            $this->assertSame($colors['green'], $color->getGreen());
            $this->assertSame($colors['blue'], $color->getBlue());
            $this->assertSame($colors['alpha'], $color->getAlpha());
        }
        
        imagedestroy($this->image);
    }
    
    
    /**
     * @expectedException \HotSpots\Exceptions\FileNotFoundException
     */
    public function testNonexistingImage() {
        // Overwriting default image used
        unset($this->Colors);
        $this->Colors = new \HotSpots\Colors\Image('NonexistingImageFile');
    }

}
{'fraction_non_alphanumeric': 0.15490430622009568, 'fraction_numerical': 0.008373205741626795, 'mean_word_length': 2.19147582697201, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 77, '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': '1194795', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1417, 'n_words': 279}