Source

gpalign-cpp / src / tests / testScripts.hpp

Full commit
//--------------------------------------------------------------------------//
// testScripts.hpp
// Lars Yencken <lars.yencken@gmail.com>
// vim: ts=4 sw=4 sts=4 expandtab:
// Tue Oct  9 10:41:08 EST 2007
//--------------------------------------------------------------------------//

#ifndef TESTSCRIPTS_HPP
#define TESTSCRIPTS_HPP

#include <cppunit/TestFixture.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestAssert.h>
#include <cppunit/TestSuite.h>
#include "../scripts.hpp"

//--------------------------------------------------------------------------//

class ScriptsTest : public CppUnit::TestFixture
{
private:

public:
    void setUp()
    {
    }

    void testSmallKana()
    {
        CPPUNIT_ASSERT(isSmallKana(L'ゅ'));
        CPPUNIT_ASSERT(isSmallKana(L'ょ'));
        CPPUNIT_ASSERT(isSmallKana(L'ゃ'));
        CPPUNIT_ASSERT(isSmallKana(L'っ'));
        CPPUNIT_ASSERT(!isSmallKana(L'や'));
        CPPUNIT_ASSERT(!isSmallKana(L'ゆ'));
        CPPUNIT_ASSERT(!isSmallKana(L'よ'));
    }

    void testToHiragana()
    {
        CPPUNIT_ASSERT(toHiragana(L'っ') == L'っ');
        CPPUNIT_ASSERT(toHiragana(L'ッ') == L'っ');
        CPPUNIT_ASSERT(toHiragana(wstring(L"コーヒー")) ==
                wstring(L"こーひー"));
        CPPUNIT_ASSERT(toHiragana(wstring(L"東京")) == wstring(L"東京"));
    }

    void testScriptType()
    {
        CPPUNIT_ASSERT(scriptType(L'亜') == Script__Kanji);
        CPPUNIT_ASSERT(scriptType(L'あ') == Script__Hiragana);
        CPPUNIT_ASSERT(scriptType(L'ア') == Script__Katakana);
        CPPUNIT_ASSERT(scriptType(L'A') == Script__Ascii);

        // Long vowel marker
        CPPUNIT_ASSERT(scriptType(L'ー') == Script__Katakana);
        
        // Kanji for "one"
        CPPUNIT_ASSERT(scriptType(L'一') == Script__Kanji);
    }

    void testScriptBoundaries()
    {
        vector<ScriptSeg> results;
        scriptBoundaries(wstring(L"此の節"), results);
        CPPUNIT_ASSERT(results.size() == 3);
        CPPUNIT_ASSERT(results[0].second == wstring(L"此"));
        CPPUNIT_ASSERT(results[1].second == wstring(L"の"));
        CPPUNIT_ASSERT(results[2].second == wstring(L"節"));
    }

    void tearDown()
    {
    }

    static CppUnit::Test* suite()
    {
        CppUnit::TestSuite* s = new CppUnit::TestSuite("ScriptsTest");
        s->addTest(new CppUnit::TestCaller<ScriptsTest>("testSmallKana",
                    &ScriptsTest::testSmallKana));
        s->addTest(new CppUnit::TestCaller<ScriptsTest>("testToHiragana",
                    &ScriptsTest::testToHiragana));
        s->addTest(new CppUnit::TestCaller<ScriptsTest>("testScriptType",
                    &ScriptsTest::testScriptType));
        s->addTest(new CppUnit::TestCaller<ScriptsTest>("testScriptBoundaries",
                    &ScriptsTest::testScriptBoundaries));

        return s;
    }
};

#endif