-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS-PassingCars.rb
More file actions
59 lines (51 loc) · 1.16 KB
/
S-PassingCars.rb
File metadata and controls
59 lines (51 loc) · 1.16 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
# you can use puts for debugging purposes, e.g.
# puts "this is a debug message"
def solution(a)
east = 0
passing = 0
a.each { |v|
case v
when 0
east += 1
when 1
passing += east
return -1 if passing > 1_000_000_000
end
}
passing
end
require "minitest/autorun"
require "byebug"
require "timeout"
class TestSolution < Minitest::Test
def test_default
input = [0, 1, 0, 1, 1]
output = 5
assert_equal output, solution(input)
end
def test_one_east
input = [0]
output = 0
assert_equal output, solution(input)
end
def test_one_west
input = [1]
output = 0
assert_equal output, solution(input)
end
def test_simple_1
input = [1, 1, 0, 1, 1, 0]
output = 2
assert_equal output, solution(input)
end
def test_many
input = [0] * 50_000 + [1] * 50_000
output = -1
assert_equal output, solution(input)
end
def test_many_2
input = [1] * 50_000 + [0] * 50_000
output = 0
assert_equal output, solution(input)
end
end