kyanite 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/0 start all Tests.bat +23 -0
  2. data/History.txt +4 -0
  3. data/License.txt +21 -0
  4. data/Manifest.txt +88 -0
  5. data/PostInstall.txt +4 -0
  6. data/README.txt +48 -0
  7. data/Rakefile.rb +79 -0
  8. data/init.rb +2 -0
  9. data/lib/kyanite.rb +39 -0
  10. data/lib/kyanite/array.rb +5 -0
  11. data/lib/kyanite/array/array.rb +172 -0
  12. data/lib/kyanite/array/array2.rb +140 -0
  13. data/lib/kyanite/array/matrix2.rb +120 -0
  14. data/lib/kyanite/array_of_enumerables.rb +2 -0
  15. data/lib/kyanite/array_of_numerics.rb +2 -0
  16. data/lib/kyanite/array_of_strings.rb +2 -0
  17. data/lib/kyanite/basics.rb +60 -0
  18. data/lib/kyanite/dictionary.rb +116 -0
  19. data/lib/kyanite/enumerable.rb +7 -0
  20. data/lib/kyanite/enumerable/enumerable_enumerables.rb +70 -0
  21. data/lib/kyanite/enumerable/enumerable_numerics.rb +171 -0
  22. data/lib/kyanite/enumerable/enumerable_strings.rb +58 -0
  23. data/lib/kyanite/enumerable/structure.rb +170 -0
  24. data/lib/kyanite/general.rb +8 -0
  25. data/lib/kyanite/general/callerutils.rb +128 -0
  26. data/lib/kyanite/general/classutils.rb +246 -0
  27. data/lib/kyanite/general/kernel.rb +105 -0
  28. data/lib/kyanite/general/nil.rb +64 -0
  29. data/lib/kyanite/general/object.rb +86 -0
  30. data/lib/kyanite/general/true_false.rb +65 -0
  31. data/lib/kyanite/general/undoable.rb +24 -0
  32. data/lib/kyanite/hash.rb +170 -0
  33. data/lib/kyanite/matrix2.rb +2 -0
  34. data/lib/kyanite/nil.rb +3 -0
  35. data/lib/kyanite/numeric.rb +4 -0
  36. data/lib/kyanite/numeric/float.rb +26 -0
  37. data/lib/kyanite/numeric/integer.rb +34 -0
  38. data/lib/kyanite/numeric/numeric.rb +45 -0
  39. data/lib/kyanite/operation.rb +5 -0
  40. data/lib/kyanite/operation/call_tracker.rb +69 -0
  41. data/lib/kyanite/operation/rake.rb +101 -0
  42. data/lib/kyanite/operation/regexp.rb +23 -0
  43. data/lib/kyanite/operation/unit_test.rb +53 -0
  44. data/lib/kyanite/optimizer.rb +119 -0
  45. data/lib/kyanite/rake.rb +2 -0
  46. data/lib/kyanite/range.rb +54 -0
  47. data/lib/kyanite/set.rb +219 -0
  48. data/lib/kyanite/smart_load_path.rb +2 -0
  49. data/lib/kyanite/string.rb +13 -0
  50. data/lib/kyanite/string/cast.rb +104 -0
  51. data/lib/kyanite/string/chars.rb +184 -0
  52. data/lib/kyanite/string/chars_const.rb +190 -0
  53. data/lib/kyanite/string/diff.rb +78 -0
  54. data/lib/kyanite/string/div.rb +19 -0
  55. data/lib/kyanite/string/include.rb +43 -0
  56. data/lib/kyanite/string/list.rb +84 -0
  57. data/lib/kyanite/string/mgsub.rb +35 -0
  58. data/lib/kyanite/string/nested.rb +253 -0
  59. data/lib/kyanite/string/random.rb +69 -0
  60. data/lib/kyanite/string/split.rb +136 -0
  61. data/lib/kyanite/symbol.rb +19 -0
  62. data/lib/kyanite/tree.rb +99 -0
  63. data/lib/kyanite/undoable.rb +2 -0
  64. data/lib/kyanite/unit_test.rb +2 -0
  65. data/test/_start_all.rb +17 -0
  66. data/test/array/test_array.rb +106 -0
  67. data/test/array/test_matrix2.rb +162 -0
  68. data/test/enumerable/test_enumerable_enumerables.rb +46 -0
  69. data/test/enumerable/test_enumerable_numerics.rb +93 -0
  70. data/test/enumerable/test_enumerable_strings.rb +22 -0
  71. data/test/enumerable/test_structure.rb +220 -0
  72. data/test/general/test_classutils.rb +45 -0
  73. data/test/general/test_nil.rb +44 -0
  74. data/test/general/test_object.rb +49 -0
  75. data/test/general/test_true_false.rb +28 -0
  76. data/test/numeric/test_numeric_integer.rb +28 -0
  77. data/test/string/test_cast.rb +108 -0
  78. data/test/string/test_chars.rb +255 -0
  79. data/test/string/test_diff.rb +95 -0
  80. data/test/string/test_list.rb +141 -0
  81. data/test/string/test_nested.rb +361 -0
  82. data/test/string/test_split.rb +187 -0
  83. data/test/test_dictionary.rb +128 -0
  84. data/test/test_hash.rb +59 -0
  85. data/test/test_optimizer.rb +150 -0
  86. data/test/test_range.rb +41 -0
  87. data/test/test_set.rb +210 -0
  88. data/test/test_tree.rb +94 -0
  89. metadata +217 -0
@@ -0,0 +1,19 @@
1
+
2
+ class Symbol
3
+
4
+ def empty?; false; end
5
+ def dup; self; end
6
+
7
+ def +(other)
8
+ (self.to_s + other.to_s).to_sym
9
+ end
10
+
11
+ def <=>(other)
12
+ self.to_s <=> other.to_s
13
+ end
14
+
15
+ def size
16
+ self.to_s.size
17
+ end
18
+
19
+ end
@@ -0,0 +1,99 @@
1
+
2
+
3
+ require 'tree'
4
+
5
+ # -----------------------------------------------------------------------------------------
6
+ # Ergänzungen zu rubytree 0.5.2
7
+ #
8
+ module Tree
9
+ class TreeNode
10
+ attr_reader :childrenHash
11
+
12
+
13
+ # kann jetzt auch mit Symbolen umgehen
14
+ def to_s
15
+ ":#{@name}"
16
+ # "Node Name: #{@name}" +
17
+ # " Content: #{@content || '<Empty>'}" +
18
+ # " Parent: #{(isRoot?() ? '<None>' : @parent.name)}" +
19
+ # " Children: #{@children.length}" +
20
+ # " Total Nodes: #{size()}"
21
+ end
22
+
23
+
24
+ # funktioniert jetzt
25
+ def printTree(level = 0, breite = 8)
26
+
27
+ if isRoot?
28
+ print "*"
29
+
30
+ elsif level == 0
31
+ print 'X'
32
+
33
+ else
34
+ print "|" unless parent.isLastSibling?
35
+ print(" " * (level - 1 ) * breite)
36
+ print(isLastSibling? ? "+" : "|")
37
+ print "---"
38
+ print(hasChildren? ? "+" : ">")
39
+ end
40
+
41
+ puts " #{name}"
42
+
43
+ children { |child| child.printTree(level + 1)}
44
+ nil
45
+ end
46
+
47
+
48
+ # anders als [] wird der gesamte Baum durchsucht
49
+ # Liefert den ersten Treffer
50
+ def find( node_name )
51
+ return self if self.name == node_name
52
+ result = self[node_name]
53
+ return result if result
54
+ children do |c|
55
+ next if c.children.empty?
56
+ #puts "durchsuche #{c.name}"
57
+ result = c.find(node_name)
58
+ return result if result
59
+ end
60
+ nil
61
+ end
62
+
63
+
64
+ # Liefert ein Array aller untergeordneten Child-Keys.
65
+ # Es wird der gesamte Baum durchsucht.
66
+ def all_child_keys
67
+ result = @childrenHash.keys || []
68
+ children do |c|
69
+ #puts "durchsuche #{c}"
70
+ next if c.childrenHash.empty?
71
+ result += c.all_child_keys
72
+ end
73
+ result
74
+ end
75
+
76
+
77
+
78
+
79
+ end # class
80
+ end # module
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
@@ -0,0 +1,2 @@
1
+
2
+ require 'kyanite/general/undoable'
@@ -0,0 +1,2 @@
1
+
2
+ require 'kyanite/operation/unit_test'
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Führt alle Tests aus
4
+ #
5
+
6
+
7
+ # Test-Verzeichnis der Applikation
8
+ test_verzeichnis = File.expand_path(File.dirname(__FILE__) )
9
+
10
+ Dir["#{test_verzeichnis}/test_*.rb"].sort.each { |t| require t }
11
+ Dir["#{test_verzeichnis}/array/test_*.rb"].sort.each { |t| require t }
12
+ Dir["#{test_verzeichnis}/enumerable/test_*.rb"].sort.each { |t| require t }
13
+ Dir["#{test_verzeichnis}/general/test_*.rb"].sort.each { |t| require t }
14
+ Dir["#{test_verzeichnis}/numeric/test_*.rb"].sort.each { |t| require t }
15
+ Dir["#{test_verzeichnis}/string/test_*.rb"].sort.each { |t| require t }
16
+
17
+
@@ -0,0 +1,106 @@
1
+
2
+ require 'kyanite/unit_test'
3
+ require 'kyanite/smart_load_path'; smart_load_path
4
+ require 'perception' if $0 == __FILE__
5
+
6
+ require 'kyanite/array/array'
7
+ require 'kyanite/numeric/numeric'
8
+ require 'kyanite/set'
9
+
10
+
11
+ # Tests für Array
12
+ #
13
+ class TestKyaniteArray < UnitTest
14
+
15
+ def test_rephrase_index
16
+ test = [ :a, :b, :c, :d]
17
+ 0.upto(3) do | i |
18
+ i_inv = test.rephrase_index(i)
19
+ i_neg = test.rephrase_index(i, :neg)
20
+ i_pos = test.rephrase_index(i, :pos)
21
+ # print "\n#{test[i]} #{i} #{i_inv}"
22
+
23
+ assert_not_equal i, i_inv
24
+ assert_not_equal i, i_neg
25
+ assert_equal i_neg, i_inv
26
+ assert_equal i, i_pos
27
+ assert_equal test[i], test[i_inv]
28
+ assert_equal test[i], test[i_pos]
29
+ assert_equal test[i], test[i_neg]
30
+ end # do
31
+
32
+ -4.upto(-1) do | i |
33
+ i_inv = test.rephrase_index(i)
34
+ i_neg = test.rephrase_index(i, :neg)
35
+ i_pos = test.rephrase_index(i, :pos)
36
+ # print "\n#{test[i]} #{i} #{i_inv}"
37
+
38
+ assert_not_equal i, i_inv
39
+ assert_not_equal i, i_pos
40
+ assert_equal i_pos, i_inv
41
+ assert_equal i, i_neg
42
+ assert_equal test[i], test[i_inv]
43
+ assert_equal test[i], test[i_pos]
44
+ assert_equal test[i], test[i_neg]
45
+ end # do
46
+
47
+ [4, 5, -5, -6].each do |i|
48
+ i_inv = test.rephrase_index(i)
49
+ i_neg = test.rephrase_index(i, :neg)
50
+ i_pos = test.rephrase_index(i, :pos)
51
+ # print "\nx #{i} #{i_inv}"
52
+ assert_equal i, i_neg
53
+ assert_equal i, i_pos
54
+ assert_equal i, i_neg
55
+ assert_equal test[i], test[i_inv]
56
+ assert_equal test[i], test[i_pos]
57
+ assert_equal test[i], test[i_neg]
58
+ end
59
+
60
+ end
61
+
62
+
63
+
64
+
65
+ def test_array_diff
66
+ a = [1,2,3,4,5, :a, 'b']
67
+ b = [1,2,4,5,6,'a',:c]
68
+
69
+ assert_equal [3,:a,'b'], a - b
70
+ assert_equal [3,:a,'b', 3,:a,'b'], a + a - b
71
+ assert_equal [6, 'a', :c], b - a
72
+ assert_equal [], b - b
73
+ assert_equal [], a - a
74
+ end
75
+
76
+
77
+ def test_array_shift_complement
78
+ assert_equal [2,3], [1,2,3].shift_complement
79
+ assert_equal 3, [1,2,3].shift_complement.shift_complement
80
+ assert_equal nil, [1,2,3].shift_complement.shift_complement.shift_complement
81
+ end
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ def test_divide
90
+ numbers = [1, 3, 4, 6, 9, 10, 11]
91
+ result = numbers.divide { |i,j| (i - j).abs == 1 }
92
+ assert_equal [[11, 10, 9], [6], [1], [3, 4]], result
93
+ end
94
+
95
+
96
+
97
+ end # class
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
@@ -0,0 +1,162 @@
1
+
2
+
3
+ require 'kyanite/unit_test'
4
+ require 'kyanite/smart_load_path'; smart_load_path
5
+ require 'perception' if $0 == __FILE__
6
+
7
+ require 'kyanite/matrix2'
8
+ require 'kyanite/general/nil'
9
+
10
+ # require 'benchmark'
11
+ # include Benchmark
12
+
13
+
14
+ class TestKyaniteMatrix2 < UnitTest
15
+
16
+
17
+ #
18
+ # Normale Matrix testen: Zellen und Zeilen
19
+ #
20
+ def test_matrix_zellen_und_zeilen
21
+ # Initialisierung
22
+ zeile0 = ['Ueberschrift', 'Spalte1', 'Spalte2']
23
+ zeile1 = ['Zeile1', 'Wert 1.1', 'Wert 1.2']
24
+ zeile2 = ['Zeile2', 'Wert 2.1', 'Wert 2.2']
25
+ zeile3 = ['Zeile3', 'Wert 3.1', 'Wert 3.2', 'Wert 3.3']
26
+ zeile4 = ['Zeile4', 'Wert 4.1', 'Wert 4.2']
27
+
28
+ table = [zeile0, zeile1, zeile2, zeile3, zeile4] # dies ist noch ein Array
29
+ mymatrix = Matrix2.new(table) # und dies ist eine Matrix2
30
+ assert_kind_of Matrix2, mymatrix
31
+
32
+
33
+ # Zellen-Funktionen testen
34
+ assert_equal 'Wert 2.2', mymatrix[2][2]
35
+ mymatrix.set_element!(2,2,'Hallo 2.2')
36
+ assert_equal 'Hallo 2.2', mymatrix[2][2]
37
+
38
+
39
+ # Zeilen-Funktionen testen
40
+ assert_equal zeile2, mymatrix.row(2)
41
+ assert_equal mymatrix.row(2).size, mymatrix.column_size
42
+ assert_nil mymatrix.row(99)
43
+ assert_nil mymatrix.row(-99)
44
+ assert_equal 0, mymatrix.row(99).size
45
+ mymatrix.set_row!(3, zeile4)
46
+ assert_equal mymatrix.row(3), mymatrix.row(4)
47
+ mymatrix[3][0] = 'Z3'
48
+ mymatrix.set_element!(3,0,'ZEILE3')
49
+ mymatrix.set_element!(3,1,'WERT 3.1')
50
+ mymatrix.set_element!(3,2,'WERT 3.2')
51
+ assert_not_equal mymatrix.row(3), mymatrix.row(4)
52
+
53
+ zeile5 = ['Zeile5', 'Wert 5.1', 'Wert 5.2']
54
+ mymatrix.set_row!(5, zeile5)
55
+ end
56
+
57
+
58
+
59
+
60
+ #
61
+ # Normale Matrix testen: resize_to_header
62
+ #
63
+ def test_resize_to_header
64
+ # Erneute Initialisierung
65
+ zeile0 = ['Ueberschrift', 'Spalte1', 'Spalte2']
66
+ zeile1 = ['Zeile1', 'Wert 1.1', 'Wert 1.2']
67
+ zeile2 = ['Zeile2', 'Wert 2.1']
68
+ zeile3 = ['Zeile3', 'Wert 3.1', 'Wert 3.2', 'Wert 3.3']
69
+ zeile4 = ['Zeile4', 'Wert 4.1', 'Wert 4.2']
70
+ zeile5 = ['Zeile5']
71
+ mymatrix = Matrix2.new([zeile0, zeile1, zeile2, zeile3, zeile4, zeile5])
72
+
73
+
74
+ # clean4view(0) testen -- Resize to header
75
+ assert_equal 16, mymatrix.flatten.size
76
+ assert_equal 18, mymatrix.clean4view(0).flatten.size
77
+ assert_equal 16, mymatrix.flatten.size
78
+ mymatrix.clean4view!(0)
79
+ assert_equal 18, mymatrix.flatten.size
80
+ assert_equal 18, mymatrix.clean4view(0).flatten.size
81
+ assert_kind_of Matrix2, mymatrix.clean4view(0)
82
+ mymatrix.clean4view!
83
+ assert_kind_of Matrix2, mymatrix
84
+ end
85
+
86
+
87
+
88
+
89
+ #
90
+ # Normale Matrix testen: Spalten
91
+ #
92
+ def test_spalten
93
+ # Erneute Initialisierung
94
+ zeile0 = ['Ueberschrift', 'Spalte1', 'Spalte2']
95
+ zeile1 = ['Zeile1', 'Wert 1.1', 'Wert 1.2']
96
+ zeile2 = ['Zeile2', 'Wert 2.1']
97
+ zeile3 = ['Zeile3', 'Wert 3.1', 'Wert 3.2', 'Wert 3.3']
98
+ zeile4 = ['Zeile4', 'Wert 4.1', 'Wert 4.2']
99
+ zeile5 = ['Zeile5']
100
+ mymatrix = Matrix2.new([zeile0, zeile1, zeile2, zeile3, zeile4, zeile5])
101
+
102
+ # Spalten-Funktionen testen
103
+ assert_equal mymatrix.column(2).size, mymatrix.row_size
104
+ assert_nil mymatrix.column(99)
105
+ assert_nil mymatrix.column(-99)
106
+ assert_equal 0, mymatrix.column(99).size
107
+ spalte2 = mymatrix.column(2)
108
+ mymatrix.set_column!(3, spalte2)
109
+ mymatrix.set_column!(4, spalte2)
110
+ assert_equal mymatrix.column(2), mymatrix.column(3)
111
+ assert_equal mymatrix.column(2), mymatrix.column(4)
112
+ assert_equal 30, mymatrix.flatten.size
113
+ end
114
+
115
+
116
+
117
+ #
118
+ # Matrix mit Fehlern testen
119
+ #
120
+ def test_fehlerhalte_matrix
121
+ # Erneute Initialisierung
122
+ zeile0 = ['X', 'Spalte1', nil, 'Spalte3']
123
+ zeile1 = [ nil, 'Wert 1.1', 'Wert 1.2','Wert 1.3']
124
+ zeile2 = []
125
+ zeile3 = nil
126
+ zeile4 = ['Zeile4', 'Wert 4.1', 'Wert 4.2']
127
+ zeile5 = [ nil , nil, nil, nil, nil, nil, nil, nil]
128
+ zeile6 = ['Zeile6', nil, 'Wert 6.2', 'Wert 6.3']
129
+ zeile7 = ['Zeile7', 'Wert 7.1', 'Wert 7.2', 'Wert 7.3']
130
+ zeile8 = ['Zeile8', 'Wert 8.1', nil, 'Wert 8.3']
131
+ zeile9 = ['Zeile9', 'Wert 9.1', nil, 'Wert 9.3', 'Wert 9.4']
132
+
133
+
134
+ assert_not_nil zeile0.row_to_nil
135
+ assert_nil zeile1.row_to_nil
136
+ assert_nil zeile2.row_to_nil
137
+ assert_nil zeile3.row_to_nil
138
+ assert_not_nil zeile4.row_to_nil
139
+ assert_nil zeile5.row_to_nil
140
+ assert_not_nil zeile6.row_to_nil
141
+
142
+
143
+ errormatrix = Matrix2.new([zeile0, zeile1, zeile2, zeile3, zeile4, zeile5, zeile6, zeile7, zeile8, zeile9])
144
+
145
+
146
+ # assert_equal 37, errormatrix.flatten.size
147
+ # assert_equal 40, errormatrix.clean4view(0).flatten.size
148
+ # assert_equal 24, errormatrix.clean4view(1).flatten.size
149
+ # assert_equal 18, errormatrix.clean4view(2).flatten.size
150
+
151
+ end
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+ end # class
@@ -0,0 +1,46 @@
1
+
2
+ require 'kyanite/unit_test'
3
+ require 'kyanite/smart_load_path'; smart_load_path
4
+ require 'perception' if $0 == __FILE__
5
+
6
+ require 'kyanite/enumerable/enumerable_enumerables'
7
+
8
+ class Array
9
+ include EnumerableEnumerables
10
+ end
11
+
12
+
13
+ # Tests für EnumerableEnumerables
14
+ #
15
+ class TestKyaniteEnumerableEnumerables < UnitTest
16
+
17
+ def test_rectangle1
18
+ test = []
19
+ test << [ :a, :b, :c ]
20
+ test << [ 1, 2, 3 ]
21
+ test << [ 'i', 'ii', 'iii' ]
22
+ assert_equal test, test.rectangle
23
+ assert_equal test, test.rectangle.rectangle
24
+ assert_equal test.transpose, test.rectangle.transpose.rectangle
25
+ end
26
+
27
+
28
+
29
+ def test_rectangle2
30
+ test = []
31
+ test << [ :a, :b, :c ]
32
+ test << [ 1, 2, 3, 4 ]
33
+ test << [ 'i', 'ii' ]
34
+
35
+ expc = []
36
+ expc << [ :a, :b, :c ]
37
+ expc << [ 1, 2, 3 ]
38
+ expc << [ 'i', 'ii', nil ]
39
+
40
+
41
+ assert_equal expc, test.rectangle
42
+ assert_equal expc, test.rectangle.rectangle
43
+ assert_equal expc.transpose, test.rectangle.transpose.rectangle
44
+ end
45
+
46
+ end # class