コード例 #1
0
    public void ParallelWorkTestPasses()
    {
        var workManager = new WorkManager();

        int result = 0;
        var work1  = SimpleWork.Create(() => result += 1);

        work1.Name = "simple work 1";
        var work2 = WaitSecondsWork.Create(2);

        work2.Name = "wait work";
        work2.ContinueWith((_) => result += 1);
        var work3 = SimpleWork.Create(() => result += 4);

        work3.Name = "simple work 2";

        var paralleWork = ParallelWork.Create(work1, work2, work3);

        Assert.That(paralleWork.RunningWorks.Count, Is.EqualTo(3));

        workManager.StartWork(paralleWork);
        workManager.Update(1, 1);
        Assert.That(result, Is.EqualTo(5));
        Assert.That(paralleWork.RunningWorks.Count, Is.EqualTo(1));
        Assert.That(paralleWork.CompleteWorks.Count, Is.EqualTo(2));

        workManager.Update(1, 1);
        Assert.That(result, Is.EqualTo(6));
    }
コード例 #2
0
    public void NormalWorkTestPasses()
    {
        var workManager = new WorkManager();

        Vector3 result = Vector3.zero;

        Work work = SimpleWork.Create(() => { result = Vector3.one; });

        workManager.StartWork(work);
        workManager.Update(1, 1);
        Assert.That(result, Is.EqualTo(Vector3.one));

        Vector3 result2 = Vector3.zero;

        work = WaitSecondsWork.Create(5);
        work.ContinueWith(_ => { result2 = Vector3.one; });
        workManager.StartWork(work);
        workManager.Update(1, 1);
        workManager.Update(1, 1);
        Assert.That((work as WaitSecondsWork).LeftSeconds, Is.EqualTo(3));
        Assert.That(work.WorkStatus == WorkStatus.Running);
        workManager.Update(1, 1);
        workManager.Update(1, 1);
        workManager.Update(1, 1);
        Assert.That(result2, Is.EqualTo(Vector3.one));

        result = Vector3.zero;
        work   = TimerWork.Create(0.5f, () => { result.x += 1; Debug.Log("Excute"); });
        workManager.StartWork(work);
        workManager.Update(0.5f, 0.5f);
        Assert.That(result.x, Is.EqualTo(1f));

        workManager.Update(1f, 1f);
        Assert.That(result.x, Is.EqualTo(3f));
    }
コード例 #3
0
    public void SequenceWorkTestPasses()
    {
        var workManager = new WorkManager();

        int result = 0;
        var work1  = SimpleWork.Create(() => result += 1);

        work1.Name = "simple work 1";
        var work2 = WaitSecondsWork.Create(2);

        work2.Name = "wait work";
        var work3 = SimpleWork.Create(() => result += 4);

        work3.Name = "simple work 2";
        var sequcenceWork = SequenceWork.Create(work1, work2, work3);

        workManager.StartWork(sequcenceWork);
        workManager.Update(1, 1);
        Assert.That(sequcenceWork.WorkStatus == WorkStatus.Complete, Is.False);
        Assert.That(result, Is.EqualTo(1));
        Assert.That(sequcenceWork.CurrentWorkIndex, Is.EqualTo(1));
        Assert.That(sequcenceWork.CurrentWork.Name, Is.EqualTo("wait work"));
        workManager.Update(2, 2);
        Assert.That(sequcenceWork.CurrentWorkIndex, Is.EqualTo(2));
        Assert.That(sequcenceWork.CurrentWork.Name, Is.EqualTo("simple work 2"));
        workManager.Update(1, 1);
        Assert.That(result, Is.EqualTo(5));
    }