#!/bin/sh
################################################################
#
#  [# Edit, Date, User, Module #]
#
#  test-script for monopoly-template
#
here=`pwd`
if test $? -ne 0 ; then exit 1; fi
tmp=/tmp/$$
mkdir $tmp
if test $? -ne 0 ; then exit 1; fi
cd $tmp
if test $? -ne 0 ; then exit 1; fi

fail()
{
	echo FAILED 1>&2
	cd $here
	chmod u+w `find $tmp -type d -print`
	rm -rf $tmp
	exit 1
}

pass()
{
	cd $here
	chmod u+w `find $tmp -type d -print`
	rm -rf $tmp
	exit 0
}

trap 'fail' 1 2 3 15

###  Enter argument list for `monopoly' here ###
arglist='checkDeque'

/public/public/monopoly/diffpp > test.in 2>/dev/null << 'endOfSampleInput'

# Empty deque
CardPtrDeque
end

# Game data so that the pointers can point to something
Game

DeedIndex
end

CardIndex

 JailCard
  Key Get_out_of_jail_for_free end 
 end
 
 GotoJailCard
  Key Go_to_jail end 
 end
 
 RepairCard
  Key Street_repairs end 
  40 115
 end
 
 PayCard
  Key Pay_hospital end 
  100
 end
 
 PayCard
  Key Pay_school_tax end 
  150
 end
 
 PayCard
  Key Doctor_fee end 
  50
 end
 
 PayCard
  Key Pay_poor_tax end 
  15
 end
 
 PayCard
  Key From_Sale_of_stock end 
  -45
 end
 
 PayCard
  Key Your_building_and_loan_matures end 
  -150
 end
 
 PayCard
  Key Receive_for_services end 
  -25
 end
 
 PayCard
  Key You_inherit end 
  -100
 end
 
 PayCard
  Key Xmas_fund_matures end 
  -100
 end
 
 PayCard
  Key Life_insurance_matures end 
  -100
 end
 
 PayCard
  Key Second_prize_in_beauty_contest end 
  -10
 end
 
 PayCard
  Key Bank_error_in_your_favor end 
  -200
 end
 
 PayCard
  Key Income_tax_refund end 
  -20
 end
 
 PayAllCard
  Key Chairman_of_the_board end 
  50
 end
 
 PayAllCard
  Key Grand_opera_opening end 
  -50
 end
 
 AdvanceCard
  Key nearest_station end 
  Key StationDeed end
 end
 
 AdvanceCard
  Key nearest_utility end 
  Key UtilityDeed end
 end
 
 AdvanceToCard
  Key Advance_to_boardwalk end 
  Key Boardwalk end
 end
 
 AdvanceToCard
  Key Advance_to_St_Charles_Place end 
  Key St_Charles_Place end
 end
 
 AdvanceToCard
  Key Advance_to_go end
  Key GO end
 end
 
 AdvanceToCard
  Key Take_a_ride_on_the_Reading end 
  Key Reading end
 end
 
 AdvanceToCard
  Key Advance_to_Illinois_Ave end 
  Key Illinois_Ave end
 end
 
 AdvanceByCard
  Key Go_back_3_spaces end 
  -3
 end

end

Dice 3 4 end

end

# test Deque
CardPtrDeque
 CardPtr Key Pay_poor_tax end end
 CardPtr Key From_Sale_of_stock end end
 CardPtr Key Your_building_and_loan_matures end end
 CardPtr Key Receive_for_services end end
 CardPtr Key You_inherit end end
 CardPtr Key Xmas_fund_matures end end
end

endOfSampleInput
if test $? -ne 0 ; then fail; fi

/public/public/monopoly/diffpp > test.ok 2>/dev/null << 'endOfExpectedOutput'

# empty -> empty
CardPtrDeque  end

# there should be no error message here.

# check if read/write works
CardPtrDeque 
 CardPtr  Key  Pay_poor_tax  end  end 
 CardPtr  Key  From_Sale_of_stock  end  end 
 CardPtr  Key  Your_building_and_loan_matures  end  end 
 CardPtr  Key  Receive_for_services  end  end 
 CardPtr  Key  You_inherit  end  end 
 CardPtr  Key  Xmas_fund_matures  end  end 
end

# Check if pointer resolution works 
PayCard
 Key  Pay_poor_tax  end 
 15
end 
PayCard
 Key  From_Sale_of_stock  end 
 -45
end 
PayCard
 Key  Your_building_and_loan_matures  end 
 -150
end 
PayCard
 Key  Receive_for_services  end 
 -25
end 
PayCard
 Key  You_inherit  end 
 -100
end 
PayCard
 Key  Xmas_fund_matures  end 
 -100
end 

# Full deque after shifting
CardPtrDeque 
 CardPtr  Key  Pay_poor_tax  end  end 
 CardPtr  Key  From_Sale_of_stock  end  end 
 CardPtr  Key  Your_building_and_loan_matures  end  end 
 CardPtr  Key  Receive_for_services  end  end 
 CardPtr  Key  You_inherit  end  end 
 CardPtr  Key  Xmas_fund_matures  end  end 
end 

# empty deque after shifting
CardPtrDeque 
end 

endOfExpectedOutput
if test $? -ne 0 ; then fail; fi

$here/monopoly $arglist < test.in | /public/public/monopoly/diffpp > test.out 2>/dev/null
if test $? -ne 0 ; then fail; fi

diff test.ok test.out
if test $? -ne 0 ; then fail; fi

# it probably worked
pass
