def test_multiple_step(self):
   q = self.q_matrix2
   
   q = QMatrix(q)
   r = RMatrix(q)
   
   
   a = self.configuration["stateA"]
   b = self.configuration["stateB"]
   time = self.configuration["time"]
   length = self.configuration["length"]
   random = self.random_numbers
   
   u = Uniformization(q, r, a, b, time, length)
   
   u.debugRandom(random)
   path = u.next() 
   
   # Combatibilty with 1-based Matlab indexing
   path += 1 
   
   desired_path = self.path
   
   #print path, len(path)
   #print desired_path, len(path)
   
   self.assertTrue(np.array_equal(desired_path, path), msg="Using the same random numbers, Q- and R-Matrices the Uniformization has generated a different path, relative to Matlab/Octave.");
  def test_single_step(self):
    """
    Test the innermost code of the loop.
    """
    
    q = self.q_matrix
    
    q = QMatrix(q)
    r = RMatrix(q)
    
    a = 0
    b = 4
    time = 200.
    
    # Iteration number, or step number i
    i = 1
    
    random0 = 0.63983762; 
    
    length = 5;
    
    path = np.zeros(length,  dtype=np.int);
    path[0] = a
    
    desired_v0 = np.array([ 0.00000, 0.58333, 0.41667, 0.00000, 5.83333])
    desired_v0 = desired_v0.reshape((1,5))
    desired_v1 = np.array([ 3.49097,1.41898,0.93171,0.30785,0.34522])
    desired_v2 = 3.2297

    desired_v3 = np.array([ 0.00000, 0.25629, 0.12020, 0.00000,0.62352]).reshape((1,5))
    desired_cdf = np.array([ 0.00000, 0.25629,0.37649,0.37649,1.00000])
                            
    desired_step =  5

    u = Uniformization(q, r, a, b, time, length)
    
    v0, v1, v2, v3, cdf, step = u.doNext(r.matrix, path, i,  u.xb, length, random0)
    
    # Combatibilty with 1-based Matlab indexing
    step += 1

    assert_allclose(v0, desired_v0, rtol=1e-4, atol=0, err_msg="Error in the v0 computation")
    
    assert_allclose(v1, desired_v1, rtol=1e-4, atol=0, err_msg="Error in the v1 computation")
    
    assert_allclose(v2, desired_v2, rtol=1e-4, atol=0, err_msg="Error in the v2 computation")
    
    assert_allclose(v3, desired_v3, rtol=1e-4, atol=0, err_msg="Error in the v3 (final) part of the computation")
    
    assert_allclose(cdf, desired_cdf, rtol=1e-4, atol=0, err_msg="CDF not equal")
    
    self.assertEqual(desired_step, step, msg="Wrong step sampled by the path generator (is %d, should be %d)" % (step, desired_step));