-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_compressor.rb
More file actions
48 lines (37 loc) · 827 Bytes
/
Copy pathstring_compressor.rb
File metadata and controls
48 lines (37 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Interview
def initialize
end
def func(string)
count = 0
compressed_string = []
while (count < string.length)
runner_count = 0
runner = count;
while(string[count] == string[runner])
runner_count += 1
runner += 1
end
if runner_count == 1
compressed_string.push(string[count])
else
compressed_string.push(string[count], runner_count)
end
count = runner
end
return compressed_string.join()
end
end
require 'minitest/autorun'
class Tests < MiniTest::Test
def setup
@interview = Interview.new
end
def test_one
input = 'aaabwwwwwssssee'
assert_equal('a3bw5s4e2', @interview.func(input))
end
def test_two
input = 'abcd'
assert_equal('abcd', @interview.func(input))
end
end