function test_suite = test_sph2cart2d
%TESTSPH2CART2D  One-line description here, please.
%
%   output = testSph2cart2d(input)
%
%   Example
%   testSph2cart2d
%
%   See also
%
%
% ------
% Author: David Legland
% e-mail: david.legland@grignon.inra.fr
% Created: 2011-06-29,    using Matlab 7.9.0.529 (R2009b)
% Copyright 2011 INRA - Cepia Software Platform.

test_suite = functiontests(localfunctions); 

function testNorthPole(testCase) %#ok<*DEFNU>

[x, y, z] = sph2cart2d(0, 0, 1);
testCase.assertEqual(0, x, 'AbsTol', .01);
testCase.assertEqual(0, y, 'AbsTol', .01);
testCase.assertEqual(1, z, 'AbsTol', .01);

function testPointOx(testCase)

[x, y, z] = sph2cart2d(90, 0, 10);
testCase.assertEqual(10, x, 'AbsTol', .01);
testCase.assertEqual(0, y, 'AbsTol', .01);
testCase.assertEqual(0, z, 'AbsTol', .01);

function testPointXY(testCase)

[x, y, z] = sph2cart2d(90, 45, 10*sqrt(2));
testCase.assertEqual(10, x, 'AbsTol', .01);
testCase.assertEqual(10, y, 'AbsTol', .01);
testCase.assertEqual(0, z, 'AbsTol', .01);



function testSingleInput(testCase)

[x, y, z] = sph2cart2d([0, 0, 1]);
testCase.assertEqual(0, x, 'AbsTol', .01);
testCase.assertEqual(0, y, 'AbsTol', .01);
testCase.assertEqual(1, z, 'AbsTol', .01);

function testSingleOutput(testCase)

res = sph2cart2d([0, 0, 1]);
testCase.assertEqual(0, res(1), 'AbsTol', .01);
testCase.assertEqual(0, res(2), 'AbsTol', .01);
testCase.assertEqual(1, res(3), 'AbsTol', .01);


function testManyPoints(testCase)

pts = [ ...
    0 0 10; ...
    90 0 10; ...
    90 90 10; ...
    90 130 10; ...
    60 230 20; ...
    120 250 2];

[theta, phi, rho] = cart2sph2d(pts);
pts2 = sph2cart2d(theta, phi, rho);

testCase.assertEqual(pts2, pts, 'AbsTol', .01);
