summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-26 20:03:54 +0100
committerhut <hut@lavabit.com>2010-01-26 20:03:54 +0100
commit5a087b1667813ad75f84d0cfbe38babd428bf5d6 (patch)
treec901efd0d637f23a8b14caf9a48989828a1f7253 /test
parent9bc5d95c8e9536cde4589f125857cb214523bbff (diff)
downloadranger-5a087b1667813ad75f84d0cfbe38babd428bf5d6.tar.gz
added unittest for flatten and unique
Diffstat (limited to 'test')
-rw-r--r--test/tc_ext.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/tc_ext.py b/test/tc_ext.py
new file mode 100644
index 00000000..f6d58033
--- /dev/null
+++ b/test/tc_ext.py
@@ -0,0 +1,69 @@
+if __name__ == '__main__': from __init__ import init; init()
+import unittest
+from collections import deque
+
+from ranger.ext.iter_tools import *
+
+class TestCases(unittest.TestCase):
+	def test_flatten(self):
+		def f(x):
+			return list(flatten(x))
+
+		self.assertEqual(
+			[1,2,3,4,5],
+			f([1,2,3,4,5]))
+		self.assertEqual(
+			[1,2,3,4,5],
+			f([1,[2,3],4,5]))
+		self.assertEqual(
+			[1,2,3,4,5],
+			f([[1,[2,3]],4,5]))
+		self.assertEqual(
+			[],
+			f([[[[]]]]))
+		self.assertEqual(
+			['a', 'b', 'fskldfjl'],
+			f(['a', ('b', 'fskldfjl')]))
+		self.assertEqual(
+			['a', 'b', 'fskldfjl'],
+			f(['a', deque(['b', 'fskldfjl'])]))
+		self.assertEqual(
+			set([3.5, 4.3, 5.2, 6.0]),
+			set(f([6.0, set((3.5, 4.3)), (5.2, )])))
+
+	def test_unique(self):
+		def u(x):
+			return list(unique(x))
+
+		self.assertEqual(
+			[1,2,3],
+			u([1,2,3]))
+		self.assertEqual(
+			[1,2,3],
+			u([1,2,3,2,1]))
+		self.assertEqual(
+			[1,2,3],
+			u([1,2,3,1,2,3,2,2,3,1,2,3,1,2,3,2,3,2,1]))
+		self.assertEqual(
+			[1,[2,3]],
+			u([1,[2,3],1,[2,3],[2,3],1,[2,3],1,[2,3],[2,3],1]))
+
+	def test_unique_keeps_type(self):
+		def u(x):
+			return unique(x)
+
+		self.assertEqual(
+			[1,2,3],
+			u([1,2,3,1]))
+		self.assertEqual(
+			(1,2,3),
+			u((1,2,3,1)))
+		self.assertEqual(
+			set((1,2,3)),
+			u(set((1,2,3,1))))
+		self.assertEqual(
+			deque((1,2,3)),
+			u(deque((1,2,3,1))))
+
+if __name__ == '__main__':
+	unittest.main()