--[[----------------------------------------------------------------------------

WFRatioTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2013 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--

local WFRatio = require 'WFRatio'

--==============================================================================

local WFRatioTest = {}

--------------------------------------------------------------------------------

function WFRatioTest.testReduce( test )
	
	local oneTenth = WFRatio.reduce { 248, 2480 }
	assert( oneTenth[ 1 ] == 1, "Reduce one tenth numerator" )
	assert( oneTenth[ 2 ] == 10, "Reduce one tenth denominator" )
	
	local negativeTwentyNineThreeHundredAndOneths = {
		-29 * 123407, 301 * 123407 }
	local reduced = WFRatio.reduce( negativeTwentyNineThreeHundredAndOneths )
	assert( reduced[ 1 ] == -29, "Reduce complex negative numerator" )
	assert( reduced[ 2 ] == 301, "Reduce complex negative denominator" )
	assert( #reduced == 2, "Two values in result array" )
	
end

--------------------------------------------------------------------------------

function WFRatioTest.testAdd( test )
	
	local oneTenth = { 1, 10 }
	local fiveThirds = { 5, 3 }
	local fiftyThreeThirieths = WFRatio.add( oneTenth, fiveThirds )
	
	assert( fiftyThreeThirieths[ 1 ] == 53, "oneTenth, fiveThirds numerator" )
	assert( fiftyThreeThirieths[ 2 ] == 30, "oneTenth, fiveThirds denominator" )
	
	fiftyThreeThirieths = WFRatio.add( fiveThirds, oneTenth )
	
	assert( fiftyThreeThirieths[ 1 ] == 53, "fiveThirds, oneTenth numerator" )
	assert( fiftyThreeThirieths[ 2 ] == 30, "fiveThirds, oneTenth denominator" )
	
	local sevenEigths = { 14, 16 }
	local nineEights = { 9, 8 }
	local two = WFRatio.add( sevenEigths, nineEights )
	
	assert( two[ 1 ] == 2, "sevenEigths, nineEights numerator" )
	assert( two[ 2 ] == 1, "sevenEigths, nineEights denominator" )
	
	two = WFRatio.add( nineEights, sevenEigths )
	
	assert( two[ 1 ] == 2, "nineEights, sevenEigths numerator" )
	assert( two[ 2 ] == 1, "nineEights, sevenEigths denominator" )

end

--------------------------------------------------------------------------------

function WFRatioTest.testMultiply( test )
	
	local oneTenth = { 1, 10 }
	local fiveThirds = { 5, 3 }
	local fiftyThreeThirieths = WFRatio.multiply( oneTenth, fiveThirds )
	
	assert( fiftyThreeThirieths[ 1 ] == 1, "oneTenth, fiveThirds numerator" )
	assert( fiftyThreeThirieths[ 2 ] == 6, "oneTenth, fiveThirds denominator" )
	
	fiftyThreeThirieths = WFRatio.multiply( fiveThirds, oneTenth )
	
	assert( fiftyThreeThirieths[ 1 ] == 1, "fiveThirds, oneTenth numerator" )
	assert( fiftyThreeThirieths[ 2 ] == 6, "fiveThirds, oneTenth denominator" )
	
	local sevenEigths = { 14, 16 }
	local nineEights = { 9, 8 }
	local two = WFRatio.multiply( sevenEigths, nineEights )
	
	assert( two[ 1 ] == 63, "sevenEigths, nineEights numerator" )
	assert( two[ 2 ] == 64, "sevenEigths, nineEights denominator" )
	
	two = WFRatio.multiply( nineEights, sevenEigths )
	
	assert( two[ 1 ] == 63, "nineEights, sevenEigths numerator" )
	assert( two[ 2 ] == 64, "nineEights, sevenEigths denominator" )

end

--------------------------------------------------------------------------------

function WFRatioTest.testCreateFromNumber( test )
	
	local oneThird = WFRatio.createFromNumber( 1 / 3 )
	assert( oneThird[ 1 ] == 1, "oneThird, numerator of one" )
	assert( oneThird[ 2 ] == 3, "oneThird, denominator of three" )
	
	local someEights = WFRatio.createFromNumber( 213.125 )
	assert( someEights[ 1 ] == 1705, "someEights, numerator of 1705" )
	assert( someEights[ 2 ] == 8, "someEights, denominator of 8" )
end

--==============================================================================

return WFRatioTest
