コード例 #1
0
 /**
  * When one RunningStat instance is merged into another, the state of the
  * target RunningInstance should have the state that it would have had if
  * all the data had been accumulated by it alone.
  * @covers RunningStat::merge
  * @covers RunningStat::count
  */
 public function testRunningStatMerge()
 {
     $expected = new RunningStat();
     foreach ($this->points as $point) {
         $expected->push($point);
     }
     // Split the data into two sets
     $sets = array_chunk($this->points, floor(count($this->points) / 2));
     // Accumulate the first half into one RunningStat object
     $first = new RunningStat();
     foreach ($sets[0] as $point) {
         $first->push($point);
     }
     // Accumulate the second half into another RunningStat object
     $second = new RunningStat();
     foreach ($sets[1] as $point) {
         $second->push($point);
     }
     // Merge the second RunningStat object into the first
     $first->merge($second);
     $this->assertEquals(count($first), count($this->points));
     $this->assertEquals($first, $expected);
 }