What is it, naokirin?

テスト駆動開発の練習(13) -C#&NUnitでクイックソート-

大分、間が空いてしまいました・・・今回はC#クイックソートを実装します。


class QuickSort
{
    private int[] sortedArray;

    public QuickSort(int[] array)
    {
        sortedArray = new int[array.Length];

        for(int i = 0; i < array.Length; i++)
            sortedArray[i] = array[i];

        sort(0, sortedArray.Length - 1);
    }

    private void sort(int left, int right)
    {
        int i, j;
        if (left < right)
        {
            int s = sortedArray[(int)((left + right) / 2)];
            i = left - 1;
            j = right + 1;
            while (true)
            {
                while (sortedArray[++i] < s) ;
                while (sortedArray[--j] > s) ;
                if (i >= j) break;
                int t = sortedArray[i];
                sortedArray[i] = sortedArray[j];
                sortedArray[j] = t;
            }
            sort(left, i - 1);
            sort(j + 1, right);
        }
    }

    public int[] getSortedArray()
    {
        return sortedArray;
    }
}

QuickSort.cs

using NUnit.Framework;

[TestFixture]
class QuickSortTest
{
    private void testQuickSort(int[] actual, int[] expected)
    {
        QuickSort qSort = new QuickSort(actual);
        Assert.That(qSort.getSortedArray(), Is.EqualTo(expected));
    }

    [Test]
    public void getSortedArrayTest()
    {
        testQuickSort(new int[] { 9, 5, 7, 8, 3, 4, 6, 1, 2, 10 }, 
            new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });

        testQuickSort(new int[] { 200, 100, 500, 150, 300, 500 },
            new int[] { 100, 150, 200, 300, 500, 500 });

    }
}

QuickSortTest.cs

一昨日でしょうか、「やりましょう! > OCaml」と言われたので、「やりましょう!」と(ノリで)言ってしまいまして、昨日はほぼ全てOCamlの環境構築に費やしてしまいました。
実際そんなに時間のかかるものではないはずだったのですが、つまづいてしまいまして・・・。
教えてもらいつつ、なんとか環境をそろえられました。
来週、おそらくOCamlの本が届くと思うので、その辺りからはOCamlのTDD練習も始めたいと思います。