This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
covers 'facets/comparable/bound'
|
||||
|
||||
test_case Comparable do
|
||||
|
||||
method :bound do
|
||||
|
||||
test 'single argument' do
|
||||
3.bound(4).assert == 4
|
||||
4.bound(4).assert == 4
|
||||
5.bound(4).assert == 5
|
||||
end
|
||||
|
||||
test 'two arguments' do
|
||||
4.bound(3,5).assert == 4
|
||||
3.bound(3,5).assert == 3
|
||||
5.bound(3,5).assert == 5
|
||||
2.bound(3,5).assert == 3
|
||||
6.bound(3,5).assert == 5
|
||||
end
|
||||
|
||||
test 'on strings' do
|
||||
'd'.bound('c','e').assert == 'd'
|
||||
'c'.bound('c','e').assert == 'c'
|
||||
'e'.bound('c','e').assert == 'e'
|
||||
'b'.bound('c','e').assert == 'c'
|
||||
'f'.bound('c','e').assert == 'e'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
covers 'facets/comparable/cap'
|
||||
|
||||
test_case Comparable do
|
||||
|
||||
method :cap do
|
||||
|
||||
test do
|
||||
3.cap(4).assert == 3
|
||||
4.cap(4).assert == 4
|
||||
5.cap(4).assert == 4
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
method :at_most do
|
||||
|
||||
test do
|
||||
3.at_most(4).assert == 3
|
||||
4.at_most(4).assert == 4
|
||||
5.at_most(4).assert == 4
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
method :at_least do
|
||||
|
||||
test do
|
||||
3.at_least(4).assert == 4
|
||||
4.at_least(4).assert == 4
|
||||
5.at_least(4).assert == 5
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
covers 'facets/comparable/clip'
|
||||
|
||||
test_case Comparable do
|
||||
|
||||
method :clip do
|
||||
|
||||
test 'single argument' do
|
||||
3.clip(4).assert == 4
|
||||
4.clip(4).assert == 4
|
||||
5.clip(4).assert == 5
|
||||
end
|
||||
|
||||
test 'two arguments' do
|
||||
4.clip(3,5).assert == 4
|
||||
3.clip(3,5).assert == 3
|
||||
5.clip(3,5).assert == 5
|
||||
2.clip(3,5).assert == 3
|
||||
6.clip(3,5).assert == 5
|
||||
end
|
||||
|
||||
test 'on strings' do
|
||||
'd'.clip('c','e').assert == 'd'
|
||||
'c'.clip('c','e').assert == 'c'
|
||||
'e'.clip('c','e').assert == 'e'
|
||||
'b'.clip('c','e').assert == 'c'
|
||||
'f'.clip('c','e').assert == 'e'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
covers 'facets/comparable/cmp'
|
||||
|
||||
test_case Comparable do
|
||||
|
||||
method :cmp do
|
||||
|
||||
test 'on integers' do
|
||||
3.cmp(4).assert == -1
|
||||
3.cmp(3).assert == 0
|
||||
3.cmp(2).assert == 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
covers 'facets/comparable/op_get'
|
||||
|
||||
test_case Comparable do
|
||||
|
||||
class_method :[] do
|
||||
|
||||
test do
|
||||
c = Class.new do
|
||||
include Comparable[:a,:b]
|
||||
|
||||
attr_accessor :a, :b
|
||||
|
||||
def initialize(a,b)
|
||||
@a=a; @b=b
|
||||
end
|
||||
end
|
||||
|
||||
a = [c.new(10,20),c.new(10,30)]
|
||||
a.sort.assert == a
|
||||
|
||||
a = [c.new(10,30),c.new(10,20)]
|
||||
a.sort.assert == a.reverse
|
||||
|
||||
a = [c.new(10,10),c.new(20,10)]
|
||||
a.sort.assert == a
|
||||
|
||||
a = [c.new(20,10),c.new(10,10)]
|
||||
a.sort.assert == a.reverse
|
||||
|
||||
a = [c.new(10,30),c.new(20,10)]
|
||||
a.sort.assert == a
|
||||
end
|
||||
|
||||
=begin
|
||||
class_method :sort_on do
|
||||
test do
|
||||
c = Class.new
|
||||
c.class_eval {
|
||||
def initialize(a,b)
|
||||
@a=a; @b=b
|
||||
end
|
||||
sort_on :a,:b
|
||||
}
|
||||
a = [c.new(10,20),c.new(10,30)]
|
||||
assert_equal( a, a.sort )
|
||||
a = [c.new(10,30),c.new(10,20)]
|
||||
assert_equal( a.reverse, a.sort )
|
||||
a = [c.new(10,10),c.new(20,10)]
|
||||
assert_equal( a, a.sort )
|
||||
a = [c.new(20,10),c.new(10,10)]
|
||||
assert_equal( a.reverse, a.sort )
|
||||
a = [c.new(10,30),c.new(20,10)]
|
||||
assert_equal( a, a.sort )
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user