fantasdic r323 - in trunk: . test



Author: mblondel
Date: Wed Aug 20 22:18:09 2008
New Revision: 323
URL: http://svn.gnome.org/viewvc/fantasdic?rev=323&view=rev

Log:
* test/test_utils.rb: Unit test for the utils.


Added:
   trunk/test/test_utils.rb
Modified:
   trunk/ChangeLog

Added: trunk/test/test_utils.rb
==============================================================================
--- (empty file)
+++ trunk/test/test_utils.rb	Wed Aug 20 22:18:09 2008
@@ -0,0 +1,120 @@
+# Fantasdic
+# Copyright (C) 2008 Mathieu Blondel
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+#Âwith this program; if not, write to the Free Software Foundation, Inc.,
+#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+test_dir = File.expand_path(File.dirname(__FILE__))
+top_dir = File.expand_path(File.join(test_dir, ".."))
+lib_dir = File.expand_path(File.join(top_dir, "lib"))
+$LOAD_PATH.unshift(lib_dir)
+
+require "test/unit"
+require "fantasdic"
+
+class TestUtils < Test::Unit::TestCase
+
+    def test_utf8_length
+        assert_equal("ããã".utf8_length, 3)
+    end
+
+    def test_utf8_slice
+        assert_equal("äääåä".utf8_slice(1..3), "ääå")
+    end
+
+    def test_utf8_reverse
+        assert_equal("ããã".utf8_reverse, "ããã")
+    end
+
+    def test_latin
+        assert_equal("English".latin?, true)
+        assert_equal("FranÃais".latin?, true)
+        assert_equal("ææè".latin?, false)
+        assert_equal("ÐÑÑÑÐÐÐ".latin?, false)
+    end
+
+    def test_hiragana        
+        assert_equal("ãããã".hiragana?, true)
+        assert_equal("ãããã".katakana?, false)
+        assert_equal("ãããã".kanji?, false)
+    end
+
+    def test_katakana        
+        assert_equal("ãããã".hiragana?, false)
+        assert_equal("ãããã".katakana?, true)
+        assert_equal("ãããã".kanji?, false)
+    end
+
+    def test_kanji      
+        assert_equal("æå".hiragana?, false)
+        assert_equal("æå".katakana?, false)
+        assert_equal("æå".kanji?, true)
+    end
+
+    def test_kana       
+        assert_equal("ãããã".kana?, true)
+        assert_equal("ãããã".kana?, true)
+        assert_equal("æå".kana?, false)
+    end
+
+    def test_japanese      
+        assert_equal("ãããã".japanese?, true)
+        assert_equal("ãããã".japanese?, true)
+        assert_equal("æå".japanese?, true)
+    end
+
+    def test_push_head(ele)
+        arr = []
+        arr.push_head(1)
+        arr.push_head(2)
+        assert_equal(arr, [2,1])
+    end
+
+    def test_push_tail(ele)
+        arr = []
+        arr.push_tail(1)
+        arr.push_tail(2)
+        assert_equal(arr, [1,2])
+    end
+
+    def test_pop_head
+        arr = [1,2]
+        ret = arr.pop_head
+        assert_equal(ret, 1)
+        assert_equal(arr, [2])
+        ret = arr.pop_head
+        assert_equal(ret, 2)
+        assert_equal(arr, [])
+        ret = arr.pop_head
+        assert_equal(ret, nil)
+    end
+
+    def test_pop_tail
+        arr = [1,2]
+        ret = arr.pop_tail
+        assert_equal(ret, 2)
+        assert_equal(arr, [1])
+        ret = arr.pop_tail
+        assert_equal(ret, 1)
+        assert_equal(arr, [])
+        ret = arr.pop_tail
+        assert_equal(ret, nil)
+    end
+
+    def test_which
+        assert_equal(File.which("true"), "/bin/true")
+        assert_equal(File.which("pgmthatdoesntexist"), nil)
+    end
+
+end



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]