/*
 * Copyright (c) 2005 Absolutely Training Limited
 * 
 * Created on 01-Dec-2005
 */
/**
 * Translation of the Java TestUtil class into JavaScript
 * 
 * @author paulb
 */
function TestUtils() {}
    
TestUtils.getNumericChoices = function( romanNumeralChoices ) {
    var choices = romanNumeralChoices.split(/\s*,\s*/);
    var numericChoices = "";
    for (var i = 0; i < choices.length; i++) {
        numericChoices += TestUtils.getArabicForRomanNumeral(choices[i]);
        if (choices.length - 1 > i) {
            numericChoices = numericChoices + ",";
        }
    }
    return numericChoices;
};   
    
TestUtils.romanNumerals = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ];

TestUtils.getNumeral = function(i) {
	if ( i >= TestUtils.romanNumerals.length ) {
		throw new Error( "Cannot convert " + i + " into Roman numeral" );
	}
	return TestUtils.romanNumerals[i];
};
 
TestUtils.letters = localisedLetters; 

TestUtils.getLetter = function( i ) {
	return (i >= TestUtils.letters.length) ? i : TestUtils.letters[i];
};   
    
TestUtils.getArabicForRomanNumeral = function( romanNumeral ) {
	for( var i = 0; i < TestUtils.romanNumerals.length; i++ ) {
		if ( TestUtils.romanNumerals[i] == romanNumeral ) {
			return i + 1;
		}
	}
	
	throw new Error( "Cannot convert " + romanNumeral + " into Arabic" );
};

// from Java ConversionUtils.format
TestUtils.format = function( value ) {
    if (value == null) {
        return null;
    } else if (value instanceof Date) {
        return TestUtils.formatDate(value);
    } else {
        return value.toString();
    }
};

TestUtils.formatDate = function( date ) {
	return date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
};
    

TestUtils.contains = function( theArr, contained ) {
	for (var i = 0; i < theArr.length; i++)
	{
		if (theArr[i] == contained)
		{
			return true;
		}
	}
	return false;
};

TestUtils.isDefined = function(obj) {
	if (obj == "undefined" || obj == null)
	{
		return false;
	}
	return true;
};
