<?php

# Copyright (c) 2002-2005 Cunningham & Cunningham, Inc.
# Released under the terms of the GNU General Public License version 2 or later.
#
# PHP5 translation by Luis A. Floreani <luis.floreani@gmail.com>

require_once 'Testing/FIT/Fixture/Primitive.php';

class Math_ArithmeticFixture extends Testing_FIT_Fixture_Primitive 
{
	private $x = 0;
	private $y = 0;
    
   /**
    * iterate through rows but skip the first one
    * 
    * @param Parse $rows
    * @see doRow()
    * @return boolean true on success
    */
    public function doRows( Testing_FIT_Node $node ) 
    {
        // start at second - the first simply contains the fixture with parameter
        $node->next();
        return parent::doRows( $node );
    }   

   /**
    * process a single cell
    *
    * As this is a primitve fixture, it knows exactly what to do
    * 
    * @param object $cell A parse object 
    * @return boolean true on success
    */
    public function doCell( Testing_FIT_Node $node  ) {
    
        switch( $node->key() ) {
            case 0:
                $this->x = intval( $node->cData );
                break;
            case 1:
                $this->y = intval( $node->cData );
                break;
            case 2:
                $this->_checkCell( $node, $this->x + $this->y ); break;
                break;
            case 3:
                $this->_checkCell( $node, $this->x - $this->y ); break;
                break;
            case 4:
                $this->_checkCell( $node, $this->x * $this->y ); break;
                break;
            case 5:
                if( $this->y == 0 ) {
                    throw new Exception( 'ArithmeticException: / by zero' );
                }               
                $this->_checkCell( $node, $this->x / $this->y ); break;
                break;
                
            default:
                break;
        }
        
        return true;
    }

}

?>
