コード例 #1
0
ファイル: HeapTester.cs プロジェクト: xeratol/Grid2D-LOS
    private bool TestKeyValueTypeIncrease()
    {
        var testHeap = new Heap <KeyValElement <int, float> >();

        for (var i = 0; i < 5; ++i)
        {
            var val        = Random.Range(0.0f, 10.0f);
            var newElement = new KeyValElement <int, float>(i, val);

            testHeap.Push(newElement);
        }

        for (var i = 0; i < 5; ++i)
        {
            var val        = Random.Range(11.0f, 20.0f);
            var newElement = new KeyValElement <int, float>(i, val);

            testHeap.IncreaseKey(newElement);
        }

        var lastElement = new KeyValElement <int, float>(0, -1.0f);

        while (!testHeap.IsEmpty)
        {
            var element = testHeap.Pop();
            if (lastElement.Equals(element) &&
                lastElement.CompareTo(element) >= 0)
            {
                return(false);
            }
            lastElement = element;
        }

        return(true);
    }
コード例 #2
0
ファイル: HeapTester.cs プロジェクト: xeratol/Grid2D-LOS
    private bool TestKeyValueTypeUpdate()
    {
        var testHeap = new Heap <KeyValElement <int, float> >();

        for (var i = 0; i < 5; ++i)
        {
            var val        = Random.Range(0.0f, 10.0f);
            var newElement = new KeyValElement <int, float>(i, val);

            testHeap.Push(newElement);
        }

        for (var i = 0; i < 5; ++i)
        {
            var newElement = new KeyValElement <int, float>(i, 0);
            var oldElement = testHeap.Find(newElement);
            newElement.Val = oldElement.Val;

            while (oldElement.Val.CompareTo(newElement.Val) == 0)
            {
                var val = Random.Range(-100.0f, 100.0f);
                newElement.Val = val;
            }

            testHeap.UpdateKey(newElement);
        }

        var lastElement = new KeyValElement <int, float>(0, -200.0f);

        while (!testHeap.IsEmpty)
        {
            var element = testHeap.Pop();
            if (lastElement.Equals(element) &&
                lastElement.CompareTo(element) >= 0)
            {
                return(false);
            }
            lastElement = element;
        }

        return(true);
    }