maset 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/categorizeYamlValues +21 -0
- data/lib/maset.rb +0 -0
- data/lib/maset/categorize.rb +56 -0
- data/lib/maset/mapping.rb +122 -0
- data/test/helper.rb +17 -0
- data/test/test_categorize.rb +26 -0
- data/test/test_mapping.rb +205 -0
- metadata +128 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", "~> 1.1.3"
|
11
|
+
gem "jeweler", "~> 1.8.3"
|
12
|
+
gem "simplecov", ">= 0"
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 ippei94da
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= maset
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to maset
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 ippei94da. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "maset"
|
18
|
+
gem.homepage = "http://github.com/ippei94da/maset"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Math Set: Mathematical library of set theory}
|
21
|
+
gem.description = %Q{This gem provides few libraries, which are Mapping and Categorize.}
|
22
|
+
gem.email = "ippei94da@gmail.com"
|
23
|
+
gem.authors = ["ippei94da"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
#require 'rcov/rcovtask'
|
36
|
+
#Rcov::RcovTask.new do |test|
|
37
|
+
# test.libs << 'test'
|
38
|
+
# test.pattern = 'test/**/test_*.rb'
|
39
|
+
# test.verbose = true
|
40
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
#end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "maset #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
#USAGE: categorizeYamlValues.rb yaml_file
|
4
|
+
#siteNames.rb などでサイト名を配列で表現した YAML から、
|
5
|
+
#同じものをカテゴライズするのに使える。
|
6
|
+
|
7
|
+
require "yaml"
|
8
|
+
require "rubygems"
|
9
|
+
gem "maset"
|
10
|
+
require "maset/categorize.rb"
|
11
|
+
|
12
|
+
cell_and_conf = YAML.load( ARGF ).to_a
|
13
|
+
|
14
|
+
cell_and_conf.extend( Categorize )
|
15
|
+
categories = cell_and_conf.categorize{ |a, b| a[1] == b[1] }
|
16
|
+
categories.each do |category|
|
17
|
+
puts category[0][1].join(",")
|
18
|
+
category.each do |i|
|
19
|
+
puts " " + i[0]
|
20
|
+
end
|
21
|
+
end
|
data/lib/maset.rb
ADDED
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#要素を分類する。
|
2
|
+
#
|
3
|
+
#USAGE:
|
4
|
+
# 基本的に、対象の Array に extend して使う。e.g.,
|
5
|
+
# arr = [ -2, -1, 0, 1, 2, 1]
|
6
|
+
# arr.extend( Categorize )
|
7
|
+
# arr.categorize #=> [ [-2], [-1], [0], [1, 1], [2] ],
|
8
|
+
# arr.categorize{ |a, b| a.abs == b.abs } #=> [ [-2, 2], [-1, 1, 1], [0] ]
|
9
|
+
#
|
10
|
+
#対象とするオブジェクトは、
|
11
|
+
#「AとBが等価 かつ BとCが等価」と判定されたなら「AとCが等価」であることを前提としている。
|
12
|
+
#たとえば、Float の近似判定のような場合にはうまくいかない可能性がある。
|
13
|
+
# a = 0.01
|
14
|
+
# b = 0.03
|
15
|
+
# c = 0.05
|
16
|
+
# a.equal_in_delta?( b, 0.03 ) => true
|
17
|
+
# b.equal_in_delta?( c, 0.03 ) => true
|
18
|
+
# c.equal_in_delta?( a, 0.03 ) => false
|
19
|
+
#
|
20
|
+
#生の配列で持っておいて必要なときに条件を渡されれば分類されたデータを返すという方式を採用。
|
21
|
+
# 条件設定が柔軟で、オブジェクトの状態がシンプルで開発し易い。
|
22
|
+
# データが追加( initialize, push ) されるたびに適切なところに入れるという方式は、( push が速いかも? )不適と判断した。
|
23
|
+
#
|
24
|
+
module Categorize
|
25
|
+
#分類する。
|
26
|
+
#等価判定が真になるもの同士で Array にまとめ、それらをまとめた 2重配列として返す。
|
27
|
+
#ブロックを渡された場合には、ブロックの条件で等価判定する。
|
28
|
+
#返り値の2重配列は、各カテゴリ内で元データの最も先頭に近かったデータの順番でソートされたものになる。
|
29
|
+
#e.g., [ 0, 1, 2, 1] ならば、[ [0], [1, 1], [2] ] のようになる。
|
30
|
+
def categorize
|
31
|
+
result = []
|
32
|
+
self.each do |item|
|
33
|
+
contained = nil #該当する category の Array 内 id
|
34
|
+
result.each_with_index do |category, i|
|
35
|
+
#category[0] と比較。
|
36
|
+
if block_given? #ブロックを渡されていたら
|
37
|
+
#そのブロックで等価判定
|
38
|
+
contained = i if yield( category[0], item )
|
39
|
+
else
|
40
|
+
#uniq と同じように eql? を使う
|
41
|
+
contained = i if category[0].eql?( item )
|
42
|
+
end
|
43
|
+
if contained
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if contained
|
48
|
+
result[contained] << item
|
49
|
+
else
|
50
|
+
result << [item]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return result
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,122 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
#引数と等価な全て要素のインデックスからなる配列を返す。
|
4
|
+
#find_all は要素を返すが、これはインデックスを返す点が異なる。
|
5
|
+
#e.g., [ 10, 20, 30 ].find_all_indices{ |i| i < 25 } #=> [ 0, 1 ]
|
6
|
+
def find_all_indices
|
7
|
+
results = []
|
8
|
+
self.each_with_index do |elem, i|
|
9
|
+
results << i if yield( elem )
|
10
|
+
end
|
11
|
+
results
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
#要素同士の対応を扱うモジュール。
|
18
|
+
module Mapping
|
19
|
+
|
20
|
+
#For module methods
|
21
|
+
|
22
|
+
#左のコンテナに注目し、右のコンテナにある条件を満たすインデックス全てを
|
23
|
+
#入れた配列を返す。
|
24
|
+
#等価なものを探すことなどに使える。
|
25
|
+
#右のコンテナに等価なものがなければ空配列が入る。
|
26
|
+
#e.g., left = ['a', 'b', 'c', 'd']
|
27
|
+
# right = ['b', 'c', 'a', 'a']
|
28
|
+
# のとき、
|
29
|
+
# self.left_to_right(left, right) #=> [ [2, 3], [0], [1], [] ]
|
30
|
+
#必ずブロックが渡されることを前提とする。
|
31
|
+
#ブロックをたとえば { |i, j| i == j } とすれば、
|
32
|
+
#left, right それぞれに由来する要素 i, j を == 演算で等価判定していることになる。
|
33
|
+
#ブロックに渡すのは等価判定でなくても構わない。
|
34
|
+
def self.map( left, right )
|
35
|
+
size = left.size
|
36
|
+
results = Array.new( size, [] )
|
37
|
+
size.times do |n|
|
38
|
+
results[n] = right.find_all_indices{ |i| yield( i, left[n] ) }
|
39
|
+
end
|
40
|
+
results
|
41
|
+
end
|
42
|
+
|
43
|
+
#2つのコンテナが一対一対応していれば true、そうでなければ false
|
44
|
+
#自分と自分でも多対多の対応になる可能性があり、その場合は false
|
45
|
+
def self.map?(left, right)
|
46
|
+
return true if ((left.size == 0 ) && (right.size == 0))
|
47
|
+
return false if ((left.size == 0 ) || (right.size == 0)) #どちらかが 0 でどちらかが非0
|
48
|
+
|
49
|
+
l2r = self.map(left, right){ |i, j| yield( i, j ) }
|
50
|
+
r2l = self.map(right, left){ |i, j| yield( i, j ) }
|
51
|
+
result = true
|
52
|
+
result = false if ( l2r.max_by{|i| i.size }.size != 1 )
|
53
|
+
result = false if ( l2r.min_by{|i| i.size }.size != 1 )
|
54
|
+
result = false if ( r2l.max_by{|i| i.size }.size != 1 )
|
55
|
+
result = false if ( r2l.min_by{|i| i.size }.size != 1 )
|
56
|
+
#max_by, min_by は要素を返すため、それに操作を改めて加えてサイズを出す。
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
#map? よりもゆるく、多対多でも等しい要素の数が同じであれば true.
|
61
|
+
#e.g.,
|
62
|
+
# a0 = ['b', 'c', 'a', 'a']
|
63
|
+
# a1 = ['a', 'a', 'b', 'c']
|
64
|
+
# のとき、Mapping::corresponding?( a0, a1 ) #=> true
|
65
|
+
def self.corresponding?( left, right )
|
66
|
+
return false if ( left.size != right.size )
|
67
|
+
|
68
|
+
l_indices = Mapping::map( left , right ){ |a, b| yield( a, b ) }
|
69
|
+
r_indices = Mapping::map( right, left ){ |a, b| yield( a, b ) }
|
70
|
+
#p r_indices; exit
|
71
|
+
l_indices.size.times do |i|
|
72
|
+
results = []
|
73
|
+
return false if l_indices[i].empty? #対応が空のものがあれば false 確定。
|
74
|
+
l_indices[i].each do |x| #左の i 番要素は 右へのインデックスの配列なので、それを each
|
75
|
+
return false if l_indices[i].size != r_indices[x].size #対応の数が異なれば false。この条件には 右側が空であることも含まれる。
|
76
|
+
r_indices[x].each do |y| #対応する右の要素は、左へのインデックスの配列なので、それを each
|
77
|
+
results << l_indices[y] #さらに左の要素で、反射して対応する全てが得られる。
|
78
|
+
end
|
79
|
+
end
|
80
|
+
#p results.flatten.uniq
|
81
|
+
#p l_indices[i]
|
82
|
+
#全部 [] のときも true になっちまう。
|
83
|
+
#対応がない場合も考えないとなー。
|
84
|
+
#どれか、どちらかが一つでも空対応のときは false でいいか。
|
85
|
+
return false if ( results.flatten.uniq != l_indices[i] )
|
86
|
+
end
|
87
|
+
return true
|
88
|
+
|
89
|
+
#l_hash = Hash.new
|
90
|
+
#r_hash = Hash.new
|
91
|
+
#left.uniq.each do |i|
|
92
|
+
# l_hash[ i ] = left .select{ |j| yield( i, j ) }.size
|
93
|
+
# r_hash[ i ] = right.select{ |j| yield( i, j ) }.size
|
94
|
+
#end
|
95
|
+
#p l_hash, r_hash
|
96
|
+
#return l_hash == r_hash
|
97
|
+
end
|
98
|
+
|
99
|
+
#For instance methods
|
100
|
+
|
101
|
+
#クラスに include されたときに Mapping::corresponding? をクラスメソッドとして使えるようにしたもの。
|
102
|
+
def corresponding?( other )
|
103
|
+
Mapping::corresponding?( self, other ){ |i, j| yield( i, j ) }
|
104
|
+
end
|
105
|
+
|
106
|
+
#自分から引数のコンテナへの写像と考えたときの、対応するインデックスを配列して返す。
|
107
|
+
def map_to(other)
|
108
|
+
Mapping::map(self, other){ |i, j| yield( i, j ) }
|
109
|
+
end
|
110
|
+
|
111
|
+
#引数のコンテナから自分数への写像と考えたときの、対応するインデックスを配列して返す。
|
112
|
+
def map_from(other)
|
113
|
+
Mapping::map(other, self){ |i, j| yield( i, j ) }
|
114
|
+
end
|
115
|
+
|
116
|
+
#引数のコンテナと一対一で対応すれば true, そうでなければ false。
|
117
|
+
#自分と比較しても多対多の対応になる可能性があり、その場合は false
|
118
|
+
def map?(other)
|
119
|
+
Mapping::map?(self, other){ |i, j| yield( i, j ) }
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
require 'maset'
|
15
|
+
|
16
|
+
class Test::Unit::TestCase
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'maset/categorize.rb'
|
5
|
+
|
6
|
+
#assert_equal(correctVal, @f.bar)
|
7
|
+
|
8
|
+
class TC_Categorize < Test::Unit::TestCase
|
9
|
+
#Array への extend として機能するか?
|
10
|
+
def test_module_extend
|
11
|
+
arr = [ -2, -1, 0, 1, 2, 1]
|
12
|
+
arr.extend( Categorize )
|
13
|
+
assert_equal( [ [-2], [-1], [0], [1, 1], [2] ], arr.categorize )
|
14
|
+
|
15
|
+
#ブロック渡しが機能するか?
|
16
|
+
assert_equal( [ [-2, 2], [-1, 1, 1], [0] ],
|
17
|
+
arr.categorize{ |a, b| a.abs == b.abs }
|
18
|
+
)
|
19
|
+
|
20
|
+
##push してできるか
|
21
|
+
#arr.push( 0 )
|
22
|
+
#assert_equal( [ [-2], [-1], [0, 0], [1, 1], [2] ], arr.categorize )
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,205 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'maset/mapping.rb'
|
5
|
+
|
6
|
+
class TC_Array < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@a0 = ['a', 'b', 'c', 'b', ]
|
9
|
+
@a1 = [ 1, 2, 3, -2 ]
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_find_all_indices
|
13
|
+
assert_equal([0], @a0.find_all_indices{|i| i == 'a' })
|
14
|
+
assert_equal([1,3], @a0.find_all_indices{|i| i == 'b' })
|
15
|
+
assert_equal([2], @a0.find_all_indices{|i| i == 'c' })
|
16
|
+
assert_equal([], @a0.find_all_indices{|i| i == 'd' })
|
17
|
+
|
18
|
+
assert_equal([0,3], @a1.find_all_indices{ |i| i < 2 } )
|
19
|
+
assert_equal([0,1,3], @a1.find_all_indices{ |i| i <= 2 } )
|
20
|
+
assert_equal([1, 3], @a1.find_all_indices{ |i| i.abs == 2 } )
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class Array
|
26
|
+
include Mapping
|
27
|
+
end
|
28
|
+
|
29
|
+
class TC_Mapping < Test::Unit::TestCase
|
30
|
+
def setup
|
31
|
+
@a0 = ['a', 'b', 'c', 'd']
|
32
|
+
@a1 = ['b', 'c', 'a', 'a']
|
33
|
+
@a2 = ['b', 'c', 'a', 'd']
|
34
|
+
@a3 = ['a', 'a', 'b', 'c']
|
35
|
+
@a4 = ['a', 'b', 'c']
|
36
|
+
@b0 = [ 1, 2, 3 ]
|
37
|
+
@b1 = [ -2, -3, -1 ]
|
38
|
+
@b2 = [ -1, 2, 3 ]
|
39
|
+
|
40
|
+
@c0 = [ 1, 2, 3, 3]
|
41
|
+
@c1 = [-3,-3,-1,-2]
|
42
|
+
@c2 = [-1,-3,-3,-3]
|
43
|
+
@c3 = [-1,-4,-3,-3]
|
44
|
+
@c4 = [-1,-1,-3,-3]
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_self_map
|
48
|
+
assert_equal( [[2,3],[0],[1],[]], Mapping::map(@a0, @a1){ |i, j| i == j } )
|
49
|
+
assert_equal( [[0],[1],[2],[2]] , Mapping::map(@a1, @a2){ |i, j| i == j } )
|
50
|
+
assert_equal( [[1],[2],[0],[3]] , Mapping::map(@a2, @a0){ |i, j| i == j } )
|
51
|
+
assert_equal( [[1],[2],[0],[0]] , Mapping::map(@a1, @a0){ |i, j| i == j } )
|
52
|
+
assert_equal( [[0],[1],[2,3],[]], Mapping::map(@a2, @a1){ |i, j| i == j } )
|
53
|
+
assert_equal( [[2],[0],[1],[3]] , Mapping::map(@a0, @a2){ |i, j| i == j } )
|
54
|
+
assert_equal( [[0],[1],[2],[]] , Mapping::map(@a0, @a4){ |i, j| i == j } )
|
55
|
+
assert_equal( [[2],[0],[1]] , Mapping::map(@b0, @b1){ |i, j| i == -j } )
|
56
|
+
assert_equal( [[0],[],[]] , Mapping::map(@b0, @b2){ |i, j| i == -j } )
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_self_map?
|
60
|
+
assert_equal(true , Mapping::map?(@a0, @a0){ |i, j| i == j } )
|
61
|
+
assert_equal(false, Mapping::map?(@a0, @a1){ |i, j| i == j } )
|
62
|
+
assert_equal(true , Mapping::map?(@a0, @a2){ |i, j| i == j } )
|
63
|
+
assert_equal(false, Mapping::map?(@a1, @a0){ |i, j| i == j } )
|
64
|
+
assert_equal(false, Mapping::map?(@a1, @a1){ |i, j| i == j } )
|
65
|
+
assert_equal(false, Mapping::map?(@a1, @a2){ |i, j| i == j } )
|
66
|
+
assert_equal(true , Mapping::map?(@a2, @a0){ |i, j| i == j } )
|
67
|
+
assert_equal(false, Mapping::map?(@a2, @a1){ |i, j| i == j } )
|
68
|
+
assert_equal(true , Mapping::map?(@a2, @a2){ |i, j| i == j } )
|
69
|
+
assert_equal(true , Mapping::map?([] , [] ){ |i, j| i == j } )
|
70
|
+
assert_equal(false, Mapping::map?(@a0, [] ){ |i, j| i == j } )
|
71
|
+
assert_equal(false, Mapping::map?([] , @a0){ |i, j| i == j } )
|
72
|
+
|
73
|
+
assert_equal(true , Mapping::map?(@b0, @b1){ |i, j| i == -j })
|
74
|
+
assert_equal(false, Mapping::map?(@b0, @b2){ |i, j| i == -j })
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_self_correspond?
|
78
|
+
assert_equal(true , Mapping::corresponding?(@a0, @a0){ |i, j| i == j })
|
79
|
+
assert_equal(false, Mapping::corresponding?(@a0, @a1){ |i, j| i == j })
|
80
|
+
assert_equal(true , Mapping::corresponding?(@a0, @a2){ |i, j| i == j })
|
81
|
+
assert_equal(false, Mapping::corresponding?(@a0, @a3){ |i, j| i == j })
|
82
|
+
assert_equal(false, Mapping::corresponding?(@a0, @a4){ |i, j| i == j })
|
83
|
+
assert_equal(false, Mapping::corresponding?(@a1, @a0){ |i, j| i == j })
|
84
|
+
assert_equal(true , Mapping::corresponding?(@a1, @a1){ |i, j| i == j })
|
85
|
+
assert_equal(false, Mapping::corresponding?(@a1, @a2){ |i, j| i == j })
|
86
|
+
assert_equal(true , Mapping::corresponding?(@a1, @a3){ |i, j| i == j })
|
87
|
+
assert_equal(false, Mapping::corresponding?(@a1, @a4){ |i, j| i == j })
|
88
|
+
assert_equal(true , Mapping::corresponding?(@a2, @a0){ |i, j| i == j })
|
89
|
+
assert_equal(false, Mapping::corresponding?(@a2, @a1){ |i, j| i == j })
|
90
|
+
assert_equal(true , Mapping::corresponding?(@a2, @a2){ |i, j| i == j })
|
91
|
+
assert_equal(false, Mapping::corresponding?(@a2, @a3){ |i, j| i == j })
|
92
|
+
assert_equal(false, Mapping::corresponding?(@a2, @a4){ |i, j| i == j })
|
93
|
+
assert_equal(false, Mapping::corresponding?(@a3, @a0){ |i, j| i == j })
|
94
|
+
assert_equal(true , Mapping::corresponding?(@a3, @a1){ |i, j| i == j })
|
95
|
+
assert_equal(false, Mapping::corresponding?(@a3, @a2){ |i, j| i == j })
|
96
|
+
assert_equal(true , Mapping::corresponding?(@a3, @a3){ |i, j| i == j })
|
97
|
+
assert_equal(false, Mapping::corresponding?(@a3, @a4){ |i, j| i == j })
|
98
|
+
assert_equal(true , Mapping::corresponding?(@b0, @b1){ |i, j| i == -j })
|
99
|
+
assert_equal(false, Mapping::corresponding?(@b0, @b2){ |i, j| i == -j })
|
100
|
+
assert_equal(false, Mapping::corresponding?(@c0, @c1){ |i, j| i == j })
|
101
|
+
assert_equal(false, Mapping::corresponding?(@c0, @c0){ |i, j| i == -j })
|
102
|
+
assert_equal(true , Mapping::corresponding?(@c0, @c1){ |i, j| i == -j })
|
103
|
+
assert_equal(false, Mapping::corresponding?(@c0, @c2){ |i, j| i == -j })
|
104
|
+
assert_equal(false, Mapping::corresponding?(@c0, @c3){ |i, j| i == -j })
|
105
|
+
assert_equal(true , Mapping::corresponding?(@c1, @c0){ |i, j| i == -j })
|
106
|
+
assert_equal(false, Mapping::corresponding?(@c1, @c1){ |i, j| i == -j })
|
107
|
+
assert_equal(false, Mapping::corresponding?(@c1, @c2){ |i, j| i == -j })
|
108
|
+
assert_equal(false, Mapping::corresponding?(@c1, @c3){ |i, j| i == -j })
|
109
|
+
assert_equal(false, Mapping::corresponding?(@c2, @c0){ |i, j| i == -j })
|
110
|
+
assert_equal(false, Mapping::corresponding?(@c2, @c1){ |i, j| i == -j })
|
111
|
+
assert_equal(false, Mapping::corresponding?(@c2, @c2){ |i, j| i == -j })
|
112
|
+
assert_equal(false, Mapping::corresponding?(@c2, @c3){ |i, j| i == -j })
|
113
|
+
assert_equal(false, Mapping::corresponding?(@c3, @c0){ |i, j| i == -j })
|
114
|
+
assert_equal(false, Mapping::corresponding?(@c3, @c1){ |i, j| i == -j })
|
115
|
+
assert_equal(false, Mapping::corresponding?(@c3, @c2){ |i, j| i == -j })
|
116
|
+
assert_equal(false, Mapping::corresponding?(@c3, @c3){ |i, j| i == -j })
|
117
|
+
assert_equal(false, Mapping::corresponding?(@c2, @c4){ |i, j| i == -j })
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_correspond?
|
121
|
+
assert_equal(true , @a0.corresponding?( @a0){ |i, j| i == j })
|
122
|
+
assert_equal(false, @a0.corresponding?( @a1){ |i, j| i == j })
|
123
|
+
assert_equal(true , @a0.corresponding?( @a2){ |i, j| i == j })
|
124
|
+
assert_equal(false, @a0.corresponding?( @a3){ |i, j| i == j })
|
125
|
+
assert_equal(false, @a0.corresponding?( @a4){ |i, j| i == j })
|
126
|
+
assert_equal(false, @a1.corresponding?( @a0){ |i, j| i == j })
|
127
|
+
assert_equal(true , @a1.corresponding?( @a1){ |i, j| i == j })
|
128
|
+
assert_equal(false, @a1.corresponding?( @a2){ |i, j| i == j })
|
129
|
+
assert_equal(true , @a1.corresponding?( @a3){ |i, j| i == j })
|
130
|
+
assert_equal(false, @a1.corresponding?( @a4){ |i, j| i == j })
|
131
|
+
assert_equal(true , @a2.corresponding?( @a0){ |i, j| i == j })
|
132
|
+
assert_equal(false, @a2.corresponding?( @a1){ |i, j| i == j })
|
133
|
+
assert_equal(true , @a2.corresponding?( @a2){ |i, j| i == j })
|
134
|
+
assert_equal(false, @a2.corresponding?( @a3){ |i, j| i == j })
|
135
|
+
assert_equal(false, @a2.corresponding?( @a4){ |i, j| i == j })
|
136
|
+
assert_equal(false, @a3.corresponding?( @a0){ |i, j| i == j })
|
137
|
+
assert_equal(true , @a3.corresponding?( @a1){ |i, j| i == j })
|
138
|
+
assert_equal(false, @a3.corresponding?( @a2){ |i, j| i == j })
|
139
|
+
assert_equal(true , @a3.corresponding?( @a3){ |i, j| i == j })
|
140
|
+
assert_equal(false, @a3.corresponding?( @a4){ |i, j| i == j })
|
141
|
+
assert_equal(true , @b0.corresponding?( @b1){ |i, j| i == -j })
|
142
|
+
assert_equal(false, @b0.corresponding?( @b2){ |i, j| i == -j })
|
143
|
+
assert_equal(false, @c0.corresponding?( @c1){ |i, j| i == j })
|
144
|
+
assert_equal(false, @c0.corresponding?( @c0){ |i, j| i == -j })
|
145
|
+
assert_equal(true , @c0.corresponding?( @c1){ |i, j| i == -j })
|
146
|
+
assert_equal(false, @c0.corresponding?( @c2){ |i, j| i == -j })
|
147
|
+
assert_equal(false, @c0.corresponding?( @c3){ |i, j| i == -j })
|
148
|
+
assert_equal(true , @c1.corresponding?( @c0){ |i, j| i == -j })
|
149
|
+
assert_equal(false, @c1.corresponding?( @c1){ |i, j| i == -j })
|
150
|
+
assert_equal(false, @c1.corresponding?( @c2){ |i, j| i == -j })
|
151
|
+
assert_equal(false, @c1.corresponding?( @c3){ |i, j| i == -j })
|
152
|
+
assert_equal(false, @c2.corresponding?( @c0){ |i, j| i == -j })
|
153
|
+
assert_equal(false, @c2.corresponding?( @c1){ |i, j| i == -j })
|
154
|
+
assert_equal(false, @c2.corresponding?( @c2){ |i, j| i == -j })
|
155
|
+
assert_equal(false, @c2.corresponding?( @c3){ |i, j| i == -j })
|
156
|
+
assert_equal(false, @c3.corresponding?( @c0){ |i, j| i == -j })
|
157
|
+
assert_equal(false, @c3.corresponding?( @c1){ |i, j| i == -j })
|
158
|
+
assert_equal(false, @c3.corresponding?( @c2){ |i, j| i == -j })
|
159
|
+
assert_equal(false, @c3.corresponding?( @c3){ |i, j| i == -j })
|
160
|
+
assert_equal(false, @c2.corresponding?( @c4){ |i, j| i == -j })
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_map_to
|
164
|
+
assert_equal([[2,3],[0],[1],[]], @a0.map_to(@a1){ |i, j| i == j })
|
165
|
+
assert_equal([[0],[1],[2],[2]], @a1.map_to(@a2){ |i, j| i == j })
|
166
|
+
assert_equal([[1],[2],[0],[3]], @a2.map_to(@a0){ |i, j| i == j })
|
167
|
+
assert_equal([[1],[2],[0],[0]], @a1.map_to(@a0){ |i, j| i == j })
|
168
|
+
assert_equal([[0],[1],[2,3],[]], @a2.map_to(@a1){ |i, j| i == j })
|
169
|
+
assert_equal([[2],[0],[1],[3]], @a0.map_to(@a2){ |i, j| i == j })
|
170
|
+
assert_equal( [[2], [0], [1]], @b0.map_to(@b1){ |i, j| i == -j })
|
171
|
+
assert_equal( [[0], [], []] , @b0.map_to(@b2){ |i, j| i == -j })
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_map_from
|
175
|
+
assert_equal([[2,3],[0],[1],[]], @a1.map_from(@a0){ |i, j| i == j })
|
176
|
+
assert_equal([[0],[1],[2],[2]], @a2.map_from(@a1){ |i, j| i == j })
|
177
|
+
assert_equal([[1],[2],[0],[3]], @a0.map_from(@a2){ |i, j| i == j })
|
178
|
+
assert_equal([[1],[2],[0],[0]], @a0.map_from(@a1){ |i, j| i == j })
|
179
|
+
assert_equal([[0],[1],[2,3],[]], @a1.map_from(@a2){ |i, j| i == j })
|
180
|
+
assert_equal([[2],[0],[1],[3]], @a2.map_from(@a0){ |i, j| i == j })
|
181
|
+
assert_equal( [[1], [2], [0]] , @b0.map_from(@b1){ |i, j| i == -j })
|
182
|
+
assert_equal( [[0], [], []] , @b0.map_from(@b2){ |i, j| i == -j })
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_map?
|
186
|
+
assert_equal(false, @a0.map?(@a1){ |i, j| i == j })
|
187
|
+
assert_equal(false, @a1.map?(@a2){ |i, j| i == j })
|
188
|
+
assert_equal(true , @a2.map?(@a0){ |i, j| i == j })
|
189
|
+
assert_equal(false, @a1.map?(@a0){ |i, j| i == j })
|
190
|
+
assert_equal(false, @a2.map?(@a1){ |i, j| i == j })
|
191
|
+
assert_equal(true , @a0.map?(@a2){ |i, j| i == j })
|
192
|
+
|
193
|
+
assert_equal( true , @b0.map?(@b1){ |i, j| i == -j })
|
194
|
+
assert_equal( false, @b0.map?(@b2){ |i, j| i == -j })
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_module_extend
|
198
|
+
a0 = ['a', 'b', 'c', 'd']
|
199
|
+
a0.extend( Mapping )
|
200
|
+
assert_equal(false, a0.map?( @a1 ){ |i, j| i == j })
|
201
|
+
assert_equal(true , a0.map?( @a2 ){ |i, j| i == j })
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maset
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ippei94da
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rdoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.12'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.12'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.1.3
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: jeweler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.8.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: This gem provides few libraries, which are Mapping and Categorize.
|
79
|
+
email: ippei94da@gmail.com
|
80
|
+
executables:
|
81
|
+
- categorizeYamlValues
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files:
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.rdoc
|
86
|
+
files:
|
87
|
+
- .document
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.rdoc
|
91
|
+
- Rakefile
|
92
|
+
- VERSION
|
93
|
+
- bin/categorizeYamlValues
|
94
|
+
- lib/maset.rb
|
95
|
+
- lib/maset/categorize.rb
|
96
|
+
- lib/maset/mapping.rb
|
97
|
+
- test/helper.rb
|
98
|
+
- test/test_categorize.rb
|
99
|
+
- test/test_mapping.rb
|
100
|
+
homepage: http://github.com/ippei94da/maset
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: -165794623
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.21
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: ! 'Math Set: Mathematical library of set theory'
|
128
|
+
test_files: []
|