local N=import("\046\047\119\097\105\116")local c=import("\046\046\047\084\097\115\107\083\099\104\101\100\117\108\101\114")describe("\116\097\115\107\070\117\110\099\116\105\111\110\115\046\119\097\105\116",function()it("\115\104\111\117\108\100 \114\101\115\099\104\101\100\117\108\101 \115\101\108\102 \097\102\116\101\114 \116\104\101 \115\112\101\099\105\102\105\101\100 \116\105\109\101",function()local y=c.new()local Q=N(y)local B=0 local e=0 local x=0 local f=coroutine.create(function()B=B+1 Q(1)e=e+1 Q(1)x=x+1 end)assert(coroutine.resume(f))assert.equal(B,1)assert.equal(e,0)assert.equal(coroutine.status(f),"\115\117\115\112\101\110\100\101\100")y:step(1)assert.equal(B,1)assert.equal(e,1)assert.equal(x,0)assert.equal(coroutine.status(f),"\115\117\115\112\101\110\100\101\100")y:step(1)assert.equal(B,1)assert.equal(e,1)assert.equal(x,1)assert.equal(coroutine.status(f),"\100\101\097\100")end)it("\115\104\111\117\108\100 \114\101\115\099\104\101\100\117\108\101 \097\102\116\101\114 \097 \115\109\097\108\108 \097\109\111\117\110\116 \111\102 \116\105\109\101 \119\105\116\104 \110\111 \097\114\103\117\109\101\110\116",function()local y=c.new()local Q=N(y)local B=0 local e=0 local x=coroutine.create(function()B=B+1 Q()e=e+1 end)assert(coroutine.resume(x))assert.equal(B,1)assert.equal(e,0)assert.equal(coroutine.status(x),"\115\117\115\112\101\110\100\101\100")y:step(.2)assert.equal(B,1)assert.equal(e,1)assert.equal(coroutine.status(x),"\100\101\097\100")end)it("\115\104\111\117\108\100 \114\101\115\099\104\101\100\117\108\101 \097\102\116\101\114 \097 \115\109\097\108\108 \097\109\111\117\110\116 \111\102 \116\105\109\101 \119\105\116\104 \097 \122\101\114\111 \097\114\103\117\109\101\110\116",function()local y=c.new()local Q=N(y)local B=0 local e=0 local x=coroutine.create(function()B=B+1 Q(0)e=e+1 end)assert(coroutine.resume(x))assert.equal(B,1)assert.equal(e,0)assert.equal(coroutine.status(x),"\115\117\115\112\101\110\100\101\100")y:step(.2)assert.equal(B,1)assert.equal(e,1)assert.equal(coroutine.status(x),"\100\101\097\100")end)end)
local createWait = import("./wait")
local TaskScheduler = import("../TaskScheduler")

describe("taskFunctions.wait", function()
	it("should reschedule self after the specified time", function()
		local scheduler = TaskScheduler.new()
		local wait = createWait(scheduler)

		local aCount = 0
		local bCount = 0
		local cCount = 0

		local co = coroutine.create(function()
			aCount = aCount + 1
			wait(1)

			bCount = bCount + 1
			wait(1)

			cCount = cCount + 1
		end)

		assert(coroutine.resume(co))

		assert.equal(aCount, 1)
		assert.equal(bCount, 0)
		assert.equal(coroutine.status(co), "suspended")

		scheduler:step(1)

		assert.equal(aCount, 1)
		assert.equal(bCount, 1)
		assert.equal(cCount, 0)
		assert.equal(coroutine.status(co), "suspended")

		scheduler:step(1)

		assert.equal(aCount, 1)
		assert.equal(bCount, 1)
		assert.equal(cCount, 1)
		assert.equal(coroutine.status(co), "dead")
	end)

	it("should reschedule after a small amount of time with no argument", function()
		local scheduler = TaskScheduler.new()
		local wait = createWait(scheduler)

		local aCount = 0
		local bCount = 0

		local co = coroutine.create(function()
			aCount = aCount + 1
			wait()
			bCount = bCount + 1
		end)

		assert(coroutine.resume(co))

		assert.equal(aCount, 1)
		assert.equal(bCount, 0)
		assert.equal(coroutine.status(co), "suspended")

		scheduler:step(0.2)

		assert.equal(aCount, 1)
		assert.equal(bCount, 1)
		assert.equal(coroutine.status(co), "dead")
	end)

	it("should reschedule after a small amount of time with a zero argument", function()
		local scheduler = TaskScheduler.new()
		local wait = createWait(scheduler)

		local aCount = 0
		local bCount = 0

		local co = coroutine.create(function()
			aCount = aCount + 1
			wait(0)
			bCount = bCount + 1
		end)

		assert(coroutine.resume(co))

		assert.equal(aCount, 1)
		assert.equal(bCount, 0)
		assert.equal(coroutine.status(co), "suspended")

		scheduler:step(0.2)

		assert.equal(aCount, 1)
		assert.equal(bCount, 1)
		assert.equal(coroutine.status(co), "dead")
	end)
end)