File tree 7 files changed +6
-42
lines changed
7 files changed +6
-42
lines changed Original file line number Diff line number Diff line change 1
1
module CompSci
2
- NEWLINE = $/ # platform-default line separator
3
-
4
2
# thanks apeiros
5
3
# https://gist.github.com/rickhull/d0b579aa08c85430b0dc82a791ff12d6
6
4
def self . power_of? ( num , base )
7
5
return false if base <= 1
8
6
mod = 0
9
- num , mod = num . divmod ( base ) until num == 1 || mod > 0
7
+ num , mod = num . divmod ( base ) until ( num == 1 ) || ( mod > 0 )
10
8
mod == 0
11
9
end
12
-
13
- def self . numeric! ( num )
14
- raise ( ArgumentError , num . inspect ) unless num . is_a? ( Numeric )
15
- num
16
- end
17
-
18
- def self . positive! ( num )
19
- numeric! ( num )
20
- raise ( ArgumentError , num . inspect ) unless num >= 0
21
- num
22
- end
23
-
24
- def self . string! ( str )
25
- raise ( ArgumentError , str . inspect ) unless str . is_a? ( String )
26
- str
27
- end
28
-
29
- def self . nonempty! ( str )
30
- string! ( str )
31
- raise ( ArgumentError , str . inspect ) if str . empty?
32
- str
33
- end
34
10
end
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ def follow(src, value)
147
147
148
148
# initial, final, graph
149
149
def to_s
150
- [ [ @initial , @final ] . inspect , @graph ] . join ( NEWLINE )
150
+ [ [ @initial , @final ] . inspect , @graph ] . join ( $/ )
151
151
end
152
152
153
153
def eval ( state )
Original file line number Diff line number Diff line change 1
- require 'compsci'
2
-
3
1
module CompSci
4
2
# has a value and an array of children; allows child gaps
5
3
class Node
@@ -51,7 +49,7 @@ def display(width: 80)
51
49
memo + Array . new ( @children . size ) { |i | n and n . children [ i ] }
52
50
}
53
51
end
54
- lines . join ( NEWLINE )
52
+ lines
55
53
end
56
54
end
57
55
Original file line number Diff line number Diff line change 2
2
# which was forked in 2017 from https://github.com/danlucraft/simplex
3
3
# which had its last commit in 2013
4
4
5
- require 'compsci'
6
-
7
5
module CompSci
8
6
class Simplex
9
7
DEFAULT_MAX_PIVOTS = 10_000
@@ -168,7 +166,7 @@ def formatted_tableau
168
166
lines = result . map { |ary | ary . join ( " " ) }
169
167
max_line_length = lines . map ( &:length ) . max
170
168
lines . insert ( 1 , "-" *max_line_length )
171
- lines . join ( NEWLINE )
169
+ lines
172
170
end
173
171
end
174
172
end
Original file line number Diff line number Diff line change 1
1
module CompSci
2
- NEWLINE: String
3
-
4
2
def self.power_of? : (Numeric, Numeric) -> bool
5
- def self.numeric! : (untyped ) -> Numeric
6
- def self.positive! : (untyped ) -> Numeric
7
- def self.string! : (untyped ) -> String
8
- def self.nonempty! : (untyped ) -> String
9
3
end
Original file line number Diff line number Diff line change 97
97
item_count = 31
98
98
# tree already has a root node
99
99
( item_count - 1 ) . times { @root . push ( rand ( 99 ) , @child_slots ) }
100
- str = @root . display
101
- line_count = str . split ( NEWLINE ) . size
102
- expect ( line_count ) . must_equal Math . log ( item_count + 1 , 2 ) . ceil
100
+ expect ( @root . display . size ) . must_equal Math . log ( item_count + 1 , 2 ) . ceil
103
101
end
104
102
105
103
describe "searching" do
Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ def test_manual_iteration
237
237
[ 0 , 0 , 1 ]
238
238
)
239
239
while simplex . can_improve?
240
- assert simplex . formatted_tableau . is_a? ( String )
240
+ assert simplex . formatted_tableau . is_a? ( Array )
241
241
simplex . pivot
242
242
end
243
243
result = simplex . solution
You can’t perform that action at this time.
0 commit comments