Skip to content

Commit 1baf003

Browse files
committed
remove compsci and NEWLINE dependency
- remove CompSci.numeric! and friends
1 parent 9fa30fe commit 1baf003

File tree

7 files changed

+6
-42
lines changed

7 files changed

+6
-42
lines changed

lib/compsci.rb

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
11
module CompSci
2-
NEWLINE = $/ # platform-default line separator
3-
42
# thanks apeiros
53
# https://gist.github.com/rickhull/d0b579aa08c85430b0dc82a791ff12d6
64
def self.power_of?(num, base)
75
return false if base <= 1
86
mod = 0
9-
num, mod = num.divmod(base) until num == 1 || mod > 0
7+
num, mod = num.divmod(base) until (num == 1) || (mod > 0)
108
mod == 0
119
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
3410
end

lib/compsci/fsm.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def follow(src, value)
147147

148148
# initial, final, graph
149149
def to_s
150-
[[@initial, @final].inspect, @graph].join(NEWLINE)
150+
[[@initial, @final].inspect, @graph].join($/)
151151
end
152152

153153
def eval(state)

lib/compsci/node.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'compsci'
2-
31
module CompSci
42
# has a value and an array of children; allows child gaps
53
class Node
@@ -51,7 +49,7 @@ def display(width: 80)
5149
memo + Array.new(@children.size) { |i| n and n.children[i] }
5250
}
5351
end
54-
lines.join(NEWLINE)
52+
lines
5553
end
5654
end
5755

lib/compsci/simplex.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# which was forked in 2017 from https://github.com/danlucraft/simplex
33
# which had its last commit in 2013
44

5-
require 'compsci'
6-
75
module CompSci
86
class Simplex
97
DEFAULT_MAX_PIVOTS = 10_000
@@ -168,7 +166,7 @@ def formatted_tableau
168166
lines = result.map { |ary| ary.join(" ") }
169167
max_line_length = lines.map(&:length).max
170168
lines.insert(1, "-"*max_line_length)
171-
lines.join(NEWLINE)
169+
lines
172170
end
173171
end
174172
end

sig/compsci.rbs

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
module CompSci
2-
NEWLINE: String
3-
42
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
93
end

test/flex_node.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@
9797
item_count = 31
9898
# tree already has a root node
9999
(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
103101
end
104102

105103
describe "searching" do

test/simplex.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def test_manual_iteration
237237
[0, 0, 1]
238238
)
239239
while simplex.can_improve?
240-
assert simplex.formatted_tableau.is_a?(String)
240+
assert simplex.formatted_tableau.is_a?(Array)
241241
simplex.pivot
242242
end
243243
result = simplex.solution

0 commit comments

Comments
 (0)