-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS-MissingElement.rb
More file actions
52 lines (43 loc) · 1.02 KB
/
S-MissingElement.rb
File metadata and controls
52 lines (43 loc) · 1.02 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
# you can use puts for debugging purposes, e.g.
# puts "this is a debug message"
def solution(a)
return 1 if a.empty?
(1..a.count + 1).inject(:+) - a.inject(:+)
end
require "minitest/autorun"
require "byebug"
require "timeout"
class TestSolution < Minitest::Test
def test_default
input = [2, 3, 1, 5]
output = 4
assert_equal output, solution(input)
end
def test_simple_1
input = [1, 2]
output = 3
assert_equal output, solution(input)
end
def test_simple_2
input = [1, 3]
output = 2
assert_equal output, solution(input)
end
def test_simple_4
input = [2, 3]
output = 1
assert_equal output, solution(input)
end
def test_empty
input = []
output = 1
assert_equal output, solution(input)
end
def test_large
input = (1..100_000).to_a
output = 100_001
Timeout::timeout(6) {
assert_equal output, solution(input)
}
end
end