<commit_before><?php 

namespace Endurance\Metric;

use Endurance\HeartRateZone;
use Endurance\HeartRateZones;
use Endurance\Metric;
use Endurance\Point;

class TimeInHeartRateZoneMetricTest extends \PHPUnit_Framework_TestCase
{
    public $metric;

    public function setUp()
    {
        $this->metric = new TimeInHeartRateZoneMetric(array('zone' => 'Z1'));
        $this->zones = new HeartRateZones(array(
            new HeartRateZone('Z1', 'Active recovery', 120, 130)
        ));
    }

    public function testCalculateReturnsZeroWithNoPoints()
    {
        $this->assertEquals(0, $this->metric->calculate(array(), $this->zones, array()));
    }

    private function createPoints(array $heartRates)
    {
        $points = array();
        foreach ($heartRates as $index => $heartRate) {
            $point = new Point();
            $point->setTime(new \DateTime('+' . ($index * 5) . ' seconds'));
            $point->setHeartRate($heartRate);
            $points[] = $point;
        }

        return $points;
    }
}<commit_msg>Added tests for time in heart rate zone metric.<commit_after><?php 

namespace Endurance\Metric;

use Endurance\HeartRateZone;
use Endurance\HeartRateZones;
use Endurance\Metric;
use Endurance\Point;

class TimeInHeartRateZoneMetricTest extends \PHPUnit_Framework_TestCase
{
    public $metric;

    public function setUp()
    {
        $this->metric = new TimeInHeartRateZoneMetric(array('zone' => 'Z1'));
        $this->zones = new HeartRateZones(array(
            new HeartRateZone('Z1', 'Active recovery', 120, 130)
        ));
    }

    public function testCalculateReturnsZeroWithNoPoints()
    {
        $this->assertEquals(0, $this->metric->calculate(array(), $this->zones, array()));
    }

    public function testCalculateReturnsCorrectValue()
    {
        $this->assertEquals(55, $this->metric->calculate($this->createPoints(range(100,200)), $this->zones, array()));
    }

    private function createPoints(array $heartRates)
    {
        $points = array();
        foreach ($heartRates as $index => $heartRate) {
            $point = new Point();
            $point->setTime(new \DateTime('+' . ($index * 5) . ' seconds'));
            $point->setHeartRate($heartRate);
            $points[] = $point;
        }

        return $points;
    }
}
{'fraction_non_alphanumeric': 0.13882863340563992, 'fraction_numerical': 0.012147505422993492, 'mean_word_length': 2.888701517706577, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '7586709', 'n_tokens_mistral': 707, 'n_tokens_neox': 665, 'n_words': 143}