% $Id: MakeStreamObjectTest.oz,v 1.2 2012/04/17 21:28:48 leavens Exp leavens $ \insert 'MakeStreamObject.oz' \insert 'Count.oz' \insert 'TestingNoStop.oz' declare {StartTesting 'MakeStreamObjectTest $Revision: 1.2 $'} SumObj = {MakeStreamObject proc {$ InVal SumSoFar ?OutVal ?NewSum} OutVal = InVal + SumSoFar NewSum = OutVal end} {Test {SumObj [1 2 3 4 5] 0} '==' [1 3 6 10 15]} AvgObj = {MakeStreamObject proc {$ InVal State ?OutVal ?NewState} Avg#Count = State NewCount = Count+1 NewAvg = (Avg*{IntToFloat Count} + InVal) / {IntToFloat NewCount} in OutVal = NewAvg NewState = NewAvg#NewCount end} {Test {AvgObj {Map {Count 10} IntToFloat} 0.0#0} '==' [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5]} {DoneTesting}