Permalink
Browse files

dos2unix

  • Loading branch information...
1 parent 4e58966 commit 36efbdbf48841d5705b4a8bf37fcb2e9c66a1a77 @quix committed Aug 9, 2009
Showing with 114 additions and 114 deletions.
  1. +28 −28 lib/quix/ext/1.8.6/enumerable.rb
  2. +39 −39 lib/quix/ext/enumerable.rb
  3. +47 −47 test/enumerable_test.rb
@@ -1,28 +1,28 @@
-
-require 'enumerator'
-
-module Enumerable
- def drop_while
- result = []
- found = false
- each { |elem|
- if found or not yield(elem)
- result << elem
- found = true
- end
- }
- result
- end
-
- def take_while
- result = []
- each { |elem|
- if yield(elem)
- result << elem
- else
- return result
- end
- }
- result
- end
-end
+
+require 'enumerator'
+
+module Enumerable
+ def drop_while
+ result = []
+ found = false
+ each { |elem|
+ if found or not yield(elem)
+ result << elem
+ found = true
+ end
+ }
+ result
+ end
+
+ def take_while
+ result = []
+ each { |elem|
+ if yield(elem)
+ result << elem
+ else
+ return result
+ end
+ }
+ result
+ end
+end
View
@@ -1,39 +1,39 @@
-
-require 'quix/ext/1.8.6/enumerable.rb' if RUBY_VERSION <= "1.8.6"
-
-module Enumerable
- def group_consecutive_by
- result = Array.new
- last_value = nil
- each_with_index { |elem, index|
- value = yield(elem)
- if index == 0 or value != last_value
- result << Array.new
- end
- result.last << elem
- last_value = value
- }
- result
- end
-
- def build_hash
- inject(Hash.new) { |acc, elem|
- result = yield(elem)
- acc.merge!(result[0] => result[1])
- }
- end
-
- def take_until(&block)
- take_while { |elem|
- not block.call(elem)
- }
- end
-
- def drop_until(&block)
- drop_while { |elem|
- not block.call(elem)
- }
- end
-
- alias_method :each_consecutive, :each_cons
-end
+
+require 'quix/ext/1.8.6/enumerable.rb' if RUBY_VERSION <= "1.8.6"
+
+module Enumerable
+ def group_consecutive_by
+ result = Array.new
+ last_value = nil
+ each_with_index { |elem, index|
+ value = yield(elem)
+ if index == 0 or value != last_value
+ result << Array.new
+ end
+ result.last << elem
+ last_value = value
+ }
+ result
+ end
+
+ def build_hash
+ inject(Hash.new) { |acc, elem|
+ result = yield(elem)
+ acc.merge!(result[0] => result[1])
+ }
+ end
+
+ def take_until(&block)
+ take_while { |elem|
+ not block.call(elem)
+ }
+ end
+
+ def drop_until(&block)
+ drop_while { |elem|
+ not block.call(elem)
+ }
+ end
+
+ alias_method :each_consecutive, :each_cons
+end
View
@@ -1,47 +1,47 @@
-require File.dirname(__FILE__) + "/common"
-
-require "quix/ext/enumerable"
-
-class TestEnumerable < Test::Unit::TestCase
- def test_group_consecutive_by
- data = [3, 4, 5, 5, 6, 5, 5, 4, 4, 4, 4, 3, 3, 2, 1]
- grouped = [[3], [4], [5, 5], [6], [5, 5], [4, 4, 4, 4], [3, 3], [2], [1]]
-
- assert_equal grouped, data.group_consecutive_by { |t| t }
-
- data = (1..6).to_a
- assert_equal data.map { |t| [t] }, data.group_consecutive_by { |t| t }
-
- expected = [[1, 2, 3], [4, 5, 6]]
- computed = data.group_consecutive_by { |t| t <= 3 }
- assert_equal expected, computed
- end
-
- def test_build_hash
- data = 3..5
- expected = {
- 3 => 9,
- 4 => 16,
- 5 => 25,
- }
- computed = data.build_hash { |elem|
- [elem, elem**2]
- }
- assert_equal expected, computed
- end
-
- def test_take_drop
- data = 3..8
-
- assert_equal [6, 7, 8], data.drop_while { |t| t < 6 }
- assert_equal [6, 7, 8], data.drop_until { |t| t == 6 }
-
- assert_equal [3, 4, 5], data.take_while { |t| t < 6 }
- assert_equal [3, 4, 5], data.take_until { |t| t == 6 }
-
- assert_equal data.to_a, data.take_while { true }
- assert_equal data.to_a, data.take_until { |t| t == 999 }
- assert_equal [], data.drop_while { true }
- assert_equal [], data.drop_until { |t| t == 999 }
- end
-end
+require File.dirname(__FILE__) + "/common"
+
+require "quix/ext/enumerable"
+
+class TestEnumerable < Test::Unit::TestCase
+ def test_group_consecutive_by
+ data = [3, 4, 5, 5, 6, 5, 5, 4, 4, 4, 4, 3, 3, 2, 1]
+ grouped = [[3], [4], [5, 5], [6], [5, 5], [4, 4, 4, 4], [3, 3], [2], [1]]
+
+ assert_equal grouped, data.group_consecutive_by { |t| t }
+
+ data = (1..6).to_a
+ assert_equal data.map { |t| [t] }, data.group_consecutive_by { |t| t }
+
+ expected = [[1, 2, 3], [4, 5, 6]]
+ computed = data.group_consecutive_by { |t| t <= 3 }
+ assert_equal expected, computed
+ end
+
+ def test_build_hash
+ data = 3..5
+ expected = {
+ 3 => 9,
+ 4 => 16,
+ 5 => 25,
+ }
+ computed = data.build_hash { |elem|
+ [elem, elem**2]
+ }
+ assert_equal expected, computed
+ end
+
+ def test_take_drop
+ data = 3..8
+
+ assert_equal [6, 7, 8], data.drop_while { |t| t < 6 }
+ assert_equal [6, 7, 8], data.drop_until { |t| t == 6 }
+
+ assert_equal [3, 4, 5], data.take_while { |t| t < 6 }
+ assert_equal [3, 4, 5], data.take_until { |t| t == 6 }
+
+ assert_equal data.to_a, data.take_while { true }
+ assert_equal data.to_a, data.take_until { |t| t == 999 }
+ assert_equal [], data.drop_while { true }
+ assert_equal [], data.drop_until { |t| t == 999 }
+ end
+end

0 comments on commit 36efbdb

Please sign in to comment.